From 0124053db8d72d0313480628c3bb089c8e008474 Mon Sep 17 00:00:00 2001 From: David Rose Date: Sat, 2 Dec 2000 18:07:23 +0000 Subject: [PATCH] *** empty log message *** --- panda/src/pnmimage/pnmFileType.cxx | 16 ++++++++ panda/src/pnmimage/pnmFileType.h | 16 ++++++-- panda/src/pnmimage/pnmFileTypeRegistry.cxx | 25 ++++++++++++- panda/src/pnmimage/pnmFileTypeRegistry.h | 6 ++- .../pnmimagetypes/config_pnmimagetypes.cxx | 15 ++++++++ panda/src/pnmimagetypes/pnmFileTypeAlias.cxx | 32 ++++++++++++++++ panda/src/pnmimagetypes/pnmFileTypeAlias.h | 7 ++++ panda/src/pnmimagetypes/pnmFileTypeBMP.cxx | 32 ++++++++++++++++ panda/src/pnmimagetypes/pnmFileTypeBMP.h | 7 ++++ panda/src/pnmimagetypes/pnmFileTypeIMG.cxx | 32 ++++++++++++++++ panda/src/pnmimagetypes/pnmFileTypeIMG.h | 7 ++++ panda/src/pnmimagetypes/pnmFileTypeJPG.cxx | 32 ++++++++++++++++ panda/src/pnmimagetypes/pnmFileTypeJPG.h | 7 ++++ panda/src/pnmimagetypes/pnmFileTypePNM.cxx | 32 ++++++++++++++++ panda/src/pnmimagetypes/pnmFileTypePNM.h | 8 ++++ .../src/pnmimagetypes/pnmFileTypeRadiance.cxx | 32 ++++++++++++++++ panda/src/pnmimagetypes/pnmFileTypeRadiance.h | 7 ++++ panda/src/pnmimagetypes/pnmFileTypeSGI.cxx | 32 ++++++++++++++++ panda/src/pnmimagetypes/pnmFileTypeSGI.h | 7 ++++ .../pnmimagetypes/pnmFileTypeSoftImage.cxx | 32 ++++++++++++++++ .../src/pnmimagetypes/pnmFileTypeSoftImage.h | 7 ++++ panda/src/pnmimagetypes/pnmFileTypeTIFF.cxx | 36 ++++++++++++++++++ panda/src/pnmimagetypes/pnmFileTypeTIFF.h | 7 ++++ panda/src/pnmimagetypes/pnmFileTypeYUV.cxx | 32 ++++++++++++++++ panda/src/pnmimagetypes/pnmFileTypeYUV.h | 7 ++++ panda/src/putil/bamReader.cxx | 37 ++++++++++++++++--- panda/src/putil/bamReader.h | 1 + 27 files changed, 498 insertions(+), 13 deletions(-) diff --git a/panda/src/pnmimage/pnmFileType.cxx b/panda/src/pnmimage/pnmFileType.cxx index 5871956856..ab5820857c 100644 --- a/panda/src/pnmimage/pnmFileType.cxx +++ b/panda/src/pnmimage/pnmFileType.cxx @@ -7,6 +7,8 @@ #include #include +#include +#include bool PNMFileType::_did_init_pnm = false; TypeHandle PNMFileType::_type_handle; @@ -152,3 +154,17 @@ init_pnm() { } } +//////////////////////////////////////////////////////////////////// +// Function: PNMFileType::write_datagram +// Access: Public, Virtual +// Description: Fills the indicated datagram up with a binary +// representation of the current object, in preparation +// for writing to a Bam file. +// +// None of the particular PNMFileType objects store any +// extra data--at least, not yet--so we just define this +// up here to do nothing. +//////////////////////////////////////////////////////////////////// +void PNMFileType:: +write_datagram(BamWriter *, Datagram &) { +} diff --git a/panda/src/pnmimage/pnmFileType.h b/panda/src/pnmimage/pnmFileType.h index 3686dac58b..2c0ffc685a 100644 --- a/panda/src/pnmimage/pnmFileType.h +++ b/panda/src/pnmimage/pnmFileType.h @@ -11,6 +11,7 @@ #include "pnmimage_base.h" #include +#include class PNMReader; class PNMWriter; @@ -21,7 +22,7 @@ class PNMWriter; // represent particular image file types that PNMImage // supports. //////////////////////////////////////////////////////////////////// -class EXPCL_PANDA PNMFileType : public TypedObject { +class EXPCL_PANDA PNMFileType : public TypedWriteable { protected: PNMFileType(); @@ -47,14 +48,23 @@ protected: private: static bool _did_init_pnm; + + // The TypedWriteable interface follows. +public: + static void register_with_read_factory(void); + virtual void write_datagram(BamWriter *writer, Datagram &datagram); + +protected: + static TypedWriteable *make_PNMFileType(const FactoryParams ¶ms); + public: static TypeHandle get_class_type() { return _type_handle; } static void init_type() { - TypedObject::init_type(); + TypedWriteable::init_type(); register_type(_type_handle, "PNMFileType", - TypedObject::get_class_type()); + TypedWriteable::get_class_type()); } virtual TypeHandle get_type() const { return get_class_type(); diff --git a/panda/src/pnmimage/pnmFileTypeRegistry.cxx b/panda/src/pnmimage/pnmFileTypeRegistry.cxx index 79dcc12e93..2b434d15b5 100644 --- a/panda/src/pnmimage/pnmFileTypeRegistry.cxx +++ b/panda/src/pnmimage/pnmFileTypeRegistry.cxx @@ -67,7 +67,7 @@ get_num_types() const { //////////////////////////////////////////////////////////////////// PNMFileType *PNMFileTypeRegistry:: get_type(int n) const { - nassertr(n >= 0 && n < _types.size(), NULL); + nassertr(n >= 0 && n < (int)_types.size(), NULL); return _types[n]; } @@ -143,6 +143,25 @@ get_type_from_magic_number(const string &magic_number) const { return NULL; } +//////////////////////////////////////////////////////////////////// +// Function: PNMFileTypeRegistry::get_type_by_handle +// Access: Public +// Description: Returns the PNMFileType instance stored in the +// registry for the given TypeHandle, e.g. as retrieved +// by a previous call to get_type() on the type +// instance. +//////////////////////////////////////////////////////////////////// +PNMFileType *PNMFileTypeRegistry:: +get_type_by_handle(TypeHandle handle) const { + Handles::const_iterator hi; + hi = _handles.find(handle); + if (hi != _handles.end()) { + return (*hi).second; + } + + return (PNMFileType *)NULL; +} + //////////////////////////////////////////////////////////////////// // Function: PNMFileTypeRegistry::write_types // Access: Public @@ -183,7 +202,8 @@ write_types(ostream &out, int indent_level) const { void PNMFileTypeRegistry:: register_type(PNMFileType *type) { // Make sure we haven't already registered this type. - if (find(_types.begin(), _types.end(), type) != _types.end()) { + Handles::iterator hi = _handles.find(type->get_type()); + if (hi != _handles.end()) { pnmimage_cat.warning() << "Attempt to register PNMFileType " << type->get_name() << " (" << type->get_type() << ") more than once.\n"; @@ -191,6 +211,7 @@ register_type(PNMFileType *type) { } _types.push_back(type); + _handles.insert(Handles::value_type(type->get_type(), type)); // Collect the unique extensions associated with the type. set unique_extensions; diff --git a/panda/src/pnmimage/pnmFileTypeRegistry.h b/panda/src/pnmimage/pnmFileTypeRegistry.h index 71fc06a8d9..33755161a2 100644 --- a/panda/src/pnmimage/pnmFileTypeRegistry.h +++ b/panda/src/pnmimage/pnmFileTypeRegistry.h @@ -10,8 +10,6 @@ #include -#include - class PNMFileType; //////////////////////////////////////////////////////////////////// @@ -33,6 +31,7 @@ public: PNMFileType *get_type_from_extension(const string &filename) const; PNMFileType *get_type_from_magic_number(const string &magic_number) const; + PNMFileType *get_type_by_handle(TypeHandle handle) const; void write_types(ostream &out, int indent_level = 0) const; @@ -47,6 +46,9 @@ private: typedef map Extensions; Extensions _extensions; + typedef map Handles; + Handles _handles; + bool _requires_sort; static PNMFileTypeRegistry *_global_ptr; diff --git a/panda/src/pnmimagetypes/config_pnmimagetypes.cxx b/panda/src/pnmimagetypes/config_pnmimagetypes.cxx index 039c4c7f8c..5d4c03e4bf 100644 --- a/panda/src/pnmimagetypes/config_pnmimagetypes.cxx +++ b/panda/src/pnmimagetypes/config_pnmimagetypes.cxx @@ -109,6 +109,7 @@ ConfigureFn(config_pnmimagetypes) { << "Invalid img-header-type: " << img_header_type_str << "\n"; } + // Register each type with the PNMFileTypeRegistry. PNMFileTypeRegistry *tr = PNMFileTypeRegistry::get_ptr(); tr->register_type(new PNMFileTypePNM); @@ -123,4 +124,18 @@ ConfigureFn(config_pnmimagetypes) { #ifdef HAVE_JPEG tr->register_type(new PNMFileTypeJPG); #endif + + // Also register with the Bam reader. + PNMFileTypePNM::register_with_read_factory(); + PNMFileTypeSGI::register_with_read_factory(); + PNMFileTypeAlias::register_with_read_factory(); + PNMFileTypeRadiance::register_with_read_factory(); + PNMFileTypeTIFF::register_with_read_factory(); + PNMFileTypeYUV::register_with_read_factory(); + PNMFileTypeIMG::register_with_read_factory(); + PNMFileTypeSoftImage::register_with_read_factory(); + PNMFileTypeBMP::register_with_read_factory(); +#ifdef HAVE_JPEG + PNMFileTypeJPG::register_with_read_factory(); +#endif } diff --git a/panda/src/pnmimagetypes/pnmFileTypeAlias.cxx b/panda/src/pnmimagetypes/pnmFileTypeAlias.cxx index 55d697bab6..e1dbadd72b 100644 --- a/panda/src/pnmimagetypes/pnmFileTypeAlias.cxx +++ b/panda/src/pnmimagetypes/pnmFileTypeAlias.cxx @@ -6,6 +6,9 @@ #include "pnmFileTypeAlias.h" #include "config_pnmimagetypes.h" +#include +#include + // Since Alias image files don't have a magic number, we'll make a // little sanity check on the size of the image. If either the width // or height is larger than this, it must be bogus. @@ -373,3 +376,32 @@ write_row(xel *row_data, xelval *) { } + +//////////////////////////////////////////////////////////////////// +// Function: PNMFileTypeAlias::register_with_read_factory +// Access: Public, Static +// Description: Registers the current object as something that can be +// read from a Bam file. +//////////////////////////////////////////////////////////////////// +void PNMFileTypeAlias:: +register_with_read_factory() { + BamReader::get_factory()-> + register_factory(get_class_type(), make_PNMFileTypeAlias); +} + +//////////////////////////////////////////////////////////////////// +// Function: PNMFileTypeAlias::make_PNMFileTypeAlias +// Access: Protected, Static +// Description: 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. +// +// In the case of the PNMFileType objects, since these +// objects are all shared, we just pull the object from +// the registry. +//////////////////////////////////////////////////////////////////// +TypedWriteable *PNMFileTypeAlias:: +make_PNMFileTypeAlias(const FactoryParams ¶ms) { + return PNMFileTypeRegistry::get_ptr()->get_type_by_handle(get_class_type()); +} diff --git a/panda/src/pnmimagetypes/pnmFileTypeAlias.h b/panda/src/pnmimagetypes/pnmFileTypeAlias.h index 394d9c17a2..f19994652e 100644 --- a/panda/src/pnmimagetypes/pnmFileTypeAlias.h +++ b/panda/src/pnmimagetypes/pnmFileTypeAlias.h @@ -49,6 +49,13 @@ public: }; + // The TypedWriteable interface follows. +public: + static void register_with_read_factory(); + +protected: + static TypedWriteable *make_PNMFileTypeAlias(const FactoryParams ¶ms); + public: static TypeHandle get_class_type() { return _type_handle; diff --git a/panda/src/pnmimagetypes/pnmFileTypeBMP.cxx b/panda/src/pnmimagetypes/pnmFileTypeBMP.cxx index ea479ac773..d8d4c9448a 100644 --- a/panda/src/pnmimagetypes/pnmFileTypeBMP.cxx +++ b/panda/src/pnmimagetypes/pnmFileTypeBMP.cxx @@ -6,6 +6,9 @@ #include "pnmFileTypeBMP.h" #include "config_pnmimagetypes.h" +#include +#include + static const char * const extensions[] = { "bmp" }; @@ -118,3 +121,32 @@ make_writer(FILE *file, bool owns_file) { return new Writer(this, file, owns_file); } + +//////////////////////////////////////////////////////////////////// +// Function: PNMFileTypeBMP::register_with_read_factory +// Access: Public, Static +// Description: Registers the current object as something that can be +// read from a Bam file. +//////////////////////////////////////////////////////////////////// +void PNMFileTypeBMP:: +register_with_read_factory() { + BamReader::get_factory()-> + register_factory(get_class_type(), make_PNMFileTypeBMP); +} + +//////////////////////////////////////////////////////////////////// +// Function: PNMFileTypeBMP::make_PNMFileTypeBMP +// Access: Protected, Static +// Description: 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. +// +// In the case of the PNMFileType objects, since these +// objects are all shared, we just pull the object from +// the registry. +//////////////////////////////////////////////////////////////////// +TypedWriteable *PNMFileTypeBMP:: +make_PNMFileTypeBMP(const FactoryParams ¶ms) { + return PNMFileTypeRegistry::get_ptr()->get_type_by_handle(get_class_type()); +} diff --git a/panda/src/pnmimagetypes/pnmFileTypeBMP.h b/panda/src/pnmimagetypes/pnmFileTypeBMP.h index 7527e9ecfc..cfb30eb10c 100644 --- a/panda/src/pnmimagetypes/pnmFileTypeBMP.h +++ b/panda/src/pnmimagetypes/pnmFileTypeBMP.h @@ -62,6 +62,13 @@ public: }; + // The TypedWriteable interface follows. +public: + static void register_with_read_factory(); + +protected: + static TypedWriteable *make_PNMFileTypeBMP(const FactoryParams ¶ms); + public: static TypeHandle get_class_type() { return _type_handle; diff --git a/panda/src/pnmimagetypes/pnmFileTypeIMG.cxx b/panda/src/pnmimagetypes/pnmFileTypeIMG.cxx index 612e832762..21964fa502 100644 --- a/panda/src/pnmimagetypes/pnmFileTypeIMG.cxx +++ b/panda/src/pnmimagetypes/pnmFileTypeIMG.cxx @@ -6,6 +6,9 @@ #include "pnmFileTypeIMG.h" #include "config_pnmimagetypes.h" +#include +#include + // Since raw image files don't have a magic number, we'll make a little // sanity check on the size of the image. If either the width or height is // larger than this, it must be bogus. @@ -332,3 +335,32 @@ write_row(xel *row_data, xelval *) { } + +//////////////////////////////////////////////////////////////////// +// Function: PNMFileTypeIMG::register_with_read_factory +// Access: Public, Static +// Description: Registers the current object as something that can be +// read from a Bam file. +//////////////////////////////////////////////////////////////////// +void PNMFileTypeIMG:: +register_with_read_factory() { + BamReader::get_factory()-> + register_factory(get_class_type(), make_PNMFileTypeIMG); +} + +//////////////////////////////////////////////////////////////////// +// Function: PNMFileTypeIMG::make_PNMFileTypeIMG +// Access: Protected, Static +// Description: 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. +// +// In the case of the PNMFileType objects, since these +// objects are all shared, we just pull the object from +// the registry. +//////////////////////////////////////////////////////////////////// +TypedWriteable *PNMFileTypeIMG:: +make_PNMFileTypeIMG(const FactoryParams ¶ms) { + return PNMFileTypeRegistry::get_ptr()->get_type_by_handle(get_class_type()); +} diff --git a/panda/src/pnmimagetypes/pnmFileTypeIMG.h b/panda/src/pnmimagetypes/pnmFileTypeIMG.h index 72774a5b52..1ef21eeb5b 100644 --- a/panda/src/pnmimagetypes/pnmFileTypeIMG.h +++ b/panda/src/pnmimagetypes/pnmFileTypeIMG.h @@ -49,6 +49,13 @@ public: }; + // The TypedWriteable interface follows. +public: + static void register_with_read_factory(); + +protected: + static TypedWriteable *make_PNMFileTypeIMG(const FactoryParams ¶ms); + public: static TypeHandle get_class_type() { return _type_handle; diff --git a/panda/src/pnmimagetypes/pnmFileTypeJPG.cxx b/panda/src/pnmimagetypes/pnmFileTypeJPG.cxx index 28ae38c721..3185f8169c 100644 --- a/panda/src/pnmimagetypes/pnmFileTypeJPG.cxx +++ b/panda/src/pnmimagetypes/pnmFileTypeJPG.cxx @@ -6,6 +6,9 @@ #include "pnmFileTypeJPG.h" #include "config_pnmimagetypes.h" +#include +#include + static const char * const extensions[] = { "jpg", "jpeg" }; @@ -119,3 +122,32 @@ make_writer(FILE *file, bool owns_file) { return new Writer(this, file, owns_file); } + +//////////////////////////////////////////////////////////////////// +// Function: PNMFileTypeJPG::register_with_read_factory +// Access: Public, Static +// Description: Registers the current object as something that can be +// read from a Bam file. +//////////////////////////////////////////////////////////////////// +void PNMFileTypeJPG:: +register_with_read_factory() { + BamReader::get_factory()-> + register_factory(get_class_type(), make_PNMFileTypeJPG); +} + +//////////////////////////////////////////////////////////////////// +// Function: PNMFileTypeJPG::make_PNMFileTypeJPG +// Access: Protected, Static +// Description: 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. +// +// In the case of the PNMFileType objects, since these +// objects are all shared, we just pull the object from +// the registry. +//////////////////////////////////////////////////////////////////// +TypedWriteable *PNMFileTypeJPG:: +make_PNMFileTypeJPG(const FactoryParams ¶ms) { + return PNMFileTypeRegistry::get_ptr()->get_type_by_handle(get_class_type()); +} diff --git a/panda/src/pnmimagetypes/pnmFileTypeJPG.h b/panda/src/pnmimagetypes/pnmFileTypeJPG.h index 0268bae4f5..52020fd86e 100644 --- a/panda/src/pnmimagetypes/pnmFileTypeJPG.h +++ b/panda/src/pnmimagetypes/pnmFileTypeJPG.h @@ -75,6 +75,13 @@ public: }; + // The TypedWriteable interface follows. +public: + static void register_with_read_factory(); + +protected: + static TypedWriteable *make_PNMFileTypeJPG(const FactoryParams ¶ms); + public: static TypeHandle get_class_type() { return _type_handle; diff --git a/panda/src/pnmimagetypes/pnmFileTypePNM.cxx b/panda/src/pnmimagetypes/pnmFileTypePNM.cxx index 81dcba5105..46aa9c836c 100644 --- a/panda/src/pnmimagetypes/pnmFileTypePNM.cxx +++ b/panda/src/pnmimagetypes/pnmFileTypePNM.cxx @@ -6,6 +6,9 @@ #include "pnmFileTypePNM.h" #include "config_pnmimagetypes.h" +#include +#include + extern "C" { #include "../pnm/pnm.h" #include "../pnm/ppm.h" @@ -316,3 +319,32 @@ write_row(xel *row_data, xelval *) { return true; } + +//////////////////////////////////////////////////////////////////// +// Function: PNMFileTypePNM::register_with_read_factory +// Access: Public, Static +// Description: Registers the current object as something that can be +// read from a Bam file. +//////////////////////////////////////////////////////////////////// +void PNMFileTypePNM:: +register_with_read_factory() { + BamReader::get_factory()-> + register_factory(get_class_type(), make_PNMFileTypePNM); +} + +//////////////////////////////////////////////////////////////////// +// Function: PNMFileTypePNM::make_PNMFileTypePNM +// Access: Protected, Static +// Description: 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. +// +// In the case of the PNMFileType objects, since these +// objects are all shared, we just pull the object from +// the registry. +//////////////////////////////////////////////////////////////////// +TypedWriteable *PNMFileTypePNM:: +make_PNMFileTypePNM(const FactoryParams ¶ms) { + return PNMFileTypeRegistry::get_ptr()->get_type_by_handle(get_class_type()); +} diff --git a/panda/src/pnmimagetypes/pnmFileTypePNM.h b/panda/src/pnmimagetypes/pnmFileTypePNM.h index 173de17ab0..5a19a3244c 100644 --- a/panda/src/pnmimagetypes/pnmFileTypePNM.h +++ b/panda/src/pnmimagetypes/pnmFileTypePNM.h @@ -58,6 +58,14 @@ public: int _pnm_format; }; + + // The TypedWriteable interface follows. +public: + static void register_with_read_factory(); + +protected: + static TypedWriteable *make_PNMFileTypePNM(const FactoryParams ¶ms); + public: static TypeHandle get_class_type() { return _type_handle; diff --git a/panda/src/pnmimagetypes/pnmFileTypeRadiance.cxx b/panda/src/pnmimagetypes/pnmFileTypeRadiance.cxx index 6735ad27f0..48ab135195 100644 --- a/panda/src/pnmimagetypes/pnmFileTypeRadiance.cxx +++ b/panda/src/pnmimagetypes/pnmFileTypeRadiance.cxx @@ -6,6 +6,9 @@ #include "pnmFileTypeRadiance.h" #include "config_pnmimagetypes.h" +#include +#include + extern "C" { #include "color.h" #include "resolu.h" @@ -335,3 +338,32 @@ write_row(xel *row_data, xelval *) { return true; } + +//////////////////////////////////////////////////////////////////// +// Function: PNMFileTypeRadiance::register_with_read_factory +// Access: Public, Static +// Description: Registers the current object as something that can be +// read from a Bam file. +//////////////////////////////////////////////////////////////////// +void PNMFileTypeRadiance:: +register_with_read_factory() { + BamReader::get_factory()-> + register_factory(get_class_type(), make_PNMFileTypeRadiance); +} + +//////////////////////////////////////////////////////////////////// +// Function: PNMFileTypeRadiance::make_PNMFileTypeRadiance +// Access: Protected, Static +// Description: 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. +// +// In the case of the PNMFileType objects, since these +// objects are all shared, we just pull the object from +// the registry. +//////////////////////////////////////////////////////////////////// +TypedWriteable *PNMFileTypeRadiance:: +make_PNMFileTypeRadiance(const FactoryParams ¶ms) { + return PNMFileTypeRegistry::get_ptr()->get_type_by_handle(get_class_type()); +} diff --git a/panda/src/pnmimagetypes/pnmFileTypeRadiance.h b/panda/src/pnmimagetypes/pnmFileTypeRadiance.h index 18bb493b30..948a6cb69d 100644 --- a/panda/src/pnmimagetypes/pnmFileTypeRadiance.h +++ b/panda/src/pnmimagetypes/pnmFileTypeRadiance.h @@ -52,6 +52,13 @@ public: }; + // The TypedWriteable interface follows. +public: + static void register_with_read_factory(); + +protected: + static TypedWriteable *make_PNMFileTypeRadiance(const FactoryParams ¶ms); + public: static TypeHandle get_class_type() { return _type_handle; diff --git a/panda/src/pnmimagetypes/pnmFileTypeSGI.cxx b/panda/src/pnmimagetypes/pnmFileTypeSGI.cxx index 52885f9b9d..acf11c76b1 100644 --- a/panda/src/pnmimagetypes/pnmFileTypeSGI.cxx +++ b/panda/src/pnmimagetypes/pnmFileTypeSGI.cxx @@ -7,6 +7,9 @@ #include "config_pnmimagetypes.h" #include "sgi.h" +#include +#include + static const char * const extensions[] = { "rgb", "rgba", "sgi" }; @@ -122,3 +125,32 @@ make_writer(FILE *file, bool owns_file) { return new Writer(this, file, owns_file); } + +//////////////////////////////////////////////////////////////////// +// Function: PNMFileTypeSGI::register_with_read_factory +// Access: Public, Static +// Description: Registers the current object as something that can be +// read from a Bam file. +//////////////////////////////////////////////////////////////////// +void PNMFileTypeSGI:: +register_with_read_factory() { + BamReader::get_factory()-> + register_factory(get_class_type(), make_PNMFileTypeSGI); +} + +//////////////////////////////////////////////////////////////////// +// Function: PNMFileTypeSGI::make_PNMFileTypeSGI +// Access: Protected, Static +// Description: 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. +// +// In the case of the PNMFileType objects, since these +// objects are all shared, we just pull the object from +// the registry. +//////////////////////////////////////////////////////////////////// +TypedWriteable *PNMFileTypeSGI:: +make_PNMFileTypeSGI(const FactoryParams ¶ms) { + return PNMFileTypeRegistry::get_ptr()->get_type_by_handle(get_class_type()); +} diff --git a/panda/src/pnmimagetypes/pnmFileTypeSGI.h b/panda/src/pnmimagetypes/pnmFileTypeSGI.h index a70e11b2d1..360baf286e 100644 --- a/panda/src/pnmimagetypes/pnmFileTypeSGI.h +++ b/panda/src/pnmimagetypes/pnmFileTypeSGI.h @@ -97,6 +97,13 @@ public: }; + // The TypedWriteable interface follows. +public: + static void register_with_read_factory(); + +protected: + static TypedWriteable *make_PNMFileTypeSGI(const FactoryParams ¶ms); + public: static TypeHandle get_class_type() { return _type_handle; diff --git a/panda/src/pnmimagetypes/pnmFileTypeSoftImage.cxx b/panda/src/pnmimagetypes/pnmFileTypeSoftImage.cxx index c721498bc3..72a1926b03 100644 --- a/panda/src/pnmimagetypes/pnmFileTypeSoftImage.cxx +++ b/panda/src/pnmimagetypes/pnmFileTypeSoftImage.cxx @@ -6,6 +6,9 @@ #include "pnmFileTypeSoftImage.h" #include "config_pnmimagetypes.h" +#include +#include + static const float imageVersionNumber = 3.0; static const int imageCommentLength = 80; static const char imageComment[imageCommentLength+1] = @@ -745,3 +748,32 @@ write_row(xel *row_data, xelval *alpha_data) { } + +//////////////////////////////////////////////////////////////////// +// Function: PNMFileTypeSoftImage::register_with_read_factory +// Access: Public, Static +// Description: Registers the current object as something that can be +// read from a Bam file. +//////////////////////////////////////////////////////////////////// +void PNMFileTypeSoftImage:: +register_with_read_factory() { + BamReader::get_factory()-> + register_factory(get_class_type(), make_PNMFileTypeSoftImage); +} + +//////////////////////////////////////////////////////////////////// +// Function: PNMFileTypeSoftImage::make_PNMFileTypeSoftImage +// Access: Protected, Static +// Description: 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. +// +// In the case of the PNMFileType objects, since these +// objects are all shared, we just pull the object from +// the registry. +//////////////////////////////////////////////////////////////////// +TypedWriteable *PNMFileTypeSoftImage:: +make_PNMFileTypeSoftImage(const FactoryParams ¶ms) { + return PNMFileTypeRegistry::get_ptr()->get_type_by_handle(get_class_type()); +} diff --git a/panda/src/pnmimagetypes/pnmFileTypeSoftImage.h b/panda/src/pnmimagetypes/pnmFileTypeSoftImage.h index be65db6b5f..a68149f3ce 100644 --- a/panda/src/pnmimagetypes/pnmFileTypeSoftImage.h +++ b/panda/src/pnmimagetypes/pnmFileTypeSoftImage.h @@ -56,6 +56,13 @@ public: }; + // The TypedWriteable interface follows. +public: + static void register_with_read_factory(); + +protected: + static TypedWriteable *make_PNMFileTypeSoftImage(const FactoryParams ¶ms); + public: static TypeHandle get_class_type() { return _type_handle; diff --git a/panda/src/pnmimagetypes/pnmFileTypeTIFF.cxx b/panda/src/pnmimagetypes/pnmFileTypeTIFF.cxx index 7c10259aa5..517a31654e 100644 --- a/panda/src/pnmimagetypes/pnmFileTypeTIFF.cxx +++ b/panda/src/pnmimagetypes/pnmFileTypeTIFF.cxx @@ -6,6 +6,13 @@ #include "pnmFileTypeTIFF.h" #include "config_pnmimagetypes.h" +#include +#include + +// Tiff will want to re-typedef these things. +#define int32 tiff_int32 +#define uint32 tiff_uint32 + extern "C" { #include "../pnm/ppmcmap.h" #include "../tiff/tiff.h" @@ -777,3 +784,32 @@ write_data(xel *array, xelval *alpha) { return _y_size; } + +//////////////////////////////////////////////////////////////////// +// Function: PNMFileTypeTIFF::register_with_read_factory +// Access: Public, Static +// Description: Registers the current object as something that can be +// read from a Bam file. +//////////////////////////////////////////////////////////////////// +void PNMFileTypeTIFF:: +register_with_read_factory() { + BamReader::get_factory()-> + register_factory(get_class_type(), make_PNMFileTypeTIFF); +} + +//////////////////////////////////////////////////////////////////// +// Function: PNMFileTypeTIFF::make_PNMFileTypeTIFF +// Access: Protected, Static +// Description: 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. +// +// In the case of the PNMFileType objects, since these +// objects are all shared, we just pull the object from +// the registry. +//////////////////////////////////////////////////////////////////// +TypedWriteable *PNMFileTypeTIFF:: +make_PNMFileTypeTIFF(const FactoryParams ¶ms) { + return PNMFileTypeRegistry::get_ptr()->get_type_by_handle(get_class_type()); +} diff --git a/panda/src/pnmimagetypes/pnmFileTypeTIFF.h b/panda/src/pnmimagetypes/pnmFileTypeTIFF.h index 0430826141..bcaf86a97d 100644 --- a/panda/src/pnmimagetypes/pnmFileTypeTIFF.h +++ b/panda/src/pnmimagetypes/pnmFileTypeTIFF.h @@ -61,6 +61,13 @@ public: }; + // The TypedWriteable interface follows. +public: + static void register_with_read_factory(); + +protected: + static TypedWriteable *make_PNMFileTypeTIFF(const FactoryParams ¶ms); + public: static TypeHandle get_class_type() { return _type_handle; diff --git a/panda/src/pnmimagetypes/pnmFileTypeYUV.cxx b/panda/src/pnmimagetypes/pnmFileTypeYUV.cxx index b69275bc3f..3a9e62c164 100644 --- a/panda/src/pnmimagetypes/pnmFileTypeYUV.cxx +++ b/panda/src/pnmimagetypes/pnmFileTypeYUV.cxx @@ -51,6 +51,9 @@ #include "pnmFileTypeYUV.h" #include "config_pnmimagetypes.h" +#include +#include + /* x must be signed for the following to work correctly */ #define limit(x) (xelval)(((x>0xffffff)?0xff0000:((x<=0xffff)?0:x&0xff0000))>>16) @@ -381,3 +384,32 @@ write_row(xel *row_data, xelval *) { } + +//////////////////////////////////////////////////////////////////// +// Function: PNMFileTypeYUV::register_with_read_factory +// Access: Public, Static +// Description: Registers the current object as something that can be +// read from a Bam file. +//////////////////////////////////////////////////////////////////// +void PNMFileTypeYUV:: +register_with_read_factory() { + BamReader::get_factory()-> + register_factory(get_class_type(), make_PNMFileTypeYUV); +} + +//////////////////////////////////////////////////////////////////// +// Function: PNMFileTypeYUV::make_PNMFileTypeYUV +// Access: Protected, Static +// Description: 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. +// +// In the case of the PNMFileType objects, since these +// objects are all shared, we just pull the object from +// the registry. +//////////////////////////////////////////////////////////////////// +TypedWriteable *PNMFileTypeYUV:: +make_PNMFileTypeYUV(const FactoryParams ¶ms) { + return PNMFileTypeRegistry::get_ptr()->get_type_by_handle(get_class_type()); +} diff --git a/panda/src/pnmimagetypes/pnmFileTypeYUV.h b/panda/src/pnmimagetypes/pnmFileTypeYUV.h index ae5051b7cb..c850e21f15 100644 --- a/panda/src/pnmimagetypes/pnmFileTypeYUV.h +++ b/panda/src/pnmimagetypes/pnmFileTypeYUV.h @@ -57,6 +57,13 @@ public: }; + // The TypedWriteable interface follows. +public: + static void register_with_read_factory(); + +protected: + static TypedWriteable *make_PNMFileTypeYUV(const FactoryParams ¶ms); + public: static TypeHandle get_class_type() { return _type_handle; diff --git a/panda/src/putil/bamReader.cxx b/panda/src/putil/bamReader.cxx index d69b91e224..26dc37c467 100644 --- a/panda/src/putil/bamReader.cxx +++ b/panda/src/putil/bamReader.cxx @@ -239,12 +239,23 @@ read_object(void) //////////////////////////////////////////////////////////////////// // Function: BamReader::read_pointer // Access: Public -// Description: Utility function provided to correctly read in objects -// from the Datagram source, that any other object contains -// pointers to. Will correctly handle all circular references -// Any caller of this function should pass a pointer to itself -// because the pointer request will be stored and completed -// at a later pointer when the object is actually generated +// Description: The interface for reading a pointer to another object +// from a Bam file. Objects reading themselves from a +// Bam file should call this when they expect to read a +// pointer, passing in the datagram iterator and a +// pointer to their own object, i.e. 'this'. +// +// Rather than returning a pointer immediately, this +// function reads the internal pointer information from +// the datagram and queues up the request. The pointer +// itself may not be available until later (it may be a +// pointer to an object that appears later in the Bam +// file). Later, when all pointers are available, the +// complete_pointers() callback function will be called +// with an array of actual pointers, one for time +// read_pointer() was called. It is then the calling +// object's responsibilty to store these pointers in the +// object properly. //////////////////////////////////////////////////////////////////// void BamReader:: read_pointer(DatagramIterator& scan, TypedWriteable* forWhom) @@ -264,6 +275,20 @@ read_pointer(DatagramIterator& scan, TypedWriteable* forWhom) queue(objId); } +//////////////////////////////////////////////////////////////////// +// Function: BamReader::read_pointers +// Access: Public +// Description: A convenience function to read a contiguous list of +// pointers. This is equivalent to calling +// read_pointer() count times. +//////////////////////////////////////////////////////////////////// +void BamReader:: +read_pointers(DatagramIterator &scan, TypedWriteable *forWhom, int count) { + for (int i = 0; i < count; i++) { + read_pointer(scan, forWhom); + } +} + //////////////////////////////////////////////////////////////////// // Function: BamReader::register_finalize // Access: Public diff --git a/panda/src/putil/bamReader.h b/panda/src/putil/bamReader.h index 2dc98946cb..12f3ac09a0 100644 --- a/panda/src/putil/bamReader.h +++ b/panda/src/putil/bamReader.h @@ -65,6 +65,7 @@ public: //points to, it needs to pass a reference to itself, that BamReader //can register in itself for later "fixing" void read_pointer(DatagramIterator &scan, TypedWriteable* forWhom); + void read_pointers(DatagramIterator &scan, TypedWriteable* forWhom, int count); //At any time you can call this function to try and resolve all //outstanding pointer requests. Will resolve all requests that