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