Panda3D
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Friends
Palettizer Class Reference

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

#include "palettizer.h"

Inheritance diagram for Palettizer:
TypedWritable TypedObject MemoryBase

List of all members.

Public Types

enum  RemapUV { RU_never, RU_group, RU_poly, RU_invalid }

Public Member Functions

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 line.
void all_params_set ()
 Called after all command line parameters have been set up, this is a hook to do whatever initialization is necessary.
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 void finalize (BamReader *manager)
 Called by the BamReader to perform any final actions needed for setting up the object after all objects have been read and all pointers have been completed.
void generate_images (bool redo_all)
 Actually generates the appropriate palette and unplaced texture images into the map directories.
PaletteGroupget_default_group ()
 Returns the default group to which an egg file should be assigned if it is not mentioned in the .txa file.
EggFileget_egg_file (const string &name)
 Returns the EggFile with the given name.
bool get_noabs () const
 Returns the current setting of the noabs flag.
PaletteGroupget_palette_group (const string &name)
 Returns the PaletteGroup with the given name.
TextureImageget_texture (const string &name)
 Returns the TextureImage with the given name.
virtual TypeHandle get_type () const
bool is_valid () const
 Returns true if the palette information file was read correctly, or false if there was some error and the palettization can't continue.
void optimal_resize ()
 Attempts to resize each PalettteImage down to its smallest possible size.
void process_all (bool force_texture_read, const Filename &state_filename)
 Reprocesses all textures known.
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.
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.
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.
bool remove_egg_file (const string &name)
 Removes the named egg file from the database, if it exists.
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 reset_images ()
 Throws away all of the current PaletteImages, so that new ones may be created (and the packing made more optimal).
void set_noabs (bool noabs)
 Changes the current setting of the noabs flag.
PaletteGrouptest_palette_group (const string &name) const
 Returns the PaletteGroup 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.
bool write_eggs ()
 Adjusts the egg files to reference the newly generated textures, and writes them out.

Static Public Member Functions

static TypeHandle get_class_type ()
static void init_type ()
 This function is declared non-inline to work around a compiler bug in g++ 2.96.
static void register_with_read_factory ()
 Registers the current object as something that can be read from a Bam file.
static RemapUV string_remap (const string &str)
 Returns the RemapUV code corresponding to the indicated string, or RU_invalid if the string is invalid.

Public Attributes

bool _aggressively_clean_mapdir
PNMFileType_alpha_type
LColord _background
PNMFileType_color_type
double _coverage_threshold
EggRenderMode::AlphaMode _cutout_mode
double _cutout_ratio
string _default_groupdir
string _default_groupname
bool _force_power_2
string _generated_image_pattern
bool _is_valid
string _map_dirname
int _margin
bool _noabs
bool _omit_everything
bool _omit_solitary
int _pal_x_size
int _pal_y_size
Filename _rel_dirname
RemapUV _remap_char_uv
RemapUV _remap_uv
double _round_fuzz
double _round_unit
bool _round_uvs
PNMFileType_shadow_alpha_type
PNMFileType_shadow_color_type
Filename _shadow_dirname
TxaFile _txa_file

Static Public Attributes

static int _min_pi_version = 8
static int _pi_version = 20
static int _read_pi_version = 0

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

static 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.

Friends

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 43 of file palettizer.h.


Member Function Documentation

Adds the indicated EggFile to the list of eggs that are considered to have been read on the command line.

These will be processed by process_command_line_eggs().

Definition at line 836 of file palettizer.cxx.

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

Definition at line 423 of file palettizer.cxx.

References PaletteGroup::setup_shadow_images().

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 1066 of file palettizer.cxx.

void Palettizer::fillin ( DatagramIterator scan,
BamReader manager 
) [protected, virtual]
void Palettizer::finalize ( BamReader manager) [virtual]

Called by the BamReader to perform any final actions needed for setting up the object after all objects have been read and all pointers have been completed.

Reimplemented from TypedWritable.

Definition at line 1129 of file palettizer.cxx.

References TextureImage::is_used().

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 669 of file palettizer.cxx.

References TextureImage::copy_unplaced(), and PaletteGroup::update_images().

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

Definition at line 884 of file palettizer.cxx.

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

Referenced by EggFile::from_command_line().

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 795 of file palettizer.cxx.

bool Palettizer::get_noabs ( ) const

Returns the current setting of the noabs flag.

See set_noabs().

Definition at line 144 of file palettizer.cxx.

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 848 of file palettizer.cxx.

Referenced by get_default_group().

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 902 of file palettizer.cxx.

Referenced by TextureReference::from_egg(), and PaletteGroup::prepare().

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

This function is declared non-inline to work around a compiler bug in g++ 2.96.

Making it inline seems to cause problems in the optimizer.

Reimplemented from TypedWritable.

Definition at line 173 of file palettizer.h.

bool Palettizer::is_valid ( ) const

Returns true if the palette information file was read correctly, or false if there was some error and the palettization can't continue.

Definition at line 175 of file palettizer.cxx.

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 1189 of file palettizer.cxx.

References fillin(), and BamReader::register_finalize().

Referenced by register_with_read_factory().

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

Definition at line 636 of file palettizer.cxx.

References PaletteGroup::optimal_resize().

void Palettizer::process_all ( bool  force_texture_read,
const Filename state_filename 
)
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 444 of file palettizer.cxx.

References TextureImage::assign_groups(), TextureImage::determine_placement_size(), EggFile::get_textures(), TextureImage::is_newer_than(), TextureImage::mark_texture_named(), TxaFile::match_egg(), TxaFile::match_texture(), PaletteGroup::place_all(), EggFile::post_txa_file(), TextureImage::post_txa_file(), EggFile::pre_txa_file(), TextureImage::pre_txa_file(), TextureImage::read_header(), TextureImage::read_source_image(), EggFile::scan_textures(), and PaletteGroup::update_unknown_textures().

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 696 of file palettizer.cxx.

References EggFile::choose_placements(), EggFile::get_source_filename(), EggFile::had_data(), EggFile::is_stale(), FilenameUnifier::make_user_filename(), EggFile::read_egg(), EggFile::release_egg_data(), EggFile::remove_egg(), EggFile::scan_textures(), and Filename::unlink().

void Palettizer::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 at line 367 of file palettizer.cxx.

References PaletteGroup::clear_depends(), TxaFile::read(), PaletteGroup::reset_dependency_level(), PaletteGroup::set_dependency_level(), PaletteGroup::set_dependency_order(), and PaletteGroup::set_dirname().

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

Definition at line 988 of file palettizer.cxx.

References BamReader::get_factory(), and make_Palettizer().

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 815 of file palettizer.cxx.

References EggFile::remove_egg().

void Palettizer::report_pi ( ) const

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

Definition at line 309 of file palettizer.cxx.

References PaletteGroup::get_complete_placements(), PaletteGroup::get_groups(), PaletteGroup::get_placements(), PaletteGroups::make_complete(), and PaletteGroups::size().

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

Definition at line 652 of file palettizer.cxx.

References PaletteGroup::reset_images().

void Palettizer::set_noabs ( bool  noabs)

Changes the current setting of the noabs flag.

If this flag is true, then it is an error to process an egg file that contains absolute pathname references. This flag is intended to help detect egg files that are incorrectly built within a model tree (which should use entirely relative pathnames).

This flag must be set before any egg files are processed.

Definition at line 163 of file palettizer.cxx.

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 945 of file palettizer.cxx.

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 868 of file palettizer.cxx.

Referenced by TxaLine::parse().

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 1001 of file palettizer.cxx.

References Datagram::add_bool(), Datagram::add_float64(), Datagram::add_int32(), Datagram::add_string(), Datagram::add_uint8(), FilenameUnifier::make_bam_filename(), and BamWriter::write_pointer().

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 757 of file palettizer.cxx.

References EggFile::had_data(), EggFile::has_data(), EggFile::read_egg(), EggFile::release_egg_data(), EggFile::update_egg(), and EggFile::write_egg().


The documentation for this class was generated from the following files:
 All Classes Functions Variables Enumerations