# PNMImageHeader

from pandac.PandaModules import PNMImageHeader

Class : PNMImageHeader
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.

## Inheritance:

PNMImageHeader:

## Methods of PNMImageHeader:

getColorType
getComment
getMaxval
getNumChannels
getType
getXSize
getYSize
hasAlpha
hasType
isGrayscale
makeReader
makeWriter
operator =
output
readHeader
readMagicNumber
setComment
setType

## Constants in PNMImageHeader:

CTInvalid | (ColorType)
CTGrayscale | (ColorType)
CTTwoChannel | (ColorType)
CTColor | (ColorType)
CTFourChannel | (ColorType)

getColorType PNMImageHeader::ColorType PNMImageHeader::get_color_type(void) const; Description: Returns the image type of the image, as an enumerated value. This is really just the number of channels cast to the enumerated type.

getComment string PNMImageHeader::get_comment(void) const; Description: Gets the user comment from the file.

getMaxval unsigned short int PNMImageHeader::get_maxval(void) const; Description: 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.

getNumChannels int PNMImageHeader::get_num_channels(void) const; Description: Returns the number of channels in the image.

getType PNMFileType *PNMImageHeader::get_type(void) const; Description: If the file type is known (e.g. has_type() returns true), returns its PNMFileType pointer; otherwise, returns NULL.

getXSize int PNMImageHeader::get_x_size(void) const; Description: Returns the number of pixels in the X direction. This is one more than the largest allowable X coordinate.

getYSize int PNMImageHeader::get_y_size(void) const; Description: Returns the number of pixels in the Y direction. This is one more than the largest allowable Y coordinate.

hasAlpha static bool PNMImageHeader::has_alpha(PNMImageHeader::ColorType color_type); Description: This static variant of has_alpha() returns true if the indicated image type includes an alpha channel, false otherwise. Description: 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.

hasType bool PNMImageHeader::has_type(void) const; Description: Returns true if the PNMImageHeader knows what type it is, false otherwise.

isGrayscale static bool PNMImageHeader::is_grayscale(PNMImageHeader::ColorType color_type); Description: This static variant of is_grayscale() returns true if the indicated image type represents a grayscale image, false otherwise. Description: 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.)

makeReader PNMReader *PNMImageHeader::make_reader(Filename const &filename, PNMFileType *type = ((void *)(0)), bool report_unknown_type = (1)) const; Description: 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. Description: 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.

makeWriter PNMWriter *PNMImageHeader::make_writer(Filename const &filename, PNMFileType *type = ((void *)(0))) const; Description: 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. Description: 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.

operator = void PNMImageHeader::operator =(PNMImageHeader const &copy); Description:

output void PNMImageHeader::output(ostream &out) const; Description:

readHeader bool PNMImageHeader::read_header(Filename const &filename, PNMFileType *type = ((void *)(0))); Description: 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.

readMagicNumber static bool PNMImageHeader::read_magic_number(istream *file, string &magic_number, int num_bytes); Description: 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 void PNMImageHeader::set_comment(string const &comment); Description: Writes a user comment string to the image (header).

setType void PNMImageHeader::set_type(PNMFileType *type); Description: 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.