Panda3D
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties
Public Member Functions
PNMImage Class Reference

The name of this class derives from the fact that we originally implemented it as a layer on top of the "pnm library", based on netpbm, which was built to implement pbm, pgm, and pbm files, and is the underlying support of a number of public-domain image file converters. More...

Inheritance diagram for PNMImage:
PNMImageHeader

List of all members.

Public Member Functions

 PNMImage ()
 PNMImage (Filename const filename, PNMFileType type)
 PNMImage (Filename const filename)
 PNMImage (PNMImage const copy)
 PNMImage (int x_size, int y_size, int num_channels, unsigned short int maxval, PNMFileType type)
 PNMImage (int x_size, int y_size, int num_channels, unsigned short int maxval)
 PNMImage (int x_size, int y_size, int num_channels)
 PNMImage (int x_size, int y_size)
 addAlpha ()
 Adds an alpha channel to the image, if it does not already have one.
 alphaFill (double alpha)
 Sets the entire alpha channel to the given level.
 alphaFill ()
 Sets the entire alpha channel to the given level.
 alphaFillVal (unsigned short int alpha)
 Sets the entire alpha channel to the given level.
 alphaFillVal ()
 Sets the entire alpha channel to the given level.
 applyExponent (double gray_exponent)
 Adjusts each channel of the image by raising the corresponding component value to the indicated exponent, such that L' = L ^ exponent.
 applyExponent (double gray_exponent, double alpha_exponent)
 Adjusts each channel of the image by raising the corresponding component value to the indicated exponent, such that L' = L ^ exponent.
 applyExponent (double red_exponent, double green_exponent, double blue_exponent)
 Adjusts each channel of the image by raising the corresponding component value to the indicated exponent, such that L' = L ^ exponent.
 applyExponent (double red_exponent, double green_exponent, double blue_exponent, double alpha_exponent)
 Adjusts each channel of the image by raising the corresponding component value to the indicated exponent, such that L' = L ^ exponent.
 blend (int x, int y, VBase3D const val, double alpha)
 Smoothly blends the indicated pixel value in with whatever was already in the image, based on the given alpha value.
 blend (int x, int y, double r, double g, double b, double alpha)
 Smoothly blends the indicated pixel value in with whatever was already in the image, based on the given alpha value.
 blendSubImage (PNMImage const copy, int xto, int yto, int xfrom, int yfrom, int x_size, int y_size, double pixel_scale)
 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.
 blendSubImage (PNMImage const copy, int xto, int yto, int xfrom, int yfrom, int x_size, int y_size)
 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.
 blendSubImage (PNMImage const copy, int xto, int yto, int xfrom, int yfrom, int x_size)
 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.
 blendSubImage (PNMImage const copy, int xto, int yto, int xfrom, int yfrom)
 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.
 blendSubImage (PNMImage const copy, int xto, int yto, int xfrom)
 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.
 blendSubImage (PNMImage const copy, int xto, int yto)
 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.
 boxFilter (double radius)
 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.
 boxFilter ()
 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 (double radius, PNMImage const copy)
 Makes a resized copy of the indicated image into this one using the indicated filter.
unsigned short int clampVal (int input_value)
 A handy function to clamp values to [0..get_maxval()].
 clear ()
 Frees all memory allocated for the image, and clears all its parameters (size, color, type, etc).
 clear (int x_size, int y_size, int num_channels, unsigned short int maxval, PNMFileType type)
 This flavor of clear() reinitializes the image to an empty (black) image with the given dimensions.
 clear (int x_size, int y_size, int num_channels, unsigned short int maxval)
 This flavor of clear() reinitializes the image to an empty (black) image with the given dimensions.
 clear (int x_size, int y_size, int num_channels)
 This flavor of clear() reinitializes the image to an empty (black) image with the given dimensions.
 clear (int x_size, int y_size)
 This flavor of clear() reinitializes the image to an empty (black) image with the given dimensions.
 clearReadSize ()
 Undoes the effect of a previous call to set_read_size().
 copyChannel (PNMImage const copy, int src_channel, int dest_channel)
 Copies a channel from one image into another.
 copyChannel (PNMImage const copy, int xto, int yto, int cto, int xfrom, int yfrom, int cfrom, int x_size, int y_size)
 Copies just a single channel from the source image into a single channel of this image, leaving the remaining channels alone.
 copyChannel (PNMImage const copy, int xto, int yto, int cto, int xfrom, int yfrom, int cfrom, int x_size)
 Copies just a single channel from the source image into a single channel of this image, leaving the remaining channels alone.
 copyChannel (PNMImage const copy, int xto, int yto, int cto, int xfrom, int yfrom, int cfrom)
 Copies just a single channel from the source image into a single channel of this image, leaving the remaining channels alone.
 copyChannel (PNMImage const copy, int xto, int yto, int cto, int xfrom, int yfrom)
 Copies just a single channel from the source image into a single channel of this image, leaving the remaining channels alone.
 copyChannel (PNMImage const copy, int xto, int yto, int cto, int xfrom)
 Copies just a single channel from the source image into a single channel of this image, leaving the remaining channels alone.
 copyChannel (PNMImage const copy, int xto, int yto, int cto)
 Copies just a single channel from the source image into a single channel of this image, leaving the remaining channels alone.
 copyFrom (PNMImage const copy)
 Makes this image become a copy of the other image.
 copyHeaderFrom (PNMImageHeader const header)
 Copies just the header information into this image.
 copySubImage (PNMImage const copy, int xto, int yto, int xfrom, int yfrom, int x_size, int y_size)
 Copies a rectangular area of another image into a rectangular area of this image.
 copySubImage (PNMImage const copy, int xto, int yto, int xfrom, int yfrom, int x_size)
 Copies a rectangular area of another image into a rectangular area of this image.
 copySubImage (PNMImage const copy, int xto, int yto, int xfrom, int yfrom)
 Copies a rectangular area of another image into a rectangular area of this image.
 copySubImage (PNMImage const copy, int xto, int yto, int xfrom)
 Copies a rectangular area of another image into a rectangular area of this image.
 copySubImage (PNMImage const copy, int xto, int yto)
 Copies a rectangular area of another image into a rectangular area of this image.
 darkenSubImage (PNMImage const copy, int xto, int yto, int xfrom, int yfrom, int x_size, int y_size, double pixel_scale)
 Behaves like copy_sub_image(), but the resulting color will be the darker of the source and destination colors at each pixel (and at each R, G, B, A component value).
 darkenSubImage (PNMImage const copy, int xto, int yto, int xfrom, int yfrom, int x_size, int y_size)
 Behaves like copy_sub_image(), but the resulting color will be the darker of the source and destination colors at each pixel (and at each R, G, B, A component value).
 darkenSubImage (PNMImage const copy, int xto, int yto, int xfrom, int yfrom, int x_size)
 Behaves like copy_sub_image(), but the resulting color will be the darker of the source and destination colors at each pixel (and at each R, G, B, A component value).
 darkenSubImage (PNMImage const copy, int xto, int yto, int xfrom, int yfrom)
 Behaves like copy_sub_image(), but the resulting color will be the darker of the source and destination colors at each pixel (and at each R, G, B, A component value).
 darkenSubImage (PNMImage const copy, int xto, int yto, int xfrom)
 Behaves like copy_sub_image(), but the resulting color will be the darker of the source and destination colors at each pixel (and at each R, G, B, A component value).
 darkenSubImage (PNMImage const copy, int xto, int yto)
 Behaves like copy_sub_image(), but the resulting color will be the darker of the source and destination colors at each pixel (and at each R, G, B, A component value).
 expandBorder (int left, int right, int bottom, int top, VBase4D const color)
 Expands the image by the indicated number of pixels on each edge.
 fill (double gray)
 Sets the entire image (except the alpha channel) to the given grayscale level.
 fill ()
 Sets the entire image (except the alpha channel) to the given grayscale level.
 fill (double red, double green, double blue)
 Sets the entire image (except the alpha channel) to the given color.
 fillVal (unsigned short int gray)
 Sets the entire image (except the alpha channel) to the given grayscale level.
 fillVal ()
 Sets the entire image (except the alpha channel) to the given grayscale level.
 fillVal (unsigned short int red, unsigned short int green, unsigned short int blue)
 Sets the entire image (except the alpha channel) to the given color.
double fromVal (unsigned short int input_value)
 A handy function to scale values from [0..get_maxval()] to [0..1].
 gammaCorrect (double from_gamma, double to_gamma)
 Assuming the image was constructed with a gamma curve of from_gamma in the RGB channels, converts it to an image with a gamma curve of to_gamma in the RGB channels.
 gammaCorrectAlpha (double from_gamma, double to_gamma)
 Assuming the image was constructed with a gamma curve of from_gamma in the alpha channel, converts it to an image with a gamma curve of to_gamma in the alpha channel.
 gaussianFilter (double radius)
 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.
 gaussianFilter ()
 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 (double radius, PNMImage const copy)
 Makes a resized copy of the indicated image into this one using the indicated filter.
double getAlpha (int x, int y)
 Returns the alpha component color at the indicated pixel.
unsigned short int getAlphaVal (int x, int y)
 Returns the alpha component color at the indicated pixel.
double getAverageGray ()
 Returns the average grayscale component of all of the pixels in the image.
VBase3D getAverageXel ()
 Returns the average color of all of the pixels in the image.
VBase4D getAverageXelA ()
 Returns the average color of all of the pixels in the image, including the alpha channel.
double getBlue (int x, int y)
 Returns the blue component color at the indicated pixel.
unsigned short int getBlueVal (int x, int y)
 Returns the blue component color at the indicated pixel.
double getBright (int x, int y)
 Returns the linear brightness of the given xel, as a double in the range 0..1.
double getBright (int x, int y, double rc, double gc, double bc)
 This flavor of get_bright() works correctly only for color images.
double getBright (int x, int y, double rc, double gc, double bc, double ac)
 This flavor of get_bright() works correctly only for four-channel images.
double getChannel (int x, int y, int channel)
 Returns the nth component color at the indicated pixel.
unsigned short int getChannelVal (int x, int y, int channel)
 Returns the nth component color at the indicated pixel.
double getGray (int x, int y)
 Returns the gray component color at the indicated pixel.
unsigned short int getGrayVal (int x, int y)
 Returns the gray component color at the indicated pixel.
double getGreen (int x, int y)
 Returns the green component color at the indicated pixel.
unsigned short int getGreenVal (int x, int y)
 Returns the green component color at the indicated pixel.
PixelSpec getPixel (int x, int y)
 Returns the (r, g, b, a) pixel value at the indicated pixel, using a PixelSpec object.
int getReadXSize ()
 Returns the requested x_size of the image if set_read_size() has been called, or the image x_size otherwise (if it is known).
int getReadYSize ()
 Returns the requested y_size of the image if set_read_size() has been called, or the image y_size otherwise (if it is known).
double getRed (int x, int y)
 Returns the red component color at the indicated pixel.
unsigned short int getRedVal (int x, int y)
 Returns the red component color at the indicated pixel.
VBase3D getXel (int x, int y)
 Returns the RGB color at the indicated pixel.
VBase4D getXelA (int x, int y)
 Returns the RGBA color at the indicated pixel.
pixel const getXelVal (int x, int y)
 Returns the RGB color at the indicated pixel.
bool hasReadSize ()
 Returns true if set_read_size() has been called.
bool isValid ()
 Returns true if the image has been read in or correctly initialized with a height and width.
 lightenSubImage (PNMImage const copy, int xto, int yto, int xfrom, int yfrom, int x_size, int y_size, double pixel_scale)
 Behaves like copy_sub_image(), but the resulting color will be the lighter of the source and destination colors at each pixel (and at each R, G, B, A component value).
 lightenSubImage (PNMImage const copy, int xto, int yto, int xfrom, int yfrom, int x_size, int y_size)
 Behaves like copy_sub_image(), but the resulting color will be the lighter of the source and destination colors at each pixel (and at each R, G, B, A component value).
 lightenSubImage (PNMImage const copy, int xto, int yto, int xfrom, int yfrom, int x_size)
 Behaves like copy_sub_image(), but the resulting color will be the lighter of the source and destination colors at each pixel (and at each R, G, B, A component value).
 lightenSubImage (PNMImage const copy, int xto, int yto, int xfrom, int yfrom)
 Behaves like copy_sub_image(), but the resulting color will be the lighter of the source and destination colors at each pixel (and at each R, G, B, A component value).
 lightenSubImage (PNMImage const copy, int xto, int yto, int xfrom)
 Behaves like copy_sub_image(), but the resulting color will be the lighter of the source and destination colors at each pixel (and at each R, G, B, A component value).
 lightenSubImage (PNMImage const copy, int xto, int yto)
 Behaves like copy_sub_image(), but the resulting color will be the lighter of the source and destination colors at each pixel (and at each R, G, B, A component value).
 makeGrayscale ()
 Converts the image from RGB to grayscale.
 makeGrayscale (double rc, double gc, double bc)
 Converts the image from RGB to grayscale.
 makeHistogram (Histogram hist)
 Computes a histogram of the colors used in the image.
 makeRgb ()
 Converts the image from grayscale to RGB.
PNMImage operator* (PNMImage const other)
 Returns a new PNMImage in which each pixel value from the left image is multiplied by each pixel value from the right image.
PNMImage operator* (double multiplier)
 Multiplies every pixel value in the image by a constant floating-point multiplier value.
PNMImage operator*= (PNMImage const other)
 Returns a new PNMImage in which each pixel value from the left image is multiplied by each pixel value from the right image.
PNMImage operator*= (double multiplier)
 Multiplies every pixel value in the image by a constant floating-point multiplier value.
PNMImage operator+ (VBase4D const other)
 Returns a new PNMImage in which the provided color is added to each pixel in the provided image.
PNMImage operator+ (PNMImage const other)
 Returns a new PNMImage in which each pixel value is the sum of the corresponding pixel values in the two given images.
PNMImage operator+= (VBase4D const other)
 Returns a new PNMImage in which the provided color is added to each pixel in the provided image.
PNMImage operator+= (PNMImage const other)
 Returns a new PNMImage in which each pixel value is the sum of the corresponding pixel values in the two given images.
PNMImage operator- (VBase4D const other)
 Returns a new PNMImage in which the provided color is subtracted from each pixel in the provided image.
PNMImage operator- (PNMImage const other)
 Returns a new PNMImage in which each pixel value from the right image is subtracted from each pixel value from the left image.
PNMImage operator-= (VBase4D const other)
 Returns a new PNMImage in which the provided color is subtracted from each pixel in the provided image.
PNMImage operator-= (PNMImage const other)
 Returns a new PNMImage in which each pixel value from the right image is subtracted from each pixel value from the left image.
PNMImage operator= (PNMImage const copy)
pixel operator[] (int y)
 Allows the PNMImage to appear to be a 2-d array of xels.
pixel const operator[] (int y)
 Allows the PNMImage to appear to be a 2-d array of xels.
PNMImage operator~ ()
 Returns a new PNMImage that is the complement of the current PNMImage.
 perlinNoiseFill (StackedPerlinNoise2 perlin)
 Variant of perlin_noise_fill that uses an existing StackedPerlinNoise2 object.
 perlinNoiseFill (double sx, double sy, int table_size, unsigned long int seed)
 Fills the image with a grayscale perlin noise pattern based on the indicated parameters.
 perlinNoiseFill (double sx, double sy, int table_size)
 Fills the image with a grayscale perlin noise pattern based on the indicated parameters.
 perlinNoiseFill (double sx, double sy)
 Fills the image with a grayscale perlin noise pattern based on the indicated parameters.
 quickFilterFrom (PNMImage const copy, int xborder, int yborder)
 Resizes from the given image, with a fixed radius of 0.5.
 quickFilterFrom (PNMImage const copy, int xborder)
 Resizes from the given image, with a fixed radius of 0.5.
 quickFilterFrom (PNMImage const copy)
 Resizes from the given image, with a fixed radius of 0.5.
bool read (Filename const filename, PNMFileType type, bool report_unknown_type)
 Reads the indicated image filename.
bool read (Filename const filename, PNMFileType type)
 Reads the indicated image filename.
bool read (Filename const filename)
 Reads the indicated image filename.
bool read (PNMReader reader)
 This flavor of read() uses an already-existing PNMReader to read the image file.
bool read (istream data, string filename, PNMFileType type, bool report_unknown_type)
 Reads the image data from the indicated stream.
bool read (istream data, string filename, PNMFileType type)
 Reads the image data from the indicated stream.
bool read (istream data, string filename)
 Reads the image data from the indicated stream.
bool read (istream data)
 Reads the image data from the indicated stream.
 remixChannels (Mat4 const conv)
 Transforms every pixel using the operation (Ro,Go,Bo) = conv.xform_point(Ri,Gi,Bi); Input must be a color image.
 removeAlpha ()
 Removes the image's alpha channel, if it exists.
 renderSpot (VBase4D const fg, VBase4D const bg, double min_radius, double max_radius)
 Renders a solid-color circle, with a fuzzy edge, into the center of the PNMImage.
 reverseRows ()
 Performs an in-place reversal of the row (y) data.
 setAlpha (int x, int y, double a)
 Sets the alpha component color only at the indicated pixel.
 setAlphaVal (int x, int y, unsigned short int a)
 Sets the alpha component color only at the indicated pixel.
 setBlue (int x, int y, double b)
 Sets the blue component color only at the indicated pixel.
 setBlueVal (int x, int y, unsigned short int b)
 Sets the blue component color only at the indicated pixel.
 setChannel (int x, int y, int channel, double value)
 Sets the nth component color at the indicated pixel.
 setChannelVal (int x, int y, int channel, unsigned short int value)
 Sets the nth component color at the indicated pixel.
 setColorType (ColorType color_type)
 Translates the image to or from grayscale, color, or four-color mode.
 setGray (int x, int y, double gray)
 Sets the gray component color at the indicated pixel.
 setGrayVal (int x, int y, unsigned short int gray)
 Sets the gray component color at the indicated pixel.
 setGreen (int x, int y, double g)
 Sets the green component color only at the indicated pixel.
 setGreenVal (int x, int y, unsigned short int g)
 Sets the green component color only at the indicated pixel.
 setMaxval (unsigned short int maxval)
 Rescales the image to the indicated maxval.
 setNumChannels (int num_channels)
 Changes the number of channels associated with the image.
 setPixel (int x, int y, PixelSpec const pixel)
 Sets the (r, g, b, a) pixel value at the indicated pixel, using a PixelSpec object.
 setReadSize (int x_size, int y_size)
 Specifies the size to we'd like to scale the image upon reading it.
 setRed (int x, int y, double r)
 Sets the red component color only at the indicated pixel.
 setRedVal (int x, int y, unsigned short int r)
 Sets the red component color only at the indicated pixel.
 setXel (int x, int y, VBase3D const value)
 Changes the RGB color at the indicated pixel.
 setXel (int x, int y, double gray)
 Changes all three color components at the indicated pixel to the same value.
 setXel (int x, int y, double r, double g, double b)
 Changes the RGB color at the indicated pixel.
 setXelA (int x, int y, VBase4D const value)
 Changes the RGBA color at the indicated pixel.
 setXelA (int x, int y, double r, double g, double b, double a)
 Changes the RGBA color at the indicated pixel.
 setXelVal (int x, int y, pixel const value)
 Changes the RGB color at the indicated pixel.
 setXelVal (int x, int y, unsigned short int gray)
 Changes all three color components at the indicated pixel to the same value.
 setXelVal (int x, int y, unsigned short int r, unsigned short int g, unsigned short int b)
 Changes the RGB color at the indicated pixel.
 takeFrom (PNMImage orig)
 Move the contents of the other image into this one, and empty the other image.
 threshold (PNMImage const select_image, int channel, double threshold, PNMImage const lt, PNMImage const ge)
 Selectively copies each pixel from either one source or another source, depending on the pixel value of the indicated channel of select_image.
unsigned short int toVal (double input_value)
 A handy function to scale values from [0..1] to [0..get_maxval()].
bool write (Filename const filename, PNMFileType type)
 Writes the image to the indicated filename.
bool write (Filename const filename)
 Writes the image to the indicated filename.
bool write (PNMWriter writer)
 This flavor of write() uses an already-existing PNMWriter to write the image file.
bool write (ostream data, string filename, PNMFileType type)
 Writes the image to the indicated ostream.
bool write (ostream data, string filename)
 Writes the image to the indicated ostream.
bool write (ostream data)
 Writes the image to the indicated ostream.

Detailed Description

The name of this class derives from the fact that we originally implemented it as a layer on top of the "pnm library", based on netpbm, which was built to implement pbm, pgm, and pbm files, and is the underlying support of a number of public-domain image file converters.

Nowadays we are no longer derived directly from the pnm library, mainly to allow support of C++ iostreams instead of the C stdio FILE interface.

Conceptually, a PNMImage is a two-dimensional array of xels, which are the PNM-defined generic pixel type. Each xel may have a red, green, and blue component, or (if the image is grayscale) a gray component. The image may be read in, the individual xels manipulated, and written out again, or a black image may be constructed from scratch.

The image is of size XSize() by YSize() xels, numbered from top to bottom, left to right, beginning at zero.

Files can be specified by filename, or by an iostream pointer. The filename "-" refers to stdin or stdout.


Constructor & Destructor Documentation

PNMImage ( )
PNMImage ( Filename const  filename,
PNMFileType  type 
)
PNMImage ( Filename const  filename)
PNMImage ( PNMImage const  copy)
PNMImage ( int  x_size,
int  y_size,
int  num_channels,
unsigned short int  maxval,
PNMFileType  type 
)
PNMImage ( int  x_size,
int  y_size,
int  num_channels,
unsigned short int  maxval 
)
PNMImage ( int  x_size,
int  y_size,
int  num_channels 
)
PNMImage ( int  x_size,
int  y_size 
)

Member Function Documentation

addAlpha ( )

Adds an alpha channel to the image, if it does not already have one.

The alpha channel is initialized to zeros.

alphaFill ( double  alpha)

Sets the entire alpha channel to the given level.

alphaFill ( )

Sets the entire alpha channel to the given level.

alphaFillVal ( unsigned short int  alpha)

Sets the entire alpha channel to the given level.

Sets the entire alpha channel to the given level.

applyExponent ( double  gray_exponent)

Adjusts each channel of the image by raising the corresponding component value to the indicated exponent, such that L' = L ^ exponent.

applyExponent ( double  gray_exponent,
double  alpha_exponent 
)

Adjusts each channel of the image by raising the corresponding component value to the indicated exponent, such that L' = L ^ exponent.

applyExponent ( double  red_exponent,
double  green_exponent,
double  blue_exponent 
)

Adjusts each channel of the image by raising the corresponding component value to the indicated exponent, such that L' = L ^ exponent.

For a grayscale image, the blue_exponent value is used for the grayscale value, and red_exponent and green_exponent are unused.

applyExponent ( double  red_exponent,
double  green_exponent,
double  blue_exponent,
double  alpha_exponent 
)

Adjusts each channel of the image by raising the corresponding component value to the indicated exponent, such that L' = L ^ exponent.

For a grayscale image, the blue_exponent value is used for the grayscale value, and red_exponent and green_exponent are unused.

blend ( int  x,
int  y,
VBase3D const  val,
double  alpha 
)

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.

blend ( int  x,
int  y,
double  r,
double  g,
double  b,
double  alpha 
)

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 ( PNMImage const  copy,
int  xto,
int  yto,
int  xfrom,
int  yfrom,
int  x_size,
int  y_size,
double  pixel_scale 
)

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 pixel_scale is not 1.0, it specifies an amount to scale each *alpha* value of the source image before applying it to the target image.

If pixel_scale is 1.0 and the copy has no alpha channel, this degenerates into copy_sub_image().

blendSubImage ( PNMImage const  copy,
int  xto,
int  yto,
int  xfrom,
int  yfrom,
int  x_size,
int  y_size 
)

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 pixel_scale is not 1.0, it specifies an amount to scale each *alpha* value of the source image before applying it to the target image.

If pixel_scale is 1.0 and the copy has no alpha channel, this degenerates into copy_sub_image().

blendSubImage ( PNMImage const  copy,
int  xto,
int  yto,
int  xfrom,
int  yfrom,
int  x_size 
)

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 pixel_scale is not 1.0, it specifies an amount to scale each *alpha* value of the source image before applying it to the target image.

If pixel_scale is 1.0 and the copy has no alpha channel, this degenerates into copy_sub_image().

blendSubImage ( PNMImage const  copy,
int  xto,
int  yto,
int  xfrom,
int  yfrom 
)

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 pixel_scale is not 1.0, it specifies an amount to scale each *alpha* value of the source image before applying it to the target image.

If pixel_scale is 1.0 and the copy has no alpha channel, this degenerates into copy_sub_image().

blendSubImage ( PNMImage const  copy,
int  xto,
int  yto,
int  xfrom 
)

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 pixel_scale is not 1.0, it specifies an amount to scale each *alpha* value of the source image before applying it to the target image.

If pixel_scale is 1.0 and the copy has no alpha channel, this degenerates into copy_sub_image().

blendSubImage ( PNMImage const  copy,
int  xto,
int  yto 
)

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 pixel_scale is not 1.0, it specifies an amount to scale each *alpha* value of the source image before applying it to the target image.

If pixel_scale is 1.0 and the copy has no alpha channel, this degenerates into copy_sub_image().

boxFilter ( double  radius)

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.

boxFilter ( )

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 ( double  radius,
PNMImage const  copy 
)

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.

unsigned short int clampVal ( int  input_value)

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

clear ( )

Frees all memory allocated for the image, and clears all its parameters (size, color, type, etc).

clear ( int  x_size,
int  y_size,
int  num_channels,
unsigned short int  maxval,
PNMFileType  type 
)

This flavor of clear() reinitializes the image to an empty (black) image with the given dimensions.

clear ( int  x_size,
int  y_size,
int  num_channels,
unsigned short int  maxval 
)

This flavor of clear() reinitializes the image to an empty (black) image with the given dimensions.

clear ( int  x_size,
int  y_size,
int  num_channels 
)

This flavor of clear() reinitializes the image to an empty (black) image with the given dimensions.

clear ( int  x_size,
int  y_size 
)

This flavor of clear() reinitializes the image to an empty (black) image with the given dimensions.

Undoes the effect of a previous call to set_read_size().

copyChannel ( PNMImage const  copy,
int  src_channel,
int  dest_channel 
)

Copies a channel from one image into another.

Images must be the same size

copyChannel ( PNMImage const  copy,
int  xto,
int  yto,
int  cto,
int  xfrom,
int  yfrom,
int  cfrom,
int  x_size,
int  y_size 
)

Copies just a single channel from the source image into a single channel of this image, leaving the remaining channels alone.

copyChannel ( PNMImage const  copy,
int  xto,
int  yto,
int  cto,
int  xfrom,
int  yfrom,
int  cfrom,
int  x_size 
)

Copies just a single channel from the source image into a single channel of this image, leaving the remaining channels alone.

copyChannel ( PNMImage const  copy,
int  xto,
int  yto,
int  cto,
int  xfrom,
int  yfrom,
int  cfrom 
)

Copies just a single channel from the source image into a single channel of this image, leaving the remaining channels alone.

copyChannel ( PNMImage const  copy,
int  xto,
int  yto,
int  cto,
int  xfrom,
int  yfrom 
)

Copies just a single channel from the source image into a single channel of this image, leaving the remaining channels alone.

copyChannel ( PNMImage const  copy,
int  xto,
int  yto,
int  cto,
int  xfrom 
)

Copies just a single channel from the source image into a single channel of this image, leaving the remaining channels alone.

copyChannel ( PNMImage const  copy,
int  xto,
int  yto,
int  cto 
)

Copies just a single channel from the source image into a single channel of this image, leaving the remaining channels alone.

copyFrom ( PNMImage const  copy)

Makes this image become a copy of the other image.

copyHeaderFrom ( PNMImageHeader const  header)

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 ( PNMImage const  copy,
int  xto,
int  yto,
int  xfrom,
int  yfrom,
int  x_size,
int  y_size 
)

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.

copySubImage ( PNMImage const  copy,
int  xto,
int  yto,
int  xfrom,
int  yfrom,
int  x_size 
)

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.

copySubImage ( PNMImage const  copy,
int  xto,
int  yto,
int  xfrom,
int  yfrom 
)

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.

copySubImage ( PNMImage const  copy,
int  xto,
int  yto,
int  xfrom 
)

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.

copySubImage ( PNMImage const  copy,
int  xto,
int  yto 
)

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.

darkenSubImage ( PNMImage const  copy,
int  xto,
int  yto,
int  xfrom,
int  yfrom,
int  x_size,
int  y_size,
double  pixel_scale 
)

Behaves like copy_sub_image(), but the resulting color will be the darker of the source and destination colors at each pixel (and at each R, G, B, A component value).

If pixel_scale is not 1.0, it specifies an amount to scale each pixel value of the source image before applying it to the target image. The scale is applied with the center at 1.0: scaling the pixel value smaller brings it closer to 1.0.

darkenSubImage ( PNMImage const  copy,
int  xto,
int  yto,
int  xfrom,
int  yfrom,
int  x_size,
int  y_size 
)

Behaves like copy_sub_image(), but the resulting color will be the darker of the source and destination colors at each pixel (and at each R, G, B, A component value).

If pixel_scale is not 1.0, it specifies an amount to scale each pixel value of the source image before applying it to the target image. The scale is applied with the center at 1.0: scaling the pixel value smaller brings it closer to 1.0.

darkenSubImage ( PNMImage const  copy,
int  xto,
int  yto,
int  xfrom,
int  yfrom,
int  x_size 
)

Behaves like copy_sub_image(), but the resulting color will be the darker of the source and destination colors at each pixel (and at each R, G, B, A component value).

If pixel_scale is not 1.0, it specifies an amount to scale each pixel value of the source image before applying it to the target image. The scale is applied with the center at 1.0: scaling the pixel value smaller brings it closer to 1.0.

darkenSubImage ( PNMImage const  copy,
int  xto,
int  yto,
int  xfrom,
int  yfrom 
)

Behaves like copy_sub_image(), but the resulting color will be the darker of the source and destination colors at each pixel (and at each R, G, B, A component value).

If pixel_scale is not 1.0, it specifies an amount to scale each pixel value of the source image before applying it to the target image. The scale is applied with the center at 1.0: scaling the pixel value smaller brings it closer to 1.0.

darkenSubImage ( PNMImage const  copy,
int  xto,
int  yto,
int  xfrom 
)

Behaves like copy_sub_image(), but the resulting color will be the darker of the source and destination colors at each pixel (and at each R, G, B, A component value).

If pixel_scale is not 1.0, it specifies an amount to scale each pixel value of the source image before applying it to the target image. The scale is applied with the center at 1.0: scaling the pixel value smaller brings it closer to 1.0.

darkenSubImage ( PNMImage const  copy,
int  xto,
int  yto 
)

Behaves like copy_sub_image(), but the resulting color will be the darker of the source and destination colors at each pixel (and at each R, G, B, A component value).

If pixel_scale is not 1.0, it specifies an amount to scale each pixel value of the source image before applying it to the target image. The scale is applied with the center at 1.0: scaling the pixel value smaller brings it closer to 1.0.

expandBorder ( int  left,
int  right,
int  bottom,
int  top,
VBase4D const  color 
)

Expands the image by the indicated number of pixels on each edge.

The new pixels are set to the indicated color.

If any of the values is negative, this actually crops the image.

fill ( double  gray)

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

fill ( )

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

fill ( double  red,
double  green,
double  blue 
)

Sets the entire image (except the alpha channel) to the given color.

fillVal ( unsigned short int  gray)

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

fillVal ( )

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

fillVal ( unsigned short int  red,
unsigned short int  green,
unsigned short int  blue 
)

Sets the entire image (except the alpha channel) to the given color.

double fromVal ( unsigned short int  input_value)

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

gammaCorrect ( double  from_gamma,
double  to_gamma 
)

Assuming the image was constructed with a gamma curve of from_gamma in the RGB channels, converts it to an image with a gamma curve of to_gamma in the RGB channels.

Does not affect the alpha channel.

gammaCorrectAlpha ( double  from_gamma,
double  to_gamma 
)

Assuming the image was constructed with a gamma curve of from_gamma in the alpha channel, converts it to an image with a gamma curve of to_gamma in the alpha channel.

Does not affect the RGB channels.

gaussianFilter ( double  radius)

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.

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 ( double  radius,
PNMImage const  copy 
)

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.

double getAlpha ( int  x,
int  y 
)

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.

unsigned short int getAlphaVal ( int  x,
int  y 
)

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.

double getAverageGray ( )

Returns the average grayscale component of all of the pixels in the image.

Returns the average color of all of the pixels in the image.

Returns the average color of all of the pixels in the image, including the alpha channel.

double getBlue ( int  x,
int  y 
)

Returns the blue component color at the indicated pixel.

The value returned is a double in the range 0..1.

unsigned short int getBlueVal ( int  x,
int  y 
)

Returns the blue component color at the indicated pixel.

The value returned is in the range 0..maxval.

double getBright ( int  x,
int  y 
)

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.

double getBright ( int  x,
int  y,
double  rc,
double  gc,
double  bc 
)

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.

double getBright ( int  x,
int  y,
double  rc,
double  gc,
double  bc,
double  ac 
)

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.

double getChannel ( int  x,
int  y,
int  channel 
)

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.

unsigned short int getChannelVal ( int  x,
int  y,
int  channel 
)

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.

double getGray ( int  x,
int  y 
)

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.

unsigned short int getGrayVal ( int  x,
int  y 
)

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.

double getGreen ( int  x,
int  y 
)

Returns the green component color at the indicated pixel.

The value returned is a double in the range 0..1.

unsigned short int getGreenVal ( int  x,
int  y 
)

Returns the green component color at the indicated pixel.

The value returned is in the range 0..maxval.

PixelSpec getPixel ( int  x,
int  y 
)

Returns the (r, g, b, a) pixel value at the indicated pixel, using a PixelSpec object.

Returns the requested x_size of the image if set_read_size() has been called, or the image x_size otherwise (if it is known).

Returns the requested y_size of the image if set_read_size() has been called, or the image y_size otherwise (if it is known).

double getRed ( int  x,
int  y 
)

Returns the red component color at the indicated pixel.

The value returned is a double in the range 0..1.

unsigned short int getRedVal ( int  x,
int  y 
)

Returns the red component color at the indicated pixel.

The value returned is in the range 0..maxval.

VBase3D getXel ( int  x,
int  y 
)

Returns the RGB color at the indicated pixel.

Each component is a double in the range 0..1.

VBase4D getXelA ( int  x,
int  y 
)

Returns the RGBA color at the indicated pixel.

Each component is a double in the range 0..1.

pixel const getXelVal ( int  x,
int  y 
)

Returns the RGB color at the indicated pixel.

Each component is in the range 0..maxval.

bool hasReadSize ( )

Returns true if set_read_size() has been called.

bool isValid ( )

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.

lightenSubImage ( PNMImage const  copy,
int  xto,
int  yto,
int  xfrom,
int  yfrom,
int  x_size,
int  y_size,
double  pixel_scale 
)

Behaves like copy_sub_image(), but the resulting color will be the lighter of the source and destination colors at each pixel (and at each R, G, B, A component value).

If pixel_scale is not 1.0, it specifies an amount to scale each pixel value of the source image before applying it to the target image.

lightenSubImage ( PNMImage const  copy,
int  xto,
int  yto,
int  xfrom,
int  yfrom,
int  x_size,
int  y_size 
)

Behaves like copy_sub_image(), but the resulting color will be the lighter of the source and destination colors at each pixel (and at each R, G, B, A component value).

If pixel_scale is not 1.0, it specifies an amount to scale each pixel value of the source image before applying it to the target image.

lightenSubImage ( PNMImage const  copy,
int  xto,
int  yto,
int  xfrom,
int  yfrom,
int  x_size 
)

Behaves like copy_sub_image(), but the resulting color will be the lighter of the source and destination colors at each pixel (and at each R, G, B, A component value).

If pixel_scale is not 1.0, it specifies an amount to scale each pixel value of the source image before applying it to the target image.

lightenSubImage ( PNMImage const  copy,
int  xto,
int  yto,
int  xfrom,
int  yfrom 
)

Behaves like copy_sub_image(), but the resulting color will be the lighter of the source and destination colors at each pixel (and at each R, G, B, A component value).

If pixel_scale is not 1.0, it specifies an amount to scale each pixel value of the source image before applying it to the target image.

lightenSubImage ( PNMImage const  copy,
int  xto,
int  yto,
int  xfrom 
)

Behaves like copy_sub_image(), but the resulting color will be the lighter of the source and destination colors at each pixel (and at each R, G, B, A component value).

If pixel_scale is not 1.0, it specifies an amount to scale each pixel value of the source image before applying it to the target image.

lightenSubImage ( PNMImage const  copy,
int  xto,
int  yto 
)

Behaves like copy_sub_image(), but the resulting color will be the lighter of the source and destination colors at each pixel (and at each R, G, B, A component value).

If pixel_scale is not 1.0, it specifies an amount to scale each pixel value of the source image before applying it to the target image.

Converts the image from RGB to grayscale.

Any alpha channel, if present, is left undisturbed.

makeGrayscale ( double  rc,
double  gc,
double  bc 
)

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.

Computes a histogram of the colors used in the image.

makeRgb ( )

Converts the image from grayscale to RGB.

Any alpha channel, if present, is left undisturbed.

PNMImage operator* ( PNMImage const  other)

Returns a new PNMImage in which each pixel value from the left image is multiplied by each pixel value from the right image.

Note that the floating-point values in the 0..1 range are multiplied, not in the 0..maxval range. Only valid when both images have the same size.

PNMImage operator* ( double  multiplier)

Multiplies every pixel value in the image by a constant floating-point multiplier value.

PNMImage operator*= ( PNMImage const  other)

Returns a new PNMImage in which each pixel value from the left image is multiplied by each pixel value from the right image.

Note that the floating-point values in the 0..1 range are multiplied, not in the 0..maxval range. Only valid when both images have the same size.

PNMImage operator*= ( double  multiplier)

Multiplies every pixel value in the image by a constant floating-point multiplier value.

PNMImage operator+ ( VBase4D const  other)

Returns a new PNMImage in which the provided color is added to each pixel in the provided image.

PNMImage operator+ ( PNMImage const  other)

Returns a new PNMImage in which each pixel value is the sum of the corresponding pixel values in the two given images.

Only valid when both images have the same size.

PNMImage operator+= ( VBase4D const  other)

Returns a new PNMImage in which the provided color is added to each pixel in the provided image.

PNMImage operator+= ( PNMImage const  other)

Returns a new PNMImage in which each pixel value is the sum of the corresponding pixel values in the two given images.

Only valid when both images have the same size.

PNMImage operator- ( VBase4D const  other)

Returns a new PNMImage in which the provided color is subtracted from each pixel in the provided image.

PNMImage operator- ( PNMImage const  other)

Returns a new PNMImage in which each pixel value from the right image is subtracted from each pixel value from the left image.

Only valid when both images have the same size.

PNMImage operator-= ( VBase4D const  other)

Returns a new PNMImage in which the provided color is subtracted from each pixel in the provided image.

PNMImage operator-= ( PNMImage const  other)

Returns a new PNMImage in which each pixel value from the right image is subtracted from each pixel value from the left image.

Only valid when both images have the same size.

PNMImage operator= ( PNMImage const  copy)
pixel operator[] ( int  y)

Allows the PNMImage to appear to be a 2-d array of xels.

pixel const operator[] ( int  y)

Allows the PNMImage to appear to be a 2-d array of xels.

Returns a new PNMImage that is the complement of the current PNMImage.

Variant of perlin_noise_fill that uses an existing StackedPerlinNoise2 object.

perlinNoiseFill ( double  sx,
double  sy,
int  table_size,
unsigned long int  seed 
)

Fills the image with a grayscale perlin noise pattern based on the indicated parameters.

Uses set_xel to set the grayscale values. The sx and sy parameters are in multiples of the size of this image. See also the PerlinNoise2 class in mathutil.

perlinNoiseFill ( double  sx,
double  sy,
int  table_size 
)

Fills the image with a grayscale perlin noise pattern based on the indicated parameters.

Uses set_xel to set the grayscale values. The sx and sy parameters are in multiples of the size of this image. See also the PerlinNoise2 class in mathutil.

perlinNoiseFill ( double  sx,
double  sy 
)

Fills the image with a grayscale perlin noise pattern based on the indicated parameters.

Uses set_xel to set the grayscale values. The sx and sy parameters are in multiples of the size of this image. See also the PerlinNoise2 class in mathutil.

quickFilterFrom ( PNMImage const  copy,
int  xborder,
int  yborder 
)

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.

quickFilterFrom ( PNMImage const  copy,
int  xborder 
)

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.

quickFilterFrom ( PNMImage const  copy)

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.

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

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.

bool read ( Filename const  filename,
PNMFileType  type 
)

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.

bool read ( Filename const  filename)

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.

bool read ( PNMReader  reader)

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 successful or not.

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

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.

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

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.

bool read ( istream  data,
string  filename 
)

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.

bool read ( istream  data)

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.

remixChannels ( Mat4 const  conv)

Transforms every pixel using the operation (Ro,Go,Bo) = conv.xform_point(Ri,Gi,Bi); Input must be a color image.

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

renderSpot ( VBase4D const  fg,
VBase4D const  bg,
double  min_radius,
double  max_radius 
)

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, the edge is sharp (but still antialiased); otherwise, the pixels between min_radius and max_radius are smoothly blended between fg and bg colors.

Performs an in-place reversal of the row (y) data.

setAlpha ( int  x,
int  y,
double  a 
)

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 ( int  x,
int  y,
unsigned short int  a 
)

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 ( int  x,
int  y,
double  b 
)

Sets the blue component color only at the indicated pixel.

The value given should be a double in the range 0..1.

setBlueVal ( int  x,
int  y,
unsigned short int  b 
)

Sets the blue component color only at the indicated pixel.

The value given should be in the range 0..maxval.

setChannel ( int  x,
int  y,
int  channel,
double  value 
)

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 ( int  x,
int  y,
int  channel,
unsigned short int  value 
)

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 ( ColorType  color_type)

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 ( int  x,
int  y,
double  gray 
)

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 ( int  x,
int  y,
unsigned short int  gray 
)

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 ( int  x,
int  y,
double  g 
)

Sets the green component color only at the indicated pixel.

The value given should be a double in the range 0..1.

setGreenVal ( int  x,
int  y,
unsigned short int  g 
)

Sets the green component color only at the indicated pixel.

The value given should be in the range 0..maxval.

setMaxval ( unsigned short int  maxval)

Rescales the image to the indicated maxval.

setNumChannels ( int  num_channels)

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 accommodate; see set_color_type().

setPixel ( int  x,
int  y,
PixelSpec const  pixel 
)

Sets the (r, g, b, a) pixel value at the indicated pixel, using a PixelSpec object.

setReadSize ( int  x_size,
int  y_size 
)

Specifies the size to we'd like to scale the image upon reading it.

This will affect the next call to read(). This is usually used to reduce the image size, e.g. for a thumbnail.

If the file type reader supports it (e.g. JPEG), then this will scale the image during the read operation, consequently reducing memory and CPU utilization. If the file type reader does not support it, this will load the image normally, and them perform a linear scale after it has been loaded.

setRed ( int  x,
int  y,
double  r 
)

Sets the red component color only at the indicated pixel.

The value given should be a double in the range 0..1.

setRedVal ( int  x,
int  y,
unsigned short int  r 
)

Sets the red component color only at the indicated pixel.

The value given should be in the range 0..maxval.

setXel ( int  x,
int  y,
VBase3D const  value 
)

Changes the RGB color at the indicated pixel.

Each component is a double in the range 0..1.

setXel ( int  x,
int  y,
double  gray 
)

Changes all three color components at the indicated pixel to the same value.

The value is a double in the range 0..1.

setXel ( int  x,
int  y,
double  r,
double  g,
double  b 
)

Changes the RGB color at the indicated pixel.

Each component is a double in the range 0..1.

setXelA ( int  x,
int  y,
VBase4D const  value 
)

Changes the RGBA color at the indicated pixel.

Each component is a double in the range 0..1.

setXelA ( int  x,
int  y,
double  r,
double  g,
double  b,
double  a 
)

Changes the RGBA color at the indicated pixel.

Each component is a double in the range 0..1.

setXelVal ( int  x,
int  y,
pixel const  value 
)

Changes the RGB color at the indicated pixel.

Each component is in the range 0..maxval.

setXelVal ( int  x,
int  y,
unsigned short int  gray 
)

Changes all three color components at the indicated pixel to the same value.

The value is in the range 0..maxval.

setXelVal ( int  x,
int  y,
unsigned short int  r,
unsigned short int  g,
unsigned short int  b 
)

Changes the RGB color at the indicated pixel.

Each component is in the range 0..maxval.

takeFrom ( PNMImage  orig)

Move the contents of the other image into this one, and empty the other image.

threshold ( PNMImage const  select_image,
int  channel,
double  threshold,
PNMImage const  lt,
PNMImage const  ge 
)

Selectively copies each pixel from either one source or another source, depending on the pixel value of the indicated channel of select_image.

For each pixel (x, y):

s = select_image.get_channel(x, y). Set this image's (x, y) to:

lt.get_xel(x, y) if s <= threshold, or

ge.get_xel(x, y) if s > threshold

Any of select_image, lt, or ge may be the same PNMImge object as this image, or the same as each other; or they may all be different. All images must be the same size.

unsigned short int toVal ( double  input_value)

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

bool write ( Filename const  filename,
PNMFileType  type 
)

Writes the image to the indicated filename.

If type is non-NULL, it is a suggestion for the type of image file to write.

bool write ( Filename const  filename)

Writes the image to the indicated filename.

If type is non-NULL, it is a suggestion for the type of image file to write.

bool write ( PNMWriter  writer)

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 successful or not.

bool write ( ostream  data,
string  filename,
PNMFileType  type 
)

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.

bool write ( ostream  data,
string  filename 
)

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.

bool write ( ostream  data)

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.

 All Classes Namespaces Functions Variables Enumerations Enumerator Properties