Panda3D
Classes | Public Types | Public Member Functions | Static Public Member Functions

PNMImageHeader Class Reference

This is the base class of PNMImage, PNMReader, and PNMWriter. More...

Inheritance diagram for PNMImageHeader:
PNMImage

List of all members.

Classes

class  Histogram
class  PixelSpec
class  PixelSpecCount

Public Types

enum  ColorType {
  CTInvalid = 0, CTGrayscale = 1, CTTwoChannel = 2, CTColor = 3,
  CTFourChannel = 4
}

Public Member Functions

 PNMImageHeader ()
 PNMImageHeader (PNMImageHeader const copy)
ColorType getColorType ()
 Returns the image type of the image, as an enumerated value.
string getComment ()
 Gets the user comment from the file.
unsigned short int getMaxval ()
 Returns the maximum channel value allowable for any pixel in this image; for instance, 255 for a typical 8-bit-per-channel image.
int getNumChannels ()
 Returns the number of channels in the image.
PNMFileType getType ()
 If the file type is known (e.g.
int getXSize ()
 Returns the number of pixels in the X direction.
int getYSize ()
 Returns the number of pixels in the Y direction.
bool hasAlpha ()
 Returns true if the image includes an alpha channel, false otherwise.
bool hasType ()
 Returns true if the PNMImageHeader knows what type it is, false otherwise.
bool isGrayscale ()
 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.
PNMReader makeReader (istream file, bool owns_file, Filename const filename, string magic_number, PNMFileType type)
 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.
PNMReader makeReader (istream file)
 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.
PNMReader makeReader (Filename const filename, PNMFileType type, bool report_unknown_type)
 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 makeReader (Filename const filename, PNMFileType type)
 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 makeReader (Filename const filename)
 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 makeReader (istream file, bool owns_file, Filename const filename, string magic_number, PNMFileType type, bool report_unknown_type)
 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.
PNMReader makeReader (istream file, bool owns_file, Filename const filename)
 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.
PNMReader makeReader (istream file, bool owns_file, Filename const filename, string magic_number)
 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.
PNMReader makeReader (istream file, bool owns_file)
 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 makeWriter (Filename const filename, PNMFileType type)
 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 makeWriter (Filename const filename)
 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 makeWriter (ostream file, bool owns_file, Filename const filename, PNMFileType type)
 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.
PNMWriter makeWriter (ostream file, bool owns_file)
 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.
PNMWriter makeWriter (ostream file, bool owns_file, Filename const filename)
 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.
PNMWriter makeWriter (ostream file)
 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.
PNMImageHeader operator= (PNMImageHeader const copy)
 output (ostream out)
bool readHeader (istream data, string filename, PNMFileType type, bool report_unknown_type)
 Reads the image header information only from the indicated stream.
bool readHeader (Filename const filename, PNMFileType type)
 Opens up the image file and tries to read its header information to determine its size, number of channels, etc.
bool readHeader (Filename const filename)
 Opens up the image file and tries to read its header information to determine its size, number of channels, etc.
bool readHeader (istream data, string filename, PNMFileType type)
 Reads the image header information only from the indicated stream.
bool readHeader (Filename const filename, PNMFileType type, bool report_unknown_type)
 Opens up the image file and tries to read its header information to determine its size, number of channels, etc.
bool readHeader (istream data)
 Reads the image header information only from the indicated stream.
bool readHeader (istream data, string filename)
 Reads the image header information only from the indicated stream.
 setComment (string comment)
 Writes a user comment string to the image (header).
 setType (PNMFileType type)
 Sets the file type of this PNMImage.

Static Public Member Functions

static bool hasAlpha (ColorType color_type)
 This static variant of has_alpha() returns true if the indicated image type includes an alpha channel, false otherwise.
static bool isGrayscale (ColorType color_type)
 This static variant of is_grayscale() returns true if the indicated image type represents a grayscale image, false otherwise.
static bool readMagicNumber (istream file, basic_stringchar magic_number, int num_bytes)
 Ensures that the first n bytes of the file are read into magic_number.

Detailed Description

This is the base class of PNMImage, PNMReader, and PNMWriter.

It encapsulates all the information associated with an image that describes its size, number of channels, etc; that is, all the information about the image except the image data itself. It's the sort of information you typically read from the image file's header.


Member Enumeration Documentation

enum ColorType
Enumerator:
CTInvalid 
CTGrayscale 
CTTwoChannel 
CTColor 
CTFourChannel 

Constructor & Destructor Documentation

PNMImageHeader ( PNMImageHeader const  copy)

Member Function Documentation

ColorType getColorType ( )

Returns the image type of the image, as an enumerated value.

This is really just the number of channels cast to the enumerated type.

string getComment ( )

Gets the user comment from the file.

unsigned short int getMaxval ( )

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.

int getNumChannels ( )

Returns the number of channels in the image.

PNMFileType getType ( )

If the file type is known (e.g.

has_type() returns true), returns its PNMFileType pointer; otherwise, returns NULL.

int getXSize ( )

Returns the number of pixels in the X direction.

This is one more than the largest allowable X coordinate.

int getYSize ( )

Returns the number of pixels in the Y direction.

This is one more than the largest allowable Y coordinate.

bool hasAlpha ( )

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.

static bool hasAlpha ( ColorType  color_type) [static]

This static variant of has_alpha() returns true if the indicated image type includes an alpha channel, false otherwise.

bool hasType ( )

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

bool isGrayscale ( )

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

static bool isGrayscale ( ColorType  color_type) [static]

This static variant of is_grayscale() returns true if the indicated image type represents a grayscale image, false otherwise.

PNMReader makeReader ( Filename const  filename,
PNMFileType  type,
bool  report_unknown_type 
)

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.

PNMReader makeReader ( istream  file,
bool  owns_file,
Filename const  filename,
string  magic_number,
PNMFileType  type 
)

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.

PNMReader makeReader ( istream  file)

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.

PNMReader makeReader ( Filename const  filename,
PNMFileType  type 
)

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.

PNMReader makeReader ( Filename const  filename)

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.

PNMReader makeReader ( istream  file,
bool  owns_file,
Filename const  filename,
string  magic_number,
PNMFileType  type,
bool  report_unknown_type 
)

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.

PNMReader makeReader ( istream  file,
bool  owns_file,
Filename const  filename,
string  magic_number 
)

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.

PNMReader makeReader ( istream  file,
bool  owns_file,
Filename const  filename 
)

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.

PNMReader makeReader ( istream  file,
bool  owns_file 
)

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.

PNMWriter makeWriter ( Filename const  filename,
PNMFileType  type 
)

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.

PNMWriter makeWriter ( ostream  file)

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.

PNMWriter makeWriter ( Filename const  filename)

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.

PNMWriter makeWriter ( ostream  file,
bool  owns_file,
Filename const  filename,
PNMFileType  type 
)

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.

PNMWriter makeWriter ( ostream  file,
bool  owns_file 
)

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.

PNMWriter makeWriter ( ostream  file,
bool  owns_file,
Filename const  filename 
)

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.

PNMImageHeader operator= ( PNMImageHeader const  copy)
output ( ostream  out)
bool readHeader ( istream  data)

Reads the image header information only from the indicated stream.

The filename is advisory only, and may be used to suggest a type if it has a known extension.

If type is non-NULL, it is a suggestion for the type of file it is (and a non-NULL type will override any magic number test or filename extension lookup).

Returns true if successful, false on error.

bool readHeader ( Filename const  filename,
PNMFileType  type,
bool  report_unknown_type 
)

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.

bool readHeader ( istream  data,
string  filename,
PNMFileType  type,
bool  report_unknown_type 
)

Reads the image header information only from the indicated stream.

The filename is advisory only, and may be used to suggest a type if it has a known extension.

If type is non-NULL, it is a suggestion for the type of file it is (and a non-NULL type will override any magic number test or filename extension lookup).

Returns true if successful, false on error.

bool readHeader ( Filename const  filename,
PNMFileType  type 
)

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.

bool readHeader ( istream  data,
string  filename 
)

Reads the image header information only from the indicated stream.

The filename is advisory only, and may be used to suggest a type if it has a known extension.

If type is non-NULL, it is a suggestion for the type of file it is (and a non-NULL type will override any magic number test or filename extension lookup).

Returns true if successful, false on error.

bool readHeader ( Filename const  filename)

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.

bool readHeader ( istream  data,
string  filename,
PNMFileType  type 
)

Reads the image header information only from the indicated stream.

The filename is advisory only, and may be used to suggest a type if it has a known extension.

If type is non-NULL, it is a suggestion for the type of file it is (and a non-NULL type will override any magic number test or filename extension lookup).

Returns true if successful, false on error.

static bool readMagicNumber ( istream  file,
basic_stringchar  magic_number,
int  num_bytes 
) [static]

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.

setComment ( string  comment)

Writes a user comment string to the image (header).

setType ( PNMFileType  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.

 All Classes Namespaces Functions Variables Enumerations Enumerator Properties