Panda3D
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Friends | List of all members
Palettizer Class Reference

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

#include "palettizer.h"

Inheritance diagram for Palettizer:
TypedWritable TypedObject MemoryBase

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. More...
 
void all_params_set ()
 Called after all command line parameters have been set up, this is a hook to do whatever initialization is necessary. More...
 
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. More...
 
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. More...
 
void generate_images (bool redo_all)
 Actually generates the appropriate palette and unplaced texture images into the map directories. More...
 
PaletteGroupget_default_group ()
 Returns the default group to which an egg file should be assigned if it is not mentioned in the .txa file. More...
 
EggFileget_egg_file (const string &name)
 Returns the EggFile with the given name. More...
 
bool get_noabs () const
 Returns the current setting of the noabs flag. More...
 
PaletteGroupget_palette_group (const string &name)
 Returns the PaletteGroup with the given name. More...
 
TextureImageget_texture (const string &name)
 Returns the TextureImage with the given name. More...
 
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. More...
 
void optimal_resize ()
 Attempts to resize each PalettteImage down to its smallest possible size. More...
 
void process_all (bool force_texture_read, const Filename &state_filename)
 Reprocesses all textures known. More...
 
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. More...
 
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. More...
 
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. More...
 
bool remove_egg_file (const string &name)
 Removes the named egg file from the database, if it exists. More...
 
void report_pi () const
 Output a verbose description of all the palettization information to standard output, for the user's perusal. More...
 
void report_statistics () const
 Output a report of the palettization effectiveness, texture memory utilization, and so on. More...
 
void reset_images ()
 Throws away all of the current PaletteImages, so that new ones may be created (and the packing made more optimal). More...
 
void set_noabs (bool noabs)
 Changes the current setting of the noabs flag. More...
 
PaletteGrouptest_palette_group (const string &name) const
 Returns the PaletteGroup with the given name. More...
 
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. More...
 
bool write_eggs ()
 Adjusts the egg files to reference the newly generated textures, and writes them out. More...
 
- Public Member Functions inherited from TypedWritable
 TypedWritable (const TypedWritable &copy)
 
virtual ReferenceCountas_reference_count ()
 Returns the pointer cast to a ReferenceCount pointer, if it is in fact of that type. More...
 
string encode_to_bam_stream () const
 Converts the TypedWritable object into a single stream of data using a BamWriter, and returns that data as a string string. More...
 
bool encode_to_bam_stream (string &data, BamWriter *writer=NULL) const
 Converts the TypedWritable object into a single stream of data using a BamWriter, and stores that data in the indicated string. More...
 
virtual TypeHandle force_init_type ()
 
UpdateSeq get_bam_modified () const
 Returns the current bam_modified counter. More...
 
void mark_bam_modified ()
 Increments the bam_modified counter, so that this object will be invalidated and retransmitted on any open bam streams. More...
 
void operator= (const TypedWritable &copy)
 
virtual bool require_fully_complete () const
 Some objects require all of their nested pointers to have been completed before the objects themselves can be completed. More...
 
virtual void update_bam_nested (BamWriter *manager)
 Called by the BamWriter when this object has not itself been modified recently, but it should check its nested objects for updates. More...
 
- Public Member Functions inherited from TypedObject
 TypedObject (const TypedObject &copy)
 
TypedObjectas_typed_object ()
 Returns the object, upcast (if necessary) to a TypedObject pointer. More...
 
const TypedObjectas_typed_object () const
 Returns the object, upcast (if necessary) to a TypedObject pointer. More...
 
int get_best_parent_from_Set (const std::set< int > &) const
 
int get_type_index () const
 Returns the internal index number associated with this object's TypeHandle, a unique number for each different type. More...
 
bool is_exact_type (TypeHandle handle) const
 Returns true if the current object is the indicated type exactly. More...
 
bool is_of_type (TypeHandle handle) const
 Returns true if the current object is or derives from the indicated type. More...
 
void operator= (const TypedObject &copy)
 

Static Public Member Functions

static TypeHandle get_class_type ()
 
static void init_type ()
 
static void register_with_read_factory ()
 Registers the current object as something that can be read from a Bam file. More...
 
static RemapUV string_remap (const string &str)
 Returns the RemapUV code corresponding to the indicated string, or RU_invalid if the string is invalid. More...
 
- Static Public Member Functions inherited from TypedWritable
static bool decode_raw_from_bam_stream (TypedWritable *&ptr, ReferenceCount *&ref_ptr, const string &data, BamReader *reader=NULL)
 Reads the string created by a previous call to encode_to_bam_stream(), and extracts the single object on that string. More...
 
static TypeHandle get_class_type ()
 
static void init_type ()
 
- Static Public Member Functions inherited from TypedObject
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. More...
 

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
 
- Static Public Attributes inherited from TypedWritable
static TypedWritable *const Null = (TypedWritable*)0L
 

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

◆ add_command_line_egg()

void Palettizer::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.

These will be processed by process_command_line_eggs().

Definition at line 836 of file palettizer.cxx.

References get_palette_group().

Referenced by EggPalettize::handle_args(), and remove_egg_file().

◆ all_params_set()

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

References process_command_line_eggs(), and PaletteGroup::setup_shadow_images().

Referenced by EggPalettize::handle_args(), and read_txa_file().

◆ complete_pointers()

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.

References TypedWritable::complete_pointers(), and finalize().

Referenced by write_datagram().

◆ finalize()

void Palettizer::finalize ( BamReader manager)
virtual

◆ generate_images()

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(), read_stale_eggs(), and PaletteGroup::update_images().

Referenced by EggPalettize::handle_args(), and reset_images().

◆ get_default_group()

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

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

Referenced by EggFile::from_command_line(), and test_palette_group().

◆ get_egg_file()

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.

References remove_egg_file().

Referenced by EggPalettize::handle_args(), and write_eggs().

◆ get_noabs()

bool Palettizer::get_noabs ( ) const

Returns the current setting of the noabs flag.

See set_noabs().

Definition at line 144 of file palettizer.cxx.

References set_noabs().

◆ get_palette_group()

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.

References test_palette_group().

Referenced by add_command_line_egg(), and TxaFile::write().

◆ get_texture()

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.

References string_remap().

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

◆ is_valid()

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.

References report_pi().

Referenced by EggPalettize::handle_args(), and set_noabs().

◆ optimal_resize()

void Palettizer::optimal_resize ( )

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

Definition at line 636 of file palettizer.cxx.

References PaletteGroup::optimal_resize(), and reset_images().

Referenced by EggPalettize::handle_args(), and process_all().

◆ process_all()

void Palettizer::process_all ( bool  force_texture_read,
const Filename state_filename 
)

◆ process_command_line_eggs()

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(), PaletteGroup::place_all(), EggFile::post_txa_file(), TextureImage::post_txa_file(), EggFile::pre_txa_file(), TextureImage::pre_txa_file(), process_all(), TextureImage::read_header(), TextureImage::read_source_image(), EggFile::scan_textures(), and PaletteGroup::update_unknown_textures().

Referenced by all_params_set(), and EggPalettize::handle_args().

◆ read_stale_eggs()

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(), Filename::exists(), 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(), Filename::unlink(), and write_eggs().

Referenced by generate_images(), and EggPalettize::handle_args().

◆ read_txa_file()

void Palettizer::read_txa_file ( istream &  txa_file,
const string &  txa_filename 
)

◆ register_with_read_factory()

void Palettizer::register_with_read_factory ( )
static

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 write_datagram().

Referenced by string_remap().

◆ remove_egg_file()

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 add_command_line_egg(), and EggFile::remove_egg().

Referenced by get_egg_file(), and EggPalettize::handle_args().

◆ report_pi()

void Palettizer::report_pi ( ) const

◆ report_statistics()

void Palettizer::report_statistics ( ) 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(), read_txa_file(), and PaletteGroups::size().

Referenced by EggPalettize::handle_args(), and report_pi().

◆ reset_images()

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

References generate_images(), and PaletteGroup::reset_images().

Referenced by EggPalettize::handle_args(), and optimal_resize().

◆ set_noabs()

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.

References is_valid().

Referenced by get_noabs(), and EggPalettize::handle_args().

◆ string_remap()

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.

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

Referenced by get_texture(), and TxaFile::write().

◆ test_palette_group()

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.

References get_default_group().

Referenced by get_palette_group(), and TxaLine::parse().

◆ write_datagram()

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(), complete_pointers(), FilenameUnifier::make_bam_filename(), TypedWritable::write_datagram(), and BamWriter::write_pointer().

Referenced by register_with_read_factory().

◆ write_eggs()

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

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

Referenced by EggPalettize::handle_args(), and read_stale_eggs().


The documentation for this class was generated from the following files: