Panda3D
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Friends | List of all members
TextureImage Class Reference

This represents a single source texture that is referenced by one or more egg files. More...

#include "textureImage.h"

Inheritance diagram for TextureImage:
ImageFile Namable TypedWritable MemoryBase TypedObject MemoryBase

Public Member Functions

void assign_groups ()
 Assigns the texture to all of the PaletteGroups the various egg files that use it need.
 
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.
 
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.
 
void copy_unplaced (bool redo_all)
 Copies the texture to whichever destination directories are appropriate for the groups in which it has been unplaced.
 
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.
 
void force_replace ()
 Removes the texture from any PaletteImages it is assigned to, but does not remove it from the groups.
 
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.
 
double get_coverage_threshold () const
 Returns the appropriate coverage threshold for this texture.
 
const PaletteGroupsget_groups () const
 Once assign_groups() has been called, this returns the actual set of groups the TextureImage has been assigned to.
 
int get_margin () const
 Returns the appropriate margin for this texture.
 
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.
 
TexturePlacementget_placement (PaletteGroup *group) const
 Gets the TexturePlacement object which represents the assignment of this texture to the indicated group.
 
SourceTextureImageget_preferred_source ()
 Determines the preferred source image for examining size and reading pixels, etc.
 
SourceTextureImageget_source (const Filename &filename, const Filename &alpha_filename, int alpha_file_channel)
 Returns the SourceTextureImage corresponding to the given filename(s).
 
EggTexture::WrapMode get_txa_wrap_u () const
 Returns the wrap mode specified in the u direction in the txa file, or WM_unspecified.
 
EggTexture::WrapMode get_txa_wrap_v () const
 Returns the wrap mode specified in the v direction in the txa file, or WM_unspecified.
 
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.
 
bool is_newer_than (const Filename &reference_filename)
 Returns true if the source image is newer than the indicated file, false otherwise.
 
bool is_surprise () const
 Returns true if this particular texture is a 'surprise', i.e.
 
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.
 
bool is_used () const
 Returns true if this particular texture has been placed somewhere, anywhere, or false if it is not used.
 
void mark_eggs_stale ()
 Marks all the egg files that reference this texture stale.
 
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.
 
void note_egg_file (EggFile *egg_file)
 Records that a particular egg file references this texture.
 
void post_txa_file ()
 Once the .txa file has been read and the TextureImage matched against it, considers applying the requested size change.
 
void pre_txa_file ()
 Updates any internal state prior to reading the .txa file.
 
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.
 
const PNMImageread_source_image ()
 Reads in the original image, if it has not already been read, and returns it.
 
void release_source_image ()
 Frees the memory that was allocated by a previous call to read_source_image().
 
void set_source_image (const PNMImage &image)
 Accepts the indicated source image as if it had been read from disk.
 
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_scale_info (std::ostream &out, int indent_level=0)
 Writes the information about the texture's size and placement.
 
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.
 
- 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.
 
bool exists () const
 Returns true if the file or files named by the image file exist, false otherwise.
 
int get_alpha_file_channel () const
 Returns the particular channel number of the alpha image file from which the alpha channel should be extracted.
 
const Filenameget_alpha_filename () const
 Returns the alpha filename of the image file.
 
const Filenameget_filename () const
 Returns the primary filename of the image file.
 
int get_num_channels () const
 Returns the number of channels of the image.
 
const TexturePropertiesget_properties () const
 Returns the grouping properties of the image.
 
int get_x_size () const
 Returns the size of the image file in pixels in the X direction.
 
int get_y_size () const
 Returns the size of the image file in pixels in the Y direction.
 
bool has_num_channels () const
 Returns true if the number of channels in the image is known, false otherwise.
 
bool is_size_known () const
 Returns true if the size of the image file is known, false otherwise.
 
bool make_shadow_image (const std::string &basename)
 Sets up the ImageFile as a "shadow image" of a particular PaletteImage.
 
void output_filename (std::ostream &out) const
 Writes the filename (or pair of filenames) to the indicated output stream.
 
bool read (PNMImage &image) const
 Reads in the image (or images, if the alpha_filename is separate) and stores it in the indicated PNMImage.
 
bool set_filename (const std::string &dirname, const std::string &basename)
 Sets the filename, and if applicable, the alpha_filename, from the indicated basename.
 
bool set_filename (PaletteGroup *group, const std::string &basename)
 Sets the filename, and if applicable, the alpha_filename, from the indicated basename.
 
void unlink ()
 Deletes the image file or files.
 
void update_egg_tex (EggTexture *egg_tex) const
 Sets the indicated EggTexture to refer to this file.
 
void update_properties (const TextureProperties &properties)
 If the indicate TextureProperties structure is more specific than this one, updates this one.
 
bool write (const PNMImage &image) const
 Writes out the image in the indicated PNMImage to the _filename and/or _alpha_filename.
 
- 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.
 
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.
 
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.
 
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.
 
virtual TypeHandle force_init_type ()
 
UpdateSeq get_bam_modified () const
 Returns the current bam_modified counter.
 
void mark_bam_modified ()
 Increments the bam_modified counter, so that this object will be invalidated and retransmitted on any open bam streams.
 
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.
 
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.
 
- Public Member Functions inherited from TypedObject
 TypedObject (const TypedObject &copy)=default
 
TypedObjectas_typed_object ()
 Returns the object, upcast (if necessary) to a TypedObject pointer.
 
const TypedObjectas_typed_object () const
 Returns the object, upcast (if necessary) to a TypedObject pointer.
 
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.
 
bool is_exact_type (TypeHandle handle) const
 Returns true if the current object is the indicated type exactly.
 
bool is_of_type (TypeHandle handle) const
 Returns true if the current object is or derives from the indicated type.
 
TypedObjectoperator= (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)
 
- Public Member Functions inherited from Namable
 Namable (const std::string &initial_name="")
 
void clear_name ()
 Resets the Namable's name to empty.
 
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.
 
void output (std::ostream &out) const
 Outputs the Namable.
 
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.
 
- 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.
 
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.
 
- 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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ TextureImage()

TextureImage::TextureImage ( )

Definition at line 41 of file textureImage.cxx.

Member Function Documentation

◆ assign_groups()

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

◆ clear_source_basic_properties()

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 632 of file textureImage.cxx.

References ImageFile::clear_basic_properties().

Referenced by Palettizer::process_all().

◆ complete_pointers()

int TextureImage::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 1299 of file textureImage.cxx.

References ImageFile::complete_pointers(), PaletteGroups::complete_pointers(), ImageFile::get_alpha_file_channel(), ImageFile::get_alpha_filename(), and ImageFile::get_filename().

◆ copy_unplaced()

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 648 of file textureImage.cxx.

References ImageFile::get_filename(), TexturePlacement::get_omit_reason(), FilenameUnifier::make_canonical(), and TexturePlacement::set_dest().

Referenced by Palettizer::generate_images().

◆ determine_placement_size()

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 421 of file textureImage.cxx.

References TexturePlacement::determine_size().

Referenced by Palettizer::process_all(), and Palettizer::process_command_line_eggs().

◆ force_replace()

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 219 of file textureImage.cxx.

Referenced by post_txa_file().

◆ get_alpha_mode()

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 489 of file textureImage.cxx.

Referenced by PT(), and TextureReference::update_egg().

◆ get_class_type()

static TypeHandle TextureImage::get_class_type ( )
inlinestatic

Definition at line 175 of file textureImage.h.

◆ get_coverage_threshold()

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 445 of file textureImage.cxx.

Referenced by TexturePlacement::determine_size().

◆ get_groups()

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 193 of file textureImage.cxx.

Referenced by EggFile::choose_placements().

◆ get_margin()

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 455 of file textureImage.cxx.

◆ get_omit()

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 434 of file textureImage.cxx.

Referenced by TexturePlacement::determine_size().

◆ get_placement()

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 203 of file textureImage.cxx.

Referenced by EggFile::choose_placements().

◆ get_preferred_source()

SourceTextureImage * TextureImage::get_preferred_source ( )

◆ get_source()

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 518 of file textureImage.cxx.

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

◆ get_txa_wrap_u()

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 498 of file textureImage.cxx.

Referenced by TexturePlacement::determine_size(), and TextureReference::update_egg().

◆ get_txa_wrap_v()

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 507 of file textureImage.cxx.

Referenced by TexturePlacement::determine_size(), and TextureReference::update_egg().

◆ get_type()

virtual TypeHandle TextureImage::get_type ( ) const
inlinevirtual

Reimplemented from ImageFile.

Definition at line 185 of file textureImage.h.

◆ got_txa_file()

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 411 of file textureImage.cxx.

Referenced by PaletteGroup::update_unknown_textures().

◆ init_type()

static void TextureImage::init_type ( )
inlinestatic

Definition at line 178 of file textureImage.h.

◆ is_newer_than()

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 767 of file textureImage.cxx.

References Filename::compare_timestamps(), ImageFile::get_filename(), and get_preferred_source().

Referenced by Palettizer::process_all(), and Palettizer::process_command_line_eggs().

◆ is_surprise()

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 464 of file textureImage.cxx.

Referenced by Palettizer::report_pi().

◆ is_texture_named()

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 256 of file textureImage.cxx.

Referenced by PaletteImage::update_image().

◆ is_used()

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 479 of file textureImage.cxx.

Referenced by Palettizer::finalize(), and Palettizer::report_pi().

◆ mark_eggs_stale()

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 233 of file textureImage.cxx.

Referenced by post_txa_file().

◆ mark_texture_named()

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 246 of file textureImage.cxx.

Referenced by Palettizer::process_all(), and Palettizer::process_command_line_eggs().

◆ note_egg_file()

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 64 of file textureImage.cxx.

References PaletteGroups::empty(), and EggFile::get_complete_groups().

Referenced by EggFile::build_cross_links().

◆ post_txa_file()

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 288 of file textureImage.cxx.

References force_replace(), ImageFile::get_num_channels(), get_preferred_source(), SourceTextureImage::get_size(), ImageFile::get_x_size(), ImageFile::get_y_size(), mark_eggs_stale(), and TexturePlacement::mark_unfilled().

Referenced by Palettizer::process_all(), Palettizer::process_command_line_eggs(), PT(), and PaletteGroup::update_unknown_textures().

◆ pre_txa_file()

void TextureImage::pre_txa_file ( )

Updates any internal state prior to reading the .txa file.

Definition at line 264 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().

◆ read_header()

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 753 of file textureImage.cxx.

References get_preferred_source(), and SourceTextureImage::read_header().

Referenced by Palettizer::process_command_line_eggs().

◆ read_source_image()

const PNMImage & TextureImage::read_source_image ( )

Reads in the original image, if it has not already been read, and returns it.

Definition at line 708 of file textureImage.cxx.

References get_preferred_source(), and ImageFile::read().

Referenced by DestTextureImage::copy(), TexturePlacement::fill_image(), TexturePlacement::fill_swapped_image(), Palettizer::process_all(), and Palettizer::process_command_line_eggs().

◆ register_with_read_factory()

void TextureImage::register_with_read_factory ( )
static

Registers the current object as something that can be read from a Bam file.

Definition at line 1234 of file textureImage.cxx.

References BamReader::get_factory().

Referenced by init_palettizer().

◆ release_source_image()

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 728 of file textureImage.cxx.

References PNMImage::clear().

Referenced by DestTextureImage::copy(), TexturePlacement::fill_image(), TexturePlacement::fill_swapped_image(), and Palettizer::process_all().

◆ set_source_image()

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 741 of file textureImage.cxx.

Referenced by PT().

◆ write_datagram()

void TextureImage::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 1244 of file textureImage.cxx.

References Datagram::add_bool(), Datagram::add_float64(), Datagram::add_int16(), Datagram::add_string(), Datagram::add_uint32(), Datagram::add_uint8(), ImageFile::write_datagram(), PaletteGroups::write_datagram(), and BamWriter::write_pointer().

◆ write_scale_info()

void TextureImage::write_scale_info ( std::ostream & out,
int indent_level = 0 )

◆ write_source_pathnames()

void TextureImage::write_source_pathnames ( std::ostream & out,
int indent_level = 0 ) const

Friends And Related Symbol Documentation

◆ TxaLine

friend class TxaLine
friend

Definition at line 192 of file textureImage.h.


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