Panda3D
Classes | Public Member Functions | Friends | List of all members
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...

#include "pnmImage.h"

Inheritance diagram for PNMImage:
PNMImageHeader

Classes

class  CRow
 
class  Row
 

Public Member Functions

 PNMImage (const Filename &filename, PNMFileType *type=nullptr)
 
 PNMImage (int x_size, int y_size, int num_channels=3, xelval maxval=255, PNMFileType *type=nullptr, ColorSpace color_space=CS_linear)
 
 PNMImage (const PNMImage &copy)
 
void add_alpha ()
 Adds an alpha channel to the image, if it does not already have one. More...
 
void add_sub_image (const PNMImage &copy, int xto, int yto, int xfrom=0, int yfrom=0, int x_size=-1, int y_size=-1, float pixel_scale=1.0)
 Behaves like copy_sub_image(), except the copy pixels are added to the pixels of the destination, after scaling by the specified pixel_scale. More...
 
void alpha_fill (float alpha=0.0)
 Sets the entire alpha channel to the given level. More...
 
void alpha_fill_val (xelval alpha=0)
 Sets the entire alpha channel to the given level. More...
 
void apply_exponent (float gray_exponent)
 Adjusts each channel of the image by raising the corresponding component value to the indicated exponent, such that L' = L ^ exponent. More...
 
void apply_exponent (float gray_exponent, float alpha_exponent)
 Adjusts each channel of the image by raising the corresponding component value to the indicated exponent, such that L' = L ^ exponent. More...
 
void apply_exponent (float red_exponent, float green_exponent, float blue_exponent)
 Adjusts each channel of the image by raising the corresponding component value to the indicated exponent, such that L' = L ^ exponent. More...
 
void apply_exponent (float red_exponent, float green_exponent, float blue_exponent, float alpha_exponent)
 Adjusts each channel of the image by raising the corresponding component value to the indicated exponent, such that L' = L ^ exponent. More...
 
void blend (int x, int y, const LRGBColorf &val, float alpha)
 Smoothly blends the indicated pixel value in with whatever was already in the image, based on the given alpha value. More...
 
void blend (int x, int y, float r, float g, float b, float alpha)
 Smoothly blends the indicated pixel value in with whatever was already in the image, based on the given alpha value. More...
 
void blend_sub_image (const PNMImage &copy, int xto, int yto, int xfrom=0, int yfrom=0, int x_size=-1, int y_size=-1, float pixel_scale=1.0)
 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. More...
 
void box_filter (float radius=1.0)
 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. More...
 
void box_filter_from (float radius, const PNMImage &copy)
 Makes a resized copy of the indicated image into this one using the indicated filter. More...
 
xelval clamp_val (int input_value) const
 A handy function to clamp values to [0..get_maxval()]. More...
 
void clear ()
 Frees all memory allocated for the image, and clears all its parameters (size, color, type, etc). More...
 
void clear (int x_size, int y_size, int num_channels=3, xelval maxval=255, PNMFileType *type=nullptr, ColorSpace color_space=CS_linear)
 This flavor of clear() reinitializes the image to an empty (black) image with the given dimensions. More...
 
void clear_read_size ()
 Undoes the effect of a previous call to set_read_size(). More...
 
void copy_channel (const PNMImage &copy, int src_channel, int dest_channel)
 Copies a channel from one image into another. More...
 
void copy_channel (const PNMImage &copy, int xto, int yto, int cto, int xfrom=0, int yfrom=0, int cfrom=0, int x_size=-1, int y_size=-1)
 Copies just a single channel from the source image into a single channel of this image, leaving the remaining channels alone. More...
 
void copy_channel_bits (const PNMImage &copy, int src_channel, int dest_channel, xelval src_mask, int right_shift)
 Copies some subset of the bits of the specified channel from one image into some subset of the bits of the specified channel in another image. More...
 
void copy_from (const PNMImage &copy)
 Makes this image become a copy of the other image. More...
 
void copy_header_from (const PNMImageHeader &header)
 Copies just the header information into this image. More...
 
void copy_sub_image (const PNMImage &copy, int xto, int yto, int xfrom=0, int yfrom=0, int x_size=-1, int y_size=-1)
 Copies a rectangular area of another image into a rectangular area of this image. More...
 
void darken_sub_image (const PNMImage &copy, int xto, int yto, int xfrom=0, int yfrom=0, int x_size=-1, int y_size=-1, float pixel_scale=1.0)
 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). More...
 
void do_fill_distance (int xi, int yi, int d)
 Recursively fills in the minimum distance measured from a certain set of points into the gray channel. More...
 
void expand_border (int left, int right, int bottom, int top, const LColorf &color)
 Expands the image by the indicated number of pixels on each edge. More...
 
void fill (float red, float green, float blue)
 Sets the entire image (except the alpha channel) to the given color. More...
 
void fill (float gray=0.0)
 Sets the entire image (except the alpha channel) to the given grayscale level. More...
 
void fill_distance_inside (const PNMImage &mask, float threshold, int radius, bool shrink_from_border)
 Replaces this image with a grayscale image whose gray channel represents the linear Manhattan distance from the nearest dark pixel in the given mask image, up to the specified radius value (which also becomes the new maxval). More...
 
void fill_distance_outside (const PNMImage &mask, float threshold, int radius)
 Replaces this image with a grayscale image whose gray channel represents the linear Manhattan distance from the nearest white pixel in the given mask image, up to the specified radius value (which also becomes the new maxval). More...
 
void fill_val (xelval red, xelval green, xelval blue)
 Sets the entire image (except the alpha channel) to the given color. More...
 
void fill_val (xelval gray=0)
 Sets the entire image (except the alpha channel) to the given grayscale level. More...
 
void flip (bool flip_x, bool flip_y, bool transpose)
 Reverses, transposes, and/or rotates the image in-place according to the specified parameters. More...
 
float from_alpha_val (xelval input_value) const
 A handy function to scale alpha values from [0..get_maxval()] to [0..1]. More...
 
float from_val (xelval input_value) const
 A handy function to scale non-alpha values from [0..get_maxval()] to [0..1]. More...
 
void gamma_correct (float from_gamma, float 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. More...
 
void gamma_correct_alpha (float from_gamma, float 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. More...
 
void gaussian_filter (float radius=1.0)
 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. More...
 
void gaussian_filter_from (float radius, const PNMImage &copy)
 Makes a resized copy of the indicated image into this one using the indicated filter. More...
 
float get_alpha (int x, int y) const
 Returns the alpha component color at the indicated pixel. More...
 
xelval * get_alpha_array ()
 Directly access the underlying PNMImage array of alpha values. More...
 
const xelval * get_alpha_array () const
 Directly access the underlying PNMImage array of alpha values. More...
 
xelval get_alpha_val (int x, int y) const
 Returns the alpha component color at the indicated pixel. More...
 
xelget_array ()
 Directly access the underlying PNMImage array. More...
 
const xelget_array () const
 Directly access the underlying PNMImage array. More...
 
float get_average_gray () const
 Returns the average grayscale component of all of the pixels in the image. More...
 
LRGBColorf get_average_xel () const
 Returns the average color of all of the pixels in the image. More...
 
LColorf get_average_xel_a () const
 Returns the average color of all of the pixels in the image, including the alpha channel. More...
 
float get_blue (int x, int y) const
 Returns the blue component color at the indicated pixel. More...
 
xelval get_blue_val (int x, int y) const
 Returns the blue component color at the indicated pixel. More...
 
float get_bright (int x, int y) const
 Returns the linear brightness of the given xel, as a linearized float in the range 0..1. More...
 
float get_bright (int x, int y, float rc, float gc, float bc) const
 This flavor of get_bright() works correctly only for color images. More...
 
float get_bright (int x, int y, float rc, float gc, float bc, float ac) const
 This flavor of get_bright() works correctly only for four-channel images. More...
 
float get_channel (int x, int y, int channel) const
 Returns the nth component color at the indicated pixel. More...
 
xelval get_channel_val (int x, int y, int channel) const
 Returns the nth component color at the indicated pixel. More...
 
ColorSpace get_color_space () const
 Returns the color space in which the image is encoded. More...
 
float get_gray (int x, int y) const
 Returns the gray component color at the indicated pixel. More...
 
xelval get_gray_val (int x, int y) const
 Returns the gray component color at the indicated pixel. More...
 
float get_green (int x, int y) const
 Returns the green component color at the indicated pixel. More...
 
xelval get_green_val (int x, int y) const
 Returns the green component color at the indicated pixel. More...
 
PixelSpec get_pixel (int x, int y) const
 Returns the (r, g, b, a) pixel value at the indicated pixel, using a PixelSpec object. More...
 
int get_read_x_size () const
 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). More...
 
int get_read_y_size () const
 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). More...
 
float get_red (int x, int y) const
 Returns the red component color at the indicated pixel. More...
 
xelval get_red_val (int x, int y) const
 Returns the red component color at the indicated pixel. More...
 
LRGBColorf get_xel (int x, int y) const
 Returns the RGB color at the indicated pixel. More...
 
LColorf get_xel_a (int x, int y) const
 Returns the RGBA color at the indicated pixel. More...
 
xelget_xel_val (int x, int y)
 Returns the RGB color at the indicated pixel. More...
 
xel get_xel_val (int x, int y) const
 Returns the RGB color at the indicated pixel. More...
 
bool has_read_size () const
 Returns true if set_read_size() has been called. More...
 
void indirect_1d_lookup (const PNMImage &index_image, int channel, const PNMImage &pixel_values)
 index_image is a WxH grayscale image, while pixel_values is an Nx1 color (or grayscale) image. More...
 
bool is_valid () const
 Returns true if the image has been read in or correctly initialized with a height and width. More...
 
void lighten_sub_image (const PNMImage &copy, int xto, int yto, int xfrom=0, int yfrom=0, int x_size=-1, int y_size=-1, float pixel_scale=1.0)
 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). More...
 
void make_grayscale ()
 Converts the image from RGB to grayscale. More...
 
void make_grayscale (float rc, float gc, float bc)
 Converts the image from RGB to grayscale. More...
 
void make_histogram (Histogram &hist)
 Computes a histogram of the colors used in the image. More...
 
void make_rgb ()
 Converts the image from grayscale to RGB. More...
 
void mult_sub_image (const PNMImage &copy, int xto, int yto, int xfrom=0, int yfrom=0, int x_size=-1, int y_size=-1, float pixel_scale=1.0)
 Behaves like copy_sub_image(), except the copy pixels are multiplied to the pixels of the destination, after scaling by the specified pixel_scale. More...
 
PNMImage operator * (const PNMImage &other) const
 Returns a new PNMImage in which each pixel value from the left image is multiplied by each pixel value from the right image. More...
 
PNMImage operator * (float multiplier) const
 Multiplies every pixel value in the image by a constant floating-point multiplier value. More...
 
PNMImage operator * (const LColorf &other) const
 Returns a new PNMImage in which the provided color is multiplied to each pixel in the provided image. More...
 
void operator *= (const PNMImage &other)
 Multiples each pixel in this image by each pixel value from the right image. More...
 
void operator *= (float multiplier)
 Multiplies every pixel value in the image by a constant floating-point multiplier value. More...
 
void operator *= (const LColorf &other)
 Multiplies the provided color to each pixel in this image. More...
 
PNMImage operator - (const PNMImage &other) const
 Returns a new PNMImage in which each pixel value from the right image is subtracted from each pixel value from the left image. More...
 
PNMImage operator - (const LColorf &other) const
 Returns a new PNMImage in which the provided color is subtracted from each pixel in the provided image. More...
 
void operator -= (const PNMImage &other)
 Subtracts each pixel from the right image from each pixel value in this image. More...
 
void operator -= (const LColorf &other)
 Subtracts the provided color from each pixel in this image. More...
 
Row operator [] (int y)
 Allows the PNMImage to appear to be a 2-d array of xels. More...
 
CRow operator [] (int y) const
 Allows the PNMImage to appear to be a 2-d array of xels. More...
 
PNMImage operator ~ () const
 Returns a new PNMImage that is the complement of this PNMImage. More...
 
PNMImage operator+ (const PNMImage &other) const
 Returns a new PNMImage in which each pixel value is the sum of the corresponding pixel values in the two given images. More...
 
PNMImage operator+ (const LColorf &other) const
 Returns a new PNMImage in which the provided color is added to each pixel in the provided image. More...
 
void operator+= (const PNMImage &other)
 Sets each pixel value to the sum of the corresponding pixel values in the two given images. More...
 
void operator+= (const LColorf &other)
 Adds the provided color to each pixel in this image. More...
 
void operator= (const PNMImage &copy)
 
void perlin_noise_fill (float sx, float sy, int table_size=256, unsigned long seed=0)
 Fills the image with a grayscale perlin noise pattern based on the indicated parameters. More...
 
void perlin_noise_fill (StackedPerlinNoise2 &perlin)
 Variant of perlin_noise_fill that uses an existing StackedPerlinNoise2 object. More...
 
void premultiply_alpha ()
 Converts an image in-place to its "premultiplied" form, where, for every pixel in the image, the red, green, and blue components are multiplied by that pixel's alpha value. More...
 
void quick_filter_from (const PNMImage &copy, int xborder=0, int yborder=0)
 Resizes from the given image, with a fixed radius of 0.5. More...
 
bool read (const Filename &filename, PNMFileType *type=nullptr, bool report_unknown_type=true)
 Reads the indicated image filename. More...
 
bool read (std::istream &data, const std::string &filename=std::string(), PNMFileType *type=nullptr, bool report_unknown_type=true)
 Reads the image data from the indicated stream. More...
 
bool read (PNMReader *reader)
 This flavor of read() uses an already-existing PNMReader to read the image file. More...
 
void remix_channels (const LMatrix4 &conv)
 Transforms every pixel using the operation (Ro,Go,Bo) = conv.xform_point(Ri,Gi,Bi); Input must be a color image. More...
 
void remove_alpha ()
 Removes the image's alpha channel, if it exists. More...
 
void render_spot (const LColorf &fg, const LColorf &bg, float min_radius, float max_radius)
 Renders a solid-color circle, with a fuzzy edge, into the center of the PNMImage. More...
 
void rescale (float min_val, float max_val)
 Rescales the RGB channel values so that any values in the original image between min_val and max_val are expanded to the range 0 . More...
 
void reverse_rows ()
 Performs an in-place reversal of the row (y) data. More...
 
void set_alpha (int x, int y, float a)
 Sets the alpha component color only at the indicated pixel. More...
 
void set_alpha_array (xelval *alpha)
 Replaces the underlying PNMImage alpha array with the indicated pointer. More...
 
void set_alpha_val (int x, int y, xelval a)
 Sets the alpha component color only at the indicated pixel. More...
 
void set_array (xel *array)
 Replaces the underlying PNMImage array with the indicated pointer. More...
 
void set_blue (int x, int y, float b)
 Sets the blue component color only at the indicated pixel. More...
 
void set_blue_val (int x, int y, xelval b)
 Sets the blue component color only at the indicated pixel. More...
 
void set_channel (int x, int y, int channel, float value)
 Sets the nth component color at the indicated pixel. More...
 
void set_channel_val (int x, int y, int channel, xelval value)
 Sets the nth component color at the indicated pixel. More...
 
void set_color_space (ColorSpace color_space)
 Converts the colors in the image to the indicated color space. More...
 
void set_color_type (ColorType color_type)
 Translates the image to or from grayscale, color, or four-color mode. More...
 
void set_gray (int x, int y, float gray)
 Sets the gray component color at the indicated pixel. More...
 
void set_gray_val (int x, int y, xelval gray)
 Sets the gray component color at the indicated pixel. More...
 
void set_green (int x, int y, float g)
 Sets the green component color only at the indicated pixel. More...
 
void set_green_val (int x, int y, xelval g)
 Sets the green component color only at the indicated pixel. More...
 
void set_maxval (xelval maxval)
 Rescales the image to the indicated maxval. More...
 
void set_num_channels (int num_channels)
 Changes the number of channels associated with the image. More...
 
void set_pixel (int x, int y, const PixelSpec &pixel)
 Sets the (r, g, b, a) pixel value at the indicated pixel, using a PixelSpec object. More...
 
void set_read_size (int x_size, int y_size)
 Specifies the size to we'd like to scale the image upon reading it. More...
 
void set_red (int x, int y, float r)
 Sets the red component color only at the indicated pixel. More...
 
void set_red_val (int x, int y, xelval r)
 Sets the red component color only at the indicated pixel. More...
 
void set_xel (int x, int y, const LRGBColorf &value)
 Changes the RGB color at the indicated pixel. More...
 
void set_xel (int x, int y, float r, float g, float b)
 Changes the RGB color at the indicated pixel. More...
 
void set_xel (int x, int y, float gray)
 Changes all three color components at the indicated pixel to the same value. More...
 
void set_xel_a (int x, int y, const LColorf &value)
 Changes the RGBA color at the indicated pixel. More...
 
void set_xel_a (int x, int y, float r, float g, float b, float a)
 Changes the RGBA color at the indicated pixel. More...
 
void set_xel_val (int x, int y, const xel &value)
 Changes the RGB color at the indicated pixel. More...
 
void set_xel_val (int x, int y, xelval r, xelval g, xelval b)
 Changes the RGB color at the indicated pixel. More...
 
void set_xel_val (int x, int y, xelval gray)
 Changes all three color components at the indicated pixel to the same value. More...
 
xelval * take_alpha_array ()
 Returns the underlying PNMImage array and removes it from the PNMImage. More...
 
xeltake_array ()
 Returns the underlying PNMImage array and removes it from the PNMImage. More...
 
void take_from (PNMImage &orig)
 Move the contents of the other image into this one, and empty the other image. More...
 
void threshold (const PNMImage &select_image, int channel, float threshold, const PNMImage &lt, const PNMImage &ge)
 Selectively copies each pixel from either one source or another source, depending on the pixel value of the indicated channel of select_image. More...
 
xelval to_alpha_val (float input_value) const
 A handy function to scale alpha values from [0..1] to [0..get_maxval()]. More...
 
xelval to_val (float input_value) const
 A handy function to scale non-alpha values from [0..1] to [0..get_maxval()]. More...
 
void unfiltered_stretch_from (const PNMImage &copy)
 Resizes from the indicated image into this one by performing a nearest- point sample. More...
 
void unpremultiply_alpha ()
 Converts an image in-place to its "straight alpha" form (presumably from a "premultiplied" form), where, for every pixel in the image, the red, green, and blue components are divided by that pixel's alpha value. More...
 
bool write (const Filename &filename, PNMFileType *type=nullptr) const
 Writes the image to the indicated filename. More...
 
bool write (std::ostream &data, const std::string &filename=std::string(), PNMFileType *type=nullptr) const
 Writes the image to the indicated ostream. More...
 
bool write (PNMWriter *writer) const
 This flavor of write() uses an already-existing PNMWriter to write the image file. More...
 
- Public Member Functions inherited from PNMImageHeader
 PNMImageHeader (const PNMImageHeader &copy)
 
ColorSpace get_color_space () const
 
ColorType get_color_type () const
 Returns the image type of the image, as an enumerated value. More...
 
std::string get_comment () const
 
xelval get_maxval () const
 
int get_num_channels () const
 
LVecBase2i get_size () const
 
PNMFileTypeget_type () const
 
int get_x_size () const
 Returns the number of pixels in the X direction. More...
 
int get_y_size () const
 Returns the number of pixels in the Y direction. More...
 
bool has_alpha () const
 Returns true if the image includes an alpha channel, false otherwise. More...
 
bool has_type () const
 
bool is_grayscale () const
 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. More...
 
PNMReadermake_reader (const Filename &filename, PNMFileType *type=nullptr, bool report_unknown_type=true) const
 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. More...
 
PNMReadermake_reader (std::istream *file, bool owns_file=true, const Filename &filename=Filename(), std::string magic_number=std::string(), PNMFileType *type=nullptr, bool report_unknown_type=true) const
 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. More...
 
PNMWritermake_writer (const Filename &filename, PNMFileType *type=nullptr) const
 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. More...
 
PNMWritermake_writer (std::ostream *file, bool owns_file=true, const Filename &filename=Filename(), PNMFileType *type=nullptr) const
 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. More...
 
void operator= (const PNMImageHeader &copy)
 
void output (std::ostream &out) const
 
bool read_header (const Filename &filename, PNMFileType *type=nullptr, bool report_unknown_type=true)
 Opens up the image file and tries to read its header information to determine its size, number of channels, etc. More...
 
bool read_header (std::istream &data, const std::string &filename=std::string(), PNMFileType *type=nullptr, bool report_unknown_type=true)
 Reads the image header information only from the indicated stream. More...
 
void set_comment (const std::string &comment)
 
void set_type (PNMFileType *type)
 Sets the file type of this PNMImage. More...
 

Friends

class Row
 
class Texture
 

Additional Inherited Members

- Public Types inherited from PNMImageHeader
enum  ColorType {
  CT_invalid = 0, CT_grayscale = 1, CT_two_channel = 2, CT_color = 3,
  CT_four_channel = 4
}
 
typedef pmap< PixelSpec, int > HistMap
 
typedef pvector< PixelSpecPalette
 
typedef pvector< PixelSpecCountPixelCount
 
- Static Public Member Functions inherited from PNMImageHeader
static bool has_alpha (ColorType color_type)
 This static variant of has_alpha() returns true if the indicated image type includes an alpha channel, false otherwise. More...
 
static bool is_grayscale (ColorType color_type)
 This static variant of is_grayscale() returns true if the indicated image type represents a grayscale image, false otherwise. More...
 
static bool read_magic_number (std::istream *file, std::string &magic_number, int num_bytes)
 Ensures that the first n bytes of the file are read into magic_number. More...
 
- Public Attributes inherited from PNMImageHeader
 get_color_space
 Returns the color space that the image is encoded in, or CS_unspecified if unknown. More...
 
 get_comment
 Gets the user comment from the file. More...
 
 get_maxval
 Returns the maximum channel value allowable for any pixel in this image; for instance, 255 for a typical 8-bit-per-channel image. More...
 
 get_num_channels
 Returns the number of channels in the image. More...
 
 get_size
 Returns the number of pixels in each direction. More...
 
 get_type
 If the file type is known (e.g. More...
 
 has_type
 Returns true if the PNMImageHeader knows what type it is, false otherwise. More...
 
 set_comment
 Writes a user comment string to the image (header). More...
 

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.

A PNMImage has a color space and a maxval, the combination of which defines how a floating-point linear color value is encoded as an integer value in memory. The functions ending in _val operate on encoded colors, whereas the regular ones work with linear floating-point values. All operations are color space correct unless otherwise specified.

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.

This class is not inherently thread-safe; use it from a single thread or protect access using a mutex.

Definition at line 58 of file pnmImage.h.

Member Function Documentation

◆ add_alpha()

void PNMImage::add_alpha ( )
inline

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

The alpha channel is initialized to zeros.

Definition at line 274 of file pnmImage.I.

References PNMImageHeader::is_grayscale(), and set_color_type().

Referenced by alpha_fill_val().

◆ add_sub_image()

void PNMImage::add_sub_image ( const PNMImage copy,
int  xto,
int  yto,
int  xfrom = 0,
int  yfrom = 0,
int  x_size = -1,
int  y_size = -1,
float  pixel_scale = 1.0 
)

Behaves like copy_sub_image(), except the copy pixels are added to the pixels of the destination, after scaling by the specified pixel_scale.

Unlike blend_sub_image(), the alpha channel is not treated specially.

Definition at line 1168 of file pnmImage.cxx.

References get_alpha(), get_xel(), PNMImageHeader::has_alpha(), set_alpha(), and set_xel().

◆ alpha_fill()

void PNMImage::alpha_fill ( float  alpha = 0.0)
inline

Sets the entire alpha channel to the given level.

Definition at line 183 of file pnmImage.I.

References alpha_fill_val(), and to_alpha_val().

Referenced by expand_border().

◆ alpha_fill_val()

void PNMImage::alpha_fill_val ( xelval  alpha = 0)

Sets the entire alpha channel to the given level.

Definition at line 258 of file pnmImage.cxx.

References add_alpha(), PNMImageHeader::get_x_size(), PNMImageHeader::get_y_size(), PNMImageHeader::has_alpha(), is_valid(), and set_alpha_val().

Referenced by alpha_fill().

◆ apply_exponent() [1/4]

void PNMImage::apply_exponent ( float  gray_exponent)
inline

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

Definition at line 933 of file pnmImage.I.

Referenced by apply_exponent(), gamma_correct(), and gamma_correct_alpha().

◆ apply_exponent() [2/4]

void PNMImage::apply_exponent ( float  gray_exponent,
float  alpha_exponent 
)
inline

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

Definition at line 942 of file pnmImage.I.

References apply_exponent().

◆ apply_exponent() [3/4]

void PNMImage::apply_exponent ( float  red_exponent,
float  green_exponent,
float  blue_exponent 
)
inline

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.

Definition at line 953 of file pnmImage.I.

References apply_exponent().

◆ apply_exponent() [4/4]

void PNMImage::apply_exponent ( float  red_exponent,
float  green_exponent,
float  blue_exponent,
float  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.

Definition at line 1990 of file pnmImage.cxx.

References get_alpha(), and PNMImageHeader::has_alpha().

◆ blend() [1/2]

void PNMImage::blend ( int  x,
int  y,
const LRGBColorf &  val,
float  alpha 
)
inline

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.

Definition at line 886 of file pnmImage.I.

Referenced by blend_sub_image().

◆ blend() [2/2]

void PNMImage::blend ( int  x,
int  y,
float  r,
float  g,
float  b,
float  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.

Definition at line 1004 of file pnmImage.cxx.

References get_alpha(), get_xel(), PNMImageHeader::has_alpha(), set_alpha(), and set_xel().

◆ blend_sub_image()

void PNMImage::blend_sub_image ( const PNMImage copy,
int  xto,
int  yto,
int  xfrom = 0,
int  yfrom = 0,
int  x_size = -1,
int  y_size = -1,
float  pixel_scale = 1.0 
)

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

Definition at line 1132 of file pnmImage.cxx.

References blend(), copy_sub_image(), get_alpha(), get_xel(), and PNMImageHeader::has_alpha().

◆ box_filter()

void PNMImage::box_filter ( float  radius = 1.0)
inline

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.

Definition at line 895 of file pnmImage.I.

References box_filter_from().

◆ box_filter_from()

void PNMImage::box_filter_from ( float  width,
const PNMImage 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.

Definition at line 532 of file pnm-image-filter.cxx.

Referenced by box_filter().

◆ clamp_val()

xelval PNMImage::clamp_val ( int  input_value) const
inline

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

Definition at line 70 of file pnmImage.I.

References PNMImageHeader::get_maxval.

Referenced by to_alpha_val(), and to_val().

◆ clear() [1/2]

void PNMImage::clear ( )

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

Definition at line 48 of file pnmImage.cxx.

Referenced by clear(), GeoMipTerrain::clear_color_map(), copy_from(), copy_header_from(), ShaderTerrainMesh::generate(), indirect_1d_lookup(), PfmVizzer::make_displacement(), read(), TextureImage::release_source_image(), PfmFile::store(), PfmFile::store_mask(), and take_from().

◆ clear() [2/2]

void PNMImage::clear ( int  x_size,
int  y_size,
int  num_channels = 3,
xelval  maxval = 255,
PNMFileType type = nullptr,
ColorSpace  color_space = CS_linear 
)

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

Definition at line 74 of file pnmImage.cxx.

References clear().

◆ clear_read_size()

void PNMImage::clear_read_size ( )
inline

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

Definition at line 209 of file pnmImage.I.

◆ copy_channel() [1/2]

void PNMImage::copy_channel ( const PNMImage copy,
int  src_channel,
int  dest_channel 
)

Copies a channel from one image into another.

Images must be the same size

Definition at line 121 of file pnmImage.cxx.

◆ copy_channel() [2/2]

void PNMImage::copy_channel ( const PNMImage copy,
int  xto,
int  yto,
int  cto,
int  xfrom = 0,
int  yfrom = 0,
int  cfrom = 0,
int  x_size = -1,
int  y_size = -1 
)

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

Definition at line 1733 of file pnmImage.cxx.

References get_alpha_val(), get_blue_val(), get_channel(), get_channel_val(), get_color_space(), PNMImageHeader::get_maxval, set_alpha_val(), set_blue_val(), set_channel(), and set_channel_val().

◆ copy_channel_bits()

void PNMImage::copy_channel_bits ( const PNMImage copy,
int  src_channel,
int  dest_channel,
xelval  src_mask,
int  right_shift 
)

Copies some subset of the bits of the specified channel from one image into some subset of the bits of the specified channel in another image.

Images must be the same size.

If right_shift is negative, it means a left shift.

Definition at line 154 of file pnmImage.cxx.

◆ copy_from()

void PNMImage::copy_from ( const PNMImage copy)

Makes this image become a copy of the other image.

Definition at line 105 of file pnmImage.cxx.

References clear(), copy_header_from(), PNMImageHeader::has_alpha(), and is_valid().

◆ copy_header_from()

void PNMImage::copy_header_from ( const PNMImageHeader 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.

Definition at line 200 of file pnmImage.cxx.

References clear(), and PNMImageHeader::has_alpha().

Referenced by copy_from(), read(), and GeoMipTerrain::set_heightfield().

◆ copy_sub_image()

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

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.

Definition at line 1077 of file pnmImage.cxx.

References get_alpha(), get_alpha_val(), get_color_space(), PNMImageHeader::get_maxval, get_xel(), get_xel_val(), PNMImageHeader::has_alpha(), set_alpha(), set_alpha_val(), set_xel(), and set_xel_val().

Referenced by blend_sub_image(), and expand_border().

◆ darken_sub_image()

void PNMImage::darken_sub_image ( const PNMImage copy,
int  xto,
int  yto,
int  xfrom = 0,
int  yfrom = 0,
int  x_size = -1,
int  y_size = -1,
float  pixel_scale = 1.0 
)

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.

Definition at line 1241 of file pnmImage.cxx.

References get_color_space(), and PNMImageHeader::get_maxval.

◆ do_fill_distance()

void PNMImage::do_fill_distance ( int  xi,
int  yi,
int  d 
)

Recursively fills in the minimum distance measured from a certain set of points into the gray channel.

Definition at line 2169 of file pnmImage.cxx.

References get_gray_val(), PNMImageHeader::get_x_size(), PNMImageHeader::get_y_size(), and set_gray_val().

◆ expand_border()

void PNMImage::expand_border ( int  left,
int  right,
int  bottom,
int  top,
const LColorf &  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.

Definition at line 1867 of file pnmImage.cxx.

References alpha_fill(), copy_sub_image(), fill(), get_color_space(), PNMImageHeader::get_maxval, PNMImageHeader::get_num_channels, PNMImageHeader::get_type, PNMImageHeader::get_x_size(), PNMImageHeader::get_y_size(), PNMImageHeader::has_alpha(), and take_from().

◆ fill() [1/2]

void PNMImage::fill ( float  red,
float  green,
float  blue 
)
inline

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

Definition at line 157 of file pnmImage.I.

References fill_val(), and to_val().

Referenced by DestTextureImage::copy(), expand_border(), and fill().

◆ fill() [2/2]

void PNMImage::fill ( float  gray = 0.0)
inline

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

Definition at line 166 of file pnmImage.I.

References fill().

◆ fill_distance_inside()

void PNMImage::fill_distance_inside ( const PNMImage mask,
float  threshold,
int  radius,
bool  shrink_from_border 
)

Replaces this image with a grayscale image whose gray channel represents the linear Manhattan distance from the nearest dark pixel in the given mask image, up to the specified radius value (which also becomes the new maxval).

radius may range from 0 to maxmaxval; smaller values will compute faster. A dark pixel is defined as one whose pixel value is < threshold.

If shrink_from_border is true, then the mask image is considered to be surrounded by a border of dark pixels; otherwise, the border isn't considered.

This can be used, in conjunction with threshold, to shrink a mask image inwards by a certain number of pixels.

The mask image may be the same image as this one, in which case it is destructively modified by this process.

Definition at line 1602 of file pnmImage.cxx.

◆ fill_distance_outside()

void PNMImage::fill_distance_outside ( const PNMImage mask,
float  threshold,
int  radius 
)

Replaces this image with a grayscale image whose gray channel represents the linear Manhattan distance from the nearest white pixel in the given mask image, up to the specified radius value (which also becomes the new maxval).

radius may range from 0 to maxmaxval; smaller values will compute faster. A white pixel is defined as one whose pixel value is >= threshold.

This can be used, in conjunction with threshold, to grow a mask image outwards by a certain number of pixels.

The mask image may be the same image as this one, in which case it is destructively modified by this process.

Definition at line 1646 of file pnmImage.cxx.

◆ fill_val() [1/2]

void PNMImage::fill_val ( xelval  red,
xelval  green,
xelval  blue 
)

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

Definition at line 244 of file pnmImage.cxx.

References PNMImageHeader::get_x_size(), PNMImageHeader::get_y_size(), is_valid(), and set_xel_val().

Referenced by fill(), and fill_val().

◆ fill_val() [2/2]

void PNMImage::fill_val ( xelval  gray = 0)
inline

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

Definition at line 175 of file pnmImage.I.

References fill_val().

◆ flip()

void PNMImage::flip ( bool  flip_x,
bool  flip_y,
bool  transpose 
)

Reverses, transposes, and/or rotates the image in-place according to the specified parameters.

If flip_x is true, the x axis is reversed; if flip_y is true, the y axis is reversed. Then, if transpose is true, the x and y axes are exchanged. These parameters can be used to select any combination of 90-degree or 180-degree rotations and flips.

Definition at line 715 of file pnmImage.cxx.

◆ from_alpha_val()

float PNMImage::from_alpha_val ( xelval  input_value) const
inline

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

Definition at line 149 of file pnmImage.I.

Referenced by get_alpha().

◆ from_val()

float PNMImage::from_val ( xelval  input_value) const
inline

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

Do not use this for alpha values, see from_alpha_val.

Definition at line 120 of file pnmImage.I.

References decode_sRGB_float().

Referenced by get_blue(), get_gray(), get_green(), and get_red().

◆ gamma_correct()

void PNMImage::gamma_correct ( float  from_gamma,
float  to_gamma 
)
inline

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.

Definition at line 914 of file pnmImage.I.

References apply_exponent().

◆ gamma_correct_alpha()

void PNMImage::gamma_correct_alpha ( float  from_gamma,
float  to_gamma 
)
inline

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.

Definition at line 924 of file pnmImage.I.

References apply_exponent().

◆ gaussian_filter()

void PNMImage::gaussian_filter ( float  radius = 1.0)
inline

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.

Definition at line 904 of file pnmImage.I.

References gaussian_filter_from().

Referenced by GeoMipTerrain::calc_ambient_occlusion().

◆ gaussian_filter_from()

void PNMImage::gaussian_filter_from ( float  width,
const PNMImage 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.

Definition at line 543 of file pnm-image-filter.cxx.

Referenced by gaussian_filter().

◆ get_alpha()

float PNMImage::get_alpha ( int  x,
int  y 
) const
inline

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 float in the range 0..1.

Definition at line 795 of file pnmImage.I.

References from_alpha_val(), and get_alpha_val().

Referenced by add_sub_image(), apply_exponent(), blend(), blend_sub_image(), copy_sub_image(), get_channel(), PfmFile::load(), mult_sub_image(), premultiply_alpha(), unfiltered_stretch_from(), and unpremultiply_alpha().

◆ get_alpha_array() [1/2]

xelval * PNMImage::get_alpha_array ( )
inline

Directly access the underlying PNMImage array of alpha values.

Know what you are doing!

Definition at line 1101 of file pnmImage.I.

Referenced by PfmFile::write().

◆ get_alpha_array() [2/2]

const xelval * PNMImage::get_alpha_array ( ) const
inline

Directly access the underlying PNMImage array of alpha values.

Know what you are doing!

Definition at line 1110 of file pnmImage.I.

◆ get_alpha_val()

xelval PNMImage::get_alpha_val ( int  x,
int  y 
) const
inline

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 and always linear.

Definition at line 405 of file pnmImage.I.

Referenced by copy_channel(), copy_sub_image(), get_alpha(), get_channel_val(), and get_pixel().

◆ get_array() [1/2]

xel * PNMImage::get_array ( )
inline

Directly access the underlying PNMImage array.

Know what you are doing!

Definition at line 1084 of file pnmImage.I.

Referenced by PfmFile::write().

◆ get_array() [2/2]

const xel * PNMImage::get_array ( ) const
inline

Directly access the underlying PNMImage array.

Know what you are doing!

Definition at line 1092 of file pnmImage.I.

◆ get_average_gray()

float PNMImage::get_average_gray ( ) const

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

Definition at line 2234 of file pnmImage.cxx.

◆ get_average_xel()

LRGBColorf PNMImage::get_average_xel ( ) const

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

Definition at line 2189 of file pnmImage.cxx.

References get_xel().

◆ get_average_xel_a()

LColorf PNMImage::get_average_xel_a ( ) const

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

Definition at line 2212 of file pnmImage.cxx.

References get_xel_a().

◆ get_blue()

float PNMImage::get_blue ( int  x,
int  y 
) const
inline

Returns the blue component color at the indicated pixel.

The value returned is a linearized float in the range 0..1.

Definition at line 774 of file pnmImage.I.

References from_val(), and get_blue_val().

Referenced by get_channel(), premultiply_alpha(), and unpremultiply_alpha().

◆ get_blue_val()

xelval PNMImage::get_blue_val ( int  x,
int  y 
) const
inline

Returns the blue component color at the indicated pixel.

The value returned is in the range 0..maxval and encoded in the configured color space.

Definition at line 383 of file pnmImage.I.

Referenced by copy_channel(), get_blue(), and get_channel_val().

◆ get_bright() [1/3]

float PNMImage::get_bright ( int  x,
int  y 
) const
inline

Returns the linear brightness of the given xel, as a linearized float in the range 0..1.

This flavor of get_bright() returns the correct grayscale brightness level for both full-color and grayscale images.

Definition at line 855 of file pnmImage.I.

Referenced by make_grayscale().

◆ get_bright() [2/3]

float PNMImage::get_bright ( int  x,
int  y,
float  rc,
float  gc,
float  bc 
) const
inline

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.

Definition at line 865 of file pnmImage.I.

References get_xel().

◆ get_bright() [3/3]

float PNMImage::get_bright ( int  x,
int  y,
float  rc,
float  gc,
float  bc,
float  ac 
) const
inline

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.

Definition at line 875 of file pnmImage.I.

References get_xel_a().

◆ get_channel()

float PNMImage::get_channel ( int  x,
int  y,
int  channel 
) const

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 float in the range 0..1.

Definition at line 904 of file pnmImage.cxx.

References get_alpha(), get_blue(), get_green(), PNMImageHeader::get_num_channels, and get_red().

Referenced by copy_channel(), and indirect_1d_lookup().

◆ get_channel_val()

xelval PNMImage::get_channel_val ( int  x,
int  y,
int  channel 
) const

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.

Definition at line 837 of file pnmImage.cxx.

References get_alpha_val(), get_blue_val(), get_green_val(), PNMImageHeader::get_num_channels, and get_red_val().

Referenced by copy_channel().

◆ get_color_space()

ColorSpace PNMImage::get_color_space ( ) const
inline

Returns the color space in which the image is encoded.

Definition at line 243 of file pnmImage.I.

Referenced by Texture::consider_rescale(), copy_channel(), copy_sub_image(), darken_sub_image(), expand_border(), lighten_sub_image(), read(), and GeoMipTerrain::set_heightfield().

◆ get_gray()

float PNMImage::get_gray ( int  x,
int  y 
) const
inline

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 linearized float in the range 0..1.

Definition at line 785 of file pnmImage.I.

References from_val(), and get_gray_val().

Referenced by GeoMipTerrain::calc_ambient_occlusion(), and PfmFile::load().

◆ get_gray_val()

xelval PNMImage::get_gray_val ( int  x,
int  y 
) const
inline

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 and encoded in the configured color space.

Definition at line 395 of file pnmImage.I.

Referenced by do_fill_distance(), get_gray(), get_pixel(), and write().

◆ get_green()

float PNMImage::get_green ( int  x,
int  y 
) const
inline

Returns the green component color at the indicated pixel.

The value returned is a linearized float in the range 0..1.

Definition at line 765 of file pnmImage.I.

References from_val(), and get_green_val().

Referenced by get_channel(), premultiply_alpha(), and unpremultiply_alpha().

◆ get_green_val()

xelval PNMImage::get_green_val ( int  x,
int  y 
) const
inline

Returns the green component color at the indicated pixel.

The value returned is in the range 0..maxval and encoded in the configured color space.

Definition at line 373 of file pnmImage.I.

Referenced by get_channel_val(), and get_green().

◆ get_pixel()

PNMImage::PixelSpec PNMImage::get_pixel ( int  x,
int  y 
) const

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

Definition at line 968 of file pnmImage.cxx.

References get_alpha_val(), get_gray_val(), and get_xel_val().

◆ get_read_x_size()

int PNMImage::get_read_x_size ( ) const
inline

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

Definition at line 226 of file pnmImage.I.

References PNMImageHeader::get_x_size().

◆ get_read_y_size()

int PNMImage::get_read_y_size ( ) const
inline

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

Definition at line 235 of file pnmImage.I.

References PNMImageHeader::get_y_size().

◆ get_red()

float PNMImage::get_red ( int  x,
int  y 
) const
inline

Returns the red component color at the indicated pixel.

The value returned is a linearized float in the range 0..1.

Definition at line 756 of file pnmImage.I.

References from_val(), and get_red_val().

Referenced by get_channel(), premultiply_alpha(), and unpremultiply_alpha().

◆ get_red_val()

xelval PNMImage::get_red_val ( int  x,
int  y 
) const
inline

Returns the red component color at the indicated pixel.

The value returned is in the range 0..maxval and encoded in the configured color space.

Definition at line 363 of file pnmImage.I.

Referenced by get_channel_val(), and get_red().

◆ get_xel()

LRGBColorf PNMImage::get_xel ( int  x,
int  y 
) const
inline

Returns the RGB color at the indicated pixel.

Each component is a linearized float in the range 0..1.

Definition at line 480 of file pnmImage.I.

Referenced by add_sub_image(), blend(), blend_sub_image(), copy_sub_image(), get_average_xel(), get_bright(), PfmFile::load(), mult_sub_image(), and unfiltered_stretch_from().

◆ get_xel_a()

LColorf PNMImage::get_xel_a ( int  x,
int  y 
) const
inline

Returns the RGBA color at the indicated pixel.

Each component is a linearized float in the range 0..1.

Definition at line 594 of file pnmImage.I.

Referenced by get_average_xel_a(), get_bright(), and PfmFile::load().

◆ get_xel_val() [1/2]

xel & PNMImage::get_xel_val ( int  x,
int  y 
)
inline

Returns the RGB color at the indicated pixel.

Each component is in the range 0..maxval.

Definition at line 309 of file pnmImage.I.

Referenced by copy_sub_image(), and get_pixel().

◆ get_xel_val() [2/2]

xel PNMImage::get_xel_val ( int  x,
int  y 
) const
inline

Returns the RGB color at the indicated pixel.

Each component is in the range 0..maxval.

Definition at line 319 of file pnmImage.I.

◆ has_read_size()

bool PNMImage::has_read_size ( ) const
inline

Returns true if set_read_size() has been called.

Definition at line 217 of file pnmImage.I.

Referenced by read().

◆ indirect_1d_lookup()

void PNMImage::indirect_1d_lookup ( const PNMImage index_image,
int  channel,
const PNMImage pixel_values 
)

index_image is a WxH grayscale image, while pixel_values is an Nx1 color (or grayscale) image.

Typically pixel_values will be a 256x1 image.

Fills the PNMImage with a new image the same width and height as index_image, with the same number of channels as pixel_values.

Each pixel of the new image is computed with the formula:

new_image(x, y) = pixel_values(index_image(x, y)[channel], 0)

At present, no interpolation is performed; the nearest value in pixel_values is discovered. This may change in the future.

Definition at line 1679 of file pnmImage.cxx.

References clear(), get_channel(), PNMImageHeader::get_maxval, PNMImageHeader::get_num_channels, PNMImageHeader::get_x_size(), and PNMImageHeader::get_y_size().

◆ is_valid()

bool PNMImage::is_valid ( ) const
inline

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.

Definition at line 253 of file pnmImage.I.

Referenced by alpha_fill_val(), Texture::consider_rescale(), DestTextureImage::copy(), copy_from(), fill_val(), PfmFile::load(), PNMTextGlyph::place(), and write().

◆ lighten_sub_image()

void PNMImage::lighten_sub_image ( const PNMImage copy,
int  xto,
int  yto,
int  xfrom = 0,
int  yfrom = 0,
int  x_size = -1,
int  y_size = -1,
float  pixel_scale = 1.0 
)

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.

Definition at line 1308 of file pnmImage.cxx.

References get_color_space(), and PNMImageHeader::get_maxval.

◆ make_grayscale() [1/2]

void PNMImage::make_grayscale ( )
inline

Converts the image from RGB to grayscale.

Any alpha channel, if present, is left undisturbed.

Definition at line 291 of file pnmImage.I.

Referenced by GeoMipTerrain::calc_ambient_occlusion(), and GeoMipTerrain::make_slope_image().

◆ make_grayscale() [2/2]

void PNMImage::make_grayscale ( float  rc,
float  gc,
float  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.

Definition at line 615 of file pnmImage.cxx.

References get_bright(), PNMImageHeader::get_x_size(), PNMImageHeader::get_y_size(), PNMImageHeader::has_alpha(), PNMImageHeader::is_grayscale(), and set_gray().

◆ make_histogram()

void PNMImage::make_histogram ( PNMImage::Histogram histogram)

Computes a histogram of the colors used in the image.

Definition at line 1911 of file pnmImage.cxx.

References PNMImageHeader::Histogram::swap().

◆ make_rgb()

void PNMImage::make_rgb ( )
inline

Converts the image from grayscale to RGB.

Any alpha channel, if present, is left undisturbed.

Definition at line 300 of file pnmImage.I.

References PNMImageHeader::has_alpha(), and set_color_type().

◆ mult_sub_image()

void PNMImage::mult_sub_image ( const PNMImage copy,
int  xto,
int  yto,
int  xfrom = 0,
int  yfrom = 0,
int  x_size = -1,
int  y_size = -1,
float  pixel_scale = 1.0 
)

Behaves like copy_sub_image(), except the copy pixels are multiplied to the pixels of the destination, after scaling by the specified pixel_scale.

Unlike blend_sub_image(), the alpha channel is not treated specially.

Definition at line 1202 of file pnmImage.cxx.

References get_alpha(), get_xel(), PNMImageHeader::has_alpha(), set_alpha(), and set_xel().

◆ operator *() [1/3]

PNMImage PNMImage::operator * ( const PNMImage other) const
inline

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.

Definition at line 1297 of file pnmImage.I.

◆ operator *() [2/3]

PNMImage PNMImage::operator * ( float  multiplier) const
inline

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

Definition at line 1308 of file pnmImage.I.

◆ operator *() [3/3]

PNMImage PNMImage::operator * ( const LColorf &  other) const
inline

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

Definition at line 1319 of file pnmImage.I.

◆ operator *=() [1/3]

void PNMImage::operator *= ( const PNMImage other)

Multiples each pixel in this image 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.

Definition at line 2418 of file pnmImage.cxx.

◆ operator *=() [2/3]

void PNMImage::operator *= ( float  multiplier)

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

This affects all channels.

Definition at line 2435 of file pnmImage.cxx.

◆ operator *=() [3/3]

void PNMImage::operator *= ( const LColorf &  other)

Multiplies the provided color to each pixel in this image.

This is a component-wise multiplication.

Definition at line 2472 of file pnmImage.cxx.

◆ operator -() [1/2]

PNMImage PNMImage::operator - ( const PNMImage other) const
inline

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.

Definition at line 1273 of file pnmImage.I.

◆ operator -() [2/2]

PNMImage PNMImage::operator - ( const LColorf &  other) const
inline

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

Definition at line 1284 of file pnmImage.I.

◆ operator -=() [1/2]

void PNMImage::operator -= ( const PNMImage other)

Subtracts each pixel from the right image from each pixel value in this image.

Only valid when both images have the same size.

Definition at line 2368 of file pnmImage.cxx.

◆ operator -=() [2/2]

void PNMImage::operator -= ( const LColorf &  other)

Subtracts the provided color from each pixel in this image.

Definition at line 2407 of file pnmImage.cxx.

◆ operator []() [1/2]

PNMImage::Row PNMImage::operator [] ( int  y)
inline

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

Definition at line 1068 of file pnmImage.I.

◆ operator []() [2/2]

PNMImage::CRow PNMImage::operator [] ( int  y) const
inline

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

Definition at line 1076 of file pnmImage.I.

◆ operator ~()

PNMImage PNMImage::operator ~ ( ) const

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

This operation is not color-space correct.

Definition at line 2256 of file pnmImage.cxx.

◆ operator+() [1/2]

PNMImage PNMImage::operator+ ( const PNMImage other) const
inline

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.

Definition at line 1250 of file pnmImage.I.

◆ operator+() [2/2]

PNMImage PNMImage::operator+ ( const LColorf &  other) const
inline

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

Definition at line 1261 of file pnmImage.I.

◆ operator+=() [1/2]

void PNMImage::operator+= ( const PNMImage other)

Sets each pixel value to the sum of the corresponding pixel values in the two given images.

Only valid when both images have the same size.

Definition at line 2286 of file pnmImage.cxx.

◆ operator+=() [2/2]

void PNMImage::operator+= ( const LColorf &  other)

Adds the provided color to each pixel in this image.

Definition at line 2325 of file pnmImage.cxx.

◆ perlin_noise_fill() [1/2]

void PNMImage::perlin_noise_fill ( float  sx,
float  sy,
int  table_size = 256,
unsigned long  seed = 0 
)

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.

Definition at line 1938 of file pnmImage.cxx.

References PerlinNoise2::noise(), and set_xel().

◆ perlin_noise_fill() [2/2]

void PNMImage::perlin_noise_fill ( StackedPerlinNoise2 perlin)

Variant of perlin_noise_fill that uses an existing StackedPerlinNoise2 object.

Definition at line 1955 of file pnmImage.cxx.

References StackedPerlinNoise2::noise(), and set_xel().

◆ premultiply_alpha()

void PNMImage::premultiply_alpha ( )

Converts an image in-place to its "premultiplied" form, where, for every pixel in the image, the red, green, and blue components are multiplied by that pixel's alpha value.

This does not modify any alpha values.

Definition at line 639 of file pnmImage.cxx.

References get_alpha(), get_blue(), get_green(), get_red(), PNMImageHeader::get_x_size(), PNMImageHeader::get_y_size(), PNMImageHeader::has_alpha(), and set_xel().

◆ quick_filter_from()

void PNMImage::quick_filter_from ( const PNMImage from,
int  xborder = 0,
int  yborder = 0 
)

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.

Definition at line 754 of file pnm-image-filter.cxx.

References PNMImageHeader::get_x_size(), and PNMImageHeader::get_y_size().

Referenced by Texture::consider_rescale(), DestTextureImage::copy(), PT(), and read().

◆ read() [1/3]

bool PNMImage::read ( const Filename filename,
PNMFileType type = nullptr,
bool  report_unknown_type = true 
)

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.

Definition at line 278 of file pnmImage.cxx.

References clear(), and PNMImageHeader::make_reader().

Referenced by PfmFile::read(), GeoMipTerrain::set_color_map(), and HeightfieldTesselator::set_heightfield().

◆ read() [2/3]

bool PNMImage::read ( std::istream &  data,
const std::string &  filename = std::string(),
PNMFileType type = nullptr,
bool  report_unknown_type = true 
)

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.

Definition at line 301 of file pnmImage.cxx.

◆ read() [3/3]

bool PNMImage::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.

Definition at line 321 of file pnmImage.cxx.

References clear(), copy_header_from(), get_color_space(), PNMImageHeader::get_maxval, PNMImageHeader::get_num_channels, PNMImageHeader::get_type, has_read_size(), PNMReader::is_floating_point(), PNMReader::is_valid(), PNMReader::prepare_read(), quick_filter_from(), PNMReader::read_data(), PNMReader::read_pfm(), PNMReader::set_read_size(), PfmFile::store(), and take_from().

◆ remix_channels()

void PNMImage::remix_channels ( const LMatrix4 &  conv)

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

Definition at line 1971 of file pnmImage.cxx.

References PNMImageHeader::get_num_channels.

◆ remove_alpha()

void PNMImage::remove_alpha ( )
inline

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

Definition at line 282 of file pnmImage.I.

References PNMImageHeader::is_grayscale(), and set_color_type().

◆ render_spot()

void PNMImage::render_spot ( const LColorf &  fg,
const LColorf &  bg,
float  min_radius,
float  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.

Definition at line 1789 of file pnmImage.cxx.

References set_xel_a().

Referenced by PT().

◆ rescale()

void PNMImage::rescale ( float  min_val,
float  max_val 
)

Rescales the RGB channel values so that any values in the original image between min_val and max_val are expanded to the range 0 .

. 1. Values below min_val are set to 0, and values above max_val are set to 1. Does not affect the alpha channel, if any.

Definition at line 1703 of file pnmImage.cxx.

◆ reverse_rows()

void PNMImage::reverse_rows ( )

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

Definition at line 685 of file pnmImage.cxx.

◆ set_alpha()

void PNMImage::set_alpha ( int  x,
int  y,
float  a 
)
inline

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.

Definition at line 845 of file pnmImage.I.

References set_alpha_val(), and to_alpha_val().

Referenced by add_sub_image(), blend(), copy_sub_image(), mult_sub_image(), set_channel(), and unfiltered_stretch_from().

◆ set_alpha_array()

void PNMImage::set_alpha_array ( xelval *  alpha)

Replaces the underlying PNMImage alpha array with the indicated pointer.

Know what you are doing! The new array must be the correct size and must have been allocated via PANDA_MALLOC_ARRAY(). The PNMImage object becomes the owner of this pointer and will eventually free it with PANDA_FREE_ARRAY(). The previous array, if any, will be freed with PANDA_FREE_ARRAY() when this call is made.

Definition at line 1062 of file pnmImage.cxx.

◆ set_alpha_val()

void PNMImage::set_alpha_val ( int  x,
int  y,
xelval  a 
)
inline

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.

This value is always linearly encoded, even if the image is set to the sRGB color space.

Definition at line 470 of file pnmImage.I.

Referenced by alpha_fill_val(), copy_channel(), copy_sub_image(), set_alpha(), and set_channel_val().

◆ set_array()

void PNMImage::set_array ( xel array)

Replaces the underlying PNMImage array with the indicated pointer.

Know what you are doing! The new array must be the correct size and must have been allocated via PANDA_MALLOC_ARRAY(). The PNMImage object becomes the owner of this pointer and will eventually free it with PANDA_FREE_ARRAY(). The previous array, if any, will be freed with PANDA_FREE_ARRAY() when this call is made.

Definition at line 1046 of file pnmImage.cxx.

◆ set_blue()

void PNMImage::set_blue ( int  x,
int  y,
float  b 
)
inline

Sets the blue component color only at the indicated pixel.

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

Definition at line 822 of file pnmImage.I.

References set_blue_val(), and to_val().

Referenced by set_channel().

◆ set_blue_val()

void PNMImage::set_blue_val ( int  x,
int  y,
xelval  b 
)
inline

Sets the blue component color only at the indicated pixel.

The value given should be in the range 0..maxval, encoded in the configured color space. See set_blue if you instead have a linearized and normalized floating-point value.

Definition at line 441 of file pnmImage.I.

Referenced by copy_channel(), set_blue(), and set_channel_val().

◆ set_channel()

void PNMImage::set_channel ( int  x,
int  y,
int  channel,
float  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 float in the range 0..1.

Definition at line 935 of file pnmImage.cxx.

References set_alpha(), set_blue(), set_green(), and set_red().

Referenced by copy_channel().

◆ set_channel_val()

void PNMImage::set_channel_val ( int  x,
int  y,
int  channel,
xelval  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.

Definition at line 868 of file pnmImage.cxx.

References set_alpha_val(), set_blue_val(), set_green_val(), and set_red_val().

Referenced by copy_channel().

◆ set_color_space()

void PNMImage::set_color_space ( ColorSpace  color_space)

Converts the colors in the image to the indicated color space.

This may be a lossy operation, in particular when going from sRGB to linear. The alpha channel remains untouched.

Note that, because functions like get_xel() and set_xel() work on linearized floating-point values, this conversion won't affect those values (aside from some minor discrepancies due to storage precision). It does affect the values used by get_xel_val() and set_xel_val(), though, since those operate on encoded colors.

Some color spaces, particularly scRGB, may enforce the use of a particular maxval setting.

Definition at line 534 of file pnmImage.cxx.

◆ set_color_type()

void PNMImage::set_color_type ( PNMImage::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.

Definition at line 478 of file pnmImage.cxx.

Referenced by add_alpha(), make_rgb(), and remove_alpha().

◆ set_gray()

void PNMImage::set_gray ( int  x,
int  y,
float  gray 
)
inline

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 linearized float in the range 0..1.

Definition at line 835 of file pnmImage.I.

References set_gray_val(), and to_val().

Referenced by make_grayscale(), and PfmFile::store_mask().

◆ set_gray_val()

void PNMImage::set_gray_val ( int  x,
int  y,
xelval  gray 
)
inline

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, encoded in the configured color space. See set_gray if you instead have a linearized normalized floating-point value.

Definition at line 456 of file pnmImage.I.

Referenced by do_fill_distance(), and set_gray().

◆ set_green()

void PNMImage::set_green ( int  x,
int  y,
float  g 
)
inline

Sets the green component color only at the indicated pixel.

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

Definition at line 813 of file pnmImage.I.

References set_green_val(), and to_val().

Referenced by set_channel().

◆ set_green_val()

void PNMImage::set_green_val ( int  x,
int  y,
xelval  g 
)
inline

Sets the green component color only at the indicated pixel.

The value given should be in the range 0..maxval, encoded in the configured color space. See set_green if you instead have a linearized and normalized floating-point value.

Definition at line 429 of file pnmImage.I.

Referenced by set_channel_val(), and set_green().

◆ set_maxval()

void PNMImage::set_maxval ( xelval  maxval)

Rescales the image to the indicated maxval.

Definition at line 794 of file pnmImage.cxx.

Referenced by GeoMipTerrain::calc_ambient_occlusion().

◆ set_num_channels()

void PNMImage::set_num_channels ( int  num_channels)
inline

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

Definition at line 264 of file pnmImage.I.

◆ set_pixel()

void PNMImage::set_pixel ( int  x,
int  y,
const PixelSpec pixel 
)

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

Definition at line 988 of file pnmImage.cxx.

◆ set_read_size()

void PNMImage::set_read_size ( int  x_size,
int  y_size 
)
inline

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.

Definition at line 199 of file pnmImage.I.

Referenced by Texture::consider_rescale(), and GeoMipTerrain::set_heightfield().

◆ set_red()

void PNMImage::set_red ( int  x,
int  y,
float  r 
)
inline

Sets the red component color only at the indicated pixel.

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

Definition at line 804 of file pnmImage.I.

References set_red_val(), and to_val().

Referenced by set_channel().

◆ set_red_val()

void PNMImage::set_red_val ( int  x,
int  y,
xelval  r 
)
inline

Sets the red component color only at the indicated pixel.

The value given should be in the range 0..maxval, encoded in the configured color space. See set_red if you instead have a linearized and normalized floating-point value.

Definition at line 417 of file pnmImage.I.

Referenced by set_channel_val(), and set_red().

◆ set_xel() [1/3]

void PNMImage::set_xel ( int  x,
int  y,
const LRGBColorf &  value 
)
inline

◆ set_xel() [2/3]

void PNMImage::set_xel ( int  x,
int  y,
float  r,
float  g,
float  b 
)
inline

Changes the RGB color at the indicated pixel.

Each component is a linearized float in the range 0..1.

Definition at line 575 of file pnmImage.I.

References set_xel().

◆ set_xel() [3/3]

void PNMImage::set_xel ( int  x,
int  y,
float  gray 
)
inline

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

The value is a linearized float in the range 0..1.

Definition at line 584 of file pnmImage.I.

References set_xel_val(), and to_val().

◆ set_xel_a() [1/2]

void PNMImage::set_xel_a ( int  x,
int  y,
const LColorf &  value 
)
inline

Changes the RGBA color at the indicated pixel.

Each component is a linearized float in the range 0..1.

Definition at line 661 of file pnmImage.I.

Referenced by render_spot(), and set_xel_a().

◆ set_xel_a() [2/2]

void PNMImage::set_xel_a ( int  x,
int  y,
float  r,
float  g,
float  b,
float  a 
)
inline

Changes the RGBA color at the indicated pixel.

Each component is a linearized float in the range 0..1.

Definition at line 747 of file pnmImage.I.

References set_xel_a().

◆ set_xel_val() [1/3]

void PNMImage::set_xel_val ( int  x,
int  y,
const xel value 
)
inline

Changes the RGB color at the indicated pixel.

Each component is in the range 0..maxval, encoded in the configured color space. See set_xel if you instead have a linearized and normalized floating-point value.

Definition at line 330 of file pnmImage.I.

Referenced by copy_sub_image(), fill_val(), and set_xel().

◆ set_xel_val() [2/3]

void PNMImage::set_xel_val ( int  x,
int  y,
xelval  r,
xelval  g,
xelval  b 
)
inline

Changes the RGB color at the indicated pixel.

Each component is in the range 0..maxval, encoded in the configured color space. See set_xel if you instead have a linearized and normalized floating-point value.

Definition at line 341 of file pnmImage.I.

◆ set_xel_val() [3/3]

void PNMImage::set_xel_val ( int  x,
int  y,
xelval  gray 
)
inline

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

The value is in the range component is in the range 0..maxval, encoded in the configured color space. See set_xel if you instead have a linearized and normalized floating-point value.

Definition at line 353 of file pnmImage.I.

◆ take_alpha_array()

xelval * PNMImage::take_alpha_array ( )
inline

Returns the underlying PNMImage array and removes it from the PNMImage.

You become the owner of this array and must eventually free it with PANDA_FREE_ARRAY() (or pass it to another PNMImage with set_alpha_array()). Know what you are doing!

Definition at line 1134 of file pnmImage.I.

◆ take_array()

xel * PNMImage::take_array ( )
inline

Returns the underlying PNMImage array and removes it from the PNMImage.

You become the owner of this array and must eventually free it with PANDA_FREE_ARRAY() (or pass it to another PNMImage with set_array()). Know what you are doing!

Definition at line 1121 of file pnmImage.I.

◆ take_from()

void PNMImage::take_from ( PNMImage orig)

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

Definition at line 224 of file pnmImage.cxx.

References clear(), and PNMImageHeader::has_alpha().

Referenced by Texture::consider_rescale(), expand_border(), and read().

◆ threshold()

void PNMImage::threshold ( const PNMImage select_image,
int  channel,
float  threshold,
const PNMImage lt,
const PNMImage 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, channel). 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. As a special case, lt and ge may both be 1x1 images instead of the source image size.

Definition at line 1384 of file pnmImage.cxx.

◆ to_alpha_val()

xelval PNMImage::to_alpha_val ( float  input_value) const
inline

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

Definition at line 111 of file pnmImage.I.

References clamp_val(), and PNMImageHeader::get_maxval.

Referenced by alpha_fill(), and set_alpha().

◆ to_val()

xelval PNMImage::to_val ( float  input_value) const
inline

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

Do not use this for alpha values, see to_alpha_val.

Definition at line 79 of file pnmImage.I.

References clamp_val(), encode_sRGB_float(), encode_sRGB_uchar(), and PNMImageHeader::get_maxval.

Referenced by fill(), set_blue(), set_gray(), set_green(), set_red(), and set_xel().

◆ unfiltered_stretch_from()

void PNMImage::unfiltered_stretch_from ( const PNMImage copy)

Resizes from the indicated image into this one by performing a nearest- point sample.

Definition at line 1887 of file pnmImage.cxx.

References get_alpha(), PNMImageHeader::get_x_size(), get_xel(), PNMImageHeader::get_y_size(), PNMImageHeader::has_alpha(), set_alpha(), and set_xel().

◆ unpremultiply_alpha()

void PNMImage::unpremultiply_alpha ( )

Converts an image in-place to its "straight alpha" form (presumably from a "premultiplied" form), where, for every pixel in the image, the red, green, and blue components are divided by that pixel's alpha value.

This does not modify any alpha values.

Definition at line 663 of file pnmImage.cxx.

References get_alpha(), get_blue(), get_green(), get_red(), PNMImageHeader::get_x_size(), PNMImageHeader::get_y_size(), PNMImageHeader::has_alpha(), and set_xel().

◆ write() [1/3]

bool PNMImage::write ( const Filename filename,
PNMFileType type = nullptr 
) const

Writes the image to the indicated filename.

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

Definition at line 385 of file pnmImage.cxx.

References is_valid(), and PNMImageHeader::make_writer().

Referenced by DisplayRegion::save_screenshot(), and ImageWriter::write_image().

◆ write() [2/3]

bool PNMImage::write ( std::ostream &  data,
const std::string &  filename = std::string(),
PNMFileType type = nullptr 
) const

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.

Definition at line 408 of file pnmImage.cxx.

◆ write() [3/3]

bool PNMImage::write ( PNMWriter writer) const

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.

Definition at line 430 of file pnmImage.cxx.

References PNMWriter::copy_header_from(), get_gray_val(), PNMImageHeader::get_x_size(), PNMImageHeader::get_y_size(), PNMImageHeader::is_grayscale(), is_valid(), PfmFile::load(), PNMWriter::supports_grayscale(), PNMWriter::supports_integer(), PNMWriter::write_data(), and PNMWriter::write_pfm().


The documentation for this class was generated from the following files: