00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "imageInfo.h"
00016 #include "pnmImageHeader.h"
00017 #include "pystub.h"
00018
00019
00020
00021
00022
00023
00024 ImageInfo::
00025 ImageInfo() {
00026 set_program_description
00027 ("This program reads the headers of a series of one or more "
00028 "image files and reports the image sizes to standard output.");
00029
00030 add_option
00031 ("2", "", 0,
00032 "Report only images that have a non-power-of-two size in either "
00033 "dimension. Images whose dimensions are both a power of two will "
00034 "not be mentioned.",
00035 &ImageInfo::dispatch_none, &_report_power_2, NULL);
00036 }
00037
00038
00039
00040
00041
00042
00043 void ImageInfo::
00044 run() {
00045 Args::const_iterator ai;
00046 for (ai = _filenames.begin(); ai != _filenames.end(); ++ai) {
00047 Filename filename = (*ai);
00048 PNMImageHeader header;
00049 if (!header.read_header(filename)) {
00050
00051 if (filename.exists()) {
00052 nout << filename << ": could not read image.\n";
00053 } else {
00054 nout << filename << ": does not exist.\n";
00055 }
00056 } else {
00057
00058 if (!_report_power_2 ||
00059 !is_power_2(header.get_x_size()) ||
00060 !is_power_2(header.get_y_size())) {
00061 nout << filename << ": " << header.get_x_size() << " x "
00062 << header.get_y_size() << " x " << header.get_num_channels()
00063 << " (maxval = " << header.get_maxval() << ")\n";
00064 }
00065 }
00066 }
00067 }
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 bool ImageInfo::
00078 handle_args(ProgramBase::Args &args) {
00079 if (args.empty()) {
00080 nout << "List one or more image filenames on command line.\n";
00081 return false;
00082 }
00083 _filenames = args;
00084
00085 return true;
00086 }
00087
00088
00089
00090
00091
00092
00093
00094 bool ImageInfo::
00095 is_power_2(int value) const {
00096 return (value & (value - 1)) == 0;
00097 }
00098
00099
00100 int main(int argc, char *argv[]) {
00101
00102 pystub();
00103
00104 ImageInfo prog;
00105 prog.parse_command_line(argc, argv);
00106 prog.run();
00107 return 0;
00108 }