Panda3D
|
00001 // Filename: config_pnmimagetypes.cxx 00002 // Created by: drose (17Jun00) 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 "config_pnmimagetypes.h" 00016 #include "pnmFileTypeSGI.h" 00017 #include "pnmFileTypeTGA.h" 00018 #include "pnmFileTypeIMG.h" 00019 #include "pnmFileTypeSoftImage.h" 00020 #include "pnmFileTypeBMP.h" 00021 #include "pnmFileTypeJPG.h" 00022 #include "pnmFileTypePNG.h" 00023 #include "pnmFileTypePNM.h" 00024 #include "pnmFileTypeTIFF.h" 00025 #include "sgi.h" 00026 00027 #include "config_pnmimage.h" 00028 #include "pnmFileTypeRegistry.h" 00029 #include "string_utils.h" 00030 #include "dconfig.h" 00031 #include "pandaSystem.h" 00032 00033 Configure(config_pnmimagetypes); 00034 NotifyCategoryDefName(pnmimage_sgi, "sgi", pnmimage_cat); 00035 NotifyCategoryDefName(pnmimage_tga, "tga", pnmimage_cat); 00036 NotifyCategoryDefName(pnmimage_img, "img", pnmimage_cat); 00037 NotifyCategoryDefName(pnmimage_soft, "soft", pnmimage_cat); 00038 NotifyCategoryDefName(pnmimage_bmp, "bmp", pnmimage_cat); 00039 NotifyCategoryDefName(pnmimage_jpg, "jpg", pnmimage_cat); 00040 NotifyCategoryDefName(pnmimage_png, "png", pnmimage_cat); 00041 NotifyCategoryDefName(pnmimage_pnm, "pnm", pnmimage_cat); 00042 NotifyCategoryDefName(pnmimage_tiff, "tiff", pnmimage_cat); 00043 00044 ConfigVariableEnum<SGIStorageType> sgi_storage_type 00045 ("sgi-storage-type", SST_rle, 00046 PRC_DESC("Use either 'rle' or 'verbatim' to indicate how SGI (*.rgb) " 00047 "files are written.")); 00048 ConfigVariableString sgi_imagename 00049 ("sgi-imagename", "", 00050 PRC_DESC("This string is written to the header of an SGI (*.rgb) file. " 00051 "It seems to have documentation purposes only.")); 00052 00053 // TGA supports RLE compression, as well as colormapping and/or 00054 // grayscale images. Set these true to enable these features, if 00055 // possible, or false to disable them. Some programs (like xv) have 00056 // difficulty reading these advanced TGA files. 00057 ConfigVariableBool tga_rle 00058 ("tga-rle", false, 00059 PRC_DESC("Set this true to enable RLE compression when writing TGA files.")); 00060 00061 ConfigVariableBool tga_colormap 00062 ("tga-colormap", false, 00063 PRC_DESC("Set this true to write colormapped TGA files.")); 00064 00065 ConfigVariableBool tga_grayscale 00066 ("tga-grayscale", false, 00067 PRC_DESC("Set this true to enable writing grayscale TGA files.")); 00068 00069 ConfigVariableEnum<IMGHeaderType> img_header_type 00070 ("img-header-type", IHT_short, 00071 PRC_DESC("IMG format is just a sequential string of r, g, b bytes. However, " 00072 "it may or may not include a \"header\" which consists of the xsize " 00073 "and the ysize of the image, either as shorts or as longs. Specify " 00074 "that with this variable, either 'short', 'long', or 'none' for " 00075 "no header at all (in which case you should also set img-size).")); 00076 00077 ConfigVariableInt img_size 00078 ("img-size", 0, 00079 PRC_DESC("If an IMG file without a header is loaded (e.g. img-header-type " 00080 "is set to 'none', this specifies the fixed x y size of the image.")); 00081 ConfigVariableInt jpeg_quality 00082 ("jpeg-quality", 95, 00083 PRC_DESC("Set this to the quality percentage for writing JPEG files. 95 is " 00084 "the highest useful value (values greater than 95 do not lead to " 00085 "significantly better quality, but do lead to significantly greater " 00086 "size).")); 00087 00088 00089 ConfigVariableInt bmp_bpp 00090 ("bmp-bpp", 0, 00091 PRC_DESC("This controls how many bits per pixel are written out for BMP " 00092 "files. If this is zero, the default, the number of bits per pixel " 00093 "is based on the image.")); 00094 00095 ostream & 00096 operator << (ostream &out, SGIStorageType sst) { 00097 switch (sst) { 00098 case SST_rle: 00099 return out << "rle"; 00100 case SST_verbatim: 00101 return out << "verbatim"; 00102 } 00103 00104 return out << "**invalid SGIStorageType(" << (int)sst << ")**"; 00105 } 00106 00107 istream & 00108 operator >> (istream &in, SGIStorageType &sst) { 00109 string word; 00110 in >> word; 00111 00112 if (cmp_nocase(word, "rle") == 0) { 00113 sst = SST_rle; 00114 } else if (cmp_nocase(word, "verbatim") == 0) { 00115 sst = SST_verbatim; 00116 } else { 00117 pnmimage_img_cat->error() 00118 << "Invalid SGIStorageType: " << word << "\n"; 00119 sst = SST_verbatim; 00120 } 00121 00122 return in; 00123 } 00124 00125 ostream & 00126 operator << (ostream &out, IMGHeaderType iht) { 00127 switch (iht) { 00128 case IHT_none: 00129 return out << "none"; 00130 case IHT_short: 00131 return out << "short"; 00132 case IHT_long: 00133 return out << "long"; 00134 } 00135 00136 return out << "**invalid IMGHeaderType(" << (int)iht << ")**"; 00137 } 00138 00139 istream & 00140 operator >> (istream &in, IMGHeaderType &iht) { 00141 string word; 00142 in >> word; 00143 00144 if (cmp_nocase(word, "none") == 0) { 00145 iht = IHT_none; 00146 } else if (cmp_nocase(word, "short") == 0) { 00147 iht = IHT_short; 00148 } else if (cmp_nocase(word, "long") == 0) { 00149 iht = IHT_long; 00150 } else { 00151 pnmimage_img_cat->error() 00152 << "Invalid IMGHeaderType: " << word << "\n"; 00153 iht = IHT_none; 00154 } 00155 00156 return in; 00157 } 00158 00159 ConfigureFn(config_pnmimagetypes) { 00160 init_libpnmimagetypes(); 00161 } 00162 00163 //////////////////////////////////////////////////////////////////// 00164 // Function: init_libpnmimagetypes 00165 // Description: Initializes the library. This must be called at 00166 // least once before any of the functions or classes in 00167 // this library can be used. Normally it will be 00168 // called by the static initializers and need not be 00169 // called explicitly, but special cases exist. 00170 //////////////////////////////////////////////////////////////////// 00171 void 00172 init_libpnmimagetypes() { 00173 static bool initialized = false; 00174 if (initialized) { 00175 return; 00176 } 00177 initialized = true; 00178 00179 init_libpnmimage(); 00180 00181 PNMFileTypeRegistry *tr = PNMFileTypeRegistry::get_global_ptr(); 00182 00183 #ifdef HAVE_SGI_RGB 00184 PNMFileTypeSGI::init_type(); 00185 PNMFileTypeSGI::register_with_read_factory(); 00186 tr->register_type(new PNMFileTypeSGI); 00187 #endif 00188 00189 #ifdef HAVE_TGA 00190 PNMFileTypeTGA::init_type(); 00191 PNMFileTypeTGA::register_with_read_factory(); 00192 tr->register_type(new PNMFileTypeTGA); 00193 #endif 00194 00195 #ifdef HAVE_IMG 00196 PNMFileTypeIMG::init_type(); 00197 PNMFileTypeIMG::register_with_read_factory(); 00198 tr->register_type(new PNMFileTypeIMG); 00199 #endif 00200 00201 #ifdef HAVE_SOFTIMAGE_PIC 00202 PNMFileTypeSoftImage::init_type(); 00203 PNMFileTypeSoftImage::register_with_read_factory(); 00204 tr->register_type(new PNMFileTypeSoftImage); 00205 #endif // HAVE_SOFTIMAGE_PIC 00206 00207 #ifdef HAVE_BMP 00208 PNMFileTypeBMP::init_type(); 00209 PNMFileTypeBMP::register_with_read_factory(); 00210 tr->register_type(new PNMFileTypeBMP); 00211 #endif 00212 00213 #ifdef HAVE_PNM 00214 PNMFileTypePNM::init_type(); 00215 PNMFileTypePNM::register_with_read_factory(); 00216 tr->register_type(new PNMFileTypePNM); 00217 #endif 00218 00219 #ifdef HAVE_JPEG 00220 PNMFileTypeJPG::init_type(); 00221 PNMFileTypeJPG::register_with_read_factory(); 00222 tr->register_type(new PNMFileTypeJPG); 00223 #endif 00224 00225 #ifdef HAVE_PNG 00226 PNMFileTypePNG::init_type(); 00227 PNMFileTypePNG::register_with_read_factory(); 00228 tr->register_type(new PNMFileTypePNG); 00229 #endif 00230 00231 #ifdef HAVE_TIFF 00232 PNMFileTypeTIFF::init_type(); 00233 PNMFileTypeTIFF::register_with_read_factory(); 00234 tr->register_type(new PNMFileTypeTIFF); 00235 #endif 00236 00237 // And register with the PandaSystem. 00238 PandaSystem *ps = PandaSystem::get_global_ptr(); 00239 00240 #ifdef HAVE_JPEG 00241 ps->add_system("libjpeg"); 00242 #endif 00243 #ifdef HAVE_PNG 00244 ps->add_system("libpng"); 00245 #endif 00246 #ifdef HAVE_TIFF 00247 ps->add_system("libtiff"); 00248 #endif 00249 }