Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

Palettizer Class Reference

This is the main engine behind egg-palettize. More...

#include <palettizer.h>

Inheritance diagram for Palettizer:

TypedWritable TypedObject List of all members.

Public Types

enum  RemapUV { RU_never, RU_group, RU_poly, RU_invalid }

Public Member Functions

 Palettizer ()
void report_pi () const
 Output a verbose description of all the palettization information to standard output, for the user's perusal.

void report_statistics () const
 Output a report of the palettization effectiveness, texture memory utilization, and so on.

void read_txa_file (const Filename &txa_filename)
 Reads in the .txa file and keeps it ready for matching textures and egg files.

void all_params_set ()
 Called after all command line parameters have been set up, this is a hook to do whatever initialization is necessary.

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 or whatever needs to be done with them.

void process_all (bool force_texture_read, const Filename &state_filename)
 Reprocesses all textures known.

void optimal_resize ()
 Attempts to resize each PalettteImage down to its smallest possible size.

void reset_images ()
 Throws away all of the current PaletteImages, so that new ones may be created (and the packing made more optimal).

void generate_images (bool redo_all)
 Actually generates the appropriate palette and unplaced texture images into the map directories.

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, so that it may be updated and written out when write_eggs() is called.

bool write_eggs ()
 Adjusts the egg files to reference the newly generated textures, and writes them out.

EggFileget_egg_file (const string &name)
 Returns the EggFile with the given name.

bool remove_egg_file (const string &name)
 Removes the named egg file from the database, if it exists.

PaletteGroupget_palette_group (const string &name)
 Returns the PaletteGroup with the given name.

PaletteGrouptest_palette_group (const string &name) const
 Returns the PaletteGroup with the given name.

PaletteGroupget_default_group ()
 Returns the default group to which an egg file should be assigned if it is not mentioned in the .txa file.

TextureImageget_texture (const string &name)
 Returns the TextureImage with the given name.

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.

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 the pointers that were retrieved from the Bam file for each pointer object written.

virtual TypeHandle get_type () const
virtual void finalize ()
virtual TypeHandle force_init_type (void)
int get_type_index () const
bool is_of_type (TypeHandle handle) const
bool is_exact_type (TypeHandle handle) const

Static Public Member Functions

RemapUV string_remap (const string &str)
 Returns the RemapUV code corresponding to the indicated string, or RU_invalid if the string is invalid.

void register_with_read_factory ()
 Registers the current object as something that can be read from a Bam file.

TypeHandle get_class_type ()
void init_type ()

Public Attributes

TxaFile _txa_file
string _default_groupname
string _default_groupdir
string _map_dirname
Filename _shadow_dirname
Filename _rel_dirname
int _pal_x_size
int _pal_y_size
int _margin
bool _omit_solitary
double _coverage_threshold
bool _force_power_2
bool _aggressively_clean_mapdir
bool _round_uvs
double _round_unit
double _round_fuzz
RemapUV _remap_uv
RemapUV _remap_char_uv
PNMFileType_color_type
PNMFileType_alpha_type
PNMFileType_shadow_color_type
PNMFileType_shadow_alpha_type

Static Public Attributes

int _pi_version = 10
int _min_pi_version = 8
int _read_pi_version = 0
TypedWritable *const Null

Protected Member Functions

void fillin (DatagramIterator &scan, BamReader *manager)
 Reads the binary data from the given datagram iterator, which was written by a previous call to write_datagram().


Static Protected Member Functions

TypedWritablemake_Palettizer (const FactoryParams &params)
 This method is called by the BamReader when an object of this type is encountered in a Bam file; it should allocate and return a new object with all the data read.


Private Types

typedef pvector< TexturePlacement * > Placements
typedef pmap< string, EggFile * > EggFiles
typedef pvector< EggFile * > CommandLineEggs
typedef pset< TextureImage * > CommandLineTextures
typedef pmap< string, PaletteGroup * > Groups
typedef pmap< string, TextureImage * > Textures

Private Member Functions

void compute_statistics (ostream &out, int indent_level, const Placements &placements) const
 Determines how much memory, etc.


Static Private Member Functions

const char * yesno (bool flag)
 A silly function to return "yes" or "no" based on a bool flag for nicely formatted output.


Private Attributes

EggFiles _egg_files
CommandLineEggs _command_line_eggs
CommandLineTextures _command_line_textures
Groups _groups
Textures _textures
int _num_egg_files
int _num_groups
int _num_textures

Static Private Attributes

TypeHandle _type_handle

Friends

class EggPalettize
class TxaLine

Detailed Description

This is the main engine behind egg-palettize.

It contains all of the program parameters, from the command line or saved from a previous session, and serves as the driving force in the actual palettizing process.

Definition at line 57 of file palettizer.h.


Member Typedef Documentation

typedef pvector<EggFile *> Palettizer::CommandLineEggs [private]
 

Definition at line 134 of file palettizer.h.

typedef pset<TextureImage *> Palettizer::CommandLineTextures [private]
 

Definition at line 137 of file palettizer.h.

typedef pmap<string, EggFile *> Palettizer::EggFiles [private]
 

Definition at line 131 of file palettizer.h.

typedef pmap<string, PaletteGroup *> Palettizer::Groups [private]
 

Definition at line 140 of file palettizer.h.

typedef pvector<TexturePlacement *> Palettizer::Placements [private]
 

Definition at line 127 of file palettizer.h.

typedef pmap<string, TextureImage *> Palettizer::Textures [private]
 

Definition at line 143 of file palettizer.h.


Member Enumeration Documentation

enum Palettizer::RemapUV
 

Enumeration values:
RU_never 
RU_group 
RU_poly 
RU_invalid 

Definition at line 90 of file palettizer.h.

Referenced by get_palette_group().


Constructor & Destructor Documentation

Palettizer::Palettizer  ) 
 

Definition at line 105 of file palettizer.cxx.

References NULL.


Member Function Documentation

void Palettizer::all_params_set  ) 
 

Called after all command line parameters have been set up, this is a hook to do whatever initialization is necessary.

Definition at line 383 of file palettizer.cxx.

References _command_line_eggs, and _txa_file.

int Palettizer::complete_pointers TypedWritable **  p_list,
BamReader manager
[virtual]
 

Called after the object is otherwise completely read from a Bam file, this function's job is to store the pointers that were retrieved from the Bam file for each pointer object written.

The return value is the number of pointers processed from the list.

Reimplemented from TypedWritable.

Definition at line 1067 of file palettizer.cxx.

void Palettizer::compute_statistics ostream &  out,
int  indent_level,
const Placements placements
const [private]
 

Determines how much memory, etc.

is required by the indicated set of texture placements, and reports this to the indicated output stream.

Definition at line 961 of file palettizer.cxx.

References _egg_files.

void Palettizer::fillin DatagramIterator scan,
BamReader manager
[protected]
 

Reads the binary data from the given datagram iterator, which was written by a previous call to write_datagram().

Reimplemented from TypedWritable.

Definition at line 1154 of file palettizer.cxx.

Referenced by register_with_read_factory().

void Palettizer::generate_images bool  redo_all  ) 
 

Actually generates the appropriate palette and unplaced texture images into the map directories.

If redo_all is true, this forces a regeneration of each image file.

Definition at line 657 of file palettizer.cxx.

References _egg_files.

TypeHandle Palettizer::get_class_type void   )  [inline, static]
 

Reimplemented from TypedWritable.

Definition at line 166 of file palettizer.h.

PaletteGroup * Palettizer::get_default_group  ) 
 

Returns the default group to which an egg file should be assigned if it is not mentioned in the .txa file.

Definition at line 867 of file palettizer.cxx.

EggFile * Palettizer::get_egg_file const string &  name  ) 
 

Returns the EggFile with the given name.

If there is no EggFile with the indicated name, creates one. This is the key name used to sort the egg files, which is typically the basename of the filename.

Definition at line 772 of file palettizer.cxx.

References _default_groupdir, _default_groupname, get_palette_group(), PaletteGroup::has_dirname(), and PaletteGroup::set_dirname().

PaletteGroup * Palettizer::get_palette_group const string &  name  ) 
 

Returns the PaletteGroup with the given name.

If there is no PaletteGroup with the indicated name, creates one.

Definition at line 822 of file palettizer.cxx.

References RemapUV, RU_group, RU_invalid, RU_never, and RU_poly.

Referenced by get_egg_file().

TextureImage * Palettizer::get_texture const string &  name  ) 
 

Returns the TextureImage with the given name.

If there is no TextureImage with the indicated name, creates one. This is the key name used to sort the textures, which is typically the basename of the primary filename.

Definition at line 892 of file palettizer.cxx.

References _egg_files, and writer().

virtual TypeHandle Palettizer::get_type void   )  const [inline, virtual]
 

Reimplemented from TypedWritable.

Definition at line 174 of file palettizer.h.

References pal.

void Palettizer::init_type void   )  [inline, static]
 

Reimplemented from TypedWritable.

Definition at line 169 of file palettizer.h.

References _type_handle.

TypedWritable * Palettizer::make_Palettizer const FactoryParams params  )  [static, protected]
 

This method is called by the BamReader when an object of this type is encountered in a Bam file; it should allocate and return a new object with all the data read.

Definition at line 1131 of file palettizer.cxx.

void Palettizer::optimal_resize  ) 
 

Attempts to resize each PalettteImage down to its smallest possible size.

Definition at line 613 of file palettizer.cxx.

void Palettizer::process_all bool  force_texture_read,
const Filename state_filename
 

Reprocesses all textures known.

If force_texture_read is true, it forces each texture image file to be read (and thus legitimately checked for grayscaleness etc.) before placing.

Definition at line 514 of file palettizer.cxx.

void Palettizer::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 or whatever needs to be done with them.

If force_texture_read is true, it forces each texture image file to be read (and thus legitimately checked for grayscaleness etc.) before placing.

Definition at line 413 of file palettizer.cxx.

References TextureImage::read_source_image().

bool Palettizer::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, so that it may be updated and written out when write_eggs() is called.

If redo_all is true, this even reads egg files that were not flagged as stale.

Returns true if successful, or false if there was some error.

Definition at line 694 of file palettizer.cxx.

References _egg_files, and Namable::set_name().

void Palettizer::read_txa_file const Filename txa_filename  ) 
 

Reads in the .txa file and keeps it ready for matching textures and egg files.

Definition at line 323 of file palettizer.cxx.

References nout.

void Palettizer::register_with_read_factory void   )  [static]
 

Registers the current object as something that can be read from a Bam file.

Definition at line 985 of file palettizer.cxx.

References fillin(), params, and parse_params().

bool Palettizer::remove_egg_file const string &  name  ) 
 

Removes the named egg file from the database, if it exists.

Returns true if the egg file was found, false if it was not.

Definition at line 797 of file palettizer.cxx.

References _textures.

void Palettizer::report_pi  )  const
 

Output a verbose description of all the palettization information to standard output, for the user's perusal.

Definition at line 139 of file palettizer.cxx.

References _coverage_threshold, _map_dirname, _margin, _pal_x_size, _pal_y_size, _round_fuzz, and _round_unit.

void Palettizer::report_statistics  )  const
 

Output a report of the palettization effectiveness, texture memory utilization, and so on.

Definition at line 261 of file palettizer.cxx.

void Palettizer::reset_images  ) 
 

Throws away all of the current PaletteImages, so that new ones may be created (and the packing made more optimal).

Definition at line 634 of file palettizer.cxx.

References _egg_files.

Palettizer::RemapUV Palettizer::string_remap const string &  str  )  [static]
 

Returns the RemapUV code corresponding to the indicated string, or RU_invalid if the string is invalid.

Definition at line 933 of file palettizer.cxx.

References _alpha_type, _color_type, _num_egg_files, _shadow_alpha_type, _shadow_color_type, TypedWritable::complete_pointers(), DCAST_INTO_R, and NULL.

Referenced by TxaFile::parse_shadowtype_line().

PaletteGroup * Palettizer::test_palette_group const string &  name  )  const
 

Returns the PaletteGroup with the given name.

If there is no PaletteGroup with the indicated name, returns NULL.

Definition at line 847 of file palettizer.cxx.

References TextureMemoryCounter::add_placement(), and TextureMemoryCounter::report().

void Palettizer::write_datagram BamWriter writer,
Datagram datagram
[virtual]
 

Fills the indicated datagram up with a binary representation of the current object, in preparation for writing to a Bam file.

Reimplemented from TypedWritable.

Definition at line 1003 of file palettizer.cxx.

References _aggressively_clean_mapdir, _coverage_threshold, _force_power_2, _map_dirname, _margin, _omit_solitary, _pal_x_size, _pal_y_size, _read_pi_version, _rel_dirname, _remap_char_uv, _remap_uv, _round_fuzz, _round_unit, _round_uvs, _shadow_dirname, TypedWritable::fillin(), FilenameUnifier::get_bam_filename(), DatagramIterator::get_bool(), DatagramIterator::get_float64(), DatagramIterator::get_int32(), DatagramIterator::get_string(), BamReader::read_pointer(), BamReader::read_pointers(), and FilenameUnifier::set_rel_dirname().

bool Palettizer::write_eggs  ) 
 

Adjusts the egg files to reference the newly generated textures, and writes them out.

Returns true if successful, or false if there was some error.

Definition at line 740 of file palettizer.cxx.

const char * Palettizer::yesno bool  flag  )  [static, private]
 

A silly function to return "yes" or "no" based on a bool flag for nicely formatted output.

Definition at line 916 of file palettizer.cxx.

References writer().


Friends And Related Function Documentation

friend class EggPalettize [friend]
 

Definition at line 181 of file palettizer.h.

friend class TxaLine [friend]
 

Definition at line 182 of file palettizer.h.


Member Data Documentation

bool Palettizer::_aggressively_clean_mapdir
 

Definition at line 116 of file palettizer.h.

Referenced by write_datagram().

PNMFileType* Palettizer::_alpha_type
 

Definition at line 122 of file palettizer.h.

Referenced by string_remap().

PNMFileType* Palettizer::_color_type
 

Definition at line 121 of file palettizer.h.

Referenced by string_remap().

CommandLineEggs Palettizer::_command_line_eggs [private]
 

Definition at line 135 of file palettizer.h.

Referenced by all_params_set().

CommandLineTextures Palettizer::_command_line_textures [private]
 

Definition at line 138 of file palettizer.h.

double Palettizer::_coverage_threshold
 

Definition at line 114 of file palettizer.h.

Referenced by report_pi(), and write_datagram().

string Palettizer::_default_groupdir
 

Definition at line 103 of file palettizer.h.

Referenced by get_egg_file().

string Palettizer::_default_groupname
 

Definition at line 102 of file palettizer.h.

Referenced by get_egg_file().

EggFiles Palettizer::_egg_files [private]
 

Definition at line 132 of file palettizer.h.

Referenced by compute_statistics(), generate_images(), get_texture(), read_stale_eggs(), and reset_images().

bool Palettizer::_force_power_2
 

Definition at line 115 of file palettizer.h.

Referenced by write_datagram().

Groups Palettizer::_groups [private]
 

Definition at line 141 of file palettizer.h.

string Palettizer::_map_dirname
 

Definition at line 108 of file palettizer.h.

Referenced by ImageFile::get_properties(), report_pi(), and write_datagram().

int Palettizer::_margin
 

Definition at line 112 of file palettizer.h.

Referenced by report_pi(), and write_datagram().

int Palettizer::_min_pi_version = 8 [static]
 

Definition at line 52 of file palettizer.cxx.

int Palettizer::_num_egg_files [private]
 

Definition at line 161 of file palettizer.h.

Referenced by string_remap().

int Palettizer::_num_groups [private]
 

Definition at line 162 of file palettizer.h.

int Palettizer::_num_textures [private]
 

Definition at line 163 of file palettizer.h.

bool Palettizer::_omit_solitary
 

Definition at line 113 of file palettizer.h.

Referenced by write_datagram().

int Palettizer::_pal_x_size
 

Definition at line 111 of file palettizer.h.

Referenced by report_pi(), and write_datagram().

int Palettizer::_pal_y_size
 

Definition at line 111 of file palettizer.h.

Referenced by report_pi(), and write_datagram().

int Palettizer::_pi_version = 10 [static]
 

Definition at line 47 of file palettizer.cxx.

int Palettizer::_read_pi_version = 0 [static]
 

Definition at line 55 of file palettizer.cxx.

Referenced by EggFile::remove_backstage(), TextureProperties::union_filter(), ImageFile::unlink(), and write_datagram().

Filename Palettizer::_rel_dirname
 

Definition at line 110 of file palettizer.h.

Referenced by write_datagram().

RemapUV Palettizer::_remap_char_uv
 

Definition at line 120 of file palettizer.h.

Referenced by TxaFile::parse_shadowtype_line(), and write_datagram().

RemapUV Palettizer::_remap_uv
 

Definition at line 120 of file palettizer.h.

Referenced by TxaFile::parse_shadowtype_line(), and write_datagram().

double Palettizer::_round_fuzz
 

Definition at line 119 of file palettizer.h.

Referenced by TexturePlacement::determine_size(), report_pi(), and write_datagram().

double Palettizer::_round_unit
 

Definition at line 118 of file palettizer.h.

Referenced by TexturePlacement::determine_size(), report_pi(), and write_datagram().

bool Palettizer::_round_uvs
 

Definition at line 117 of file palettizer.h.

Referenced by write_datagram().

PNMFileType* Palettizer::_shadow_alpha_type
 

Definition at line 124 of file palettizer.h.

Referenced by TxaFile::parse_coverage_line(), and string_remap().

PNMFileType* Palettizer::_shadow_color_type
 

Definition at line 123 of file palettizer.h.

Referenced by TxaFile::parse_coverage_line(), and string_remap().

Filename Palettizer::_shadow_dirname
 

Definition at line 109 of file palettizer.h.

Referenced by write_datagram().

Textures Palettizer::_textures [private]
 

Definition at line 144 of file palettizer.h.

Referenced by remove_egg_file().

TxaFile Palettizer::_txa_file
 

Definition at line 101 of file palettizer.h.

Referenced by all_params_set().

TypeHandle Palettizer::_type_handle [static, private]
 

Reimplemented from TypedWritable.

Definition at line 57 of file palettizer.cxx.

Referenced by init_type().


The documentation for this class was generated from the following files:
Generated on Fri May 2 03:27:46 2003 for Panda-Tool by doxygen1.3