39 return "Portable Float Map";
85 return (magic_number.size() >= 2) &&
86 (magic_number.substr(0, 2) ==
"PF" ||
87 magic_number.substr(0, 2) ==
"Pf" ||
88 magic_number.substr(0, 2) ==
"pf");
97 make_reader(istream *file,
bool owns_file,
const string &magic_number) {
98 return new Reader(
this, file, owns_file, magic_number);
108 return new Writer(
this, file, owns_file);
115 PNMFileTypePfm::Reader::
116 Reader(
PNMFileType *type, istream *file,
bool owns_file,
string magic_number) :
119 read_magic_number(_file, magic_number, 2);
121 if (magic_number ==
"pf") {
125 read_magic_number(_file, magic_number, 4);
128 if (magic_number ==
"PF") {
131 }
else if (magic_number ==
"Pf") {
134 }
else if (magic_number ==
"pf2c") {
138 }
else if (magic_number ==
"pf4c") {
144 <<
"Not a PFM file\n";
149 _maxval = PGM_MAXMAXVAL;
151 (*_file) >> _x_size >> _y_size >> _scale;
154 <<
"Error parsing PFM header\n";
183 bool little_endian =
false;
186 little_endian =
true;
188 if (pfm_force_littleendian) {
189 little_endian =
true;
191 if (pfm_reverse_dimensions) {
197 pfm.
clear(_x_size, _y_size, _num_channels);
201 int size = _x_size * _y_size * _num_channels;
206 (*_file).read((
char *)&table[0],
sizeof(PN_float32) * size);
207 if ((*_file).fail() && !(*_file).eof()) {
213 #ifdef WORDS_BIGENDIAN 214 bool endian_reversed = little_endian;
216 bool endian_reversed = !little_endian;
219 if (endian_reversed) {
220 for (
int ti = 0; ti < size; ++ti) {
234 PNMFileTypePfm::Writer::
235 Writer(
PNMFileType *type, ostream *file,
bool owns_file) :
266 nassertr(pfm.is_valid(),
false);
274 (*_file) <<
"pf2c\n";
282 (*_file) <<
"pf4c\n";
286 nassert_raise(
"unexpected channel count");
291 PN_float32 scale = cabs(pfm.
get_scale());
295 #ifndef WORDS_BIGENDIAN 300 (*_file) << scale <<
"\n";
304 (*_file).write((
const char *)&table[0],
sizeof(PN_float32) * size);
306 if ((*_file).fail()) {
309 nassertr(
sizeof(PN_float32) == 4,
false);
319 register_factory(get_class_type(), make_PNMFileTypePfm);
virtual std::string get_name() const
Returns a few words describing the file type.
virtual std::string get_extension(int n) const
Returns the nth possible filename extension associated with this particular file type,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual bool write_pfm(const PfmFile &pfm)
Writes floating-point data from the indicated PfmFile.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Base class for objects that can be written to and read from Bam files.
This is the base class of a family of classes that represent particular image file types that PNMImag...
virtual PNMWriter * make_writer(std::ostream *file, bool owns_file=true)
Allocates and returns a new PNMWriter suitable for reading from this file type, if possible.
virtual bool matches_magic_number(const std::string &magic_number) const
Returns true if the indicated "magic number" byte stream (the initial few bytes read from the file) m...
static PNMFileTypeRegistry * get_global_ptr()
Returns a pointer to the global PNMFileTypeRegistry object.
This is our own Panda specialization on the default STL vector.
virtual bool is_floating_point()
Returns true if this PNMFileType represents a floating-point image type, false if it is a normal,...
void swap_table(vector_float &table)
This is a very low-level function that completely exchanges the PfmFile's internal table of floating-...
virtual bool has_magic_number() const
Returns true if this particular file type uses a magic number to identify it, false otherwise.
virtual bool supports_floating_point()
Returns true if this PNMFileType can accept a floating-point image type, false if it can only accept ...
Defines a pfm file, a 2-d table of floating-point numbers, either 3-component or 1-component,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual bool read_pfm(PfmFile &pfm)
Reads floating-point data directly into the indicated PfmFile.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
const vector_float & get_table() const
This is a very low-level function that returns a read-only reference to the internal table of floatin...
PNMFileType * get_type_by_handle(TypeHandle handle) const
Returns the PNMFileType instance stored in the registry for the given TypeHandle, e....
virtual bool supports_integer()
Returns true if this PNMFileType can accept an integer image type, false if it can only accept a floa...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual std::string get_suggested_extension() const
Returns a suitable filename extension (without a leading dot) to suggest for files of this type,...
get_scale
The "scale" is reported in the pfm header and is probably meaningless.
This is an abstract base class that defines the interface for reading image files of various types.
This is an abstract base class that defines the interface for writing image files of various types.
NativeNumericData and ReversedNumericData work together to provide a sneaky interface for automatical...
virtual int get_num_extensions() const
Returns the number of different possible filename extensions associated with this particular file typ...
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual PNMReader * make_reader(std::istream *file, bool owns_file=true, const std::string &magic_number=std::string())
Allocates and returns a new PNMReader suitable for reading from this file type, if possible.
static void register_with_read_factory()
Registers the current object as something that can be read from a Bam file.
TypeHandle is the identifier used to differentiate C++ class types.
void store_value(void *dest, size_t length) const
Copies the data, with byte reversal if appropriate, into the indicated numeric variable,...
set_scale
The "scale" is reported in the pfm header and is probably meaningless.
void clear()
Eliminates all data in the file.