Panda3D
palettizer.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 palettizer.h
10  * @author drose
11  * @date 2000-12-01
12  */
13 
14 #ifndef PALETTIZER_H
15 #define PALETTIZER_H
16 
17 #include "pandatoolbase.h"
18 
19 #include "txaFile.h"
20 
21 #include "typedWritable.h"
22 #include "eggRenderMode.h"
23 #include "pvector.h"
24 #include "pset.h"
25 #include "pmap.h"
26 
27 class PNMFileType;
28 class EggFile;
29 class PaletteGroup;
30 class TextureImage;
31 class TexturePlacement;
32 class FactoryParams;
33 
34 /**
35  * This is the main engine behind egg-palettize. It contains all of the
36  * program parameters, from the command line or saved from a previous session,
37  * and serves as the driving force in the actual palettizing process.
38  */
39 class Palettizer : public TypedWritable {
40 public:
41  Palettizer();
42 
43  bool get_noabs() const;
44  void set_noabs(bool noabs);
45 
46  bool is_valid() const;
47  void report_pi() const;
48  void report_statistics() const;
49 
50  void read_txa_file(std::istream &txa_file, const std::string &txa_filename);
51  void all_params_set();
52  void process_command_line_eggs(bool force_texture_read, const Filename &state_filename);
53  void process_all(bool force_texture_read, const Filename &state_filename);
54  void optimal_resize();
55  void reset_images();
56  void generate_images(bool redo_all);
57  bool read_stale_eggs(bool redo_all);
58  bool write_eggs();
59 
60  EggFile *get_egg_file(const std::string &name);
61  bool remove_egg_file(const std::string &name);
62 
63  void add_command_line_egg(EggFile *egg_file);
64 
65  PaletteGroup *get_palette_group(const std::string &name);
66  PaletteGroup *test_palette_group(const std::string &name) const;
68  TextureImage *get_texture(const std::string &name);
69 
70 private:
71  static const char *yesno(bool flag);
72 
73 public:
74  static int _pi_version;
75  static int _min_pi_version;
76  static int _read_pi_version;
77 
78  enum RemapUV {
79  RU_never,
80  RU_group,
81  RU_poly,
82  RU_invalid
83  };
84 
85  static RemapUV string_remap(const std::string &str);
86 
87  bool _is_valid;
88 
89  // These values are not stored in the textures.boo file, but are specific to
90  // each session.
91  TxaFile _txa_file;
92  std::string _default_groupname;
93  std::string _default_groupdir;
94  bool _noabs;
95 
96  // The following parameter values specifically relate to textures and
97  // palettes. These values are stored in the textures.boo file for future
98  // reference.
99  std::string _generated_image_pattern;
100  std::string _map_dirname;
101  Filename _shadow_dirname;
102  Filename _rel_dirname;
103  int _pal_x_size, _pal_y_size;
104  LColord _background;
105  int _margin;
106  bool _omit_solitary;
107  bool _omit_everything;
108  double _coverage_threshold;
109  bool _force_power_2;
110  bool _aggressively_clean_mapdir;
111  bool _round_uvs;
112  double _round_unit;
113  double _round_fuzz;
114  RemapUV _remap_uv, _remap_char_uv;
115  PNMFileType *_color_type;
116  PNMFileType *_alpha_type;
117  PNMFileType *_shadow_color_type;
118  PNMFileType *_shadow_alpha_type;
119  EggRenderMode::AlphaMode _cutout_mode;
120  double _cutout_ratio;
121 
122 private:
124  void compute_statistics(std::ostream &out, int indent_level,
125  const Placements &placements) const;
126 
128  EggFiles _egg_files;
129 
131  CommandLineEggs _command_line_eggs;
132 
134  CommandLineTextures _command_line_textures;
135 
137  Groups _groups;
138 
140  Textures _textures;
142  TextureConflicts _texture_conflicts;
143 
144 
145  // The TypedWritable interface follows.
146 public:
147  static void register_with_read_factory();
148  virtual void write_datagram(BamWriter *writer, Datagram &datagram);
149  virtual int complete_pointers(TypedWritable **p_list,
150  BamReader *manager);
151 
152  virtual void finalize(BamReader *manager);
153 
154 protected:
155  static TypedWritable *make_Palettizer(const FactoryParams &params);
156  void fillin(DatagramIterator &scan, BamReader *manager);
157 
158 private:
159  // These values are only filled in while reading from the bam file; don't
160  // use them otherwise.
161  int _num_egg_files;
162  int _num_groups;
163  int _num_textures;
164 
165 public:
166  static TypeHandle get_class_type() {
167  return _type_handle;
168  }
169  static void init_type() {
170  TypedWritable::init_type();
171  register_type(_type_handle, "Palettizer",
172  TypedWritable::get_class_type());
173  }
174  virtual TypeHandle get_type() const {
175  return get_class_type();
176  }
177 
178 private:
179  static TypeHandle _type_handle;
180 
181  friend class TxaLine;
182 };
183 
184 // This is a global Palettizer pointer that may be filled in when the
185 // Palettizer is created, for convenience in referencing it from multiple
186 // places. (Generally, a standalone program will only create one Palettizer
187 // object in a session.)
188 extern Palettizer *pal;
189 
190 #endif
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
A class to retrieve the individual data elements previously stored in a Datagram.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
This represents a single egg file known to the palettizer.
Definition: eggFile.h:36
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:39
This is the base class of a family of classes that represent particular image file types that PNMImag...
Definition: pnmFileType.h:32
This is the highest level of grouping for TextureImages.
Definition: paletteGroup.h:43
This is the main engine behind egg-palettize.
Definition: palettizer.h:39
void set_noabs(bool noabs)
Changes the current setting of the noabs flag.
Definition: palettizer.cxx:158
void process_all(bool force_texture_read, const Filename &state_filename)
Reprocesses all textures known.
Definition: palettizer.cxx:514
PaletteGroup * test_palette_group(const std::string &name) const
Returns the PaletteGroup with the given name.
Definition: palettizer.cxx:810
bool remove_egg_file(const std::string &name)
Removes the named egg file from the database, if it exists.
Definition: palettizer.cxx:766
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:423
TextureImage * get_texture(const std::string &name)
Returns the TextureImage with the given name.
Definition: palettizer.cxx:838
void optimal_resize()
Attempts to resize each PalettteImage down to its smallest possible size.
Definition: palettizer.cxx:606
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:824
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:406
static void register_with_read_factory()
Registers the current object as something that can be read from a Bam file.
Definition: palettizer.cxx:913
virtual void finalize(BamReader *manager)
Called by the BamReader to perform any final actions needed for setting up the object after all objec...
EggFile * get_egg_file(const std::string &name)
Returns the EggFile with the given name.
Definition: palettizer.cxx:749
PaletteGroup * get_palette_group(const std::string &name)
Returns the PaletteGroup with the given name.
Definition: palettizer.cxx:793
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:784
bool write_eggs()
Adjusts the egg files to reference the newly generated textures, and writes them out.
Definition: palettizer.cxx:714
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:167
static RemapUV string_remap(const std::string &str)
Returns the RemapUV code corresponding to the indicated string, or RU_invalid if the string is invali...
Definition: palettizer.cxx:876
void report_pi() const
Output a verbose description of all the palettization information to standard output,...
Definition: palettizer.cxx:176
virtual void write_datagram(BamWriter *writer, Datagram &datagram)
Fills the indicated datagram up with a binary representation of the current object,...
Definition: palettizer.cxx:923
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:619
void read_txa_file(std::istream &txa_file, const std::string &txa_filename)
Reads in the .txa file and keeps it ready for matching textures and egg files.
Definition: palettizer.cxx:353
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: palettizer.cxx:984
void report_statistics() const
Output a report of the palettization effectiveness, texture memory utilization, and so on.
Definition: palettizer.cxx:297
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:656
bool get_noabs() const
Returns the current setting of the noabs flag.
Definition: palettizer.cxx:143
void generate_images(bool redo_all)
Actually generates the appropriate palette and unplaced texture images into the map directories.
Definition: palettizer.cxx:633
This represents a single source texture that is referenced by one or more egg files.
Definition: textureImage.h:46
This corresponds to a particular assignment of a TextureImage with a PaletteGroup,...
This represents the .txa file (usually textures.txa) that contains the user instructions for resizing...
Definition: txaFile.h:30
This is a single matching line in the .txa file.
Definition: txaLine.h:36
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.