Panda3D
imageFile.cxx
1 // Filename: imageFile.cxx
2 // Created by: drose (29Nov00)
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 "imageFile.h"
16 #include "palettizer.h"
17 #include "filenameUnifier.h"
18 #include "paletteGroup.h"
19 
20 #include "pnmImage.h"
21 #include "pnmFileType.h"
22 #include "eggTexture.h"
23 #include "datagram.h"
24 #include "datagramIterator.h"
25 #include "bamReader.h"
26 #include "bamWriter.h"
27 
28 TypeHandle ImageFile::_type_handle;
29 
30 ////////////////////////////////////////////////////////////////////
31 // Function: ImageFile::Constructor
32 // Access: Public
33 // Description:
34 ////////////////////////////////////////////////////////////////////
35 ImageFile::
36 ImageFile() {
37  _alpha_file_channel = 0;
38  _size_known = false;
39  _x_size = 0;
40  _y_size = 0;
41 }
42 
43 ////////////////////////////////////////////////////////////////////
44 // Function: ImageFile::make_shadow_image
45 // Access: Public
46 // Description: Sets up the ImageFile as a "shadow image" of a
47 // particular PaletteImage. This is a temporary
48 // ImageFile that's used to read and write the shadow
49 // palette image, which is used to keep a working copy
50 // of the palette.
51 //
52 // Returns true if the filename changes from what it was
53 // previously, false otherwise.
54 ////////////////////////////////////////////////////////////////////
55 bool ImageFile::
56 make_shadow_image(const string &basename) {
57  bool any_changed = false;
58 
59  if (_properties._color_type != pal->_shadow_color_type ||
60  _properties._alpha_type != pal->_shadow_alpha_type) {
61 
62  _properties._color_type = pal->_shadow_color_type;
63  _properties._alpha_type = pal->_shadow_alpha_type;
64  any_changed = true;
65  }
66 
67  if (set_filename(pal->_shadow_dirname, basename)) {
68  any_changed = true;
69  }
70 
71  return any_changed;
72 }
73 
74 ////////////////////////////////////////////////////////////////////
75 // Function: ImageFile::is_size_known
76 // Access: Public
77 // Description: Returns true if the size of the image file is known,
78 // false otherwise.
79 ////////////////////////////////////////////////////////////////////
80 bool ImageFile::
81 is_size_known() const {
82  return _size_known;
83 }
84 
85 ////////////////////////////////////////////////////////////////////
86 // Function: ImageFile::get_x_size
87 // Access: Public
88 // Description: Returns the size of the image file in pixels in the X
89 // direction. It is an error to call this unless
90 // is_size_known() returns true.
91 ////////////////////////////////////////////////////////////////////
92 int ImageFile::
93 get_x_size() const {
94  nassertr(is_size_known(), 0);
95  return _x_size;
96 }
97 
98 ////////////////////////////////////////////////////////////////////
99 // Function: ImageFile::get_y_size
100 // Access: Public
101 // Description: Returns the size of the image file in pixels in the Y
102 // direction. It is an error to call this unless
103 // is_size_known() returns true.
104 ////////////////////////////////////////////////////////////////////
105 int ImageFile::
106 get_y_size() const {
107  nassertr(is_size_known(), 0);
108  return _y_size;
109 }
110 
111 ////////////////////////////////////////////////////////////////////
112 // Function: ImageFile::has_num_channels
113 // Access: Public
114 // Description: Returns true if the number of channels in the image
115 // is known, false otherwise.
116 ////////////////////////////////////////////////////////////////////
117 bool ImageFile::
119  return _properties.has_num_channels();
120 }
121 
122 ////////////////////////////////////////////////////////////////////
123 // Function: ImageFile::get_num_channels
124 // Access: Public
125 // Description: Returns the number of channels of the image. It is
126 // an error to call this unless has_num_channels()
127 // returns true.
128 ////////////////////////////////////////////////////////////////////
129 int ImageFile::
131  return _properties.get_num_channels();
132 }
133 
134 ////////////////////////////////////////////////////////////////////
135 // Function: ImageFile::get_properties
136 // Access: Public
137 // Description: Returns the grouping properties of the image.
138 ////////////////////////////////////////////////////////////////////
140 get_properties() const {
141  return _properties;
142 }
143 
144 ////////////////////////////////////////////////////////////////////
145 // Function: ImageFile::clear_basic_properties
146 // Access: Public
147 // Description: Resets the properties to a neutral state, for
148 // instance in preparation for calling
149 // update_properties() with all the known contributing
150 // properties.
151 ////////////////////////////////////////////////////////////////////
152 void ImageFile::
154  _properties.clear_basic();
155 }
156 
157 ////////////////////////////////////////////////////////////////////
158 // Function: ImageFile::update_properties
159 // Access: Public
160 // Description: If the indicate TextureProperties structure is more
161 // specific than this one, updates this one.
162 ////////////////////////////////////////////////////////////////////
163 void ImageFile::
165  _properties.update_properties(properties);
166 }
167 
168 ////////////////////////////////////////////////////////////////////
169 // Function: ImageFile::set_filename
170 // Access: Public
171 // Description: Sets the filename, and if applicable, the
172 // alpha_filename, from the indicated basename. The
173 // extension appropriate to the image file type
174 // specified in _color_type (and _alpha_type) is
175 // automatically applied.
176 //
177 // Returns true if the filename changes from what it was
178 // previously, false otherwise.
179 ////////////////////////////////////////////////////////////////////
180 bool ImageFile::
181 set_filename(PaletteGroup *group, const string &basename) {
182  // Synthesize the directory name based on the map_dirname set to the
183  // palettizer, and the group's dirname.
184  string dirname;
185  string::iterator pi;
186  pi = pal->_map_dirname.begin();
187  while (pi != pal->_map_dirname.end()) {
188  if (*pi == '%') {
189  ++pi;
190  switch (*pi) {
191  case '%':
192  dirname += '%';
193  break;
194 
195  case 'g':
196  if (group != (PaletteGroup *)NULL) {
197  dirname += group->get_dirname();
198  }
199  break;
200  }
201  } else {
202  dirname += *pi;
203  }
204  ++pi;
205  }
206 
207  return set_filename(dirname, basename);
208 }
209 
210 ////////////////////////////////////////////////////////////////////
211 // Function: ImageFile::set_filename
212 // Access: Public
213 // Description: Sets the filename, and if applicable, the
214 // alpha_filename, from the indicated basename. The
215 // extension appropriate to the image file type
216 // specified in _color_type (and _alpha_type) is
217 // automatically applied.
218 //
219 // Returns true if the filename changes from what it was
220 // previously, false otherwise.
221 ////////////////////////////////////////////////////////////////////
222 bool ImageFile::
223 set_filename(const string &dirname, const string &basename) {
224  Filename orig_filename = _filename;
225  Filename orig_alpha_filename = _alpha_filename;
226 
227  _filename = Filename(dirname, basename);
228  _filename.standardize();
229 
230  // Since we use set_extension() here, if the file already contains a
231  // filename extension it will be lost.
232 
233  // It is particularly important to note that a single embedded dot
234  // will appear to begin a filename extension, so if the filename
235  // does *not* contain an extension, but does contain an embedded
236  // dot, the filename will be truncated at that dot. It is therefore
237  // important that the supplied basename always contains either an
238  // extension or a terminating dot.
239 
240  if (_properties._color_type != (PNMFileType *)NULL) {
241  _filename.set_extension
242  (_properties._color_type->get_suggested_extension());
243  }
244 
245  if (_properties._alpha_type != (PNMFileType *)NULL) {
246  _alpha_filename = _filename.get_fullpath_wo_extension() + "_a.";
247  _alpha_filename.set_extension
248  (_properties._alpha_type->get_suggested_extension());
249  } else {
250  _alpha_filename = Filename();
251  }
252 
253  return (_filename != orig_filename ||
254  _alpha_filename != orig_alpha_filename);
255 }
256 
257 ////////////////////////////////////////////////////////////////////
258 // Function: ImageFile::get_filename
259 // Access: Public
260 // Description: Returns the primary filename of the image file.
261 ////////////////////////////////////////////////////////////////////
262 const Filename &ImageFile::
263 get_filename() const {
264  return _filename;
265 }
266 
267 ////////////////////////////////////////////////////////////////////
268 // Function: ImageFile::get_alpha_filename
269 // Access: Public
270 // Description: Returns the alpha filename of the image file. This
271 // is the name of the file that contains the alpha
272 // channel, if it is stored in a separate file, or the
273 // empty string if it is not.
274 ////////////////////////////////////////////////////////////////////
275 const Filename &ImageFile::
277  return _alpha_filename;
278 }
279 
280 ////////////////////////////////////////////////////////////////////
281 // Function: ImageFile::get_alpha_file_channel
282 // Access: Public
283 // Description: Returns the particular channel number of the alpha
284 // image file from which the alpha channel should be
285 // extracted. This is normally 0 to represent the
286 // grayscale combination of r, g, and b; or it may be a
287 // 1-based channel number (for instance, 4 for the alpha
288 // channel of a 4-component image).
289 ////////////////////////////////////////////////////////////////////
290 int ImageFile::
292  return _alpha_file_channel;
293 }
294 
295 
296 ////////////////////////////////////////////////////////////////////
297 // Function: ImageFile::exists
298 // Access: Public
299 // Description: Returns true if the file or files named by the image
300 // file exist, false otherwise.
301 ////////////////////////////////////////////////////////////////////
302 bool ImageFile::
303 exists() const {
304  if (!_filename.exists()) {
305  return false;
306  }
307  if (_properties._alpha_type != (PNMFileType *)NULL &&
308  _properties.uses_alpha() &&
309  !_alpha_filename.empty()) {
310  if (!_alpha_filename.exists()) {
311  return false;
312  }
313  }
314 
315  return true;
316 }
317 
318 ////////////////////////////////////////////////////////////////////
319 // Function: ImageFile::read
320 // Access: Public
321 // Description: Reads in the image (or images, if the alpha_filename
322 // is separate) and stores it in the indicated PNMImage.
323 // Returns true on success, false on failure.
324 ////////////////////////////////////////////////////////////////////
325 bool ImageFile::
326 read(PNMImage &image) const {
327  nassertr(!_filename.empty(), false);
328 
329  image.set_type(_properties._color_type);
330  nout << "Reading " << FilenameUnifier::make_user_filename(_filename) << "\n";
331  if (!image.read(_filename)) {
332  nout << "Unable to read.\n";
333  return false;
334  }
335 
336  if (!_alpha_filename.empty() && _alpha_filename.exists()) {
337  // Read in a separate color image and an alpha channel image.
338  PNMImage alpha_image;
339  alpha_image.set_type(_properties._alpha_type);
340  nout << "Reading " << FilenameUnifier::make_user_filename(_alpha_filename) << "\n";
341  if (!alpha_image.read(_alpha_filename)) {
342  nout << "Unable to read.\n";
343  return false;
344  }
345  if (image.get_x_size() != alpha_image.get_x_size() ||
346  image.get_y_size() != alpha_image.get_y_size()) {
347  return false;
348  }
349 
350  image.add_alpha();
351 
352  if (_alpha_file_channel == 4 ||
353  (_alpha_file_channel == 2 && alpha_image.get_num_channels() == 2)) {
354  // Use the alpha channel.
355  for (int x = 0; x < image.get_x_size(); x++) {
356  for (int y = 0; y < image.get_y_size(); y++) {
357  image.set_alpha(x, y, alpha_image.get_alpha(x, y));
358  }
359  }
360 
361  } else if (_alpha_file_channel >= 1 && _alpha_file_channel <= 3 &&
362  alpha_image.get_num_channels() >= 3) {
363  // Use the appropriate red, green, or blue channel.
364  for (int x = 0; x < image.get_x_size(); x++) {
365  for (int y = 0; y < image.get_y_size(); y++) {
366  image.set_alpha(x, y, alpha_image.get_channel_val(x, y, _alpha_file_channel - 1));
367  }
368  }
369 
370  } else {
371  // Use the grayscale channel.
372  for (int x = 0; x < image.get_x_size(); x++) {
373  for (int y = 0; y < image.get_y_size(); y++) {
374  image.set_alpha(x, y, alpha_image.get_gray(x, y));
375  }
376  }
377  }
378  }
379 
380  return true;
381 }
382 
383 ////////////////////////////////////////////////////////////////////
384 // Function: ImageFile::write
385 // Access: Public
386 // Description: Writes out the image in the indicated PNMImage to the
387 // _filename and/or _alpha_filename. Returns true on
388 // success, false on failure.
389 ////////////////////////////////////////////////////////////////////
390 bool ImageFile::
391 write(const PNMImage &image) const {
392  nassertr(!_filename.empty(), false);
393 
394  if (!image.has_alpha() ||
395  _properties._alpha_type == (PNMFileType *)NULL) {
396  if (!_alpha_filename.empty() && _alpha_filename.exists()) {
397  nout << "Deleting " << FilenameUnifier::make_user_filename(_alpha_filename) << "\n";
398  _alpha_filename.unlink();
399  }
400  nout << "Writing " << FilenameUnifier::make_user_filename(_filename) << "\n";
401  _filename.make_dir();
402  if (!image.write(_filename, _properties._color_type)) {
403  nout << "Unable to write.\n";
404  return false;
405  }
406  return true;
407  }
408 
409  // Write out a separate color image and an alpha channel image.
410  PNMImage alpha_image(image.get_x_size(), image.get_y_size(), 1,
411  image.get_maxval());
412  for (int y = 0; y < image.get_y_size(); y++) {
413  for (int x = 0; x < image.get_x_size(); x++) {
414  alpha_image.set_gray_val(x, y, image.get_alpha_val(x, y));
415  }
416  }
417 
418  PNMImage image_copy(image);
419  image_copy.remove_alpha();
420  nout << "Writing " << FilenameUnifier::make_user_filename(_filename) << "\n";
421  _filename.make_dir();
422  if (!image_copy.write(_filename, _properties._color_type)) {
423  nout << "Unable to write.\n";
424  return false;
425  }
426 
427  nout << "Writing " << FilenameUnifier::make_user_filename(_alpha_filename) << "\n";
428  _alpha_filename.make_dir();
429  if (!alpha_image.write(_alpha_filename, _properties._alpha_type)) {
430  nout << "Unable to write.\n";
431  return false;
432  }
433  return true;
434 }
435 
436 ////////////////////////////////////////////////////////////////////
437 // Function: ImageFile::unlink
438 // Access: Public
439 // Description: Deletes the image file or files.
440 ////////////////////////////////////////////////////////////////////
441 void ImageFile::
443  if (!_filename.empty() && _filename.exists()) {
444  nout << "Deleting " << FilenameUnifier::make_user_filename(_filename) << "\n";
445  _filename.unlink();
446  }
447  if (!_alpha_filename.empty() && _alpha_filename.exists()) {
448  nout << "Deleting " << FilenameUnifier::make_user_filename(_alpha_filename) << "\n";
449  _alpha_filename.unlink();
450  }
451 }
452 
453 ////////////////////////////////////////////////////////////////////
454 // Function: ImageFile::update_egg_tex
455 // Access: Public
456 // Description: Sets the indicated EggTexture to refer to this file.
457 ////////////////////////////////////////////////////////////////////
458 void ImageFile::
459 update_egg_tex(EggTexture *egg_tex) const {
460  nassertv(egg_tex != (EggTexture *)NULL);
461 
462  egg_tex->set_filename(FilenameUnifier::make_egg_filename(_filename));
463 
464  if (_properties.uses_alpha() &&
465  !_alpha_filename.empty()) {
466  egg_tex->set_alpha_filename(FilenameUnifier::make_egg_filename(_alpha_filename));
467  egg_tex->set_alpha_file_channel(_alpha_file_channel);
468  } else {
469  egg_tex->clear_alpha_filename();
470  egg_tex->clear_alpha_file_channel();
471  }
472 
473  _properties.update_egg_tex(egg_tex);
474 }
475 
476 ////////////////////////////////////////////////////////////////////
477 // Function: ImageFile::output_filename
478 // Access: Public
479 // Description: Writes the filename (or pair of filenames) to the
480 // indicated output stream.
481 ////////////////////////////////////////////////////////////////////
482 void ImageFile::
483 output_filename(ostream &out) const {
484  out << FilenameUnifier::make_user_filename(_filename);
485  if (_properties.uses_alpha() && !_alpha_filename.empty()) {
486  out << " " << FilenameUnifier::make_user_filename(_alpha_filename);
487  }
488 }
489 
490 ////////////////////////////////////////////////////////////////////
491 // Function: ImageFile::write_datagram
492 // Access: Public, Virtual
493 // Description: Fills the indicated datagram up with a binary
494 // representation of the current object, in preparation
495 // for writing to a Bam file.
496 ////////////////////////////////////////////////////////////////////
497 void ImageFile::
498 write_datagram(BamWriter *writer, Datagram &datagram) {
499  TypedWritable::write_datagram(writer, datagram);
500  _properties.write_datagram(writer, datagram);
501  datagram.add_string(FilenameUnifier::make_bam_filename(_filename));
502  datagram.add_string(FilenameUnifier::make_bam_filename(_alpha_filename));
503  datagram.add_uint8(_alpha_file_channel);
504  datagram.add_bool(_size_known);
505  datagram.add_int32(_x_size);
506  datagram.add_int32(_y_size);
507 }
508 
509 ////////////////////////////////////////////////////////////////////
510 // Function: ImageFile::complete_pointers
511 // Access: Public, Virtual
512 // Description: Called after the object is otherwise completely read
513 // from a Bam file, this function's job is to store the
514 // pointers that were retrieved from the Bam file for
515 // each pointer object written. The return value is the
516 // number of pointers processed from the list.
517 ////////////////////////////////////////////////////////////////////
518 int ImageFile::
520  int pi = TypedWritable::complete_pointers(p_list, manager);
521 
522  pi += _properties.complete_pointers(p_list + pi, manager);
523 
524  return pi;
525 }
526 
527 ////////////////////////////////////////////////////////////////////
528 // Function: ImageFile::fillin
529 // Access: Protected
530 // Description: Reads the binary data from the given datagram
531 // iterator, which was written by a previous call to
532 // write_datagram().
533 ////////////////////////////////////////////////////////////////////
534 void ImageFile::
535 fillin(DatagramIterator &scan, BamReader *manager) {
536  TypedWritable::fillin(scan, manager);
537  _properties.fillin(scan, manager);
538  _filename = FilenameUnifier::get_bam_filename(scan.get_string());
539  _alpha_filename = FilenameUnifier::get_bam_filename(scan.get_string());
540  if (Palettizer::_read_pi_version >= 10) {
541  _alpha_file_channel = scan.get_uint8();
542  } else {
543  _alpha_file_channel = 0;
544  }
545  _size_known = scan.get_bool();
546  _x_size = scan.get_int32();
547  _y_size = scan.get_int32();
548 }
void set_gray_val(int x, int y, xelval gray)
Sets the gray component color at the indicated pixel.
Definition: pnmImage.I:568
bool write(const PNMImage &image) const
Writes out the image in the indicated PNMImage to the _filename and/or _alpha_filename.
Definition: imageFile.cxx:391
static Filename make_bam_filename(Filename filename)
Returns a new filename that&#39;s made relative to the bam file itself, suitable for writing to the bam f...
void set_extension(const string &s)
Replaces the file extension.
Definition: filename.cxx:837
bool read(PNMImage &image) const
Reads in the image (or images, if the alpha_filename is separate) and stores it in the indicated PNMI...
Definition: imageFile.cxx:326
void add_uint8(PN_uint8 value)
Adds an unsigned 8-bit integer to the datagram.
Definition: datagram.I:138
int get_num_channels() const
Returns the number of channels (1 through 4) associated with the image.
void update_egg_tex(EggTexture *egg_tex) const
Sets the indicated EggTexture to refer to this file.
Definition: imageFile.cxx:459
xelval get_channel_val(int x, int y, int channel) const
Returns the nth component color at the indicated pixel.
Definition: pnmImage.cxx:850
bool get_bool()
Extracts a boolean value.
void add_string(const string &str)
Adds a variable-length string to the datagram.
Definition: datagram.I:351
The name of this class derives from the fact that we originally implemented it as a layer on top of t...
Definition: pnmImage.h:68
bool exists() const
Returns true if the file or files named by the image file exist, false otherwise. ...
Definition: imageFile.cxx:303
void set_alpha_file_channel(int alpha_file_channel)
If a separate alpha-file is specified, this indicates which channel number should be extracted from t...
Definition: eggTexture.I:907
int get_alpha_file_channel() const
Returns the particular channel number of the alpha image file from which the alpha channel should be ...
Definition: imageFile.cxx:291
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Called after the object is otherwise completely read from a Bam file, this function&#39;s job is to store...
Definition: imageFile.cxx:519
bool set_filename(PaletteGroup *group, const string &basename)
Sets the filename, and if applicable, the alpha_filename, from the indicated basename.
Definition: imageFile.cxx:181
float get_gray(int x, int y) const
Returns the gray component color at the indicated pixel.
Definition: pnmImage.I:928
Defines a texture map that may be applied to geometry.
Definition: eggTexture.h:33
bool read(const Filename &filename, PNMFileType *type=NULL, bool report_unknown_type=true)
Reads the indicated image filename.
Definition: pnmImage.cxx:245
int get_y_size() const
Returns the size of the image file in pixels in the Y direction.
Definition: imageFile.cxx:106
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
This is the highest level of grouping for TextureImages.
Definition: paletteGroup.h:47
This is the base class of a family of classes that represent particular image file types that PNMImag...
Definition: pnmFileType.h:35
void output_filename(ostream &out) const
Writes the filename (or pair of filenames) to the indicated output stream.
Definition: imageFile.cxx:483
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Called after the object is otherwise completely read from a Bam file, this function&#39;s job is to store...
virtual void write_datagram(BamWriter *writer, Datagram &datagram)
Fills the indicated datagram up with a binary representation of the current object, in preparation for writing to a Bam file.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
bool make_shadow_image(const string &basename)
Sets up the ImageFile as a "shadow image" of a particular PaletteImage.
Definition: imageFile.cxx:56
PN_int32 get_int32()
Extracts a signed 32-bit integer.
PN_uint8 get_uint8()
Extracts an unsigned 8-bit integer.
void set_type(PNMFileType *type)
Sets the file type of this PNMImage.
void remove_alpha()
Removes the image&#39;s alpha channel, if it exists.
Definition: pnmImage.I:346
string get_string()
Extracts a variable-length string.
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class&#39;s make_from_bam() method to read in all...
void standardize()
Converts the filename to standard form by replacing consecutive slashes with a single slash...
Definition: filename.cxx:945
int get_y_size() const
Returns the number of pixels in the Y direction.
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
int get_x_size() const
Returns the number of pixels in the X direction.
void update_egg_tex(EggTexture *egg_tex) const
Adjusts the texture properties of the indicated egg reference to match these properties.
virtual void write_datagram(BamWriter *writer, Datagram &datagram)
Fills the indicated datagram up with a binary representation of the current object, in preparation for writing to a Bam file.
Definition: imageFile.cxx:498
const TextureProperties & get_properties() const
Returns the grouping properties of the image.
Definition: imageFile.cxx:140
void set_alpha_filename(const Filename &filename)
Specifies a separate file that will be loaded in with the 1- or 3-component texture and applied as th...
Definition: eggTexture.I:820
void add_bool(bool value)
Adds a boolean value to the datagram.
Definition: datagram.I:118
static Filename make_user_filename(Filename filename)
Returns a new filename that&#39;s made relative to the current directory, suitable for reporting to the u...
bool is_size_known() const
Returns true if the size of the image file is known, false otherwise.
Definition: imageFile.cxx:81
static Filename make_egg_filename(Filename filename)
Returns a new filename that&#39;s made relative to the rel_directory, suitable for writing out within egg...
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
int get_x_size() const
Returns the size of the image file in pixels in the X direction.
Definition: imageFile.cxx:93
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin()...
static bool has_alpha(ColorType color_type)
This static variant of has_alpha() returns true if the indicated image type includes an alpha channel...
xelval get_maxval() const
Returns the maximum channel value allowable for any pixel in this image; for instance, 255 for a typical 8-bit-per-channel image.
static Filename get_bam_filename(Filename filename)
Returns an absolute pathname based on the given relative pathname, presumably read from the bam file ...
const string & get_dirname() const
Returns the directory name associated with the palette group.
int get_num_channels() const
Returns the number of channels of the image.
Definition: imageFile.cxx:130
void clear_basic_properties()
Resets the properties to a neutral state, for instance in preparation for calling update_properties()...
Definition: imageFile.cxx:153
bool unlink() const
Permanently deletes the file associated with the filename, if possible.
Definition: filename.cxx:2554
bool uses_alpha() const
Returns true if the texture uses an alpha channel, false otherwise.
bool write(const Filename &filename, PNMFileType *type=NULL) const
Writes the image to the indicated filename.
Definition: pnmImage.cxx:362
bool has_num_channels() const
Returns true if the number of channels is known.
void clear_alpha_file_channel()
Removes the specification of a particular channel to use from the alpha-file image.
Definition: eggTexture.I:919
void fillin(DatagramIterator &scan, BamReader *manager)
Reads the binary data from the given datagram iterator, which was written by a previous call to write...
const Filename & get_alpha_filename() const
Returns the alpha filename of the image file.
Definition: imageFile.cxx:276
void add_alpha()
Adds an alpha channel to the image, if it does not already have one.
Definition: pnmImage.I:336
void unlink()
Deletes the image file or files.
Definition: imageFile.cxx:442
void set_alpha(int x, int y, float a)
Sets the alpha component color only at the indicated pixel.
Definition: pnmImage.I:1007
int get_num_channels() const
Returns the number of channels in the image.
bool has_num_channels() const
Returns true if the number of channels in the image is known, false otherwise.
Definition: imageFile.cxx:118
void clear_basic()
Resets only the properties that might be changed by update_properties() to a neutral state...
void update_properties(const TextureProperties &properties)
If the indicate TextureProperties structure is more specific than this one, updates this one...
Definition: imageFile.cxx:164
bool make_dir() const
Creates all the directories in the path to the file specified in the filename, except for the basenam...
Definition: filename.cxx:2730
void add_int32(PN_int32 value)
Adds a signed 32-bit integer to the datagram.
Definition: datagram.I:159
A class to retrieve the individual data elements previously stored in a Datagram. ...
xelval get_alpha_val(int x, int y) const
Returns the alpha component color at the indicated pixel.
Definition: pnmImage.I:503
void update_properties(const TextureProperties &other)
If the indicate TextureProperties structure is more specific than this one, updates this one...
string get_fullpath_wo_extension() const
Returns the full filename–directory and basename parts–except for the extension.
Definition: filename.I:448
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
const Filename & get_filename() const
Returns the primary filename of the image file.
Definition: imageFile.cxx:263
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
bool exists() const
Returns true if the filename exists on the disk, false otherwise.
Definition: filename.cxx:1356
virtual string get_suggested_extension() const
Returns a suitable filename extension (without a leading dot) to suggest for files of this type...
Definition: pnmFileType.cxx:75
float get_alpha(int x, int y) const
Returns the alpha component color at the indicated pixel.
Definition: pnmImage.I:941
This is the set of characteristics of a texture that, if different from another texture, prevent the two textures from sharing a PaletteImage.