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:

## 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...
PaletteGroup * | get_default_group ()
| Returns the default group to which an egg file should be assigned if it is not mentioned in the .txa file. More...
EggFile * | get_egg_file (const std::string &name)
| Returns the EggFile with the given name. More...
bool | get_noabs () const
| Returns the current setting of the noabs flag. More...
PaletteGroup * | get_palette_group (const std::string &name)
| Returns the PaletteGroup with the given name. More...
TextureImage * | get_texture (const std::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 (std::istream &txa_file, const std::string &txa_filename)
| Reads in the .txa file and keeps it ready for matching textures and egg files. More...
bool | remove_egg_file (const std::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...
PaletteGroup * | test_palette_group (const std::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 ReferenceCount * | as_reference_count ()
| Returns the pointer cast to a ReferenceCount pointer, if it is in fact of that type. More...
vector_uchar | encode_to_bam_stream () const
| Converts the TypedWritable object into a single stream of data using a BamWriter, and returns that data as a bytes object. More...
bool | encode_to_bam_stream (vector_uchar &data, BamWriter *writer=nullptr) 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)=default
TypedObject * | as_typed_object ()
| Returns the object, upcast (if necessary) to a TypedObject pointer. More...
const TypedObject * | as_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...
TypedObject & | operator= (const TypedObject &copy)=default
Public Member Functions inherited from MemoryBase
void | operator delete (void *, void *)
void | operator delete (void *ptr)
void | operator delete[] (void *, void *)
void | operator delete[] (void *ptr)
void * | operator new (size_t size)
void * | operator new (size_t size, void *ptr)
void * | operator new[] (size_t size)
void * | operator new[] (size_t size, void *ptr)

## 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 std::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, vector_uchar data, BamReader *reader=nullptr)
| Reads the bytes created by a previous call to encode_to_bam_stream(), and extracts the single object on those bytes. 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
std::string | _default_groupdir
std::string | _default_groupname
bool | _force_power_2
std::string | _generated_image_pattern
bool | _is_valid
std::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
Public Attributes inherited from TypedObject
| get_type

## 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 = nullptr

## 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 39 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 783 of file palettizer.cxx.

## ◆ 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 405 of file palettizer.cxx.

References PaletteGroup::setup_shadow_images().

## ◆ 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 983 of file palettizer.cxx.

References TypedWritable::complete_pointers().

## ◆ finalize()

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

References downcase().

## ◆ 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 632 of file palettizer.cxx.

References TextureImage::copy_unplaced(), and PaletteGroup::update_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 823 of file palettizer.cxx.

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

## ◆ get_egg_file()

EggFile * Palettizer::get_egg_file | ( | const std::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 748 of file palettizer.cxx.

## ◆ get_noabs()

bool Palettizer::get_noabs | ( |  | ) | const

Returns the current setting of the noabs flag.

See set_noabs().

Definition at line 142 of file palettizer.cxx.

## ◆ get_palette_group()

PaletteGroup * Palettizer::get_palette_group | ( | const std::string & | name | ) |

Returns the PaletteGroup with the given name.

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

Definition at line 792 of file palettizer.cxx.

Referenced by get_default_group().

## ◆ get_texture()

TextureImage * Palettizer::get_texture | ( | const std::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 837 of file palettizer.cxx.

References downcase().

## ◆ 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 166 of file palettizer.cxx.

## ◆ optimal_resize()

void Palettizer::optimal_resize | ( |  | ) |

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

Definition at line 605 of file palettizer.cxx.

References PaletteGroup::optimal_resize().

## ◆ process_all()

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

References TextureImage::assign_groups(), TextureImage::clear_source_basic_properties(), 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_source_image(), TextureImage::release_source_image(), EggFile::scan_textures(), and PaletteGroup::update_unknown_textures().

## ◆ 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 422 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().

## ◆ 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 655 of file palettizer.cxx.

## ◆ read_txa_file()

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

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

## ◆ 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 912 of file palettizer.cxx.

References BamReader::get_factory().

Referenced by init_palettizer().

## ◆ remove_egg_file()

bool Palettizer::remove_egg_file | ( | const std::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 765 of file palettizer.cxx.

References EggFile::remove_egg().

## ◆ report_pi()

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

References PaletteGroup::get_groups(), PNMFileType::get_suggested_extension, EggFile::is_surprise(), TextureImage::is_surprise(), TextureImage::is_used(), FilenameUnifier::make_user_filename(), EggFile::write_description(), PaletteGroup::write_image_info(), TextureImage::write_scale_info(), TextureImage::write_source_pathnames(), and EggFile::write_texture_refs().

## ◆ report_statistics()

void Palettizer::report_statistics | ( |  | ) | const

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

Definition at line 296 of file palettizer.cxx.

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

## ◆ 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 618 of file palettizer.cxx.

References PaletteGroup::reset_images().

## ◆ 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 157 of file palettizer.cxx.

## ◆ string_remap()

Palettizer::RemapUV Palettizer::string_remap | ( | const std::string & | str | ) |
| static

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

Definition at line 875 of file palettizer.cxx.

## ◆ test_palette_group()

PaletteGroup * Palettizer::test_palette_group | ( | const std::string & | name | ) | const

Returns the PaletteGroup with the given name.

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

Definition at line 809 of file palettizer.cxx.

## ◆ 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 922 of file palettizer.cxx.

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

## ◆ 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 713 of file palettizer.cxx.

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

- pandatool/src/palettizer/palettizer.h
- pandatool/src/palettizer/palettizer.cxx