Panda3D
 All Classes Functions Variables Enumerations
palettizer.h
1 // Filename: palettizer.h
2 // Created by: drose (01Dec00)
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 PALETTIZER_H
16 #define PALETTIZER_H
17 
18 #include "pandatoolbase.h"
19 
20 #include "txaFile.h"
21 
22 #include "typedWritable.h"
23 #include "eggRenderMode.h"
24 #include "pvector.h"
25 #include "pset.h"
26 #include "pmap.h"
27 
28 class PNMFileType;
29 class EggFile;
30 class PaletteGroup;
31 class TextureImage;
32 class TexturePlacement;
33 class FactoryParams;
34 
35 ////////////////////////////////////////////////////////////////////
36 // Class : Palettizer
37 // Description : This is the main engine behind egg-palettize. It
38 // contains all of the program parameters, from the
39 // command line or saved from a previous session, and
40 // serves as the driving force in the actual palettizing
41 // process.
42 ////////////////////////////////////////////////////////////////////
43 class Palettizer : public TypedWritable {
44 public:
45  Palettizer();
46 
47  bool get_noabs() const;
48  void set_noabs(bool noabs);
49 
50  bool is_valid() const;
51  void report_pi() const;
52  void report_statistics() const;
53 
54  void read_txa_file(istream &txa_file, const string &txa_filename);
55  void all_params_set();
56  void process_command_line_eggs(bool force_texture_read, const Filename &state_filename);
57  void process_all(bool force_texture_read, const Filename &state_filename);
58  void optimal_resize();
59  void reset_images();
60  void generate_images(bool redo_all);
61  bool read_stale_eggs(bool redo_all);
62  bool write_eggs();
63 
64  EggFile *get_egg_file(const string &name);
65  bool remove_egg_file(const string &name);
66 
67  void add_command_line_egg(EggFile *egg_file);
68 
69  PaletteGroup *get_palette_group(const string &name);
70  PaletteGroup *test_palette_group(const string &name) const;
72  TextureImage *get_texture(const string &name);
73 
74 private:
75  static const char *yesno(bool flag);
76 
77 public:
78  static int _pi_version;
79  static int _min_pi_version;
80  static int _read_pi_version;
81 
82  enum RemapUV {
83  RU_never,
84  RU_group,
85  RU_poly,
86  RU_invalid
87  };
88 
89  static RemapUV string_remap(const string &str);
90 
91  bool _is_valid;
92 
93  // These values are not stored in the textures.boo file, but are
94  // specific to each session.
95  TxaFile _txa_file;
96  string _default_groupname;
97  string _default_groupdir;
98  bool _noabs;
99 
100  // The following parameter values specifically relate to textures
101  // and palettes. These values are stored in the textures.boo file
102  // for future reference.
103  string _generated_image_pattern;
104  string _map_dirname;
105  Filename _shadow_dirname;
106  Filename _rel_dirname;
107  int _pal_x_size, _pal_y_size;
108  LColord _background;
109  int _margin;
110  bool _omit_solitary;
111  bool _omit_everything;
112  double _coverage_threshold;
113  bool _force_power_2;
114  bool _aggressively_clean_mapdir;
115  bool _round_uvs;
116  double _round_unit;
117  double _round_fuzz;
118  RemapUV _remap_uv, _remap_char_uv;
119  PNMFileType *_color_type;
120  PNMFileType *_alpha_type;
121  PNMFileType *_shadow_color_type;
122  PNMFileType *_shadow_alpha_type;
123  EggRenderMode::AlphaMode _cutout_mode;
124  double _cutout_ratio;
125 
126 private:
128  void compute_statistics(ostream &out, int indent_level,
129  const Placements &placements) const;
130 
132  EggFiles _egg_files;
133 
135  CommandLineEggs _command_line_eggs;
136 
138  CommandLineTextures _command_line_textures;
139 
141  Groups _groups;
142 
144  Textures _textures;
146  TextureConflicts _texture_conflicts;
147 
148 
149  // The TypedWritable interface follows.
150 public:
151  static void register_with_read_factory();
152  virtual void write_datagram(BamWriter *writer, Datagram &datagram);
153  virtual int complete_pointers(TypedWritable **p_list,
154  BamReader *manager);
155 
156  virtual void finalize(BamReader *manager);
157 
158 protected:
159  static TypedWritable *make_Palettizer(const FactoryParams &params);
160  void fillin(DatagramIterator &scan, BamReader *manager);
161 
162 private:
163  // These values are only filled in while reading from the bam file;
164  // don't use them otherwise.
165  int _num_egg_files;
166  int _num_groups;
167  int _num_textures;
168 
169 public:
170  static TypeHandle get_class_type() {
171  return _type_handle;
172  }
173  static void init_type() {
174  TypedWritable::init_type();
175  register_type(_type_handle, "Palettizer",
176  TypedWritable::get_class_type());
177  }
178  virtual TypeHandle get_type() const {
179  return get_class_type();
180  }
181 
182 private:
183  static TypeHandle _type_handle;
184 
185  friend class TxaLine;
186 };
187 
188 // This is a global Palettizer pointer that may be filled in when the
189 // Palettizer is created, for convenience in referencing it from
190 // multiple places. (Generally, a standalone program will only create
191 // one Palettizer object in a session.)
192 extern Palettizer *pal;
193 
194 #endif
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
This is the main engine behind egg-palettize.
Definition: palettizer.h:43
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
void process_all(bool force_texture_read, const Filename &state_filename)
Reprocesses all textures known.
Definition: palettizer.cxx:539
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
virtual void finalize(BamReader *manager)
Called by the BamReader to perform any final actions needed for setting up the object after all objec...
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:1661
PaletteGroup * test_palette_group(const string &name) const
Returns the PaletteGroup with the given name.
Definition: palettizer.cxx:868
EggFile * get_egg_file(const string &name)
Returns the EggFile with the given name.
Definition: palettizer.cxx:795
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 get_noabs() const
Returns the current setting of the noabs flag.
Definition: palettizer.cxx:144
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.
void report_statistics() const
Output a report of the palettization effectiveness, texture memory utilization, and so on...
Definition: palettizer.cxx:309
bool remove_egg_file(const string &name)
Removes the named egg file from the database, if it exists.
Definition: palettizer.cxx:815
void read_txa_file(istream &txa_file, const string &txa_filename)
Reads in the .txa file and keeps it ready for matching textures and egg files.
Definition: palettizer.cxx:367
static RemapUV string_remap(const string &str)
Returns the RemapUV code corresponding to the indicated string, or RU_invalid if the string is invali...
Definition: palettizer.cxx:945
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
void all_params_set()
Called after all command line parameters have been set up, this is a hook to do whatever initializati...
Definition: palettizer.cxx:423
void reset_images()
Throws away all of the current PaletteImages, so that new ones may be created (and the packing made m...
Definition: palettizer.cxx:652
bool write_eggs()
Adjusts the egg files to reference the newly generated textures, and writes them out.
Definition: palettizer.cxx:757
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
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.
void generate_images(bool redo_all)
Actually generates the appropriate palette and unplaced texture images into the map directories...
Definition: palettizer.cxx:669
void report_pi() const
Output a verbose description of all the palettization information to standard output, for the user's perusal.
Definition: palettizer.cxx:187
void process_command_line_eggs(bool force_texture_read, const Filename &state_filename)
Processes all the textures named in the _command_line_eggs, placing them on the appropriate palettes ...
Definition: palettizer.cxx:444
void set_noabs(bool noabs)
Changes the current setting of the noabs flag.
Definition: palettizer.cxx:163
static void register_with_read_factory()
Registers the current object as something that can be read from a Bam file.
Definition: palettizer.cxx:988
PaletteGroup * get_default_group()
Returns the default group to which an egg file should be assigned if it is not mentioned in the ...
Definition: palettizer.cxx:884
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
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...
void optimal_resize()
Attempts to resize each PalettteImage down to its smallest possible size.
Definition: palettizer.cxx:636
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
bool read_stale_eggs(bool redo_all)
Reads in any egg file that is known to be stale, even if it was not listed on the command line...
Definition: palettizer.cxx:696
void add_command_line_egg(EggFile *egg_file)
Adds the indicated EggFile to the list of eggs that are considered to have been read on the command l...
Definition: palettizer.cxx:836
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
TextureImage * get_texture(const string &name)
Returns the TextureImage with the given name.
Definition: palettizer.cxx:902
PaletteGroup * get_palette_group(const string &name)
Returns the PaletteGroup with the given name.
Definition: palettizer.cxx:848
bool is_valid() const
Returns true if the palette information file was read correctly, or false if there was some error and...
Definition: palettizer.cxx:175
This represents a single egg file known to the palettizer.
Definition: eggFile.h:39
This represents the .txa file (usually textures.txa) that contains the user instructions for resizing...
Definition: txaFile.h:33