#include <pnmWriter.h>
Inheritance diagram for PNMWriter:
Public Types | |
enum | ColorType { CT_invalid = 0, CT_grayscale = 1, CT_two_channel = 2, CT_color = 3, CT_four_channel = 4 } |
Public Member Functions | |
virtual | ~PNMWriter () |
PNMFileType * | get_type () const |
Returns a pointer to the PNMFileType object that created this PNMWriter. | |
void | set_color_type (ColorType type) |
void | set_num_channels (int num_channels) |
void | set_maxval (xelval maxval) |
void | set_x_size (int x_size) |
void | set_y_size (int y_size) |
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. | |
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 | 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 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. | |
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. | |
ColorType | get_color_type () const |
Returns the image type of the image, as an enumerated value. | |
int | get_num_channels () const |
Returns the number of channels in the image. | |
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. | |
bool | has_alpha () const |
Returns true if the image includes an alpha channel, false otherwise. | |
xelval | get_maxval () const |
Returns the maximum channel value allowable for any pixel in this image; for instance, 255 for a typical 8-bit-per-channel image. | |
int | get_x_size () const |
Returns the number of pixels in the X direction. | |
int | get_y_size () const |
Returns the number of pixels in the Y direction. | |
bool | has_type () const |
Returns true if the PNMImageHeader knows what type it is, false otherwise. | |
void | set_type (PNMFileType *type) |
Sets the file type of this PNMImage. | |
bool | read_header (const Filename &filename, PNMFileType *type=NULL) |
Opens up the image file and tries to read its header information to determine its size, number of channels, etc. | |
PNMReader * | make_reader (const Filename &filename, PNMFileType *type=NULL) 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. | |
PNMReader * | make_reader (istream *file, bool owns_file=true, const Filename &filename=Filename(), string magic_number=string(), PNMFileType *type=NULL) 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. | |
PNMWriter * | make_writer (const Filename &filename, PNMFileType *type=NULL) 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. | |
PNMWriter * | make_writer (ostream *file, bool owns_file=true, const Filename &filename=Filename(), PNMFileType *type=NULL) 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. | |
void | output (ostream &out) const |
Static Public Member Functions | |
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. | |
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. | |
bool | read_magic_number (istream *file, string &magic_number, int num_bytes) |
Ensures that the first n bytes of the file are read into magic_number. | |
Protected Member Functions | |
PNMWriter (PNMFileType *type, ostream *file, bool owns_file) | |
Protected Attributes | |
PNMFileType * | _type |
bool | _owns_file |
ostream * | _file |
int | _x_size |
int | _y_size |
int | _num_channels |
xelval | _maxval |
Any particular image file type that can be written must define a class that inherits from PNMWriter to write it.
Definition at line 44 of file pnmWriter.h.
|
Definition at line 65 of file pnmImageHeader.h. |
|
Definition at line 31 of file pnmWriter.I. |
|
Definition at line 32 of file pnmWriter.cxx. |
|
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 131 of file pnmWriter.I. |
|
Returns the image type of the image, as an enumerated value. This is really just the number of channels cast to the enumerated type. Definition at line 95 of file pnmImageHeader.I. References PNMImageHeader::CT_grayscale, PNMImageHeader::CT_two_channel, and INLINE. Referenced by PNMImageHeader::get_num_channels(), PNMImage::write(), and PixelBuffer::write(). |
|
Returns the maximum channel value allowable for any pixel in this image; for instance, 255 for a typical 8-bit-per-channel image. A pixel with this value is full on. Definition at line 203 of file pnmImageHeader.I. References PNMImageHeader::_type. Referenced by PNMImage::clamp_val(), PNMImage::fill(), PNMImage::operator=(), and PNMImage::~PNMImage(). |
|
Returns the number of channels in the image.
Definition at line 109 of file pnmImageHeader.I. References PNMImageHeader::get_color_type(), INLINE, and PNMImageHeader::is_grayscale(). Referenced by PixelBuffer::write(). |
|
Returns a pointer to the PNMFileType object that created this PNMWriter.
Reimplemented from PNMImageHeader. Definition at line 49 of file pnmWriter.I. References INLINE, and set_num_channels(). |
|
Returns the number of pixels in the X direction. This is one more than the largest allowable X coordinate. Definition at line 220 of file pnmImageHeader.I. Referenced by PNMImage::copy_header_from(), down_to_power_2(), Texture::read(), WindowFramework::set_background_type(), PNMImage::set_color_type(), and PNMImage::write(). |
|
Returns the number of pixels in the Y direction. This is one more than the largest allowable Y coordinate. Definition at line 237 of file pnmImageHeader.I. Referenced by PNMImage::copy_header_from(), down_to_power_2(), Texture::read(), WindowFramework::set_background_type(), PNMImage::set_color_type(), and PNMImage::write(). |
|
Returns true if the image includes an alpha channel, false otherwise. Unlike is_grayscale(), if this returns false it is an error to call any of the functions accessing the alpha channel. Definition at line 184 of file pnmImageHeader.I. References PNMImageHeader::_type, INLINE, and NULL. Referenced by PNMImage::copy_from(), PNMImage::set_color_type(), and PNMImage::write(). |
|
This static variant of has_alpha() returns true if the indicated image type includes an alpha channel, false otherwise.
Definition at line 165 of file pnmImageHeader.I. References PNMImageHeader::_x_size, and INLINE. Referenced by filter_image(), and WindowFramework::set_background_type(). |
|
Returns true if the PNMImageHeader knows what type it is, false otherwise.
Definition at line 252 of file pnmImageHeader.I. |
|
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. (The gray color is actually stored in the blue channel, and the red and green channels are ignored.) Definition at line 148 of file pnmImageHeader.I. References PNMImageHeader::_maxval, INLINE, and xelval. Referenced by PNMImageHeader::get_num_channels(), PNMImage::set_color_type(), PNMImage::write(), PNMFileTypeTGA::Writer::Writer(), and PNMFileTypeAlias::Writer::Writer(). |
|
This static variant of is_grayscale() returns true if the indicated image type represents a grayscale image, false otherwise.
Definition at line 127 of file pnmImageHeader.I. References PNMImageHeader::CT_four_channel, PNMImageHeader::CT_two_channel, and INLINE. Referenced by filter_image(). |
|
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. owns_file should be set true if the PNMReader is to be considered the owner of the stream pointer (in which case the stream will be deleted on completion, whether successful or not), or false if it should not delete it. The filename parameter is optional here, since the file has already been opened; it is only used to examine the extension and attempt to guess the file type. If magic_number is nonempty, it is assumed to represent the first few bytes that have already been read from the file. Some file types may have difficulty if this is more than two bytes. If type is non-NULL, it is a suggestion for the file type to use. The PNMReader should be deleted when it is no longer needed. Definition at line 189 of file pnmImageHeader.cxx. References PNMImageHeader::_type, PNMFileType::get_name(), and NULL. |
|
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. The filename "-" always stands for standard input. If type is specified, it is a suggestion for the file type to use. The PNMReader should be deleted when it is no longer needed. Definition at line 84 of file pnmImageHeader.cxx. |
|
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. owns_file should be set true if the PNMWriter is to be considered the owner of the stream pointer (in which case the stream will be deleted on completion, whether successful or not), or false if it should not delete it. The filename parameter is optional here, since the file has already been opened; it is only used to examine the extension and attempt to guess the intended file type. If type is non-NULL, it is a suggestion for the file type to use. The PNMWriter should be deleted when it is no longer needed. Definition at line 386 of file pnmImageHeader.cxx. |
|
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. The filename "-" always stands for standard output. If type is specified, it is a suggestion for the file type to use. The PNMWriter should be deleted when it is no longer needed. Definition at line 299 of file pnmImageHeader.cxx. References PNMImageHeader::_type, Filename::empty(), PNMFileType::get_name(), PNMFileTypeRegistry::get_ptr(), PNMFileTypeRegistry::get_type_from_extension(), PNMFileType::make_writer(), NULL, and writer(). |
|
Definition at line 474 of file pnmImageHeader.cxx. |
|
Opens up the image file and tries to read its header information to determine its size, number of channels, etc. If successful, updates the header information and returns true; otherwise, returns false. Definition at line 47 of file pnmImageHeader.cxx. Referenced by WindowFramework::set_background_type(). |
|
Ensures that the first n bytes of the file are read into magic_number. If magic_number is initially nonempty, assumes these represent the first few bytes already extracted. Returns true if successful, false if an end of file or error occurred before num_bytes could be read. Definition at line 454 of file pnmImageHeader.cxx. |
|
Definition at line 61 of file pnmWriter.I. References PNMImageHeader::_num_channels. |
|
Definition at line 86 of file pnmWriter.I. References PNMImageHeader::_y_size, INLINE, and nassertv. |
|
Definition at line 73 of file pnmWriter.I. Referenced by get_type(). |
|
Sets the file type of this PNMImage. This will be the default type used when an image is read, if the type cannot be determined by magic number or inferred by extension, or the type used when the image is written, if the type cannot be inferred from the filename extension. Definition at line 292 of file pnmImageHeader.I. |
|
Definition at line 98 of file pnmWriter.I. References INLINE, and PNMImageHeader::operator=(). |
|
Definition at line 111 of file pnmWriter.I. |
|
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 205 of file pnmWriter.cxx. |
|
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(). Reimplemented in PNMFileTypeAlias::Writer, PNMFileTypeIMG::Writer, PNMFileTypeSGI::Writer, and PNMFileTypeSoftImage::Writer. Definition at line 120 of file pnmWriter.cxx. |
|
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. Reimplemented in PNMFileTypeBMP::Writer, PNMFileTypeJPG::Writer, PNMFileTypeJPG2000::Writer, PNMFileTypeTGA::Writer, and PNMFileTypeTIFF::Writer. Definition at line 82 of file pnmWriter.cxx. |
|
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(). Reimplemented in PNMFileTypeAlias::Writer, PNMFileTypeIMG::Writer, PNMFileTypeSGI::Writer, and PNMFileTypeSoftImage::Writer. Definition at line 151 of file pnmWriter.cxx. |
|
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! Reimplemented in PNMFileTypeAlias::Writer, PNMFileTypeIMG::Writer, PNMFileTypeSGI::Writer, and PNMFileTypeSoftImage::Writer. Definition at line 184 of file pnmWriter.cxx. |
|
Definition at line 75 of file pnmWriter.h. Referenced by PNMFileTypeSGI::Writer::write_rgb_header(), PNMFileTypeSGI::Writer::Writer(), and PNMFileTypeIMG::Writer::Writer(). |
|
|
Definition at line 113 of file pnmImageHeader.h. Referenced by PNMImage::make_grayscale(), set_color_type(), PNMImage::set_maxval(), PNMFileTypeSGI::Writer::write_channels(), PNMFileTypeSGI::Writer::write_rgb_header(), PNMFileTypeSGI::Writer::write_table(), and PNMImageHeader::~PNMImageHeader(). |
|
Definition at line 74 of file pnmWriter.h. |
|
Reimplemented from PNMImageHeader. Definition at line 73 of file pnmWriter.h. |
|
|