Panda3D
imageFile.h
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 imageFile.h
10  * @author drose
11  * @date 2000-11-28
12  */
13 
14 #ifndef IMAGEFILE_H
15 #define IMAGEFILE_H
16 
17 #include "pandatoolbase.h"
18 
19 #include "textureProperties.h"
20 
21 #include "filename.h"
22 #include "typedWritable.h"
23 
24 class PNMImage;
25 class EggTexture;
26 class PaletteGroup;
27 
28 /**
29  * This is the base class of both TextureImage and PaletteImage. It
30  * encapsulates all the information specific to an image file that can be
31  * assigned as a texture image to egg geometry.
32  */
33 class ImageFile : public TypedWritable {
34 public:
35  ImageFile();
36 
37  bool make_shadow_image(const std::string &basename);
38 
39  bool is_size_known() const;
40  int get_x_size() const;
41  int get_y_size() const;
42  bool has_num_channels() const;
43  int get_num_channels() const;
44 
45  const TextureProperties &get_properties() const;
47  void update_properties(const TextureProperties &properties);
48 
49  bool set_filename(PaletteGroup *group, const std::string &basename);
50  bool set_filename(const std::string &dirname, const std::string &basename);
51  const Filename &get_filename() const;
52  const Filename &get_alpha_filename() const;
53  int get_alpha_file_channel() const;
54  bool exists() const;
55 
56  bool read(PNMImage &image) const;
57  bool write(const PNMImage &image) const;
58  void unlink();
59 
60  void update_egg_tex(EggTexture *egg_tex) const;
61 
62  void output_filename(std::ostream &out) const;
63 
64 protected:
65  TextureProperties _properties;
66  Filename _filename;
67  Filename _alpha_filename;
68  int _alpha_file_channel;
69 
70  bool _size_known;
71  int _x_size, _y_size;
72 
73  // The TypedWritable interface follows.
74 public:
75  virtual void write_datagram(BamWriter *writer, Datagram &datagram);
76  virtual int complete_pointers(TypedWritable **p_list,
77  BamReader *manager);
78 
79 protected:
80  void fillin(DatagramIterator &scan, BamReader *manager);
81 
82 public:
83  static TypeHandle get_class_type() {
84  return _type_handle;
85  }
86  static void init_type() {
87  TypedWritable::init_type();
88  register_type(_type_handle, "ImageFile",
89  TypedWritable::get_class_type());
90  }
91  virtual TypeHandle get_type() const {
92  return get_class_type();
93  }
94 
95 private:
96  static TypeHandle _type_handle;
97 
98 };
99 
100 #endif
bool write(const PNMImage &image) const
Writes out the image in the indicated PNMImage to the _filename and/or _alpha_filename.
Definition: imageFile.cxx:339
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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:277
void update_egg_tex(EggTexture *egg_tex) const
Sets the indicated EggTexture to refer to this file.
Definition: imageFile.cxx:403
The name of this class derives from the fact that we originally implemented it as a layer on top of t...
Definition: pnmImage.h:58
bool exists() const
Returns true if the file or files named by the image file exist, false otherwise.
Definition: imageFile.cxx:256
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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:246
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
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:454
Defines a texture map that may be applied to geometry.
Definition: eggTexture.h:30
int get_y_size() const
Returns the size of the image file in pixels in the Y direction.
Definition: imageFile.cxx:92
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
This is the highest level of grouping for TextureImages.
Definition: paletteGroup.h:43
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void output_filename(std::ostream &out) const
Writes the filename (or pair of filenames) to the indicated output stream.
Definition: imageFile.cxx:424
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
virtual void write_datagram(BamWriter *writer, Datagram &datagram)
Fills the indicated datagram up with a binary representation of the current object,...
Definition: imageFile.cxx:436
const TextureProperties & get_properties() const
Returns the grouping properties of the image.
Definition: imageFile.cxx:119
bool set_filename(PaletteGroup *group, const std::string &basename)
Sets the filename, and if applicable, the alpha_filename, from the indicated basename.
Definition: imageFile.cxx:150
bool is_size_known() const
Returns true if the size of the image file is known, false otherwise.
Definition: imageFile.cxx:73
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:39
int get_x_size() const
Returns the size of the image file in pixels in the X direction.
Definition: imageFile.cxx:82
This is the base class of both TextureImage and PaletteImage.
Definition: imageFile.h:33
int get_num_channels() const
Returns the number of channels of the image.
Definition: imageFile.cxx:111
void clear_basic_properties()
Resets the properties to a neutral state, for instance in preparation for calling update_properties()...
Definition: imageFile.cxx:128
const Filename & get_alpha_filename() const
Returns the alpha filename of the image file.
Definition: imageFile.cxx:235
void unlink()
Deletes the image file or files.
Definition: imageFile.cxx:388
bool has_num_channels() const
Returns true if the number of channels in the image is known, false otherwise.
Definition: imageFile.cxx:102
bool make_shadow_image(const std::string &basename)
Sets up the ImageFile as a "shadow image" of a particular PaletteImage.
Definition: imageFile.cxx:51
void update_properties(const TextureProperties &properties)
If the indicate TextureProperties structure is more specific than this one, updates this one.
Definition: imageFile.cxx:137
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:81
const Filename & get_filename() const
Returns the primary filename of the image file.
Definition: imageFile.cxx:225
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
This is the set of characteristics of a texture that, if different from another texture,...