from panda3d.core import PNMImageHeader

class PNMImageHeader

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 diagram

__init__() → None
__init__(copy: PNMImageHeader) → None
assign(copy: PNMImageHeader) → PNMImageHeader
Return type

getColorType() → ColorType

Returns the image type of the image, as an enumerated value. This is really just the number of channels cast to the enumerated type.

Return type

ColorType

getNumChannels() → int

Returns the number of channels in the image.

isGrayscale() → bool

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

isGrayscale(color_type: ColorType) → bool

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

hasAlpha() → bool

Returns true if the image includes an alpha channel, false otherwise. Unlike isGrayscale(), if this returns false it is an error to call any of the functions accessing the alpha channel.

hasAlpha(color_type: ColorType) → bool

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

getMaxval() → xelval

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.

Return type

xelval

getColorSpace() → ColorSpace

Returns the color space that the image is encoded in, or CS_unspecified if unknown.

Return type

ColorSpace

getXSize() → int

Returns the number of pixels in the X direction. This is one more than the largest allowable X coordinate.

getYSize() → int

Returns the number of pixels in the Y direction. This is one more than the largest allowable Y coordinate.

getSize() → LVecBase2i

Returns the number of pixels in each direction. This is one more than the largest allowable coordinates.

Return type

LVecBase2i

getComment() → str

Gets the user comment from the file.

setComment(comment: str) → None

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

hasType() → bool

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

getType() → PNMFileType

If the file type is known (e.g. hasType() returns true), returns its PNMFileType pointer; otherwise, returns NULL.

Return type

PNMFileType

setType(type: PNMFileType) → None

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.

readHeader(filename: Filename, type: PNMFileType, report_unknown_type: bool) → bool

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.

readHeader(data: istream, filename: str, type: PNMFileType, report_unknown_type: bool) → bool

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.

makeReader(filename: Filename, type: PNMFileType, report_unknown_type: bool) → PNMReader

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.

Return type

makeReader(file: istream, owns_file: bool, filename: Filename, magic_number: str, type: PNMFileType, report_unknown_type: bool) → PNMReader

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.

Return type

makeWriter(filename: Filename, type: PNMFileType) → PNMWriter

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.

Return type

PNMWriter

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

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.

Return type

PNMWriter

output(out: ostream) → None
property num_channels

Returns the number of channels in the image.

Return type

int

property maxval

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.

Return type

xelval

property color_space

Returns the color space that the image is encoded in, or CS_unspecified if unknown.

Return type

ColorSpace

property size

Returns the number of pixels in each direction. This is one more than the largest allowable coordinates.

Return type

LVecBase2i

property comment
Getter

Gets the user comment from the file.

Setter

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

Return type

string

property type

If the file type is known (e.g. hasType() returns true), returns its PNMFileType pointer; otherwise, returns NULL.

Return type

PNMFileType

enum ColorType

This enumerated type indicates the number of channels in the image, and also implies an image type. You can treat it either as an integer number of channels or as an enumerated image type.

enumerator CT_invalid = 0
enumerator CT_grayscale = 1
enumerator CT_two_channel = 2
enumerator CT_color = 3
enumerator CT_four_channel = 4
class PixelSpec

Contains a single pixel specification used in compute_histogram() and make_histogram(). Note that pixels are stored by integer value, not by floating-point scaled value.

__init__(param0: PixelSpec) → None
__init__(rgb: xel) → None
__init__(rgb: xel, alpha: xelval) → None
__init__(gray_value: xelval) → None
__init__(gray_value: xelval, alpha: xelval) → None
__init__(red: xelval, green: xelval, blue: xelval) → None
__init__(red: xelval, green: xelval, blue: xelval, alpha: xelval) → None
compareTo(other: PixelSpec) → int
getRed() → xelval
Return type

xelval

getGreen() → xelval
Return type

xelval

getBlue() → xelval
Return type

xelval

getAlpha() → xelval
Return type

xelval

setRed(red: xelval) → None
setGreen(green: xelval) → None
setBlue(blue: xelval) → None
setAlpha(alpha: xelval) → None
static size() → int

Specifies the number of components in the PixelSpec; this is always 4, regardless of the type of image it was taken from.

output(out: ostream) → None
class PixelSpecCount

Associates a pixel specification with an appearance count, for use in Histogram, below.

__init__(param0: PixelSpecCount) → None
HistMap

alias of map_PixelSpec_int

PixelCount

alias of pvector_PixelSpecCount

Palette

alias of pvector_PixelSpec

class Histogram

Used to return a pixel histogram in PNMImage::get_histogram().

__init__() → None
__init__(param0: Histogram) → None
getNumPixels() → int

Returns the number of unique pixel colors in the histogram.

getPixel(n: int) → PixelSpec

Returns the nth unique pixel color in the histogram. These are ordered by default from most common to least common.

Return type

PixelSpec

getCount(pixel: PixelSpec) → int

Returns the number of occurrences in the image of the indicated pixel color.

getCount(n: int) → int

Returns the number of occurrences in the image of the nth unique pixel color in the histogram.

write(out: ostream) → None
getPixels() → list