Panda3D
config_pnmimagetypes.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file config_pnmimagetypes.cxx
10  * @author drose
11  * @date 2000-06-17
12  */
13 
14 #include "config_pnmimagetypes.h"
15 #include "pnmFileTypeSGI.h"
16 #include "pnmFileTypeTGA.h"
17 #include "pnmFileTypeIMG.h"
18 #include "pnmFileTypeSoftImage.h"
19 #include "pnmFileTypeBMP.h"
20 #include "pnmFileTypeJPG.h"
21 #include "pnmFileTypePNG.h"
22 #include "pnmFileTypePNM.h"
23 #include "pnmFileTypePfm.h"
24 #include "pnmFileTypeTIFF.h"
25 #include "pnmFileTypeEXR.h"
26 #include "pnmFileTypeStbImage.h"
27 #include "sgi.h"
28 
29 #include "config_pnmimage.h"
30 #include "pnmFileTypeRegistry.h"
31 #include "string_utils.h"
32 #include "dconfig.h"
33 #include "pandaSystem.h"
34 
35 #if !defined(CPPPARSER) && !defined(LINK_ALL_STATIC) && !defined(BUILDING_PANDA_PNMIMAGETYPES)
36  #error Buildsystem error: BUILDING_PANDA_PNMIMAGETYPES not defined
37 #endif
38 
39 using std::istream;
40 using std::ostream;
41 using std::string;
42 
43 Configure(config_pnmimagetypes);
44 NotifyCategoryDefName(pnmimage_sgi, "sgi", pnmimage_cat);
45 NotifyCategoryDefName(pnmimage_tga, "tga", pnmimage_cat);
46 NotifyCategoryDefName(pnmimage_img, "img", pnmimage_cat);
47 NotifyCategoryDefName(pnmimage_soft, "soft", pnmimage_cat);
48 NotifyCategoryDefName(pnmimage_bmp, "bmp", pnmimage_cat);
49 NotifyCategoryDefName(pnmimage_jpg, "jpg", pnmimage_cat);
50 NotifyCategoryDefName(pnmimage_png, "png", pnmimage_cat);
51 NotifyCategoryDefName(pnmimage_pnm, "pnm", pnmimage_cat);
52 NotifyCategoryDefName(pnmimage_tiff, "tiff", pnmimage_cat);
53 NotifyCategoryDefName(pnmimage_exr, "exr", pnmimage_cat);
54 
56 ("sgi-storage-type", SST_rle,
57  PRC_DESC("Use either 'rle' or 'verbatim' to indicate how SGI (*.rgb) "
58  "files are written."));
59 ConfigVariableString sgi_imagename
60 ("sgi-imagename", "",
61  PRC_DESC("This string is written to the header of an SGI (*.rgb) file. "
62  "It seems to have documentation purposes only."));
63 
64 // TGA supports RLE compression, as well as colormapping andor grayscale
65 // images. Set these true to enable these features, if possible, or false to
66 // disable them. Some programs (like xv) have difficulty reading these
67 // advanced TGA files.
68 ConfigVariableBool tga_rle
69 ("tga-rle", false,
70  PRC_DESC("Set this true to enable RLE compression when writing TGA files."));
71 
72 ConfigVariableBool tga_colormap
73 ("tga-colormap", false,
74  PRC_DESC("Set this true to write colormapped TGA files."));
75 
76 ConfigVariableBool tga_grayscale
77 ("tga-grayscale", false,
78  PRC_DESC("Set this true to enable writing grayscale TGA files."));
79 
81 ("img-header-type", IHT_short,
82  PRC_DESC("IMG format is just a sequential string of r, g, b bytes. However, "
83  "it may or may not include a \"header\" which consists of the xsize "
84  "and the ysize of the image, either as shorts or as longs. Specify "
85  "that with this variable, either 'short', 'long', or 'none' for "
86  "no header at all (in which case you should also set img-size)."));
87 
88 ConfigVariableInt img_size
89 ("img-size", 0,
90  PRC_DESC("If an IMG file without a header is loaded (e.g. img-header-type "
91  "is set to 'none', this specifies the fixed x y size of the image."));
92 
93 ConfigVariableInt jpeg_quality
94 ("jpeg-quality", 95,
95  PRC_DESC("Set this to the quality percentage for writing JPEG files. 95 is "
96  "the highest useful value (values greater than 95 do not lead to "
97  "significantly better quality, but do lead to significantly greater "
98  "size)."));
99 
100 ConfigVariableInt png_compression_level
101 ("png-compression-level", 6,
102  PRC_DESC("Set this to the desired compression level for writing PNG images. "
103  "Valid values are 0 (no compression), or 1 (compression, best "
104  "speed) to 9 (best compression). Default is 6. PNG compression is "
105  "lossless."));
106 
107 ConfigVariableBool png_palette
108 ("png-palette", true,
109  PRC_DESC("Set this true to allow writing palette-based PNG images when "
110  "possible."));
111 
112 ConfigVariableInt bmp_bpp
113 ("bmp-bpp", 0,
114  PRC_DESC("This controls how many bits per pixel are written out for BMP "
115  "files. If this is zero, the default, the number of bits per pixel "
116  "is based on the image."));
117 
118 ostream &
119 operator << (ostream &out, SGIStorageType sst) {
120  switch (sst) {
121  case SST_rle:
122  return out << "rle";
123  case SST_verbatim:
124  return out << "verbatim";
125  }
126 
127  return out << "**invalid SGIStorageType(" << (int)sst << ")**";
128 }
129 
130 istream &
131 operator >> (istream &in, SGIStorageType &sst) {
132  string word;
133  in >> word;
134 
135  if (cmp_nocase(word, "rle") == 0) {
136  sst = SST_rle;
137  } else if (cmp_nocase(word, "verbatim") == 0) {
138  sst = SST_verbatim;
139  } else {
140  pnmimage_img_cat->error()
141  << "Invalid SGIStorageType: " << word << "\n";
142  sst = SST_verbatim;
143  }
144 
145  return in;
146 }
147 
148 ostream &
149 operator << (ostream &out, IMGHeaderType iht) {
150  switch (iht) {
151  case IHT_none:
152  return out << "none";
153  case IHT_short:
154  return out << "short";
155  case IHT_long:
156  return out << "long";
157  }
158 
159  return out << "**invalid IMGHeaderType(" << (int)iht << ")**";
160 }
161 
162 istream &
163 operator >> (istream &in, IMGHeaderType &iht) {
164  string word;
165  in >> word;
166 
167  if (cmp_nocase(word, "none") == 0) {
168  iht = IHT_none;
169  } else if (cmp_nocase(word, "short") == 0) {
170  iht = IHT_short;
171  } else if (cmp_nocase(word, "long") == 0) {
172  iht = IHT_long;
173  } else {
174  pnmimage_img_cat->error()
175  << "Invalid IMGHeaderType: " << word << "\n";
176  iht = IHT_none;
177  }
178 
179  return in;
180 }
181 
182 ConfigureFn(config_pnmimagetypes) {
184 }
185 
186 /**
187  * Initializes the library. This must be called at least once before any of
188  * the functions or classes in this library can be used. Normally it will be
189  * called by the static initializers and need not be called explicitly, but
190  * special cases exist.
191  */
192 void
194  static bool initialized = false;
195  if (initialized) {
196  return;
197  }
198  initialized = true;
199 
201 
203 
204 #ifdef HAVE_SGI_RGB
205  PNMFileTypeSGI::init_type();
206  PNMFileTypeSGI::register_with_read_factory();
207  tr->register_type(new PNMFileTypeSGI);
208 #endif
209 
210 #ifdef HAVE_TGA
211  PNMFileTypeTGA::init_type();
212  PNMFileTypeTGA::register_with_read_factory();
213  tr->register_type(new PNMFileTypeTGA);
214 #endif
215 
216 #ifdef HAVE_IMG
217  PNMFileTypeIMG::init_type();
218  PNMFileTypeIMG::register_with_read_factory();
219  tr->register_type(new PNMFileTypeIMG);
220 #endif
221 
222 #ifdef HAVE_SOFTIMAGE_PIC
223  PNMFileTypeSoftImage::init_type();
224  PNMFileTypeSoftImage::register_with_read_factory();
225  tr->register_type(new PNMFileTypeSoftImage);
226 #endif // HAVE_SOFTIMAGE_PIC
227 
228 #ifdef HAVE_BMP
229  PNMFileTypeBMP::init_type();
230  PNMFileTypeBMP::register_with_read_factory();
231  tr->register_type(new PNMFileTypeBMP);
232 #endif
233 
234 #ifdef HAVE_PNM
235  PNMFileTypePNM::init_type();
236  PNMFileTypePNM::register_with_read_factory();
237  tr->register_type(new PNMFileTypePNM);
238 #endif
239 
240  PNMFileTypePfm::init_type();
242  tr->register_type(new PNMFileTypePfm);
243 
244 #ifdef HAVE_JPEG
245  PNMFileTypeJPG::init_type();
246  PNMFileTypeJPG::register_with_read_factory();
247  tr->register_type(new PNMFileTypeJPG);
248 #endif
249 
250 #ifdef HAVE_PNG
251  PNMFileTypePNG::init_type();
252  PNMFileTypePNG::register_with_read_factory();
253  tr->register_type(new PNMFileTypePNG);
254 #endif
255 
256 #ifdef HAVE_TIFF
257  PNMFileTypeTIFF::init_type();
258  PNMFileTypeTIFF::register_with_read_factory();
259  tr->register_type(new PNMFileTypeTIFF);
260 #endif
261 
262 #ifdef HAVE_OPENEXR
263  PNMFileTypeEXR::init_type();
264  PNMFileTypeEXR::register_with_read_factory();
265  tr->register_type(new PNMFileTypeEXR);
266 #endif
267 
268 #ifdef HAVE_STB_IMAGE
269  PNMFileTypeStbImage::init_type();
270  PNMFileTypeStbImage::register_with_read_factory();
271  tr->register_type(new PNMFileTypeStbImage);
272 #endif
273 
274  // And register with the PandaSystem.
276  (void)ps; // Suppress unused variable warning
277 
278 #ifdef HAVE_JPEG
279  ps->add_system("libjpeg");
280 #endif
281 #ifdef HAVE_PNG
282  ps->add_system("libpng");
283 #endif
284 #ifdef HAVE_TIFF
285  ps->add_system("libtiff");
286 #endif
287 #ifdef HAVE_OPENEXR
288  ps->add_system("openexr");
289 #endif
290 }
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static PandaSystem * get_global_ptr()
Returns the global PandaSystem object.
This class is used as a namespace to group several global properties of Panda.
Definition: pandaSystem.h:26
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is a convenience class to specialize ConfigVariable as a boolean type.
void init_libpnmimagetypes()
Initializes the library.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static PNMFileTypeRegistry * get_global_ptr()
Returns a pointer to the global PNMFileTypeRegistry object.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is a convenience class to specialize ConfigVariable as a string type.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This class specializes ConfigVariable as an enumerated type.
void add_system(const std::string &system)
Intended for use by each subsystem to register itself at startup.
For reading and writing PFM files using the basic PNMImage interface, as if they were basic RGB files...
This class maintains the set of all known PNMFileTypes in the universe.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is a convenience class to specialize ConfigVariable as an integer type.
static void register_with_read_factory()
Registers the current object as something that can be read from a Bam file.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void init_libpnmimage()
Initializes the library.
void register_type(PNMFileType *type)
Defines a new PNMFileType in the universe.