Panda3D
|
This is an abstract base class that defines the interface for reading image files of various types. More...
#include "pnmReader.h"
Public Member Functions | |
PNMFileType * | get_type () const |
Returns a pointer to the PNMFileType object that created this PNMReader. | |
bool | is_valid () const |
Returns true if the PNMReader can be used to read data, false if something is wrong. | |
virtual void | prepare_read () |
This method will be called before read_data() or read_row() is called. | |
virtual int | read_data (xel *array, xelval *alpha) |
Reads in an entire image all at once, storing it in the pre-allocated _x_size * _y_size array and alpha pointers. | |
virtual bool | read_row (xel *array, xelval *alpha, int x_size, int y_size) |
If supports_read_row(), above, returns true, this function may be called repeatedly to read the image, one horizontal row at a time, beginning from the top. | |
void | set_read_size (int x_size, int y_size) |
Instructs the reader to attempt to scale the image to the indicated size while reading it. | |
virtual bool | supports_read_row () const |
Returns true if this particular PNMReader is capable of returning the data one row at a time, via repeated calls to read_row(). | |
virtual bool | supports_stream_read () const |
Returns true if this particular PNMReader can read from a general stream (including pipes, etc.), or false if the reader must occasionally fseek() on its input stream, and thus only disk streams are supported. | |
Protected Member Functions | |
PNMReader (PNMFileType *type, istream *file, bool owns_file) | |
Protected Attributes | |
istream * | _file |
bool | _has_read_size |
bool | _is_valid |
int | _orig_x_size |
int | _orig_y_size |
bool | _owns_file |
int | _read_x_size |
int | _read_y_size |
PNMFileType * | _type |
int | _x_shift |
int | _y_shift |
This is an abstract base class that defines the interface for reading image files of various types.
Any particular image file type that can be read must define a class that inherits from PNMReader to read it.
Definition at line 31 of file pnmReader.h.
PNMFileType * PNMReader::get_type | ( | ) | const [inline] |
Returns a pointer to the PNMFileType object that created this PNMReader.
Reimplemented from PNMImageHeader.
Definition at line 54 of file pnmReader.I.
bool PNMReader::is_valid | ( | ) | const [inline] |
Returns true if the PNMReader can be used to read data, false if something is wrong.
Definition at line 65 of file pnmReader.I.
Referenced by PNMImageHeader::make_reader(), PNMImage::read(), and read_data().
void PNMReader::prepare_read | ( | ) | [virtual] |
This method will be called before read_data() or read_row() is called.
It instructs the reader to initialize its data structures as necessary to actually perform the read operation.
After this call, _x_size and _y_size should reflect the actual size that will be filled by read_data() (as possibly modified by set_read_size()).
Definition at line 52 of file pnmReader.cxx.
References supports_read_row().
Referenced by PNMImage::read().
int PNMReader::read_data | ( | xel * | array, |
xelval * | alpha | ||
) | [virtual] |
Reads in an entire image all at once, storing it in the pre-allocated _x_size * _y_size array and alpha pointers.
(If the image type has no alpha channel, alpha is ignored.) Returns the number of rows correctly read.
Derived classes need not override this if they instead provide supports_read_row() and read_row(), below.
Definition at line 87 of file pnmReader.cxx.
References Thread::consider_yield(), PNMImageHeader::has_alpha(), is_valid(), and read_row().
Referenced by PNMImage::read().
bool PNMReader::read_row | ( | xel * | array, |
xelval * | alpha, | ||
int | x_size, | ||
int | y_size | ||
) | [virtual] |
If supports_read_row(), above, returns true, this function may be called repeatedly to read the image, one horizontal row at a time, beginning from the top.
Returns true if the row is successfully read, false if there is an error or end of file.
The x_size and y_size parameters are the value of _x_size and _y_size as originally filled in by the constructor; it is the actual number of pixels in the image. (The _x_size and _y_size members may have been automatically modified by the time this method is called if we are scaling on load, so should not be used.)
Definition at line 227 of file pnmReader.cxx.
Referenced by read_data().
void PNMReader::set_read_size | ( | int | x_size, |
int | y_size | ||
) | [inline] |
Instructs the reader to attempt to scale the image to the indicated size while reading it.
The reader may or may not follow this suggestion, or may follow it only partially (e.g. by reading a file which is slightly reduced in size, but not the precise size requested).
Definition at line 41 of file pnmReader.I.
Referenced by PNMImage::read().
bool PNMReader::supports_read_row | ( | ) | const [virtual] |
Returns true if this particular PNMReader is capable of returning the data one row at a time, via repeated calls to read_row().
Returns false if the only way to read from this file is all at once, via read_data().
Definition at line 205 of file pnmReader.cxx.
Referenced by prepare_read().
bool PNMReader::supports_stream_read | ( | ) | const [virtual] |
Returns true if this particular PNMReader can read from a general stream (including pipes, etc.), or false if the reader must occasionally fseek() on its input stream, and thus only disk streams are supported.
Definition at line 242 of file pnmReader.cxx.