Panda3D
|
00001 // Filename: imageInfo.cxx 00002 // Created by: drose (13Mar03) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #include "imageInfo.h" 00016 #include "pnmImageHeader.h" 00017 #include "pystub.h" 00018 00019 //////////////////////////////////////////////////////////////////// 00020 // Function: ImageInfo::Constructor 00021 // Access: Public 00022 // Description: 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 // Function: ImageInfo::run 00040 // Access: Public 00041 // Description: 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 // Could not read the image header. 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 // Successfully read the image header. 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 // Function: ImageInfo::handle_args 00071 // Access: Protected, Virtual 00072 // Description: Does something with the additional arguments on the 00073 // command line (after all the -options have been 00074 // parsed). Returns true if the arguments are good, 00075 // false otherwise. 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 // Function: ImageInfo::is_power_2 00090 // Access: Private 00091 // Description: Returns true if the indicated value is a power of 2, 00092 // false otherwise. 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 // A call to pystub() to force libpystub.so to be linked in. 00102 pystub(); 00103 00104 ImageInfo prog; 00105 prog.parse_command_line(argc, argv); 00106 prog.run(); 00107 return 0; 00108 }