Panda3D
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes

ImageFile Class Reference

This is the base class of both TextureImage and PaletteImage. More...

#include "imageFile.h"

Inheritance diagram for ImageFile:
TypedWritable TypedObject MemoryBase DestTextureImage PaletteImage SourceTextureImage TextureImage

List of all members.

Public Member Functions

virtual ReferenceCountas_reference_count ()
 Returns the pointer cast to a ReferenceCount pointer, if it is in fact of that type.
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.
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.
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.
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.
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.
bool exists () const
 Returns true if the file or files named by the image file exist, false otherwise.
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 ()
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.
UpdateSeq get_bam_modified () const
 Returns the current bam_modified counter.
int get_best_parent_from_Set (const std::set< int > &) const
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.
virtual TypeHandle get_type () const
int get_type_index () const
 Returns the internal index number associated with this object's TypeHandle, a unique number for each different type.
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_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.
bool is_size_known () const
 Returns true if the size of the image file is known, false otherwise.
bool make_shadow_image (const string &basename)
 Sets up the ImageFile as a "shadow image" of a particular PaletteImage.
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 delete (void *ptr)
void operator delete (void *ptr, void *)
void operator delete[] (void *ptr)
void operator delete[] (void *, void *)
void * operator new (size_t size, void *ptr)
void * operator new (size_t size)
void * operator new[] (size_t size, void *ptr)
void * operator new[] (size_t size)
void output_filename (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.
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.
bool set_filename (PaletteGroup *group, const string &basename)
 Sets the filename, and if applicable, the alpha_filename, from the indicated basename.
bool set_filename (const string &dirname, const string &basename)
 Sets the filename, and if applicable, the alpha_filename, from the indicated basename.
void unlink ()
 Deletes the image file or files.
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.
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.
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.

Static Public Member Functions

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.
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 Attributes

static TypedWritable *const Null = (TypedWritable*)0L

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

Protected Attributes

int _alpha_file_channel
Filename _alpha_filename
Filename _filename
TextureProperties _properties
bool _size_known
int _x_size
int _y_size

Detailed Description

This is the base class of both TextureImage and PaletteImage.

It encapsulates all the information specific to an image file that can be assigned as a texture image to egg geometry.

Definition at line 36 of file imageFile.h.


Member Function Documentation

ReferenceCount * TypedWritable::as_reference_count ( ) [virtual, inherited]

Returns the pointer cast to a ReferenceCount pointer, if it is in fact of that type.

Reimplemented in PandaNode, and TypedWritableReferenceCount.

Definition at line 155 of file typedWritable.cxx.

Referenced by BamReader::change_pointer(), BamReader::register_change_this(), and BamReader::resolve().

TypedObject * TypedObject::as_typed_object ( ) [inline, inherited]

Returns the object, upcast (if necessary) to a TypedObject pointer.

Definition at line 99 of file typedObject.I.

const TypedObject * TypedObject::as_typed_object ( ) const [inline, inherited]

Returns the object, upcast (if necessary) to a TypedObject pointer.

Definition at line 110 of file typedObject.I.

void ImageFile::clear_basic_properties ( )

Resets the properties to a neutral state, for instance in preparation for calling update_properties() with all the known contributing properties.

Definition at line 153 of file imageFile.cxx.

References TextureProperties::clear_basic().

Referenced by TextureImage::clear_source_basic_properties().

int ImageFile::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.

Reimplemented in PaletteImage, SourceTextureImage, and TextureImage.

Definition at line 519 of file imageFile.cxx.

References TextureProperties::complete_pointers().

bool TypedWritable::decode_raw_from_bam_stream ( TypedWritable *&  ptr,
ReferenceCount *&  ref_ptr,
const string &  data,
BamReader reader = NULL 
) [static, inherited]

Reads the string created by a previous call to encode_to_bam_stream(), and extracts the single object on that string.

Returns true on success, false on on error.

This variant sets the TypedWritable and ReferenceCount pointers separately; both are pointers to the same object. The reference count is not incremented; it is the caller's responsibility to manage the reference count.

Note that this method cannot be used to retrieve objects that do not inherit from ReferenceCount, because these objects cannot persist beyond the lifetime of the BamReader that reads them. To retrieve these objects from a bam stream, you must construct a BamReader directly.

If you happen to know that the particular object in question inherits from TypedWritableReferenceCount or PandaNode, consider calling the variant of decode_from_bam_stream() defined for those methods, which presents a simpler interface.

Definition at line 353 of file typedWritable.cxx.

References BamReader::init(), DatagramInputFile::open(), DatagramInputFile::read_header(), BamReader::read_object(), ReferenceCount::ref(), BamReader::resolve(), BamReader::set_source(), and ReferenceCount::unref().

string TypedWritable::encode_to_bam_stream ( ) const [inline, inherited]

Converts the TypedWritable object into a single stream of data using a BamWriter, and returns that data as a string string.

Returns empty string on failure.

This is a convenience method particularly useful for cases when you are only serializing a single object. If you have many objects to process, it is more efficient to use the same BamWriter to serialize all of them together.

Definition at line 86 of file typedWritable.I.

bool TypedWritable::encode_to_bam_stream ( string &  data,
BamWriter writer = NULL 
) const [inherited]

Converts the TypedWritable object into a single stream of data using a BamWriter, and stores that data in the indicated string.

Returns true on success, false on failure.

This is a convenience method particularly useful for cases when you are only serializing a single object. If you have many objects to process, it is more efficient to use the same BamWriter to serialize all of them together.

Definition at line 283 of file typedWritable.cxx.

References BamWriter::init(), DatagramOutputFile::open(), BamWriter::set_target(), DatagramOutputFile::write_header(), and BamWriter::write_object().

bool ImageFile::exists ( ) const

Returns true if the file or files named by the image file exist, false otherwise.

Definition at line 303 of file imageFile.cxx.

References TextureProperties::uses_alpha().

Referenced by TextureImage::get_preferred_source(), and PaletteImage::update_image().

void ImageFile::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 TypedWritable.

Reimplemented in DestTextureImage, PaletteImage, SourceTextureImage, and TextureImage.

Definition at line 535 of file imageFile.cxx.

References TextureProperties::fillin(), FilenameUnifier::get_bam_filename(), DatagramIterator::get_bool(), DatagramIterator::get_int32(), DatagramIterator::get_string(), and DatagramIterator::get_uint8().

void TypedWritable::finalize ( BamReader manager) [virtual, inherited]

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 in PartBundle, Geom, GeomPrimitive, GeomVertexArrayData, GeomVertexArrayFormat, GeomVertexData, InternalName, GeomNode, LightAttrib, RenderAttrib, RenderEffect, RenderEffects, RenderState, PaletteGroup, and Palettizer.

Definition at line 145 of file typedWritable.cxx.

Referenced by BamReader::finalize_now().

int ImageFile::get_alpha_file_channel ( ) const

Returns the particular channel number of the alpha image file from which the alpha channel should be extracted.

This is normally 0 to represent the grayscale combination of r, g, and b; or it may be a 1-based channel number (for instance, 4 for the alpha channel of a 4-component image).

Definition at line 291 of file imageFile.cxx.

Referenced by TextureImage::complete_pointers(), and PaletteGroup::prepare().

const Filename & ImageFile::get_alpha_filename ( ) const

Returns the alpha filename of the image file.

This is the name of the file that contains the alpha channel, if it is stored in a separate file, or the empty string if it is not.

Definition at line 276 of file imageFile.cxx.

Referenced by TextureImage::complete_pointers(), and PaletteGroup::prepare().

UpdateSeq TypedWritable::get_bam_modified ( ) const [inline, inherited]

Returns the current bam_modified counter.

This counter is normally incremented automatically whenever the object is modified.

Definition at line 66 of file typedWritable.I.

Referenced by BamWriter::consider_update(), and BamWriter::write_pointer().

const Filename & ImageFile::get_filename ( ) const
int ImageFile::get_num_channels ( ) const

Returns the number of channels of the image.

It is an error to call this unless has_num_channels() returns true.

Definition at line 130 of file imageFile.cxx.

References TextureProperties::get_num_channels().

Referenced by DestTextureImage::copy(), DestTextureImage::copy_if_stale(), TextureReference::from_egg(), TextureImage::post_txa_file(), TextureReference::update_egg(), and TextureImage::write_scale_info().

const TextureProperties & ImageFile::get_properties ( ) const

Returns the grouping properties of the image.

Definition at line 140 of file imageFile.cxx.

Referenced by TexturePlacement::get_properties(), TextureImage::pre_txa_file(), and TextureImage::write_source_pathnames().

int TypedObject::get_type_index ( ) const [inline, inherited]

Returns the internal index number associated with this object's TypeHandle, a unique number for each different type.

This is equivalent to get_type().get_index().

Definition at line 52 of file typedObject.I.

References TypeHandle::get_index().

int ImageFile::get_x_size ( ) const
int ImageFile::get_y_size ( ) const
bool ImageFile::has_num_channels ( ) const

Returns true if the number of channels in the image is known, false otherwise.

Definition at line 118 of file imageFile.cxx.

References TextureProperties::has_num_channels().

Referenced by TextureReference::update_egg().

static void ImageFile::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 TypedWritable.

Reimplemented in DestTextureImage, PaletteImage, and SourceTextureImage.

Definition at line 89 of file imageFile.h.

bool TypedObject::is_exact_type ( TypeHandle  handle) const [inline, inherited]
bool TypedObject::is_of_type ( TypeHandle  handle) const [inline, inherited]

Returns true if the current object is or derives from the indicated type.

Definition at line 63 of file typedObject.I.

References TypeHandle::is_derived_from().

Referenced by EggSliderData::add_back_pointer(), EggJointData::add_back_pointer(), CIntervalManager::add_c_interval(), XFileNode::add_child(), CollisionTraverser::add_collider(), CollisionHandlerPhysical::add_collider(), EggXfmSAnim::add_data(), CharacterJointBundle::add_node(), NonlinearImager::add_screen(), EggGroupNode::apply_first_attribute(), EggGroupNode::apply_last_attribute(), DeferredNodeProperty::apply_to_node(), RecorderController::begin_playback(), NodePath::clear_clip_plane(), EggGroupNode::clear_connected_shading(), NodePath::clear_light(), EggBase::convert_paths(), NodePath::decode_from_bam_stream(), VrpnClient::disconnect_device(), PhysicsManager::do_physics(), GraphicsStateGuardian::fetch_specified_part(), EggRenderState::fill_state(), AnimBundleNode::find_anim_bundle(), EggGroupNode::find_coordsys_entry(), XFile::find_data_object(), Character::find_joint(), EggGroupNode::find_materials(), Character::find_slider(), XFile::find_template(), EggGroupNode::find_textures(), EggMaterialCollection::find_used_materials(), EggTextureCollection::find_used_textures(), EggGroupNode::force_filenames(), EggJointData::force_initial_rest_frame(), WindowFramework::get_aspect_2d(), EggPoolUniquifier::get_category(), EggGroupUniquifier::get_category(), EggGroupNode::get_connected_shading(), PandaFramework::get_mouse(), FactoryParams::get_param_of_type(), EggGroupNode::has_absolute_pathnames(), NodePath::has_clip_plane(), NodePath::has_clip_plane_off(), NodePath::has_light(), PandaFramework::hide_collision_solids(), x11GraphicsWindow::open_window(), eglGraphicsWindow::open_window(), EggNode::parse_egg(), CharacterMaker::part_to_node(), EggGroupNode::post_apply_flat_attribute(), EggBinner::prepare_node(), PortalClipper::prepare_portal(), NodePath::project_texture(), EggMatrixTablePointer::quantize_channels(), ParametricCurveCollection::r_add_curves(), SceneGraphReducer::r_collect_vertex_data(), EggGroupNode::r_load_externals(), EggGroupNode::rebuild_vertex_pools(), EggGroupNode::recompute_polygon_normals(), EggGroupNode::remove_invalid_primitives(), EggGroupNode::remove_unused_vertices(), EggLoader::reparent_decals(), EggMaterialCollection::replace_materials(), EggTextureCollection::replace_textures(), EggGroupNode::resolve_filenames(), EggGroupNode::reverse_vertex_ordering(), NodePath::set_clip_plane(), NodePath::set_clip_plane_off(), NodePath::set_light(), ProjectionScreen::set_projector(), NonlinearImager::set_source_camera(), EggXfmSAnim::set_value(), NonlinearImager::set_viewer_camera(), PandaFramework::show_collision_solids(), BamCache::store(), XFileToEggConverter::strip_nodes(), EggGroupNode::strip_normals(), DataGraphTraverser::traverse(), DataGraphTraverser::traverse_below(), EggGroupNode::triangulate_polygons(), EggGroupNode::unify_attributes(), EggNameUniquifier::uniquify(), NodeCullCallbackData::upcall(), PhysicsCollisionHandler::validate_target(), EggXfmSAnim::write(), EggGroup::write(), EggToDXFLayer::write_3d_face(), and EggToDXFLayer::write_entities().

bool ImageFile::is_size_known ( ) const

Returns true if the size of the image file is known, false otherwise.

Definition at line 81 of file imageFile.cxx.

Referenced by TexturePlacement::determine_size(), get_x_size(), get_y_size(), TextureImage::write_scale_info(), and TextureImage::write_source_pathnames().

bool ImageFile::make_shadow_image ( const string &  basename)

Sets up the ImageFile as a "shadow image" of a particular PaletteImage.

This is a temporary ImageFile that's used to read and write the shadow palette image, which is used to keep a working copy of the palette.

Returns true if the filename changes from what it was previously, false otherwise.

Definition at line 56 of file imageFile.cxx.

References set_filename().

Referenced by PaletteImage::setup_shadow_image().

void TypedWritable::mark_bam_modified ( ) [inline, inherited]
void ImageFile::output_filename ( ostream &  out) const

Writes the filename (or pair of filenames) to the indicated output stream.

Definition at line 483 of file imageFile.cxx.

References FilenameUnifier::make_user_filename(), and TextureProperties::uses_alpha().

Referenced by PalettePage::write_image_info(), and TextureImage::write_source_pathnames().

bool ImageFile::read ( PNMImage image) const

Reads in the image (or images, if the alpha_filename is separate) and stores it in the indicated PNMImage.

Returns true on success, false on failure.

Definition at line 326 of file imageFile.cxx.

References PNMImage::add_alpha(), PNMImage::get_alpha(), PNMImage::get_channel_val(), PNMImage::get_gray(), PNMImageHeader::get_num_channels(), PNMImageHeader::get_x_size(), PNMImageHeader::get_y_size(), FilenameUnifier::make_user_filename(), PNMImage::read(), PNMImage::set_alpha(), and PNMImageHeader::set_type().

Referenced by TextureImage::read_source_image().

bool TypedWritable::require_fully_complete ( ) const [virtual, inherited]

Some objects require all of their nested pointers to have been completed before the objects themselves can be completed.

If this is the case, override this method to return true, and be careful with circular references (which would make the object unreadable from a bam file).

Reimplemented in GeomVertexData, ClipPlaneAttrib, and RenderEffects.

Definition at line 118 of file typedWritable.cxx.

bool ImageFile::set_filename ( const string &  dirname,
const string &  basename 
)

Sets the filename, and if applicable, the alpha_filename, from the indicated basename.

The extension appropriate to the image file type specified in _color_type (and _alpha_type) is automatically applied.

Returns true if the filename changes from what it was previously, false otherwise.

Definition at line 223 of file imageFile.cxx.

References Filename::get_fullpath_wo_extension(), and PNMFileType::get_suggested_extension().

bool ImageFile::set_filename ( PaletteGroup group,
const string &  basename 
)

Sets the filename, and if applicable, the alpha_filename, from the indicated basename.

The extension appropriate to the image file type specified in _color_type (and _alpha_type) is automatically applied.

Returns true if the filename changes from what it was previously, false otherwise.

Definition at line 181 of file imageFile.cxx.

References PaletteGroup::get_dirname().

Referenced by make_shadow_image().

void ImageFile::unlink ( )

Deletes the image file or files.

Definition at line 442 of file imageFile.cxx.

References FilenameUnifier::make_user_filename(), and Filename::unlink().

void TypedWritable::update_bam_nested ( BamWriter manager) [virtual, inherited]

Called by the BamWriter when this object has not itself been modified recently, but it should check its nested objects for updates.

Reimplemented in CFDoCullCommand, and PandaNode.

Definition at line 77 of file typedWritable.cxx.

void ImageFile::update_egg_tex ( EggTexture egg_tex) const
void ImageFile::update_properties ( const TextureProperties properties)

If the indicate TextureProperties structure is more specific than this one, updates this one.

Definition at line 164 of file imageFile.cxx.

References TextureProperties::update_properties().

Referenced by TextureReference::apply_properties_to_source(), and TextureReference::from_egg().

bool ImageFile::write ( const PNMImage image) const
void ImageFile::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.

Reimplemented in DestTextureImage, PaletteImage, SourceTextureImage, and TextureImage.

Definition at line 498 of file imageFile.cxx.

References Datagram::add_bool(), Datagram::add_int32(), Datagram::add_string(), Datagram::add_uint8(), FilenameUnifier::make_bam_filename(), and TextureProperties::write_datagram().


The documentation for this class was generated from the following files:
 All Classes Functions Variables Enumerations