Panda3D
|
This is a single palette image, one of several within a PalettePage, which is in turn one of several pages within a PaletteGroup. More...
#include "paletteImage.h"
Public Member Functions | |
PaletteImage (PalettePage *page, int index) | |
PaletteImage (PalettePage *page, int index, unsigned swapIndex) | |
void | check_solitary () |
To be called after all textures have been placed on the image, this checks to see if there is only one texture on the image. 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... | |
double | count_coverage () const |
Returns the a weighted average of the fraction of coverage represented by all of the textures placed on the palette. More... | |
double | count_utilization () const |
Returns the fraction of the PaletteImage that is actually used by any textures. More... | |
PalettePage * | get_page () const |
Returns the particular PalettePage this image is associated with. More... | |
virtual TypeHandle | get_type () const |
bool | is_empty () const |
Returns true if there are no textures, or only one "solitary" texture, placed on the image. More... | |
void | optimal_resize () |
Attempts to resize the palette image to as small as it can go. More... | |
bool | place (TexturePlacement *placement) |
Attempts to place the indicated texture on the image. More... | |
void | reset_image () |
Unpacks each texture that has been placed on this image, resetting the image to empty. More... | |
bool | resize_image (int x_size, int y_size) |
Attempts to resize the palette image, and repack all of the textures within the new size. More... | |
void | resize_swapped_image (int x_size, int y_size) |
Attempts to resize the palette image, and repack all of the textures within the new size. More... | |
void | setup_shadow_image () |
Ensures the _shadow_image has the correct filename and image types, based on what was supplied on the command line and in the .txa file. More... | |
void | unplace (TexturePlacement *placement) |
Removes the texture from the image. More... | |
bool | update_filename () |
Changes the image filename to match the current naming scheme, assuming something has changed since the image was created. More... | |
void | update_image (bool redo_all) |
If the palette has changed since it was last written out, updates the image and writes out a new one. 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... | |
void | write_placements (ostream &out, int indent_level=0) const |
Writes a list of the textures that have been placed on this image to the indicated output stream, one per line. More... | |
![]() | |
void | clear_basic_properties () |
Resets the properties to a neutral state, for instance in preparation for calling update_properties() with all the known contributing properties. More... | |
bool | exists () const |
Returns true if the file or files named by the image file exist, false otherwise. More... | |
int | get_alpha_file_channel () const |
Returns the particular channel number of the alpha image file from which the alpha channel should be extracted. More... | |
const Filename & | get_alpha_filename () const |
Returns the alpha filename of the image file. More... | |
const Filename & | get_filename () const |
Returns the primary filename of the image file. More... | |
int | get_num_channels () const |
Returns the number of channels of the image. More... | |
const TextureProperties & | get_properties () const |
Returns the grouping properties of the image. More... | |
int | get_x_size () const |
Returns the size of the image file in pixels in the X direction. More... | |
int | get_y_size () const |
Returns the size of the image file in pixels in the Y direction. More... | |
bool | has_num_channels () const |
Returns true if the number of channels in the image is known, false otherwise. More... | |
bool | is_size_known () const |
Returns true if the size of the image file is known, false otherwise. More... | |
bool | make_shadow_image (const string &basename) |
Sets up the ImageFile as a "shadow image" of a particular PaletteImage. More... | |
void | output_filename (ostream &out) const |
Writes the filename (or pair of filenames) to the indicated output stream. More... | |
bool | read (PNMImage &image) const |
Reads in the image (or images, if the alpha_filename is separate) and stores it in the indicated PNMImage. More... | |
bool | set_filename (PaletteGroup *group, const string &basename) |
Sets the filename, and if applicable, the alpha_filename, from the indicated basename. More... | |
bool | set_filename (const string &dirname, const string &basename) |
Sets the filename, and if applicable, the alpha_filename, from the indicated basename. More... | |
void | unlink () |
Deletes the image file or files. More... | |
void | update_egg_tex (EggTexture *egg_tex) const |
Sets the indicated EggTexture to refer to this file. More... | |
void | update_properties (const TextureProperties &properties) |
If the indicate TextureProperties structure is more specific than this one, updates this one. More... | |
bool | write (const PNMImage &image) const |
Writes out the image in the indicated PNMImage to the _filename and/or _alpha_filename. More... | |
![]() | |
TypedWritable (const TypedWritable ©) | |
virtual ReferenceCount * | as_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 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... | |
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 ©) |
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... | |
![]() | |
TypedObject (const TypedObject ©) | |
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... | |
void | operator= (const TypedObject ©) |
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 TypeHandle | get_class_type () |
static void | init_type () |
![]() | |
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 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... | |
Additional Inherited Members | |
![]() | |
static TypedWritable *const | Null = (TypedWritable*)0L |
This is a single palette image, one of several within a PalettePage, which is in turn one of several pages within a PaletteGroup.
Each palette image is a collage of several different textures that were all assigned to the same PaletteGroup, and all share the same properties of the PalettePage.
Definition at line 36 of file paletteImage.h.
void PaletteImage::check_solitary | ( | ) |
To be called after all textures have been placed on the image, this checks to see if there is only one texture on the image.
If there is, it is flagged as 'solitary' so that the egg files will not needlessly reference the palettized image.
However, if pal->_omit_solitary is false, we generally don't change textures to solitary state.
Definition at line 369 of file paletteImage.cxx.
References TexturePlacement::get_omit_reason(), TexturePlacement::not_solitary(), TexturePlacement::omit_solitary(), and optimal_resize().
Referenced by PalettePage::place_all(), and unplace().
|
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 ImageFile.
Definition at line 1121 of file paletteImage.cxx.
References ImageFile::complete_pointers(), DatagramIterator::get_bool(), DatagramIterator::get_string(), DatagramIterator::get_uint32(), BamReader::read_pointer(), and BamReader::read_pointers().
Referenced by write_datagram().
double PaletteImage::count_coverage | ( | ) | const |
Returns the a weighted average of the fraction of coverage represented by all of the textures placed on the palette.
This number represents the fraction of wasted pixels in the palette image consumed by copying the same pixels multiple times into the palette, or if the number is negative, it represents the fraction of pixels saved by not having to copy the entire texture into the palette.
Definition at line 281 of file paletteImage.cxx.
References TexturePlacement::get_placed_x_size(), TexturePlacement::get_placed_y_size(), TexturePlacement::get_texture(), ImageFile::get_x_size(), ImageFile::get_y_size(), and place().
Referenced by count_utilization(), and TextureMemoryCounter::report().
double PaletteImage::count_utilization | ( | ) | const |
Returns the fraction of the PaletteImage that is actually used by any textures.
This is 1.0 if every pixel in the PaletteImage is used, or 0.0 if none are. Normally it will be somewhere in between.
Definition at line 250 of file paletteImage.cxx.
References count_coverage(), TexturePlacement::get_placed_x_size(), and TexturePlacement::get_placed_y_size().
Referenced by is_empty(), and TextureMemoryCounter::report().
PalettePage * PaletteImage::get_page | ( | ) | const |
Returns the particular PalettePage this image is associated with.
Definition at line 212 of file paletteImage.cxx.
References is_empty().
bool PaletteImage::is_empty | ( | ) | const |
Returns true if there are no textures, or only one "solitary" texture, placed on the image.
In either case, the PaletteImage need not be generated.
Definition at line 224 of file paletteImage.cxx.
References count_utilization().
Referenced by get_page(), and PalettePage::write_image_info().
void PaletteImage::optimal_resize | ( | ) |
Attempts to resize the palette image to as small as it can go.
Definition at line 410 of file paletteImage.cxx.
References FilenameUnifier::make_user_filename(), resize_image(), and resize_swapped_image().
Referenced by check_solitary(), and PalettePage::optimal_resize().
bool PaletteImage::place | ( | TexturePlacement * | placement | ) |
Attempts to place the indicated texture on the image.
Returns true if successful, or false if there was no available space.
Definition at line 313 of file paletteImage.cxx.
References TexturePlacement::get_x_size(), TexturePlacement::get_y_size(), TexturePlacement::is_placed(), TexturePlacement::is_size_known(), TexturePlacement::place_at(), and unplace().
Referenced by count_coverage(), PalettePage::place(), and PalettePage::place_all().
|
static |
Registers the current object as something that can be read from a Bam file.
Definition at line 1069 of file paletteImage.cxx.
References BamReader::get_factory(), and write_datagram().
Referenced by update_filename().
void PaletteImage::reset_image | ( | ) |
Unpacks each texture that has been placed on this image, resetting the image to empty.
Definition at line 556 of file paletteImage.cxx.
References TexturePlacement::force_replace(), and setup_shadow_image().
Referenced by PalettePage::reset_images(), and write_placements().
bool PaletteImage::resize_image | ( | int | x_size, |
int | y_size | ||
) |
Attempts to resize the palette image, and repack all of the textures within the new size.
Returns true if successful, false otherwise. If this fails, it will still result in repacking all the textures in the original size.
Definition at line 457 of file paletteImage.cxx.
References PaletteGroups::begin(), and resize_swapped_image().
Referenced by optimal_resize().
void PaletteImage::resize_swapped_image | ( | int | x_size, |
int | y_size | ||
) |
Attempts to resize the palette image, and repack all of the textures within the new size.
Returns true if successful, false otherwise. If this fails, it will still result in repacking all the textures in the original size.
Definition at line 527 of file paletteImage.cxx.
References write_placements().
Referenced by optimal_resize(), and resize_image().
void PaletteImage::setup_shadow_image | ( | ) |
Ensures the _shadow_image has the correct filename and image types, based on what was supplied on the command line and in the .txa file.
Definition at line 578 of file paletteImage.cxx.
References setup_shadow_image(), and update_image().
Referenced by reset_image(), setup_shadow_image(), and PalettePage::setup_shadow_images().
void PaletteImage::unplace | ( | TexturePlacement * | placement | ) |
Removes the texture from the image.
Definition at line 344 of file paletteImage.cxx.
References check_solitary(), TexturePlacement::get_image(), and TexturePlacement::is_placed().
Referenced by place(), and PalettePage::unplace().
bool PaletteImage::update_filename | ( | ) |
Changes the image filename to match the current naming scheme, assuming something has changed since the image was created.
Returns true if the image filename changes (which means update_image() should be called).
Definition at line 737 of file paletteImage.cxx.
References Filename::exists(), TexturePlacement::fill_image(), TexturePlacement::fill_swapped_image(), TexturePlacement::get_placed_x(), TexturePlacement::get_placed_x_size(), TexturePlacement::get_placed_y(), TexturePlacement::get_placed_y_size(), TexturePlacement::intersects(), TexturePlacement::is_placed(), FilenameUnifier::make_user_filename(), TexturePlacement::mark_eggs_stale(), register_with_read_factory(), and Filename::unlink().
Referenced by update_image().
void PaletteImage::update_image | ( | bool | redo_all | ) |
If the palette has changed since it was last written out, updates the image and writes out a new one.
If redo_all is true, regenerates the image from scratch and writes it out again, whether it needed it or not.
Definition at line 598 of file paletteImage.cxx.
References Filename::compare_timestamps(), TexturePlacement::fill_image(), TexturePlacement::fill_swapped_image(), ImageFile::get_filename(), TextureImage::get_preferred_source(), TexturePlacement::get_texture(), TexturePlacement::is_filled(), TextureImage::is_texture_named(), TexturePlacement::mark_unfilled(), update_filename(), and ImageFile::write().
Referenced by setup_shadow_image(), and PalettePage::update_images().
Fills the indicated datagram up with a binary representation of the current object, in preparation for writing to a Bam file.
Reimplemented from ImageFile.
Definition at line 1082 of file paletteImage.cxx.
References Datagram::add_bool(), Datagram::add_string(), Datagram::add_uint32(), complete_pointers(), ImageFile::write_datagram(), and BamWriter::write_pointer().
Referenced by register_with_read_factory().
void PaletteImage::write_placements | ( | ostream & | out, |
int | indent_level = 0 |
||
) | const |
Writes a list of the textures that have been placed on this image to the indicated output stream, one per line.
Definition at line 541 of file paletteImage.cxx.
References reset_image(), and TexturePlacement::write_placed().
Referenced by resize_swapped_image(), and PalettePage::write_image_info().