diff --git a/pandatool/src/imageprogs/imageInfo.cxx b/pandatool/src/imageprogs/imageInfo.cxx index 8f9ead949c..9432aa61a4 100755 --- a/pandatool/src/imageprogs/imageInfo.cxx +++ b/pandatool/src/imageprogs/imageInfo.cxx @@ -30,6 +30,13 @@ ImageInfo() { set_program_description ("This program reads the headers of a series of one or more " "image files and reports the image sizes to standard output."); + + add_option + ("2", "", 0, + "Report only images that have a non-power-of-two size in either " + "dimension. Images whose dimensions are both a power of two will " + "not be mentioned.", + &ImageInfo::dispatch_none, &_report_power_2, NULL); } //////////////////////////////////////////////////////////////////// @@ -52,9 +59,13 @@ run() { } } else { // Successfully read the image header. - nout << filename << ": " << header.get_x_size() << " x " - << header.get_y_size() << " x " << header.get_num_channels() - << " (maxval = " << header.get_maxval() << ")\n"; + if (!_report_power_2 || + !is_power_2(header.get_x_size()) || + !is_power_2(header.get_y_size())) { + nout << filename << ": " << header.get_x_size() << " x " + << header.get_y_size() << " x " << header.get_num_channels() + << " (maxval = " << header.get_maxval() << ")\n"; + } } } } @@ -78,6 +89,17 @@ handle_args(ProgramBase::Args &args) { return true; } +//////////////////////////////////////////////////////////////////// +// Function: ImageInfo::is_power_2 +// Access: Private +// Description: Returns true if the indicated value is a power of 2, +// false otherwise. +//////////////////////////////////////////////////////////////////// +bool ImageInfo:: +is_power_2(int value) const { + return (value & (value - 1)) == 0; +} + int main(int argc, char *argv[]) { // A call to pystub() to force libpystub.so to be linked in. diff --git a/pandatool/src/imageprogs/imageInfo.h b/pandatool/src/imageprogs/imageInfo.h index 989c08e3d2..ec16e89275 100755 --- a/pandatool/src/imageprogs/imageInfo.h +++ b/pandatool/src/imageprogs/imageInfo.h @@ -38,7 +38,11 @@ public: protected: virtual bool handle_args(Args &args); +private: + bool is_power_2(int value) const; + Args _filenames; + bool _report_power_2; }; #endif