Panda3D
imageFile.h
1 // Filename: imageFile.h
2 // Created by: drose (28Nov00)
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 #ifndef IMAGEFILE_H
16 #define IMAGEFILE_H
17 
18 #include "pandatoolbase.h"
19 
20 #include "textureProperties.h"
21 
22 #include "filename.h"
23 #include "typedWritable.h"
24 
25 class PNMImage;
26 class EggTexture;
27 class PaletteGroup;
28 
29 ////////////////////////////////////////////////////////////////////
30 // Class : ImageFile
31 // Description : This is the base class of both TextureImage and
32 // PaletteImage. It encapsulates all the information
33 // specific to an image file that can be assigned as a
34 // texture image to egg geometry.
35 ////////////////////////////////////////////////////////////////////
36 class ImageFile : public TypedWritable {
37 public:
38  ImageFile();
39 
40  bool make_shadow_image(const string &basename);
41 
42  bool is_size_known() const;
43  int get_x_size() const;
44  int get_y_size() const;
45  bool has_num_channels() const;
46  int get_num_channels() const;
47 
48  const TextureProperties &get_properties() const;
50  void update_properties(const TextureProperties &properties);
51 
52  bool set_filename(PaletteGroup *group, const string &basename);
53  bool set_filename(const string &dirname, const string &basename);
54  const Filename &get_filename() const;
55  const Filename &get_alpha_filename() const;
56  int get_alpha_file_channel() const;
57  bool exists() const;
58 
59  bool read(PNMImage &image) const;
60  bool write(const PNMImage &image) const;
61  void unlink();
62 
63  void update_egg_tex(EggTexture *egg_tex) const;
64 
65  void output_filename(ostream &out) const;
66 
67 protected:
68  TextureProperties _properties;
69  Filename _filename;
70  Filename _alpha_filename;
71  int _alpha_file_channel;
72 
73  bool _size_known;
74  int _x_size, _y_size;
75 
76  // The TypedWritable interface follows.
77 public:
78  virtual void write_datagram(BamWriter *writer, Datagram &datagram);
79  virtual int complete_pointers(TypedWritable **p_list,
80  BamReader *manager);
81 
82 protected:
83  void fillin(DatagramIterator &scan, BamReader *manager);
84 
85 public:
86  static TypeHandle get_class_type() {
87  return _type_handle;
88  }
89  static void init_type() {
90  TypedWritable::init_type();
91  register_type(_type_handle, "ImageFile",
92  TypedWritable::get_class_type());
93  }
94  virtual TypeHandle get_type() const {
95  return get_class_type();
96  }
97 
98 private:
99  static TypeHandle _type_handle;
100 
101 };
102 
103 #endif
104 
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
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 update_egg_tex(EggTexture *egg_tex) const
Sets the indicated EggTexture to refer to this file.
Definition: imageFile.cxx:459
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
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'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
Defines a texture map that may be applied to geometry.
Definition: eggTexture.h:33
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
void output_filename(ostream &out) const
Writes the filename (or pair of filenames) to the indicated output stream.
Definition: imageFile.cxx:483
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
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
bool is_size_known() const
Returns true if the size of the image file is known, false otherwise.
Definition: imageFile.cxx:81
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
This is the base class of both TextureImage and PaletteImage.
Definition: imageFile.h:36
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
const Filename & get_alpha_filename() const
Returns the alpha filename of the image file.
Definition: imageFile.cxx:276
void unlink()
Deletes the image file or files.
Definition: imageFile.cxx:442
bool has_num_channels() const
Returns true if the number of channels in the image is known, false otherwise.
Definition: imageFile.cxx:118
void update_properties(const TextureProperties &properties)
If the indicate TextureProperties structure is more specific than this one, updates this one...
Definition: imageFile.cxx:164
A class to retrieve the individual data elements previously stored in a Datagram. ...
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
This is the set of characteristics of a texture that, if different from another texture, prevent the two textures from sharing a PaletteImage.