Panda3D
 All Classes Functions Variables Enumerations
textureImage.h
1 // Filename: textureImage.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 TEXTUREIMAGE_H
16 #define TEXTUREIMAGE_H
17 
18 #include "pandatoolbase.h"
19 
20 #include "imageFile.h"
21 #include "paletteGroups.h"
22 #include "textureRequest.h"
23 
24 #include "namable.h"
25 #include "filename.h"
26 #include "pnmImage.h"
27 #include "eggRenderMode.h"
28 
29 #include "pmap.h"
30 #include "pset.h"
31 
32 class SourceTextureImage;
33 class DestTextureImage;
34 class TexturePlacement;
35 class EggFile;
36 
37 ////////////////////////////////////////////////////////////////////
38 // Class : TextureImage
39 // Description : This represents a single source texture that is
40 // referenced by one or more egg files. It may be
41 // assigned to multiple PaletteGroups, and thus placed
42 // on multiple PaletteImages (up to one per
43 // PaletteGroup).
44 //
45 // Since a TextureImage may be referenced by multiple
46 // egg files that are each assigned to a different set
47 // of groups, it tries to maximize sharing between egg
48 // files and minimize the number of different
49 // PaletteGroups it is assigned to.
50 ////////////////////////////////////////////////////////////////////
51 class TextureImage : public ImageFile, public Namable {
52 public:
53  TextureImage();
54 
55  void note_egg_file(EggFile *egg_file);
56  void assign_groups();
57 
58  const PaletteGroups &get_groups() const;
60  void force_replace();
61  void mark_eggs_stale();
62 
63  void mark_texture_named();
64  bool is_texture_named() const;
65 
66  void pre_txa_file();
67  void post_txa_file();
68  bool got_txa_file() const;
70 
71  bool get_omit() const;
72  double get_coverage_threshold() const;
73  int get_margin() const;
74  bool is_surprise() const;
75  bool is_used() const;
76  EggRenderMode::AlphaMode get_alpha_mode() const;
77 
78  EggTexture::WrapMode get_txa_wrap_u() const;
79  EggTexture::WrapMode get_txa_wrap_v() const;
80 
81  SourceTextureImage *get_source(const Filename &filename,
82  const Filename &alpha_filename,
83  int alpha_file_channel);
84 
87 
88  void copy_unplaced(bool redo_all);
89 
90  const PNMImage &read_source_image();
91  void release_source_image();
92  void set_source_image(const PNMImage &image);
93  void read_header();
94  bool is_newer_than(const Filename &reference_filename);
95 
96  void write_source_pathnames(ostream &out, int indent_level = 0) const;
97  void write_scale_info(ostream &out, int indent_level = 0);
98 
99 private:
100  typedef pset<EggFile *> EggFiles;
104 
105  static int compute_egg_count(PaletteGroup *group,
106  const WorkingEggs &egg_files);
107 
108  void assign_to_groups(const PaletteGroups &groups);
109  void consider_grayscale();
110  void consider_alpha();
111 
112  void remove_old_dests(const Dests &a, const Dests &b);
113  void copy_new_dests(const Dests &a, const Dests &b);
114 
115  string get_source_key(const Filename &filename,
116  const Filename &alpha_filename,
117  int alpha_file_channel);
118 
119 private:
120  TextureRequest _request;
121  TextureProperties _pre_txa_properties;
122  EggRenderMode::AlphaMode _pre_txa_alpha_mode;
123  SourceTextureImage *_preferred_source;
124  bool _is_surprise;
125 
126  bool _ever_read_image;
127  bool _forced_grayscale;
128 
129  enum AlphaBits {
130  // consider_alpha() sets alpha_bits to the union of all of these
131  // pixel values that might be found in the alpha channel.
132  AB_one = 0x01,
133  AB_mid = 0x02,
134  AB_zero = 0x04,
135  AB_all = 0x07 // == AB_zero | AB_mid | AB_one
136  };
137  int _alpha_bits;
138  double _mid_pixel_ratio;
139  bool _is_cutout;
140  EggRenderMode::AlphaMode _alpha_mode;
141  EggTexture::WrapMode _txa_wrap_u, _txa_wrap_v;
142 
143  PaletteGroups _explicitly_assigned_groups;
144  PaletteGroups _actual_assigned_groups;
145 
146  EggFiles _egg_files;
147 
149  Placement _placement;
150 
151  Sources _sources;
152  Dests _dests;
153 
154  bool _read_source_image;
155  bool _allow_release_source_image;
156  PNMImage _source_image;
157  bool _texture_named;
158  bool _got_txa_file;
159 
160 
161  // The TypedWritable interface follows.
162 public:
163  static void register_with_read_factory();
164  virtual void write_datagram(BamWriter *writer, Datagram &datagram);
165  virtual int complete_pointers(TypedWritable **p_list,
166  BamReader *manager);
167 
168 protected:
169  static TypedWritable *make_TextureImage(const FactoryParams &params);
170  void fillin(DatagramIterator &scan, BamReader *manager);
171 
172 private:
173  // These values are only filled in while reading from the bam file;
174  // don't use them otherwise.
175  int _num_placement;
176  int _num_sources;
177  int _num_dests;
178 
179 public:
180  static TypeHandle get_class_type() {
181  return _type_handle;
182  }
183  static void init_type() {
184  ImageFile::init_type();
185  Namable::init_type();
186  register_type(_type_handle, "TextureImage",
187  ImageFile::get_class_type(),
188  Namable::get_class_type());
189  }
190  virtual TypeHandle get_type() const {
191  return get_class_type();
192  }
193 
194 private:
195  static TypeHandle _type_handle;
196 
197  friend class TxaLine;
198 };
199 
200 #endif
201 
void mark_eggs_stale()
Marks all the egg files that reference this texture stale.
int get_margin() const
Returns the appropriate margin for this texture.
This represents a texture filename as it has been resized and copied to the map directory (e...
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
void pre_txa_file()
Updates any internal state prior to reading the .txa file.
bool got_txa_file() const
Returns true if this TextureImage has been looked up in the .txa file this session, false otherwise.
bool is_newer_than(const Filename &reference_filename)
Returns true if the source image is newer than the indicated file, false otherwise.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
void clear_source_basic_properties()
Calls clear_basic_properties() on each source texture image used by this texture, to reset the proper...
SourceTextureImage * get_source(const Filename &filename, const Filename &alpha_filename, int alpha_file_channel)
Returns the SourceTextureImage corresponding to the given filename(s).
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
void determine_placement_size()
Calls determine_size() on each TexturePlacement for the texture, to ensure that each TexturePlacement...
This is the highest level of grouping for TextureImages.
Definition: paletteGroup.h:47
double get_coverage_threshold() const
Returns the appropriate coverage threshold for this texture.
static void register_with_read_factory()
Registers the current object as something that can be read from a Bam file.
This is a single matching line in the .txa file.
Definition: txaLine.h:39
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
bool is_texture_named() const
Returns true if this particular texture has been named by the user for procession this session...
bool is_surprise() const
Returns true if this particular texture is a &#39;surprise&#39;, i.e.
void note_egg_file(EggFile *egg_file)
Records that a particular egg file references this texture.
SourceTextureImage * get_preferred_source()
Determines the preferred source image for examining size and reading pixels, etc. ...
TexturePlacement * get_placement(PaletteGroup *group) const
Gets the TexturePlacement object which represents the assignment of this texture to the indicated gro...
void force_replace()
Removes the texture from any PaletteImages it is assigned to, but does not remove it from the groups...
A base class for all things which can have a name.
Definition: namable.h:29
void read_header()
Causes the header part of the image to be reread, usually to confirm that its image properties (size...
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
bool is_used() const
Returns true if this particular texture has been placed somewhere, anywhere, or false if it is not us...
EggTexture::WrapMode get_txa_wrap_u() const
Returns the wrap mode specified in the u direction in the txa file, or WM_unspecified.
This is the base class of both TextureImage and PaletteImage.
Definition: imageFile.h:36
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
void copy_unplaced(bool redo_all)
Copies the texture to whichever destination directories are appropriate for the groups in which it ha...
This corresponds to a particular assignment of a TextureImage with a PaletteGroup, and specifically describes which PaletteImage (if any), and where on the PaletteImage, the TextureImage has been assigned to.
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 a texture image reference as it appears in an egg file: the source image of the texture...
const PaletteGroups & get_groups() const
Once assign_groups() has been called, this returns the actual set of groups the TextureImage has been...
EggRenderMode::AlphaMode get_alpha_mode() const
Returns the alpha mode that should be used to render objects with this texture, as specified by the u...
void assign_groups()
Assigns the texture to all of the PaletteGroups the various egg files that use it need...
EggTexture::WrapMode get_txa_wrap_v() const
Returns the wrap mode specified in the v direction in the txa file, or WM_unspecified.
void mark_texture_named()
Indicates that this particular texture has been named by the user for processing this session...
void set_source_image(const PNMImage &image)
Accepts the indicated source image as if it had been read from disk.
const PNMImage & read_source_image()
Reads in the original image, if it has not already been read, and returns it.
void write_scale_info(ostream &out, int indent_level=0)
Writes the information about the texture&#39;s size and placement.
A set of PaletteGroups.
Definition: paletteGroups.h:31
bool get_omit() const
Returns true if the user specifically requested to omit this texture via the &quot;omit&quot; keyword in the ...
void write_source_pathnames(ostream &out, int indent_level=0) const
Writes the list of source pathnames that might contribute to this texture to the indicated output str...
A class to retrieve the individual data elements previously stored in a Datagram. ...
This represents a single source texture that is referenced by one or more egg files.
Definition: textureImage.h:51
void post_txa_file()
Once the .txa file has been read and the TextureImage matched against it, considers applying the requ...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
These are the things that a user might explicitly request to adjust on a texture via a line in the ...
This represents a single egg file known to the palettizer.
Definition: eggFile.h:39
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...
void release_source_image()
Frees the memory that was allocated by a previous call to read_source_image().
This is the set of characteristics of a texture that, if different from another texture, prevent the two textures from sharing a PaletteImage.