Panda3D
|
This is an abstract base class that defines the interface for writing image files of various types. More...
#include "pnmWriter.h"
Public Member Functions | |
void | copy_header_from (const PNMImageHeader &header) |
Initializes all the data in the header (x_size, y_size, num_channels, etc.) to the same values indicated in the given header. | |
PNMFileType * | get_type () const |
Returns a pointer to the PNMFileType object that created this PNMWriter. | |
bool | is_valid () const |
Returns true if the PNMWriter can be used to write data, false if something is wrong. | |
void | set_color_type (ColorType type) |
void | set_maxval (xelval maxval) |
void | set_num_channels (int num_channels) |
void | set_x_size (int x_size) |
void | set_y_size (int y_size) |
virtual bool | supports_grayscale () const |
Returns true if this particular PNMWriter understands grayscale images. | |
virtual bool | supports_stream_write () const |
Returns true if this particular PNMWriter can write to a general stream (including pipes, etc.), or false if the writer must occasionally fseek() on its output stream, and thus only disk streams are supported. | |
virtual bool | supports_write_row () const |
Returns true if this particular PNMWriter supports a streaming interface to writing the data: that is, it is capable of writing the image one row at a time, via repeated calls to write_row(). | |
virtual int | write_data (xel *array, xelval *alpha) |
Writes out an entire image all at once, including the header, based on the image data stored in the given _x_size * _y_size array and alpha pointers. | |
virtual bool | write_header () |
If supports_write_row(), above, returns true, this function may be called to write out the image header in preparation to writing out the image data one row at a time. | |
virtual bool | write_row (xel *array, xelval *alpha) |
If supports_write_row(), above, returns true, this function may be called repeatedly to write the image, one horizontal row at a time, beginning from the top. | |
Protected Member Functions | |
PNMWriter (PNMFileType *type, ostream *file, bool owns_file) | |
Protected Attributes | |
ostream * | _file |
bool | _is_valid |
bool | _owns_file |
PNMFileType * | _type |
This is an abstract base class that defines the interface for writing image files of various types.
Any particular image file type that can be written must define a class that inherits from PNMWriter to write it.
Definition at line 30 of file pnmWriter.h.
void PNMWriter::copy_header_from | ( | const PNMImageHeader & | header | ) | [inline] |
Initializes all the data in the header (x_size, y_size, num_channels, etc.) to the same values indicated in the given header.
This should be done before writing anything to the file.
Definition at line 103 of file pnmWriter.I.
Referenced by PNMImage::write().
PNMFileType * PNMWriter::get_type | ( | ) | const [inline] |
Returns a pointer to the PNMFileType object that created this PNMWriter.
Reimplemented from PNMImageHeader.
Definition at line 37 of file pnmWriter.I.
bool PNMWriter::is_valid | ( | ) | const [inline] |
Returns true if the PNMWriter can be used to write data, false if something is wrong.
Definition at line 114 of file pnmWriter.I.
Referenced by PNMImageHeader::make_writer().
bool PNMWriter::supports_grayscale | ( | ) | const [virtual] |
Returns true if this particular PNMWriter understands grayscale images.
If this is false, then the rgb values of the xel array will be pre-filled with the same value across all three channels, to allow the writer to simply write out RGB data for a grayscale image.
Definition at line 100 of file pnmWriter.cxx.
Referenced by PNMImage::write().
bool PNMWriter::supports_stream_write | ( | ) | const [virtual] |
Returns true if this particular PNMWriter can write to a general stream (including pipes, etc.), or false if the writer must occasionally fseek() on its output stream, and thus only disk streams are supported.
Definition at line 153 of file pnmWriter.cxx.
bool PNMWriter::supports_write_row | ( | ) | const [virtual] |
Returns true if this particular PNMWriter supports a streaming interface to writing the data: that is, it is capable of writing the image one row at a time, via repeated calls to write_row().
Returns false if the only way to write from this file is all at once, via write_data().
Definition at line 85 of file pnmWriter.cxx.
int PNMWriter::write_data | ( | xel * | array, |
xelval * | alpha | ||
) | [virtual] |
Writes out an entire image all at once, including the header, based on the image data stored in the given _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 written.
It is the user's responsibility to fill in the header data via calls to set_x_size(), set_num_channels(), etc., or copy_header_from(), before calling write_data().
It is important to delete the PNMWriter class after successfully writing the data. Failing to do this may result in some data not getting flushed!
Derived classes need not override this if they instead provide supports_streaming() and write_row(), below.
Definition at line 54 of file pnmWriter.cxx.
References Thread::consider_yield(), write_header(), and write_row().
Referenced by PNMImage::write().
bool PNMWriter::write_header | ( | ) | [virtual] |
If supports_write_row(), above, returns true, this function may be called to write out the image header in preparation to writing out the image data one row at a time.
Returns true if the header is successfully written, false if there is an error.
It is the user's responsibility to fill in the header data via calls to set_x_size(), set_num_channels(), etc., or copy_header_from(), before calling write_header().
Definition at line 119 of file pnmWriter.cxx.
Referenced by write_data().
bool PNMWriter::write_row | ( | xel * | array, |
xelval * | alpha | ||
) | [virtual] |
If supports_write_row(), above, returns true, this function may be called repeatedly to write the image, one horizontal row at a time, beginning from the top.
Returns true if the row is successfully written, false if there is an error.
You must first call write_header() before writing the individual rows. It is also important to delete the PNMWriter class after successfully writing the last row. Failing to do this may result in some data not getting flushed!
Definition at line 139 of file pnmWriter.cxx.
Referenced by write_data().