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"
Classes | |
class | ClearedRegion |
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. | |
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. | |
double | count_coverage () const |
Returns the a weighted average of the fraction of coverage represented by all of the textures placed on the palette. | |
double | count_utilization () const |
Returns the fraction of the PaletteImage that is actually used by any textures. | |
PalettePage * | get_page () const |
Returns the particular PalettePage this image is associated with. | |
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. | |
void | optimal_resize () |
Attempts to resize the palette image to as small as it can go. | |
bool | place (TexturePlacement *placement) |
Attempts to place the indicated texture on the image. | |
void | reset_image () |
Unpacks each texture that has been placed on this image, resetting the image to empty. | |
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. | |
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. | |
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. | |
void | unplace (TexturePlacement *placement) |
Removes the texture from the image. | |
bool | update_filename () |
Changes the image filename to match the current naming scheme, assuming something has changed since the image was created. | |
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. | |
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. | |
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. | |
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. | |
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 TypedWritable * | make_PaletteImage (const FactoryParams ¶ms) |
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. |
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(), and TexturePlacement::omit_solitary().
Referenced by PalettePage::place_all().
int PaletteImage::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 ImageFile.
Definition at line 1120 of file paletteImage.cxx.
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(), and ImageFile::get_y_size().
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 TexturePlacement::get_placed_x_size(), TexturePlacement::get_placed_y_size(), ImageFile::get_x_size(), and ImageFile::get_y_size().
void PaletteImage::fillin | ( | DatagramIterator & | scan, |
BamReader * | manager | ||
) | [protected, virtual] |
Reads the binary data from the given datagram iterator, which was written by a previous call to write_datagram().
Reimplemented from ImageFile.
Definition at line 1167 of file paletteImage.cxx.
References DatagramIterator::get_bool(), DatagramIterator::get_string(), DatagramIterator::get_uint32(), BamReader::read_pointer(), and BamReader::read_pointers().
Referenced by make_PaletteImage().
PalettePage * PaletteImage::get_page | ( | ) | const |
Returns the particular PalettePage this image is associated with.
Definition at line 212 of file paletteImage.cxx.
Referenced by TexturePlacement::get_page().
static void PaletteImage::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 ImageFile.
Definition at line 136 of file paletteImage.h.
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.
Referenced by optimal_resize(), update_image(), and PalettePage::write_image_info().
TypedWritable * PaletteImage::make_PaletteImage | ( | 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 1149 of file paletteImage.cxx.
References fillin().
Referenced by register_with_read_factory().
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 ImageFile::get_filename(), is_empty(), FilenameUnifier::make_user_filename(), resize_image(), and resize_swapped_image().
Referenced by 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(), and TexturePlacement::place_at().
Referenced by PalettePage::place(), and resize_image().
void PaletteImage::register_with_read_factory | ( | ) | [static] |
Registers the current object as something that can be read from a Bam file.
Definition at line 1068 of file paletteImage.cxx.
References BamReader::get_factory(), and make_PaletteImage().
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().
Referenced by PalettePage::reset_images().
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 place().
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.
Referenced by optimal_resize().
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 ImageFile::make_shadow_image(), and setup_shadow_image().
Referenced by 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 TexturePlacement::get_image(), and TexturePlacement::is_placed().
Referenced by TexturePlacement::force_replace(), 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 ImageFile::get_filename(), FilenameUnifier::make_user_filename(), TexturePlacement::mark_eggs_stale(), 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 ImageFile::exists(), TexturePlacement::fill_image(), TexturePlacement::fill_swapped_image(), ImageFile::get_filename(), TextureImage::get_preferred_source(), TexturePlacement::get_texture(), is_empty(), TexturePlacement::is_filled(), TextureImage::is_texture_named(), TexturePlacement::mark_unfilled(), update_filename(), and ImageFile::write().
Referenced by PalettePage::update_images().
void PaletteImage::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 ImageFile.
Definition at line 1081 of file paletteImage.cxx.
References Datagram::add_bool(), Datagram::add_string(), Datagram::add_uint32(), and BamWriter::write_pointer().
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 TexturePlacement::write_placed().
Referenced by PalettePage::write_image_info().