This represents a single source texture that is referenced by one or more egg files. More...
#include "textureImage.h"
Public Member Functions | |
void | assign_groups () |
Assigns the texture to all of the PaletteGroups the various egg files that use it need. More... | |
void | clear_source_basic_properties () |
Calls clear_basic_properties() on each source texture image used by this texture, to reset the properties in preparation for re-applying them from the set of all known egg files. 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... | |
void | copy_unplaced (bool redo_all) |
Copies the texture to whichever destination directories are appropriate for the groups in which it has been unplaced. More... | |
void | determine_placement_size () |
Calls determine_size() on each TexturePlacement for the texture, to ensure that each TexturePlacement is still requesting the best possible size for the texture. More... | |
void | force_replace () |
Removes the texture from any PaletteImages it is assigned to, but does not remove it from the groups. More... | |
EggRenderMode::AlphaMode | get_alpha_mode () const |
Returns the alpha mode that should be used to render objects with this texture, as specified by the user or as determined from examining the texture's alpha channel. More... | |
double | get_coverage_threshold () const |
Returns the appropriate coverage threshold for this texture. More... | |
const PaletteGroups & | get_groups () const |
Once assign_groups() has been called, this returns the actual set of groups the TextureImage has been assigned to. More... | |
int | get_margin () const |
Returns the appropriate margin for this texture. More... | |
bool | get_omit () const |
Returns true if the user specifically requested to omit this texture via the "omit" keyword in the .txa file, or false otherwise. More... | |
TexturePlacement * | get_placement (PaletteGroup *group) const |
Gets the TexturePlacement object which represents the assignment of this texture to the indicated group. More... | |
SourceTextureImage * | get_preferred_source () |
Determines the preferred source image for examining size and reading pixels, etc. More... | |
SourceTextureImage * | get_source (const Filename &filename, const Filename &alpha_filename, int alpha_file_channel) |
Returns the SourceTextureImage corresponding to the given filename(s). More... | |
EggTexture::WrapMode | get_txa_wrap_u () const |
Returns the wrap mode specified in the u direction in the txa file, or WM_unspecified. More... | |
EggTexture::WrapMode | get_txa_wrap_v () const |
Returns the wrap mode specified in the v direction in the txa file, or WM_unspecified. More... | |
virtual TypeHandle | get_type () const |
bool | got_txa_file () const |
Returns true if this TextureImage has been looked up in the .txa file this session, false otherwise. More... | |
bool | is_newer_than (const Filename &reference_filename) |
Returns true if the source image is newer than the indicated file, false otherwise. More... | |
bool | is_surprise () const |
Returns true if this particular texture is a 'surprise', i.e. More... | |
bool | is_texture_named () const |
Returns true if this particular texture has been named by the user for procession this session, for instance by listing an egg file on the command line that references it. More... | |
bool | is_used () const |
Returns true if this particular texture has been placed somewhere, anywhere, or false if it is not used. More... | |
void | mark_eggs_stale () |
Marks all the egg files that reference this texture stale. More... | |
void | mark_texture_named () |
Indicates that this particular texture has been named by the user for processing this session, normally by listing an egg file on the command line that references it. More... | |
void | note_egg_file (EggFile *egg_file) |
Records that a particular egg file references this texture. More... | |
void | post_txa_file () |
Once the .txa file has been read and the TextureImage matched against it, considers applying the requested size change. More... | |
void | pre_txa_file () |
Updates any internal state prior to reading the .txa file. More... | |
void | read_header () |
Causes the header part of the image to be reread, usually to confirm that its image properties (size, number of channels, etc.) haven't changed. More... | |
const PNMImage & | read_source_image () |
Reads in the original image, if it has not already been read, and returns it. More... | |
void | release_source_image () |
Frees the memory that was allocated by a previous call to read_source_image(). More... | |
void | set_source_image (const PNMImage &image) |
Accepts the indicated source image as if it had been read from disk. 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_scale_info (std::ostream &out, int indent_level=0) |
Writes the information about the texture's size and placement. More... | |
void | write_source_pathnames (std::ostream &out, int indent_level=0) const |
Writes the list of source pathnames that might contribute to this texture to the indicated output stream, one per line. More... | |
Public Member Functions inherited from ImageFile | |
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 std::string &basename) |
Sets up the ImageFile as a "shadow image" of a particular PaletteImage. More... | |
void | output_filename (std::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 std::string &basename) |
Sets the filename, and if applicable, the alpha_filename, from the indicated basename. More... | |
bool | set_filename (const std::string &dirname, const std::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... | |
Public Member Functions inherited from TypedWritable | |
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... | |
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 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... | |
Public Member Functions inherited from TypedObject | |
TypedObject (const TypedObject ©)=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 ©)=default |
Public Member Functions inherited from Namable | |
Namable (const std::string &initial_name="") | |
void | clear_name () |
Resets the Namable's name to empty. More... | |
const std::string & | get_name () const |
bool | has_name () const |
Returns true if the Namable has a nonempty name set, false if the name is empty. More... | |
void | output (std::ostream &out) const |
Outputs the Namable. More... | |
void | set_name (const std::string &name) |
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 Public Member Functions inherited from ImageFile | |
static TypeHandle | get_class_type () |
static void | init_type () |
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... | |
Static Public Member Functions inherited from Namable | |
static TypeHandle | get_class_type () |
static void | init_type () |
Friends | |
class | TxaLine |
Additional Inherited Members | |
Public Attributes inherited from TypedObject | |
get_type | |
Public Attributes inherited from Namable | |
get_name | |
set_name | |
Static Public Attributes inherited from TypedWritable | |
static TypedWritable *const | Null = nullptr |
This represents a single source texture that is referenced by one or more egg files.
It may be assigned to multiple PaletteGroups, and thus placed on multiple PaletteImages (up to one per PaletteGroup).
Since a TextureImage may be referenced by multiple egg files that are each assigned to a different set of groups, it tries to maximize sharing between egg files and minimize the number of different PaletteGroups it is assigned to.
Definition at line 46 of file textureImage.h.
void TextureImage::assign_groups | ( | ) |
Assigns the texture to all of the PaletteGroups the various egg files that use it need.
Attempts to choose the minimum set of PaletteGroups that satisfies all of the egg files.
Definition at line 76 of file textureImage.cxx.
References PaletteGroups::begin(), PaletteGroups::empty(), PaletteGroups::end(), PaletteGroups::insert(), PaletteGroup::is_preferred_over(), PaletteGroups::make_intersection(), PaletteGroups::make_union(), and PaletteGroups::remove_null().
Referenced by Palettizer::process_all(), and Palettizer::process_command_line_eggs().
void TextureImage::clear_source_basic_properties | ( | ) |
Calls clear_basic_properties() on each source texture image used by this texture, to reset the properties in preparation for re-applying them from the set of all known egg files.
Definition at line 633 of file textureImage.cxx.
References ImageFile::clear_basic_properties().
Referenced by Palettizer::process_all().
|
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 1300 of file textureImage.cxx.
void TextureImage::copy_unplaced | ( | bool | redo_all | ) |
Copies the texture to whichever destination directories are appropriate for the groups in which it has been unplaced.
Also removes the old filenames for previous sessions where it was unplaced, but is no longer.
If redo_all is true, this recopies the texture whether it needed to or not.
Definition at line 649 of file textureImage.cxx.
Referenced by Palettizer::generate_images().
void TextureImage::determine_placement_size | ( | ) |
Calls determine_size() on each TexturePlacement for the texture, to ensure that each TexturePlacement is still requesting the best possible size for the texture.
Definition at line 422 of file textureImage.cxx.
Referenced by Palettizer::process_all(), and Palettizer::process_command_line_eggs().
void TextureImage::force_replace | ( | ) |
Removes the texture from any PaletteImages it is assigned to, but does not remove it from the groups.
It will be re-placed within each group when PaletteGroup::place_all() is called.
Definition at line 220 of file textureImage.cxx.
EggRenderMode::AlphaMode TextureImage::get_alpha_mode | ( | ) | const |
Returns the alpha mode that should be used to render objects with this texture, as specified by the user or as determined from examining the texture's alpha channel.
Definition at line 490 of file textureImage.cxx.
Referenced by PT(), and TextureReference::update_egg().
double TextureImage::get_coverage_threshold | ( | ) | const |
Returns the appropriate coverage threshold for this texture.
This is either the Palettizer::_coverage_threshold parameter, given globally via -r, or a particular value for this texture as supplied by the "coverage" keyword in the .txa file.
Definition at line 446 of file textureImage.cxx.
const PaletteGroups & TextureImage::get_groups | ( | ) | const |
Once assign_groups() has been called, this returns the actual set of groups the TextureImage has been assigned to.
Definition at line 194 of file textureImage.cxx.
Referenced by EggFile::choose_placements().
int TextureImage::get_margin | ( | ) | const |
Returns the appropriate margin for this texture.
This is either the Palettizer::_margin parameter, or a particular value for this texture as supplied by the "margin" keyword in the .txa file.
Definition at line 456 of file textureImage.cxx.
bool TextureImage::get_omit | ( | ) | const |
Returns true if the user specifically requested to omit this texture via the "omit" keyword in the .txa file, or false otherwise.
Definition at line 435 of file textureImage.cxx.
TexturePlacement * TextureImage::get_placement | ( | PaletteGroup * | group | ) | const |
Gets the TexturePlacement object which represents the assignment of this texture to the indicated group.
If the texture has not been assigned to the indicated group, returns NULL.
Definition at line 204 of file textureImage.cxx.
Referenced by EggFile::choose_placements().
SourceTextureImage * TextureImage::get_preferred_source | ( | ) |
Determines the preferred source image for examining size and reading pixels, etc.
This is the largest and most recent of all the available source images.
Definition at line 547 of file textureImage.cxx.
References Filename::compare_timestamps(), ImageFile::exists(), SourceTextureImage::get_egg_count(), ImageFile::get_filename(), SourceTextureImage::get_size(), ImageFile::get_x_size(), and ImageFile::get_y_size().
Referenced by DestTextureImage::copy_if_stale(), is_newer_than(), post_txa_file(), pre_txa_file(), read_header(), read_source_image(), and write_scale_info().
SourceTextureImage * TextureImage::get_source | ( | const Filename & | filename, |
const Filename & | alpha_filename, | ||
int | alpha_file_channel | ||
) |
Returns the SourceTextureImage corresponding to the given filename(s).
If the given filename has never been used as a SourceTexture for this particular texture, creates a new SourceTextureImage and returns that.
Definition at line 519 of file textureImage.cxx.
Referenced by PT().
EggTexture::WrapMode TextureImage::get_txa_wrap_u | ( | ) | const |
Returns the wrap mode specified in the u direction in the txa file, or WM_unspecified.
Definition at line 499 of file textureImage.cxx.
Referenced by TextureReference::update_egg().
EggTexture::WrapMode TextureImage::get_txa_wrap_v | ( | ) | const |
Returns the wrap mode specified in the v direction in the txa file, or WM_unspecified.
Definition at line 508 of file textureImage.cxx.
Referenced by TextureReference::update_egg().
bool TextureImage::got_txa_file | ( | ) | const |
Returns true if this TextureImage has been looked up in the .txa file this session, false otherwise.
Definition at line 412 of file textureImage.cxx.
Referenced by PaletteGroup::update_unknown_textures().
bool TextureImage::is_newer_than | ( | const Filename & | reference_filename | ) |
Returns true if the source image is newer than the indicated file, false otherwise.
If the image has already been read, this always returns false.
Definition at line 768 of file textureImage.cxx.
References get_preferred_source().
Referenced by Palettizer::process_all(), and Palettizer::process_command_line_eggs().
bool TextureImage::is_surprise | ( | ) | const |
Returns true if this particular texture is a 'surprise', i.e.
it wasn't matched by a line in the .txa file that didn't include the keyword 'cont'.
Definition at line 465 of file textureImage.cxx.
Referenced by Palettizer::report_pi().
bool TextureImage::is_texture_named | ( | ) | const |
Returns true if this particular texture has been named by the user for procession this session, for instance by listing an egg file on the command line that references it.
Definition at line 257 of file textureImage.cxx.
bool TextureImage::is_used | ( | ) | const |
Returns true if this particular texture has been placed somewhere, anywhere, or false if it is not used.
Definition at line 480 of file textureImage.cxx.
Referenced by Palettizer::report_pi().
void TextureImage::mark_eggs_stale | ( | ) |
Marks all the egg files that reference this texture stale.
Should be called only when the texture properties change in some catastrophic way that will require every egg file referencing it to be regenerated, even if it is not palettized.
Definition at line 234 of file textureImage.cxx.
Referenced by post_txa_file().
void TextureImage::mark_texture_named | ( | ) |
Indicates that this particular texture has been named by the user for processing this session, normally by listing an egg file on the command line that references it.
Definition at line 247 of file textureImage.cxx.
Referenced by Palettizer::process_all(), and Palettizer::process_command_line_eggs().
void TextureImage::note_egg_file | ( | EggFile * | egg_file | ) |
Records that a particular egg file references this texture.
This is essential to know when deciding how to assign the TextureImage to the various PaletteGroups.
Definition at line 65 of file textureImage.cxx.
void TextureImage::post_txa_file | ( | ) |
Once the .txa file has been read and the TextureImage matched against it, considers applying the requested size change.
Updates the TextureImage's size with the size the texture ought to be, if this can be determined.
Definition at line 289 of file textureImage.cxx.
References ImageFile::get_num_channels(), get_preferred_source(), SourceTextureImage::get_size(), ImageFile::get_x_size(), ImageFile::get_y_size(), and mark_eggs_stale().
Referenced by Palettizer::process_all(), Palettizer::process_command_line_eggs(), PT(), and PaletteGroup::update_unknown_textures().
void TextureImage::pre_txa_file | ( | ) |
Updates any internal state prior to reading the .txa file.
Definition at line 265 of file textureImage.cxx.
References get_preferred_source(), ImageFile::get_properties(), and TextureRequest::pre_txa_file().
Referenced by Palettizer::process_all(), Palettizer::process_command_line_eggs(), PT(), and PaletteGroup::update_unknown_textures().
void TextureImage::read_header | ( | ) |
Causes the header part of the image to be reread, usually to confirm that its image properties (size, number of channels, etc.) haven't changed.
Definition at line 754 of file textureImage.cxx.
References get_preferred_source(), and SourceTextureImage::read_header().
Referenced by Palettizer::process_command_line_eggs().
const PNMImage & TextureImage::read_source_image | ( | ) |
Reads in the original image, if it has not already been read, and returns it.
Definition at line 709 of file textureImage.cxx.
References get_preferred_source(), and ImageFile::read().
Referenced by DestTextureImage::copy(), Palettizer::process_all(), and Palettizer::process_command_line_eggs().
|
static |
Registers the current object as something that can be read from a Bam file.
Definition at line 1235 of file textureImage.cxx.
References BamReader::get_factory().
Referenced by init_palettizer().
void TextureImage::release_source_image | ( | ) |
Frees the memory that was allocated by a previous call to read_source_image().
The next time read_source_image() is called, it will have to read the disk again.
Definition at line 729 of file textureImage.cxx.
References PNMImage::clear().
Referenced by DestTextureImage::copy(), and Palettizer::process_all().
void TextureImage::set_source_image | ( | const PNMImage & | image | ) |
Accepts the indicated source image as if it had been read from disk.
This image is copied into the structure, and will be returned by future calls to read_source_image().
Definition at line 742 of file textureImage.cxx.
Referenced by PT().
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 1245 of file textureImage.cxx.
References Datagram::add_bool(), Datagram::add_float64(), Datagram::add_int16(), Datagram::add_string(), Datagram::add_uint32(), Datagram::add_uint8(), PaletteGroups::write_datagram(), and ImageFile::write_datagram().
void TextureImage::write_scale_info | ( | std::ostream & | out, |
int | indent_level = 0 |
||
) |
Writes the information about the texture's size and placement.
Definition at line 858 of file textureImage.cxx.
References get_preferred_source(), and indent().
Referenced by Palettizer::report_pi().
void TextureImage::write_source_pathnames | ( | std::ostream & | out, |
int | indent_level = 0 |
||
) | const |
Writes the list of source pathnames that might contribute to this texture to the indicated output stream, one per line.
Definition at line 785 of file textureImage.cxx.
References SourceTextureImage::get_egg_count(), TextureProperties::get_num_channels(), ImageFile::get_properties(), ImageFile::get_x_size(), ImageFile::get_y_size(), TextureProperties::has_num_channels(), indent(), ImageFile::is_size_known(), and ImageFile::output_filename().
Referenced by Palettizer::report_pi().