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

PNMReader Class Reference

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

#include <pnmReader.h>

Inheritance diagram for PNMReader:

PNMImageHeader PNMFileTypeAlias::Reader PNMFileTypeBMP::Reader PNMFileTypeIMG::Reader PNMFileTypeJPG2000::Reader PNMFileTypeJPG::Reader PNMFileTypeSGI::Reader PNMFileTypeSoftImage::Reader PNMFileTypeTGA::Reader PNMFileTypeTIFF::Reader 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 ~PNMReader ()
PNMFileTypeget_type () const
 Returns a pointer to the PNMFileType object that created this PNMReader.

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 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 read_row (xel *array, xelval *alpha)
 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.

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.

bool is_valid () const
 Returns true if the PNMReader can be used to read data, false if something is wrong.

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.

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

PNMWritermake_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

 PNMReader (PNMFileType *type, istream *file, bool owns_file)

Protected Attributes

PNMFileType_type
bool _owns_file
istream * _file
bool _is_valid
int _x_size
int _y_size
int _num_channels
xelval _maxval

Detailed Description

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 45 of file pnmReader.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

PNMReader::PNMReader PNMFileType type,
istream *  file,
bool  owns_file
[inline, protected]
 

Definition at line 30 of file pnmReader.I.

PNMReader::~PNMReader  )  [virtual]
 

Definition at line 32 of file pnmReader.cxx.


Member Function Documentation

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 * PNMReader::get_type void   )  const [inline]
 

Returns a pointer to the PNMFileType object that created this PNMReader.

Reimplemented from PNMImageHeader.

Definition at line 49 of file pnmReader.I.

References _is_valid, and INLINE.

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

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 64 of file pnmReader.I.

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.

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.

Reimplemented in PNMFileTypeBMP::Reader, PNMFileTypeJPG::Reader, PNMFileTypeJPG2000::Reader, and PNMFileTypeTGA::Reader.

Definition at line 64 of file pnmReader.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.

bool PNMReader::read_row xel array,
xelval alpha
[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.

Reimplemented in PNMFileTypeAlias::Reader, PNMFileTypeIMG::Reader, PNMFileTypeSGI::Reader, PNMFileTypeSoftImage::Reader, and PNMFileTypeTIFF::Reader.

Definition at line 118 of file pnmReader.cxx.

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.

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

Reimplemented in PNMFileTypeAlias::Reader, PNMFileTypeIMG::Reader, PNMFileTypeSGI::Reader, PNMFileTypeSoftImage::Reader, and PNMFileTypeTIFF::Reader.

Definition at line 97 of file pnmReader.cxx.

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 140 of file pnmReader.cxx.


Member Data Documentation

istream* PNMReader::_file [protected]
 

Definition at line 65 of file pnmReader.h.

Referenced by PNMFileTypeIMG::Reader::read_row().

bool PNMReader::_is_valid [protected]
 

Reimplemented in PNMFileTypeJPG::Reader.

Definition at line 66 of file pnmReader.h.

Referenced by get_type().

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(), PNMWriter::set_color_type(), PNMImage::set_maxval(), PNMFileTypeSGI::Writer::write_channels(), PNMFileTypeSGI::Writer::write_rgb_header(), PNMFileTypeSGI::Writer::write_table(), and PNMImageHeader::~PNMImageHeader().

bool PNMReader::_owns_file [protected]
 

Definition at line 64 of file pnmReader.h.

PNMFileType* PNMReader::_type [protected]
 

Reimplemented from PNMImageHeader.

Definition at line 63 of file pnmReader.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(), PNMWriter::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