PNMImage

Inheritance:

Methods of PNMImage:

Methods of PNMImageHeader:

addAlpha
void PNMImage::add_alpha(void);

Description: Adds an alpha channel to the image, if it does not already have one. The alpha channel is initialized to zeros.

alphaFill
void PNMImage::alpha_fill(double alpha = (0));

Description: Sets the entire alpha channel to the given level.

alphaFillVal
void PNMImage::alpha_fill_val(unsigned short int alpha = (0));

Description: Sets the entire alpha channel to the given level.

blend
void PNMImage::blend(int x, int y, LVecBase3d const &val, double alpha);

Description: Smoothly blends the indicated pixel value in with whatever was already in the image, based on the given alpha value. An alpha of 1.0 is fully opaque and completely replaces whatever was there previously; alpha of 0.0 is fully transparent and does nothing.

blendSubImage
void PNMImage::blend_sub_image(PNMImage const &copy, int xto, int yto, int xfrom = (0), int yfrom = (0), int x_size = (-1), int y_size = (-1));

Description: Behaves like copy_sub_image(), except the alpha channel of the copy is used to blend the copy into the destination image, instead of overwriting pixels unconditionally.
If the copy has no alpha channel, this degenerates into copy_sub_image().

boxFilter
void PNMImage::box_filter(double radius = (1));

The bodies for the non-inline *_filter() functions can be found in the file pnm-image-filter.cxx.
Description: This flavor of box_filter() will apply the filter over the entire image without resizing or copying; the effect is that of a blur operation.

boxFilterFrom
void PNMImage::box_filter_from(double radius, PNMImage const &copy);

Description: Makes a resized copy of the indicated image into this one using the indicated filter. The image to be copied is squashed and stretched to match the dimensions of the current image, applying the appropriate filter to perform the stretching.

clampVal
unsigned short int PNMImage::clamp_val(int input_value) const;

Description: A handy function to clamp values to [0..get_maxval()].

clear
void PNMImage::clear(void);

Description: Frees all memory allocated for the image, and clears all its parameters (size, color, type, etc).
Description: This flavor of clear() reinitializes the image to an empty (black) image with the given dimensions.

copyFrom
void PNMImage::copy_from(PNMImage const &copy);

Description: Makes this image become a copy of the other image.

copyHeaderFrom
void PNMImage::copy_header_from(PNMImageHeader const &header);

Description: Copies just the header information into this image. This will blow away any image data stored in the image. The new image data will be allocated, but left unitialized.

copySubImage
void PNMImage::copy_sub_image(PNMImage const &copy, int xto, int yto, int xfrom = (0), int yfrom = (0), int x_size = (-1), int y_size = (-1));

Description: Copies a rectangular area of another image into a rectangular area of this image. Both images must already have been initialized. The upper-left corner of the region in both images is specified, and the size of the area; if the size is omitted, it defaults to the entire other image, or the largest piece that will fit.

fill
void PNMImage::fill(double red, double green, double blue);

Description: Sets the entire image (except the alpha channel) to the given color.
Description: Sets the entire image (except the alpha channel) to the given grayscale level.

fillVal
void PNMImage::fill_val(unsigned short int red, unsigned short int green, unsigned short int blue);

Description: Sets the entire image (except the alpha channel) to the given grayscale level.
Description: Sets the entire image (except the alpha channel) to the given color.

fromVal
double PNMImage::from_val(unsigned short int input_value) const;

Description: A handy function to scale values from [0..get_maxval()] to [0..1].

gaussianFilter
void PNMImage::gaussian_filter(double radius = (1));

Description: This flavor of gaussian_filter() will apply the filter over the entire image without resizing or copying; the effect is that of a blur operation.

gaussianFilterFrom
void PNMImage::gaussian_filter_from(double radius, PNMImage const &copy);

Description: Makes a resized copy of the indicated image into this one using the indicated filter. The image to be copied is squashed and stretched to match the dimensions of the current image, applying the appropriate filter to perform the stretching.

getAlpha
double PNMImage::get_alpha(int x, int y) const;

Description: Returns the alpha component color at the indicated pixel. It is an error to call this unless has_alpha() is true. The value returned is a double in the range 0..1.

getAlphaVal
unsigned short int PNMImage::get_alpha_val(int x, int y) const;

Description: Returns the alpha component color at the indicated pixel. It is an error to call this unless has_alpha() is true. The value returned is in the range 0..maxval.

getBlue
double PNMImage::get_blue(int x, int y) const;

Description: Returns the blue component color at the indicated pixel. The value returned is a double in the range 0..1.

getBlueVal
unsigned short int PNMImage::get_blue_val(int x, int y) const;

Description: Returns the blue component color at the indicated pixel. The value returned is in the range 0..maxval.

getBright
double PNMImage::get_bright(int x, int y) const;

Description: Returns the linear brightness of the given xel, as a double in the range 0..1. This flavor of get_bright() returns the correct grayscale brightness level for both full-color and grayscale images.
Description: This flavor of get_bright() works correctly only for color images. It returns a single brightness value for the RGB color at the indicated pixel, based on the supplied weights for each component.
Description: This flavor of get_bright() works correctly only for four-channel images. It returns a single brightness value for the RGBA color at the indicated pixel, based on the supplied weights for each component.

getChannel
double PNMImage::get_channel(int x, int y, int channel) const;

Description: Returns the nth component color at the indicated pixel. The channel index should be in the range 0..(get_num_channels()-1). The channels are ordered B, G, R, A. This is slightly less optimal than accessing the component values directly by named methods. The value returned is a double in the range 0..1.

getChannelVal
unsigned short int PNMImage::get_channel_val(int x, int y, int channel) const;

Description: Returns the nth component color at the indicated pixel. The channel index should be in the range 0..(get_num_channels()-1). The channels are ordered B, G, R, A. This is slightly less optimal than accessing the component values directly by named methods. The value returned is in the range 0..maxval.

getGray
double PNMImage::get_gray(int x, int y) const;

Description: Returns the gray component color at the indicated pixel. This only has a meaningful value for grayscale images; for other image types, this returns the value of the blue channel only. However, also see the get_bright() function. The value returned is a double in the range 0..1.

getGrayVal
unsigned short int PNMImage::get_gray_val(int x, int y) const;

Description: Returns the gray component color at the indicated pixel. This only has a meaningful value for grayscale images; for other image types, this returns the value of the blue channel only. However, also see the get_bright() function. The value returned is in the range 0..maxval.

getGreen
double PNMImage::get_green(int x, int y) const;

Description: Returns the green component color at the indicated pixel. The value returned is a double in the range 0..1.

getGreenVal
unsigned short int PNMImage::get_green_val(int x, int y) const;

Description: Returns the green component color at the indicated pixel. The value returned is in the range 0..maxval.

getRed
double PNMImage::get_red(int x, int y) const;

Description: Returns the red component color at the indicated pixel. The value returned is a double in the range 0..1.

getRedVal
unsigned short int PNMImage::get_red_val(int x, int y) const;

Description: Returns the red component color at the indicated pixel. The value returned is in the range 0..maxval.

getXel
LVecBase3d PNMImage::get_xel(int x, int y) const;

The corresponding get_xel(), set_xel(), get_red(), etc. functions automatically scale their values by get_maxval() into the range [0..1].
Description: Returns the RGB color at the indicated pixel. Each component is a double in the range 0..1.

getXelA
LVecBase4d PNMImage::get_xel_a(int x, int y) const;

Description: Returns the RGBA color at the indicated pixel. Each component is a double in the range 0..1.

getXelVal
pixel const &PNMImage::get_xel_val(int x, int y) const;

The *_val() functions return or set the color values in the range [0..get_maxval()]. This range may be different for different images! Use the corresponding functions (without _val()) to work in the normalized range [0..1].
Description: Returns the RGB color at the indicated pixel. Each component is in the range 0..maxval.

isValid
bool PNMImage::is_valid(void) const;

Description: Returns true if the image has been read in or correctly initialized with a height and width. If this returns false, virtually all member functions except clear() and read() are invalid function calls.

makeGrayscale
void PNMImage::make_grayscale(void);

Description: Converts the image from RGB to grayscale. Any alpha channel, if present, is left undisturbed.
Description: Converts the image from RGB to grayscale. Any alpha channel, if present, is left undisturbed. The optional rc, gc, bc values represent the relative weights to apply to each channel to convert it to grayscale.

makeRgb
void PNMImage::make_rgb(void);

Description: Converts the image from grayscale to RGB. Any alpha channel, if present, is left undisturbed.

operator =
void PNMImage::operator =(PNMImage const &copy);

Description:

operator []
pixel *PNMImage::operator [](int y);

If you're used to the NetPBM library and like working with a 2-d array of xels, and using the PNM macros to access their components, you may treat the PNMImage as such directly.
Description: Allows the PNMImage to appear to be a 2-d array of xels.

quickFilterFrom
void PNMImage::quick_filter_from(PNMImage const &copy, int xborder = (0), int yborder = (0));

Description: Resizes from the given image, with a fixed radius of 0.5. This is a very specialized and simple algorithm that doesn't handle dropping below the Nyquist rate very well, but is quite a bit faster than the more general box_filter(), above. If borders are specified, they will further restrict the size of the resulting image. There's no point in using quick_box_filter() on a single image.

read
bool PNMImage::read(Filename const &filename, PNMFileType *type = ((void *)(0)), bool report_unknown_type = (1));

Description: Reads the indicated image filename. If type is non-NULL, it is a suggestion for the type of file it is. Returns true if successful, false on error.
Description: Reads the image data 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.
Description: This flavor of read() uses an already-existing PNMReader to read the image file. You can get a reader via the PNMImageHeader::make_reader() methods. This is a good way to examine the header of a file (for instance, to determine its size) before actually reading the entire image.
The PNMReader is always deleted upon completion, whether succesful or not.

removeAlpha
void PNMImage::remove_alpha(void);

Description: Removes the image's alpha channel, if it exists.

renderSpot
void PNMImage::render_spot(LVecBase4d const &fg, LVecBase4d const &bg, double min_radius, double max_radius);

Description: Renders a solid-color circle, with a fuzzy edge, into the center of the PNMImage. If the PNMImage is non-square, this actually renders an ellipse.
The min_radius and max_radius are in the scale 0..1, where 1.0 means the full width of the image. If min_radius == max_radius, there is no fuzzy edge; otherwise, the pixels between min_radius and max_radius are smoothly blended between fg and bg colors.

setAlpha
void PNMImage::set_alpha(int x, int y, double a);

Description: Sets the alpha component color only at the indicated pixel. It is an error to call this unless has_alpha() is true. The value given should be in the range 0..1.

setAlphaVal
void PNMImage::set_alpha_val(int x, int y, unsigned short int a);

Description: Sets the alpha component color only at the indicated pixel. It is an error to call this unless has_alpha() is true. The value given should be in the range 0..maxval.

setBlue
void PNMImage::set_blue(int x, int y, double b);

Description: Sets the blue component color only at the indicated pixel. The value given should be a double in the range 0..1.

setBlueVal
void PNMImage::set_blue_val(int x, int y, unsigned short int b);

Description: Sets the blue component color only at the indicated pixel. The value given should be in the range 0..maxval.

setChannel
void PNMImage::set_channel(int x, int y, int channel, double value);

Description: Sets the nth component color at the indicated pixel. The channel index should be in the range 0..(get_num_channels()-1). The channels are ordered B, G, R, A. This is slightly less optimal than setting the component values directly by named methods. The value given should be a double in the range 0..1.

setChannelVal
void PNMImage::set_channel_val(int x, int y, int channel, unsigned short int value);

Description: Sets the nth component color at the indicated pixel. The channel index should be in the range 0..(get_num_channels()-1). The channels are ordered B, G, R, A. This is slightly less optimal than setting the component values directly by named methods. The value given should be in the range 0..maxval.

setColorType
void PNMImage::set_color_type(PNMImageHeader::ColorType color_type);

Description: Translates the image to or from grayscale, color, or four-color mode. Grayscale images are converted to full-color images with R, G, B set to the original gray level; color images are converted to grayscale according to the value of Bright(). The alpha channel, if added, is initialized to zero.

setGray
void PNMImage::set_gray(int x, int y, double gray);

Description: Sets the gray component color at the indicated pixel. This is only meaningful for grayscale images; for other image types, this simply sets the blue component color. However, also see set_xel(), which can set all the component colors to the same grayscale level, and hence works correctly both for grayscale and color images. The value given should be a double in the range 0..1.

setGrayVal
void PNMImage::set_gray_val(int x, int y, unsigned short int gray);

Description: Sets the gray component color at the indicated pixel. This is only meaningful for grayscale images; for other image types, this simply sets the blue component color. However, also see set_xel_val(), which can set all the component colors to the same grayscale level, and hence works correctly both for grayscale and color images. The value given should be in the range 0..maxval.

setGreen
void PNMImage::set_green(int x, int y, double g);

Description: Sets the green component color only at the indicated pixel. The value given should be a double in the range 0..1.

setGreenVal
void PNMImage::set_green_val(int x, int y, unsigned short int g);

Description: Sets the green component color only at the indicated pixel. The value given should be in the range 0..maxval.

setMaxval
void PNMImage::set_maxval(unsigned short int maxval);

Description: Rescales the image to the indicated maxval.

setNumChannels
void PNMImage::set_num_channels(int num_channels);

Description: Changes the number of channels associated with the image. The new number of channels must be an integer in the range 1 through 4, inclusive. This will allocate and/or deallocate memory as necessary to accomodate; see set_color_type().

setRed
void PNMImage::set_red(int x, int y, double r);

Description: Sets the red component color only at the indicated pixel. The value given should be a double in the range 0..1.

setRedVal
void PNMImage::set_red_val(int x, int y, unsigned short int r);

Description: Sets the red component color only at the indicated pixel. The value given should be in the range 0..maxval.

setXel
void PNMImage::set_xel(int x, int y, LVecBase3d const &value);

Description: Changes the RGB color at the indicated pixel. Each component is a double in the range 0..1.
Description: Changes all three color components at the indicated pixel to the same value. The value is a double in the range 0..1.

setXelA
void PNMImage::set_xel_a(int x, int y, LVecBase4d const &value);

Description: Changes the RGBA color at the indicated pixel. Each component is a double in the range 0..1.

setXelVal
void PNMImage::set_xel_val(int x, int y, pixel const &value);

Description: Changes the RGB color at the indicated pixel. Each component is in the range 0..maxval.
Description: Changes all three color components at the indicated pixel to the same value. The value is in the range 0..maxval.

toVal
unsigned short int PNMImage::to_val(double input_value) const;

Description: A handy function to scale values from [0..1] to [0..get_maxval()].

write
bool PNMImage::write(Filename const &filename, PNMFileType *type = ((void *)(0))) const;

Description: Writes the image to the indicated filename. If type is non-NULL, it is a suggestion for the type of image file to write.
Description: Writes the image to the indicated ostream.
The filename is advisory only, and may be used suggest a type if it has a known extension.
If type is non-NULL, it is a suggestion for the type of image file to write.
Description: This flavor of write() uses an already-existing PNMWriter to write the image file. You can get a writer via the PNMImageHeader::make_writer() methods.
The PNMWriter is always deleted upon completion, whether succesful or not.

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.

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.

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.