Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

PNMWriter Class Reference

This is an abstract base class that defines the interface for writing image files of various types. More...

#include <pnmWriter.h>

Inheritance diagram for PNMWriter:

PNMImageHeader PNMFileTypeAlias::Writer PNMFileTypeBMP::Writer PNMFileTypeIMG::Writer PNMFileTypeJPG2000::Writer PNMFileTypeJPG::Writer PNMFileTypeSGI::Writer PNMFileTypeSoftImage::Writer PNMFileTypeTGA::Writer PNMFileTypeTIFF::Writer List of all members.

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 ()
PNMFileTypeget_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.

PNMReadermake_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.

PNMReadermake_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

Detailed Description

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 44 of file pnmWriter.h.


Member Enumeration Documentation

enum PNMImageHeader::ColorType [inherited]
 

Enumeration values:
CT_invalid 
CT_grayscale 
CT_two_channel 
CT_color 
CT_four_channel 

Definition at line 65 of file pnmImageHeader.h.


Constructor & Destructor Documentation

PNMWriter::PNMWriter PNMFileType type,
ostream *  file,
bool  owns_file
[inline, protected]
 

Definition at line 31 of file pnmWriter.I.

PNMWriter::~PNMWriter  )  [virtual]
 

Definition at line 32 of file pnmWriter.cxx.


Member Function Documentation

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 131 of file pnmWriter.I.

PNMImageHeader::ColorType PNMImageHeader::get_color_type  )  const [inline, inherited]
 

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().

xelval PNMImageHeader::get_maxval  )  const [inline, inherited]
 

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().

int PNMImageHeader::get_num_channels  )  const [inline, inherited]
 

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().

PNMFileType * PNMWriter::get_type void   )  const [inline]
 

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().

int PNMImageHeader::get_x_size  )  const [inline, inherited]
 

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().

int PNMImageHeader::get_y_size  )  const [inline, inherited]
 

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().

bool PNMImageHeader::has_alpha  )  const [inline, inherited]
 

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().

bool PNMImageHeader::has_alpha PNMImageHeader::ColorType  color_type  )  [inline, static, inherited]
 

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().

bool PNMImageHeader::has_type  )  const [inline, inherited]
 

Returns true if the PNMImageHeader knows what type it is, false otherwise.

Definition at line 252 of file pnmImageHeader.I.

bool PNMImageHeader::is_grayscale  )  const [inline, inherited]
 

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().

bool PNMImageHeader::is_grayscale PNMImageHeader::ColorType  color_type  )  [inline, static, inherited]
 

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().

PNMReader * PNMImageHeader::make_reader istream *  file,
bool  owns_file = true,
const Filename filename = Filename(),
string  magic_number = string(),
PNMFileType type = NULL
const [inherited]
 

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.

PNMReader * PNMImageHeader::make_reader const Filename filename,
PNMFileType type = NULL
const [inherited]
 

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.

PNMWriter * PNMImageHeader::make_writer ostream *  file,
bool  owns_file = true,
const Filename filename = Filename(),
PNMFileType type = NULL
const [inherited]
 

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.

PNMWriter * PNMImageHeader::make_writer const Filename filename,
PNMFileType type = NULL
const [inherited]
 

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().

void PNMImageHeader::output ostream &  out  )  const [inherited]
 

Definition at line 474 of file pnmImageHeader.cxx.

bool PNMImageHeader::read_header const Filename filename,
PNMFileType type = NULL
[inherited]
 

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().

bool PNMImageHeader::read_magic_number istream *  file,
string &  magic_number,
int  num_bytes
[static, inherited]
 

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.

void PNMWriter::set_color_type ColorType  type  )  [inline]
 

Definition at line 61 of file pnmWriter.I.

References PNMImageHeader::_num_channels.

void PNMWriter::set_maxval xelval  maxval  )  [inline]
 

Definition at line 86 of file pnmWriter.I.

References PNMImageHeader::_y_size, INLINE, and nassertv.

void PNMWriter::set_num_channels int  num_channels  )  [inline]
 

Definition at line 73 of file pnmWriter.I.

Referenced by get_type().

void PNMImageHeader::set_type PNMFileType type  )  [inline, inherited]
 

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.

void PNMWriter::set_x_size int  x_size  )  [inline]
 

Definition at line 98 of file pnmWriter.I.

References INLINE, and PNMImageHeader::operator=().

void PNMWriter::set_y_size int  y_size  )  [inline]
 

Definition at line 111 of file pnmWriter.I.

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 205 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().

Reimplemented in PNMFileTypeAlias::Writer, PNMFileTypeIMG::Writer, PNMFileTypeSGI::Writer, and PNMFileTypeSoftImage::Writer.

Definition at line 120 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.

Reimplemented in PNMFileTypeBMP::Writer, PNMFileTypeJPG::Writer, PNMFileTypeJPG2000::Writer, PNMFileTypeTGA::Writer, and PNMFileTypeTIFF::Writer.

Definition at line 82 of file pnmWriter.cxx.

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().

Reimplemented in PNMFileTypeAlias::Writer, PNMFileTypeIMG::Writer, PNMFileTypeSGI::Writer, and PNMFileTypeSoftImage::Writer.

Definition at line 151 of file pnmWriter.cxx.

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!

Reimplemented in PNMFileTypeAlias::Writer, PNMFileTypeIMG::Writer, PNMFileTypeSGI::Writer, and PNMFileTypeSoftImage::Writer.

Definition at line 184 of file pnmWriter.cxx.


Member Data Documentation

ostream* PNMWriter::_file [protected]
 

Definition at line 75 of file pnmWriter.h.

Referenced by PNMFileTypeSGI::Writer::write_rgb_header(), PNMFileTypeSGI::Writer::Writer(), and PNMFileTypeIMG::Writer::Writer().

xelval PNMImageHeader::_maxval [protected, inherited]
 

Definition at line 114 of file pnmImageHeader.h.

Referenced by PNMImageHeader::is_grayscale(), PNMImage::set_color_type(), PNMFileTypeSGI::Writer::supports_write_row(), PNMFileTypeAlias::Writer::supports_write_row(), PNMFileTypeSGI::Writer::write_channels(), PNMFileTypeSGI::Writer::write_table(), PNMFileTypeIMG::Writer::Writer(), and PNMFileTypeAlias::Writer::Writer().

int PNMImageHeader::_num_channels [protected, inherited]
 

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().

bool PNMWriter::_owns_file [protected]
 

Definition at line 74 of file pnmWriter.h.

PNMFileType* PNMWriter::_type [protected]
 

Reimplemented from PNMImageHeader.

Definition at line 73 of file pnmWriter.h.

int PNMImageHeader::_x_size [protected, inherited]
 

Definition at line 112 of file pnmImageHeader.h.

Referenced by PNMImage::clear(), PNMImageHeader::has_alpha(), PNMFileTypeJPG::Reader::read_data(), PNMFileTypeJPG2000::Reader::read_data(), PNMFileTypeIMG::Reader::read_row(), PNMImage::set_blue(), PNMImage::set_green(), PNMImage::set_red(), PNMFileTypeTIFF::Writer::write_data(), PNMFileTypeJPG::Writer::write_data(), PNMFileTypeJPG2000::Writer::write_data(), PNMFileTypeTGA::Writer::Writer(), PNMFileTypeJPG::Writer::Writer(), PNMFileTypeJPG2000::Writer::Writer(), PNMFileTypeIMG::Writer::Writer(), PNMFileTypeBMP::Writer::Writer(), and PNMFileTypeAlias::Writer::Writer().

int PNMImageHeader::_y_size [protected, inherited]
 

Definition at line 112 of file pnmImageHeader.h.

Referenced by PNMImage::clear(), PNMFileTypeJPG::Reader::read_data(), PNMFileTypeJPG2000::Reader::read_data(), PNMFileTypeIMG::Reader::read_row(), PNMImage::set_green(), set_maxval(), PNMImage::set_red(), PNMFileTypeJPG::Writer::write_data(), PNMFileTypeJPG2000::Writer::write_data(), PNMFileTypeTGA::Writer::Writer(), PNMFileTypeJPG::Writer::Writer(), PNMFileTypeJPG2000::Writer::Writer(), and PNMFileTypeBMP::Writer::Writer().


The documentation for this class was generated from the following files:
Generated on Fri May 2 00:54:08 2003 for Panda by doxygen1.3