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. More... | |
PNMFileType * | get_type () const |
Returns a pointer to the PNMFileType object that created this PNMWriter. More... | |
bool | is_valid () const |
Returns true if the PNMWriter can be used to write data, false if something is wrong. More... | |
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_floating_point () |
Returns true if this PNMFileType can accept a floating-point image type, false if it can only accept a normal, integer type. More... | |
virtual bool | supports_grayscale () const |
Returns true if this particular PNMWriter understands grayscale images. More... | |
virtual bool | supports_integer () |
Returns true if this PNMFileType can accept an integer image type, false if it can only accept a floating-point type. More... | |
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. More... | |
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(). More... | |
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. More... | |
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. More... | |
virtual bool | write_pfm (const PfmFile &pfm) |
Writes floating-point data from the indicated PfmFile. More... | |
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. More... | |
![]() | |
PNMImageHeader (const PNMImageHeader ©) | |
ColorSpace | get_color_space () const |
ColorType | get_color_type () const |
Returns the image type of the image, as an enumerated value. More... | |
std::string | get_comment () const |
xelval | get_maxval () const |
int | get_num_channels () const |
LVecBase2i | get_size () const |
PNMFileType * | get_type () const |
int | get_x_size () const |
Returns the number of pixels in the X direction. More... | |
int | get_y_size () const |
Returns the number of pixels in the Y direction. More... | |
bool | has_alpha () const |
Returns true if the image includes an alpha channel, false otherwise. More... | |
bool | has_type () const |
bool | is_grayscale () const |
Returns false if the image is a full-color image, and has red, green, and blue components; true if it is a grayscale image and has only a gray component. More... | |
PNMReader * | make_reader (const Filename &filename, PNMFileType *type=nullptr, bool report_unknown_type=true) const |
Returns a newly-allocated PNMReader of the suitable type for reading from the indicated image filename, or NULL if the filename cannot be read for some reason. More... | |
PNMReader * | make_reader (std::istream *file, bool owns_file=true, const Filename &filename=Filename(), std::string magic_number=std::string(), PNMFileType *type=nullptr, bool report_unknown_type=true) const |
Returns a newly-allocated PNMReader of the suitable type for reading from the already-opened image file, or NULL if the file cannot be read for some reason. More... | |
PNMWriter * | make_writer (const Filename &filename, PNMFileType *type=nullptr) const |
Returns a newly-allocated PNMWriter of the suitable type for writing an image to the indicated filename, or NULL if the filename cannot be written for some reason. More... | |
PNMWriter * | make_writer (std::ostream *file, bool owns_file=true, const Filename &filename=Filename(), PNMFileType *type=nullptr) const |
Returns a newly-allocated PNMWriter of the suitable type for writing to the already-opened image file, or NULL if the file cannot be written for some reason. More... | |
void | operator= (const PNMImageHeader ©) |
void | output (std::ostream &out) const |
bool | read_header (const Filename &filename, PNMFileType *type=nullptr, bool report_unknown_type=true) |
Opens up the image file and tries to read its header information to determine its size, number of channels, etc. More... | |
bool | read_header (std::istream &data, const std::string &filename=std::string(), PNMFileType *type=nullptr, bool report_unknown_type=true) |
Reads the image header information only from the indicated stream. More... | |
void | set_comment (const std::string &comment) |
void | set_type (PNMFileType *type) |
Sets the file type of this PNMImage. More... | |
Additional Inherited Members | |
![]() | |
enum | ColorType { CT_invalid = 0, CT_grayscale = 1, CT_two_channel = 2, CT_color = 3, CT_four_channel = 4 } |
typedef pmap< PixelSpec, int > | HistMap |
typedef pvector< PixelSpec > | Palette |
typedef pvector< PixelSpecCount > | PixelCount |
![]() | |
static bool | has_alpha (ColorType color_type) |
This static variant of has_alpha() returns true if the indicated image type includes an alpha channel, false otherwise. More... | |
static bool | is_grayscale (ColorType color_type) |
This static variant of is_grayscale() returns true if the indicated image type represents a grayscale image, false otherwise. More... | |
static bool | read_magic_number (std::istream *file, std::string &magic_number, int num_bytes) |
Ensures that the first n bytes of the file are read into magic_number. More... | |
![]() | |
get_color_space | |
Returns the color space that the image is encoded in, or CS_unspecified if unknown. More... | |
get_comment | |
Gets the user comment from the file. More... | |
get_maxval | |
Returns the maximum channel value allowable for any pixel in this image; for instance, 255 for a typical 8-bit-per-channel image. More... | |
get_num_channels | |
Returns the number of channels in the image. More... | |
get_size | |
Returns the number of pixels in each direction. More... | |
get_type | |
If the file type is known (e.g. More... | |
has_type | |
Returns true if the PNMImageHeader knows what type it is, false otherwise. More... | |
set_comment | |
Writes a user comment string to the image (header). More... | |
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 27 of file pnmWriter.h.
|
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 83 of file pnmWriter.I.
Referenced by PfmFile::write(), and PNMImage::write().
|
inline |
Returns a pointer to the PNMFileType object that created this PNMWriter.
Definition at line 30 of file pnmWriter.I.
|
inline |
Returns true if the PNMWriter can be used to write data, false if something is wrong.
Definition at line 92 of file pnmWriter.I.
Referenced by PNMImageHeader::make_writer().
|
virtual |
Returns true if this PNMFileType can accept a floating-point image type, false if it can only accept a normal, integer type.
If this returns true, write_pfm() is implemented.
Reimplemented in PNMFileTypePfm::Writer.
Definition at line 34 of file pnmWriter.cxx.
Referenced by PfmFile::write().
|
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 112 of file pnmWriter.cxx.
Referenced by PNMImage::write().
|
virtual |
Returns true if this PNMFileType can accept an integer image type, false if it can only accept a floating-point type.
If this returns true, write_data() or write_row() is implemented.
Reimplemented in PNMFileTypePfm::Writer.
Definition at line 44 of file pnmWriter.cxx.
Referenced by PNMImage::write().
|
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.
|
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 101 of file pnmWriter.cxx.
|
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 74 of file pnmWriter.cxx.
References Thread::consider_yield(), write_header(), and write_row().
Referenced by PfmFile::write(), and PNMImage::write().
|
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 127 of file pnmWriter.cxx.
Referenced by write_data().
|
virtual |
Writes floating-point data from the indicated PfmFile.
Returns true on success, false on failure.
Reimplemented in PNMFileTypePfm::Writer.
Definition at line 53 of file pnmWriter.cxx.
Referenced by PfmFile::write(), and PNMImage::write().
|
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 143 of file pnmWriter.cxx.
Referenced by write_data().