This commit is contained in:
David Rose 2007-05-16 02:47:46 +00:00
parent 161e2cd5b3
commit 679e73b012
2 changed files with 29 additions and 3 deletions

View File

@ -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.

View File

@ -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