Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File 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 List of all members.

Public Types

enum  ColorType {
  CT_invalid = 0, CT_grayscale = 1, CT_two_channel = 2, CT_color = 3,
  CT_four_channel = 4
}

Public Member Functions

 PNMImage ()
 PNMImage (const Filename &filename, PNMFileType *type=NULL)
 PNMImage (int x_size, int y_size, int num_channels=3, xelval maxval=255, PNMFileType *type=NULL)
 PNMImage (const PNMImage &copy)
void operator= (const PNMImage &copy)
 ~PNMImage ()
xelval clamp_val (int input_value) const
 A handy function to clamp values to [0..get_maxval()].

xelval to_val (double input_value) const
 A handy function to scale values from [0..1] to [0..get_maxval()].

double from_val (xelval input_value) const
 A handy function to scale values from [0..get_maxval()] to [0..1].

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

void clear (int x_size, int y_size, int num_channels=3, xelval maxval=255, PNMFileType *type=NULL)
 This flavor of clear() reinitializes the image to an empty (black) image with the given dimensions.

void copy_from (const PNMImage &copy)
 Makes this image become a copy of the other image.

void copy_header_from (const PNMImageHeader &header)
 Copies just the header information into this image.

void fill (double red, double green, double blue)
 Sets the entire image (except the alpha channel) to the given color.

void fill (double gray=0.0)
 Sets the entire image (except the alpha channel) to the given grayscale level.

void fill_val (xelval red, xelval green, xelval blue)
 Sets the entire image (except the alpha channel) to the given color.

void fill_val (xelval gray=0)
 Sets the entire image (except the alpha channel) to the given grayscale level.

void alpha_fill (double alpha=0.0)
 Sets the entire alpha channel to the given level.

void alpha_fill_val (xelval alpha=0)
 Sets the entire alpha channel to the given level.

bool read (const Filename &filename, PNMFileType *type=NULL)
 Reads the indicated image filename.

bool read (PNMReader *reader)
 This flavor of read() uses an already-existing PNMReader to read the image file.

bool write (const Filename &filename, PNMFileType *type=NULL) const
 Writes the image to the indicated filename.

bool write (PNMWriter *writer) const
 This flavor of write() uses an already-existing PNMWriter to write the image file.

bool is_valid () const
 Returns true if the image has been read in or correctly initialized with a height and width.

void set_num_channels (int num_channels)
 Changes the number of channels associated with the image.

void set_color_type (ColorType color_type)
 Translates the image to or from grayscale, color, or four-color mode.

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

void remove_alpha ()
 Removes the image's alpha channel, if it exists.

void make_grayscale ()
 Converts the image from RGB to grayscale.

void make_grayscale (double rc, double gc, double bc)
 Converts the image from RGB to grayscale.

void make_rgb ()
 Converts the image from grayscale to RGB.

void set_maxval (xelval maxval)
 Rescales the image to the indicated maxval.

const xelget_xel_val (int x, int y) const
 Returns the RGB color at the indicated pixel.

void set_xel_val (int x, int y, const xel &value)
 Changes the RGB color at the indicated pixel.

void set_xel_val (int x, int y, xelval r, xelval g, xelval b)
 Changes the RGB color at the indicated pixel.

void set_xel_val (int x, int y, xelval gray)
 Changes all three color components at the indicated pixel to the same value.

xelval get_red_val (int x, int y) const
 Returns the red component color at the indicated pixel.

xelval get_green_val (int x, int y) const
 Returns the green component color at the indicated pixel.

xelval get_blue_val (int x, int y) const
 Returns the blue component color at the indicated pixel.

xelval get_gray_val (int x, int y) const
 Returns the gray component color at the indicated pixel.

xelval get_alpha_val (int x, int y) const
 Returns the alpha component color at the indicated pixel.

void set_red_val (int x, int y, xelval r)
 Sets the red component color only at the indicated pixel.

void set_green_val (int x, int y, xelval g)
 Sets the green component color only at the indicated pixel.

void set_blue_val (int x, int y, xelval b)
 Sets the blue component color only at the indicated pixel.

void set_gray_val (int x, int y, xelval gray)
 Sets the gray component color at the indicated pixel.

void set_alpha_val (int x, int y, xelval a)
 Sets the alpha component color only at the indicated pixel.

xelval get_channel_val (int x, int y, int channel) const
 Returns the nth component color at the indicated pixel.

void set_channel_val (int x, int y, int channel, xelval value)
 Sets the nth component color at the indicated pixel.

RGBColord get_xel (int x, int y) const
 Returns the RGB color at the indicated pixel.

void set_xel (int x, int y, const RGBColord &value)
 Changes the RGB color at the indicated pixel.

void set_xel (int x, int y, double r, double g, double b)
 Changes the RGB color at the indicated pixel.

void set_xel (int x, int y, double gray)
 Changes all three color components at the indicated pixel to the same value.

double get_red (int x, int y) const
 Returns the red component color at the indicated pixel.

double get_green (int x, int y) const
 Returns the green component color at the indicated pixel.

double get_blue (int x, int y) const
 Returns the blue component color at the indicated pixel.

double get_gray (int x, int y) const
 Returns the gray component color at the indicated pixel.

double get_alpha (int x, int y) const
 Returns the alpha component color at the indicated pixel.

void set_red (int x, int y, double r)
 Sets the red component color only at the indicated pixel.

void set_green (int x, int y, double g)
 Sets the green component color only at the indicated pixel.

void set_blue (int x, int y, double b)
 Sets the blue component color only at the indicated pixel.

void set_gray (int x, int y, double gray)
 Sets the gray component color at the indicated pixel.

void set_alpha (int x, int y, double a)
 Sets the alpha component color only at the indicated pixel.

double get_channel (int x, int y, int channel) const
 Returns the nth component color at the indicated pixel.

void set_channel (int x, int y, int channel, double value)
 Sets the nth component color at the indicated pixel.

double get_bright (int x, int y) const
 Returns the linear brightness of the given xel, as a double in the range 0..1.

double get_bright (int x, int y, double rc, double gc, double bc) const
 This flavor of get_bright() works correctly only for color images.

double get_bright (int x, int y, double rc, double gc, double bc, double ac) const
 This flavor of get_bright() works correctly only for four-channel images.

void blend (int x, int y, const RGBColord &val, double alpha)
 Smoothly blends the indicated pixel value in with whatever was already in the image, based on the given alpha value.

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

xeloperator[] (int y)
 Allows the PNMImage to appear to be a 2-d array of xels.

const xeloperator[] (int y) const
 Allows the PNMImage to appear to be a 2-d array of xels.

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.

void box_filter (double 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.

void gaussian_filter (double 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.

void box_filter_from (double radius, const PNMImage &copy)
 Makes a resized copy of the indicated image into this one using the indicated filter.

void gaussian_filter_from (double radius, const PNMImage &copy)
 Makes a resized copy of the indicated image into this one using the indicated filter.

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.

ColorType get_color_type () const
 Returns the image type of the image, as an enumerated value.

int get_num_channels () const
 Returns the number of channels in the image.

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.

bool has_alpha () const
 Returns true if the image includes an alpha channel, false otherwise.

xelval get_maxval () const
 Returns the maximum channel value allowable for any pixel in this image; for instance, 255 for a typical 8-bit-per-channel image.

int get_x_size () const
 Returns the number of pixels in the X direction.

int get_y_size () const
 Returns the number of pixels in the Y direction.

bool has_type () const
 Returns true if the PNMImageHeader knows what type it is, false otherwise.

PNMFileTypeget_type () const
 If the file type is known (e.g.

void set_type (PNMFileType *type)
 Sets the file type of this PNMImage.

bool read_header (const Filename &filename, PNMFileType *type=NULL)
 Opens up the image file and tries to read its header information to determine its size, number of channels, etc.

PNMReadermake_reader (const Filename &filename, PNMFileType *type=NULL) 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.

PNMReadermake_reader (istream *file, bool owns_file=true, const Filename &filename=Filename(), string magic_number=string(), PNMFileType *type=NULL) 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.

PNMWritermake_writer (const Filename &filename, PNMFileType *type=NULL) 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.

PNMWritermake_writer (ostream *file, bool owns_file=true, const Filename &filename=Filename(), PNMFileType *type=NULL) 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.

void output (ostream &out) const

Static Public Member Functions

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.

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.

bool read_magic_number (istream *file, string &magic_number, int num_bytes)
 Ensures that the first n bytes of the file are read into magic_number.


Protected Attributes

int _x_size
int _y_size
int _num_channels
xelval _maxval
PNMFileType_type

Private Member Functions

void allocate_array ()
 Allocates the internal memory for the RGB or grayscale pixels in the image (except alpha).

void allocate_alpha ()
 Allocates the internal memory for the alpha pixels in the image.

xelrow (int row) const
 Returns an array of xels corresponding to the nth row of the image.

xelvalalpha_row (int row) const
 Returns an array of xelvals corresponding to the nth row of the alpha channel.

void setup_rc ()
 Sets the _default_rc,bc,gc values appropriately according to the color type of the image, so that get_bright() will return a meaningful value for both color and grayscale images.


Private Attributes

xel_array
xelval_alpha
double _default_rc
double _default_gc
double _default_bc

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.

Definition at line 88 of file pnmImage.h.


Member Enumeration Documentation

enum PNMImageHeader::ColorType [inherited]
 

Enumeration values:
CT_invalid 
CT_grayscale 
CT_two_channel 
CT_color 
CT_four_channel 

Definition at line 65 of file pnmImageHeader.h.


Constructor & Destructor Documentation

PNMImage::PNMImage  )  [inline]
 

Definition at line 30 of file pnmImage.I.

References _alpha, _array, INLINE, NULL, and read().

PNMImage::PNMImage const Filename filename,
PNMFileType type = NULL
[inline]
 

Definition at line 43 of file pnmImage.I.

References _alpha, _array, clear(), INLINE, and NULL.

PNMImage::PNMImage int  x_size,
int  y_size,
int  num_channels = 3,
xelval  maxval = 255,
PNMFileType type = NULL
[inline]
 

Definition at line 58 of file pnmImage.I.

References _alpha, _array, copy_from(), INLINE, and NULL.

PNMImage::PNMImage const PNMImage &  copy  )  [inline]
 

Definition at line 74 of file pnmImage.I.

References copy_from(), and INLINE.

PNMImage::~PNMImage  )  [inline]
 

Definition at line 103 of file pnmImage.I.

References clamp_val(), PNMImageHeader::get_maxval(), INLINE, and xelval.


Member Function Documentation

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 267 of file pnmImage.I.

References INLINE, PPM_ASSIGN, row(), x, and y.

void PNMImage::allocate_alpha  )  [inline, private]
 

Allocates the internal memory for the alpha pixels in the image.

Definition at line 1038 of file pnmImage.I.

Referenced by clear(), and copy_from().

void PNMImage::allocate_array  )  [inline, private]
 

Allocates the internal memory for the RGB or grayscale pixels in the image (except alpha).

Definition at line 1023 of file pnmImage.I.

Referenced by copy_from().

void PNMImage::alpha_fill double  alpha = 0.0  )  [inline]
 

Sets the entire alpha channel to the given level.

Definition at line 209 of file pnmImage.I.

void PNMImage::alpha_fill_val xelval  alpha = 0  ) 
 

Sets the entire alpha channel to the given level.

Definition at line 166 of file pnmImage.cxx.

Referenced by fill().

xelval * PNMImage::alpha_row int  row  )  const [inline, private]
 

Returns an array of xelvals corresponding to the nth row of the alpha channel.

Definition at line 1068 of file pnmImage.I.

Referenced by get_green_val(), and set_xel_val().

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

Definition at line 564 of file pnmImage.cxx.

References _default_bc.

void PNMImage::blend int  x,
int  y,
const RGBColord val,
double  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 943 of file pnmImage.I.

Referenced by get_blue().

void PNMImage::box_filter double  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 990 of file pnmImage.I.

void PNMImage::box_filter_from double  radius,
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 455 of file pnm-image-filter.cxx.

References filter_image(), gaussian_filter_impl(), and width.

xelval PNMImage::clamp_val int  input_value  )  const [inline]
 

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

Definition at line 119 of file pnmImage.I.

References PNMImageHeader::get_maxval(), and INLINE.

Referenced by ~PNMImage().

void PNMImage::clear int  x_size,
int  y_size,
int  num_channels = 3,
xelval  maxval = 255,
PNMFileType type = NULL
 

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

Definition at line 65 of file pnmImage.cxx.

References _alpha, PNMImageHeader::_x_size, PNMImageHeader::_y_size, allocate_alpha(), and xelval.

void PNMImage::clear void   ) 
 

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

Definition at line 38 of file pnmImage.cxx.

References NULL, and xelval.

Referenced by copy_from(), and PNMImage().

void PNMImage::copy_from const PNMImage &  copy  ) 
 

Makes this image become a copy of the other image.

Definition at line 96 of file pnmImage.cxx.

References allocate_alpha(), allocate_array(), clear(), PNMImageHeader::has_alpha(), PNMImageHeader::operator=(), and setup_rc().

Referenced by PNMImage().

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 124 of file pnmImage.cxx.

References PNMImageHeader::get_x_size(), PNMImageHeader::get_y_size(), set_xel_val(), x, and y.

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 618 of file pnmImage.cxx.

void PNMImage::fill double  gray = 0.0  )  [inline]
 

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

Definition at line 181 of file pnmImage.I.

References _array, and NULL.

void PNMImage::fill double  red,
double  green,
double  blue
[inline]
 

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

Definition at line 164 of file pnmImage.I.

References alpha_fill_val(), PNMImageHeader::get_maxval(), INLINE, and xelval.

void PNMImage::fill_val xelval  gray = 0  )  [inline]
 

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

Definition at line 196 of file pnmImage.I.

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 147 of file pnmImage.cxx.

Referenced by from_val().

double PNMImage::from_val xelval  input_value  )  const [inline]
 

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

Definition at line 149 of file pnmImage.I.

References fill_val(), gray, and INLINE.

Referenced by get_blue_val(), get_green(), get_red(), set_green_val(), set_red_val(), and set_xel().

void PNMImage::gaussian_filter double  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 1007 of file pnmImage.I.

void PNMImage::gaussian_filter_from double  radius,
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 476 of file pnm-image-filter.cxx.

References get_alpha_val(), x, and y.

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

Definition at line 713 of file pnmImage.I.

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.

Definition at line 459 of file pnmImage.I.

Referenced by gaussian_filter_from(), get_green(), and set_color_type().

double PNMImage::get_blue int  x,
int  y
const [inline]
 

Returns the blue component color at the indicated pixel.

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

Definition at line 671 of file pnmImage.I.

References blend(), INLINE, x, and y.

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.

Definition at line 417 of file pnmImage.I.

References from_val(), get_green_val(), get_red_val(), INLINE, RGBColord, x, and y.

Referenced by get_green(), get_red(), set_color_type(), and set_green_val().

double PNMImage::get_bright int  x,
int  y,
double  rc,
double  gc,
double  bc,
double  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 919 of file pnmImage.I.

double PNMImage::get_bright int  x,
int  y,
double  rc,
double  gc,
double  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 898 of file pnmImage.I.

double PNMImage::get_bright int  x,
int  y
const [inline]
 

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.

Definition at line 879 of file pnmImage.I.

Referenced by write().

double PNMImage::get_channel int  x,
int  y,
int  channel
const [inline]
 

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.

Definition at line 835 of file pnmImage.I.

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 476 of file pnmImage.cxx.

References set_alpha(), set_xel(), x, and y.

Referenced by set_xel().

PNMImageHeader::ColorType PNMImageHeader::get_color_type  )  const [inline, inherited]
 

Returns the image type of the image, as an enumerated value.

This is really just the number of channels cast to the enumerated type.

Definition at line 95 of file pnmImageHeader.I.

References PNMImageHeader::CT_grayscale, PNMImageHeader::CT_two_channel, and INLINE.

Referenced by PNMImageHeader::get_num_channels(), write(), and PixelBuffer::write().

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

Definition at line 694 of file pnmImage.I.

References INLINE, row(), and y.

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.

Definition at line 440 of file pnmImage.I.

References INLINE, set_xel_val(), to_val(), x, and y.

Referenced by set_color_type(), and write().

double PNMImage::get_green int  x,
int  y
const [inline]
 

Returns the green component color at the indicated pixel.

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

Definition at line 654 of file pnmImage.I.

References from_val(), get_alpha_val(), get_blue_val(), get_green_val(), get_red_val(), INLINE, x, and y.

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.

Definition at line 402 of file pnmImage.I.

References alpha_row(), INLINE, x, and y.

Referenced by get_blue_val(), get_green(), get_red(), make_grayscale(), set_color_type(), and set_red_val().

xelval PNMImageHeader::get_maxval  )  const [inline, inherited]
 

Returns the maximum channel value allowable for any pixel in this image; for instance, 255 for a typical 8-bit-per-channel image.

A pixel with this value is full on.

Definition at line 203 of file pnmImageHeader.I.

References PNMImageHeader::_type.

Referenced by clamp_val(), fill(), operator=(), and ~PNMImage().

int PNMImageHeader::get_num_channels  )  const [inline, inherited]
 

Returns the number of channels in the image.

Definition at line 109 of file pnmImageHeader.I.

References PNMImageHeader::get_color_type(), INLINE, and PNMImageHeader::is_grayscale().

Referenced by PixelBuffer::write().

double PNMImage::get_red int  x,
int  y
const [inline]
 

Returns the red component color at the indicated pixel.

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

Definition at line 637 of file pnmImage.I.

References from_val(), get_blue_val(), get_green_val(), get_red_val(), INLINE, x, and y.

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.

Definition at line 387 of file pnmImage.I.

References gray, INLINE, PPM_PUTB, row(), x, and y.

Referenced by get_blue_val(), get_green(), get_red(), and set_color_type().

PNMFileType * PNMImageHeader::get_type void   )  const [inline, inherited]
 

If the file type is known (e.g.

has_type() returns true), returns its PNMFileType pointer; otherwise, returns NULL.

Reimplemented in PNMReader, and PNMWriter.

Definition at line 269 of file pnmImageHeader.I.

int PNMImageHeader::get_x_size  )  const [inline, inherited]
 

Returns the number of pixels in the X direction.

This is one more than the largest allowable X coordinate.

Definition at line 220 of file pnmImageHeader.I.

Referenced by copy_header_from(), down_to_power_2(), Texture::read(), WindowFramework::set_background_type(), set_color_type(), and write().

RGBColord PNMImage::get_xel int  x,
int  y
const [inline]
 

Returns the RGB color at the indicated pixel.

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

Definition at line 571 of file pnmImage.I.

References INLINE, set_gray_val(), to_val(), x, and y.

const 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 325 of file pnmImage.I.

References INLINE, PPM_GETB, x, xelval, and y.

Referenced by make_grayscale(), and make_rgb().

int PNMImageHeader::get_y_size  )  const [inline, inherited]
 

Returns the number of pixels in the Y direction.

This is one more than the largest allowable Y coordinate.

Definition at line 237 of file pnmImageHeader.I.

Referenced by copy_header_from(), down_to_power_2(), Texture::read(), WindowFramework::set_background_type(), set_color_type(), and write().

bool PNMImageHeader::has_alpha  )  const [inline, inherited]
 

Returns true if the image includes an alpha channel, false otherwise.

Unlike is_grayscale(), if this returns false it is an error to call any of the functions accessing the alpha channel.

Definition at line 184 of file pnmImageHeader.I.

References PNMImageHeader::_type, INLINE, and NULL.

Referenced by copy_from(), set_color_type(), and write().

bool PNMImageHeader::has_alpha PNMImageHeader::ColorType  color_type  )  [inline, static, inherited]
 

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

Definition at line 165 of file pnmImageHeader.I.

References PNMImageHeader::_x_size, and INLINE.

Referenced by filter_image(), and WindowFramework::set_background_type().

bool PNMImageHeader::has_type  )  const [inline, inherited]
 

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

Definition at line 252 of file pnmImageHeader.I.

bool PNMImageHeader::is_grayscale  )  const [inline, inherited]
 

Returns false if the image is a full-color image, and has red, green, and blue components; true if it is a grayscale image and has only a gray component.

(The gray color is actually stored in the blue channel, and the red and green channels are ignored.)

Definition at line 148 of file pnmImageHeader.I.

References PNMImageHeader::_maxval, INLINE, and xelval.

Referenced by PNMImageHeader::get_num_channels(), set_color_type(), write(), PNMFileTypeTGA::Writer::Writer(), and PNMFileTypeAlias::Writer::Writer().

bool PNMImageHeader::is_grayscale PNMImageHeader::ColorType  color_type  )  [inline, static, inherited]
 

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

Definition at line 127 of file pnmImageHeader.I.

References PNMImageHeader::CT_four_channel, PNMImageHeader::CT_two_channel, and INLINE.

Referenced by filter_image().

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 228 of file pnmImage.I.

References _default_bc, _default_gc, _default_rc, and make_grayscale().

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

Definition at line 397 of file pnmImage.cxx.

References PNMImageHeader::_num_channels, get_green_val(), x, and y.

void PNMImage::make_grayscale  )  [inline]
 

Converts the image from RGB to grayscale.

Any alpha channel, if present, is left undisturbed.

Definition at line 295 of file pnmImage.I.

References get_xel_val(), PPM_GETR, x, and y.

Referenced by is_valid().

PNMReader * PNMImageHeader::make_reader istream *  file,
bool  owns_file = true,
const Filename filename = Filename(),
string  magic_number = string(),
PNMFileType type = NULL
const [inherited]
 

Returns a newly-allocated PNMReader of the suitable type for reading from the already-opened image file, or NULL if the file cannot be read for some reason.

owns_file should be set true if the PNMReader is to be considered the owner of the stream pointer (in which case the stream will be deleted on completion, whether successful or not), or false if it should not delete it.

The filename parameter is optional here, since the file has already been opened; it is only used to examine the extension and attempt to guess the file type.

If magic_number is nonempty, it is assumed to represent the first few bytes that have already been read from the file. Some file types may have difficulty if this is more than two bytes.

If type is non-NULL, it is a suggestion for the file type to use.

The PNMReader should be deleted when it is no longer needed.

Definition at line 189 of file pnmImageHeader.cxx.

References PNMImageHeader::_type, PNMFileType::get_name(), and NULL.

PNMReader * PNMImageHeader::make_reader const Filename filename,
PNMFileType type = NULL
const [inherited]
 

Returns a newly-allocated PNMReader of the suitable type for reading from the indicated image filename, or NULL if the filename cannot be read for some reason.

The filename "-" always stands for standard input. If type is specified, it is a suggestion for the file type to use.

The PNMReader should be deleted when it is no longer needed.

Definition at line 84 of file pnmImageHeader.cxx.

void PNMImage::make_rgb  )  [inline]
 

Converts the image from grayscale to RGB.

Any alpha channel, if present, is left undisturbed.

Definition at line 310 of file pnmImage.I.

References get_xel_val(), INLINE, PPM_GETB, x, xelval, and y.

PNMWriter * PNMImageHeader::make_writer ostream *  file,
bool  owns_file = true,
const Filename filename = Filename(),
PNMFileType type = NULL
const [inherited]
 

Returns a newly-allocated PNMWriter of the suitable type for writing to the already-opened image file, or NULL if the file cannot be written for some reason.

owns_file should be set true if the PNMWriter is to be considered the owner of the stream pointer (in which case the stream will be deleted on completion, whether successful or not), or false if it should not delete it.

The filename parameter is optional here, since the file has already been opened; it is only used to examine the extension and attempt to guess the intended file type.

If type is non-NULL, it is a suggestion for the file type to use.

The PNMWriter should be deleted when it is no longer needed.

Definition at line 386 of file pnmImageHeader.cxx.

PNMWriter * PNMImageHeader::make_writer const Filename filename,
PNMFileType type = NULL
const [inherited]
 

Returns a newly-allocated PNMWriter of the suitable type for writing an image to the indicated filename, or NULL if the filename cannot be written for some reason.

The filename "-" always stands for standard output. If type is specified, it is a suggestion for the file type to use.

The PNMWriter should be deleted when it is no longer needed.

Definition at line 299 of file pnmImageHeader.cxx.

References PNMImageHeader::_type, Filename::empty(), PNMFileType::get_name(), PNMFileTypeRegistry::get_ptr(), PNMFileTypeRegistry::get_type_from_extension(), PNMFileType::make_writer(), NULL, and writer().

void PNMImage::operator= const PNMImage &  copy  )  [inline]
 

Definition at line 91 of file pnmImage.I.

References PNMImageHeader::get_maxval(), INLINE, and xelval.

const xel * PNMImage::operator[] int  y  )  const [inline]
 

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

Definition at line 973 of file pnmImage.I.

xel * PNMImage::operator[] int  y  )  [inline]
 

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

Definition at line 958 of file pnmImage.I.

void PNMImageHeader::output ostream &  out  )  const [inherited]
 

Definition at line 474 of file pnmImageHeader.cxx.

void PNMImage::quick_filter_from const PNMImage &  copy,
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 594 of file pnm-image-filter.cxx.

References xelval.

Referenced by GLGraphicsStateGuardian::enable_clip_plane().

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

Definition at line 228 of file pnmImage.cxx.

References NULL, and writer().

bool PNMImage::read const Filename filename,
PNMFileType type = NULL
 

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 193 of file pnmImage.cxx.

References reader().

Referenced by PNMImage(), Texture::read(), and Texture::Texture().

bool PNMImageHeader::read_header const Filename filename,
PNMFileType type = NULL
[inherited]
 

Opens up the image file and tries to read its header information to determine its size, number of channels, etc.

If successful, updates the header information and returns true; otherwise, returns false.

Definition at line 47 of file pnmImageHeader.cxx.

Referenced by WindowFramework::set_background_type().

bool PNMImageHeader::read_magic_number istream *  file,
string &  magic_number,
int  num_bytes
[static, inherited]
 

Ensures that the first n bytes of the file are read into magic_number.

If magic_number is initially nonempty, assumes these represent the first few bytes already extracted. Returns true if successful, false if an end of file or error occurred before num_bytes could be read.

Definition at line 454 of file pnmImageHeader.cxx.

void PNMImage::remove_alpha  )  [inline]
 

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

Definition at line 280 of file pnmImage.I.

References gray, INLINE, PPM_ASSIGN, row(), x, and y.

xel * PNMImage::row int  row  )  const [inline, private]
 

Returns an array of xels corresponding to the nth row of the image.

Definition at line 1053 of file pnmImage.I.

Referenced by add_alpha(), get_gray(), get_red_val(), remove_alpha(), set_num_channels(), and set_xel_val().

void PNMImage::set_alpha int  x,
int  y,
double  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 810 of file pnmImage.I.

Referenced by get_channel_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.

Definition at line 556 of file pnmImage.I.

References INLINE, set_blue_val(), to_val(), x, and y.

Referenced by set_color_type(), set_maxval(), and set_xel().

void PNMImage::set_blue int  x,
int  y,
double  b
[inline]
 

Sets the blue component color only at the indicated pixel.

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

Definition at line 764 of file pnmImage.I.

References _alpha, PNMImageHeader::_x_size, INLINE, xelval, and y.

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.

Definition at line 510 of file pnmImage.I.

Referenced by set_alpha_val(), set_color_type(), and set_maxval().

void PNMImage::set_channel int  x,
int  y,
int  channel,
double  value
[inline]
 

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.

Definition at line 860 of file pnmImage.I.

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 520 of file pnmImage.cxx.

References x, and y.

Referenced by set_xel().

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 340 of file pnmImage.cxx.

References PNMImageHeader::_maxval, get_alpha_val(), get_blue_val(), get_gray_val(), get_green_val(), get_red_val(), PNMImageHeader::get_x_size(), PNMImageHeader::get_y_size(), PNMImageHeader::has_alpha(), PNMImageHeader::is_grayscale(), nassertv, set_alpha_val(), set_blue_val(), set_gray_val(), set_green_val(), set_red_val(), x, xelval, and y.

void PNMImage::set_gray int  x,
int  y,
double  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 double in the range 0..1.

Definition at line 791 of file pnmImage.I.

Referenced by PixelBuffer::store(), and write().

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.

Definition at line 537 of file pnmImage.I.

References INLINE, set_green_val(), to_val(), x, and y.

Referenced by get_xel(), and set_color_type().

void PNMImage::set_green int  x,
int  y,
double  g
[inline]
 

Sets the green component color only at the indicated pixel.

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

Definition at line 747 of file pnmImage.I.

References _alpha, PNMImageHeader::_x_size, PNMImageHeader::_y_size, and xelval.

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.

Definition at line 493 of file pnmImage.I.

References from_val(), get_blue_val(), INLINE, x, and y.

Referenced by set_color_type(), set_gray_val(), and set_maxval().

void PNMImage::set_maxval xelval  maxval  ) 
 

Rescales the image to the indicated maxval.

Definition at line 421 of file pnmImage.cxx.

References PNMImageHeader::_num_channels, nassertv, set_alpha_val(), set_blue_val(), set_green_val(), set_red_val(), x, and y.

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

Definition at line 249 of file pnmImage.I.

References INLINE, row(), x, and y.

void PNMImage::set_red int  x,
int  y,
double  r
[inline]
 

Sets the red component color only at the indicated pixel.

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

Definition at line 730 of file pnmImage.I.

References _array, PNMImageHeader::_x_size, PNMImageHeader::_y_size, and INLINE.

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.

Definition at line 476 of file pnmImage.I.

References from_val(), get_green_val(), INLINE, x, and y.

Referenced by set_color_type(), and set_maxval().

void PNMImageHeader::set_type PNMFileType type  )  [inline, inherited]
 

Sets the file type of this PNMImage.

This will be the default type used when an image is read, if the type cannot be determined by magic number or inferred by extension, or the type used when the image is written, if the type cannot be inferred from the filename extension.

Definition at line 292 of file pnmImageHeader.I.

void PNMImage::set_xel int  x,
int  y,
double  gray
[inline]
 

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

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

Definition at line 620 of file pnmImage.I.

References set_channel_val(), to_val(), x, and y.

void PNMImage::set_xel int  x,
int  y,
double  r,
double  g,
double  b
[inline]
 

Changes the RGB color at the indicated pixel.

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

Definition at line 603 of file pnmImage.I.

References from_val(), get_channel_val(), INLINE, x, and y.

void PNMImage::set_xel int  x,
int  y,
const RGBColord value
[inline]
 

Changes the RGB color at the indicated pixel.

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

Definition at line 588 of file pnmImage.I.

References set_alpha_val(), to_val(), x, and y.

Referenced by get_channel_val().

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 0..maxval.

Definition at line 372 of file pnmImage.I.

References INLINE, PPM_PUTB, row(), x, and y.

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.

Definition at line 355 of file pnmImage.I.

References INLINE, PPM_PUTR, row(), x, and y.

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.

Definition at line 340 of file pnmImage.I.

References alpha_row(), INLINE, x, xelval, and y.

Referenced by copy_header_from(), get_gray_val(), and write().

void PNMImage::setup_rc  )  [private]
 

Sets the _default_rc,bc,gc values appropriately according to the color type of the image, so that get_bright() will return a meaningful value for both color and grayscale images.

Definition at line 674 of file pnmImage.cxx.

Referenced by copy_from().

xelval PNMImage::to_val double  input_value  )  const [inline]
 

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

Definition at line 134 of file pnmImage.I.

Referenced by get_gray_val(), get_xel(), set_alpha_val(), set_gray_val(), and set_xel().

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

Definition at line 302 of file pnmImage.cxx.

References _alpha, and NULL.

bool PNMImage::write const Filename filename,
PNMFileType type = NULL
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 270 of file pnmImage.cxx.

References _alpha, get_bright(), PNMImageHeader::get_color_type(), get_gray_val(), PNMImageHeader::get_x_size(), PNMImageHeader::get_y_size(), PNMImageHeader::has_alpha(), PNMImageHeader::is_grayscale(), nassertv, NULL, set_gray(), set_xel_val(), x, and y.

Referenced by PixelBuffer::read().


Member Data Documentation

xelval* PNMImage::_alpha [private]
 

Definition at line 230 of file pnmImage.h.

Referenced by clear(), PNMImage(), set_blue(), set_green(), and write().

xel* PNMImage::_array [private]
 

Definition at line 229 of file pnmImage.h.

Referenced by fill(), PNMImage(), and set_red().

double PNMImage::_default_bc [private]
 

Definition at line 231 of file pnmImage.h.

Referenced by blend(), and is_valid().

double PNMImage::_default_gc [private]
 

Definition at line 231 of file pnmImage.h.

Referenced by is_valid().

double PNMImage::_default_rc [private]
 

Definition at line 231 of file pnmImage.h.

Referenced by is_valid().

xelval PNMImageHeader::_maxval [protected, inherited]
 

Definition at line 114 of file pnmImageHeader.h.

Referenced by PNMImageHeader::is_grayscale(), set_color_type(), PNMFileTypeSGI::Writer::supports_write_row(), PNMFileTypeAlias::Writer::supports_write_row(), PNMFileTypeSGI::Writer::write_channels(), PNMFileTypeSGI::Writer::write_table(), PNMFileTypeIMG::Writer::Writer(), and PNMFileTypeAlias::Writer::Writer().

int PNMImageHeader::_num_channels [protected, inherited]
 

Definition at line 113 of file pnmImageHeader.h.

Referenced by make_grayscale(), PNMWriter::set_color_type(), set_maxval(), PNMFileTypeSGI::Writer::write_channels(), PNMFileTypeSGI::Writer::write_rgb_header(), PNMFileTypeSGI::Writer::write_table(), and PNMImageHeader::~PNMImageHeader().

PNMFileType* PNMImageHeader::_type [protected, inherited]
 

Reimplemented in PNMReader, and PNMWriter.

Definition at line 115 of file pnmImageHeader.h.

Referenced by PNMImageHeader::get_maxval(), PNMImageHeader::has_alpha(), PNMImageHeader::make_reader(), PNMImageHeader::make_writer(), and PNMImageHeader::PNMImageHeader().

int PNMImageHeader::_x_size [protected, inherited]
 

Definition at line 112 of file pnmImageHeader.h.

Referenced by clear(), PNMImageHeader::has_alpha(), PNMFileTypeJPG::Reader::read_data(), PNMFileTypeJPG2000::Reader::read_data(), PNMFileTypeIMG::Reader::read_row(), set_blue(), set_green(), set_red(), PNMFileTypeTIFF::Writer::write_data(), PNMFileTypeJPG::Writer::write_data(), PNMFileTypeJPG2000::Writer::write_data(), PNMFileTypeTGA::Writer::Writer(), PNMFileTypeJPG::Writer::Writer(), PNMFileTypeJPG2000::Writer::Writer(), PNMFileTypeIMG::Writer::Writer(), PNMFileTypeBMP::Writer::Writer(), and PNMFileTypeAlias::Writer::Writer().

int PNMImageHeader::_y_size [protected, inherited]
 

Definition at line 112 of file pnmImageHeader.h.

Referenced by clear(), PNMFileTypeJPG::Reader::read_data(), PNMFileTypeJPG2000::Reader::read_data(), PNMFileTypeIMG::Reader::read_row(), set_green(), PNMWriter::set_maxval(), set_red(), PNMFileTypeJPG::Writer::write_data(), PNMFileTypeJPG2000::Writer::write_data(), PNMFileTypeTGA::Writer::Writer(), PNMFileTypeJPG::Writer::Writer(), PNMFileTypeJPG2000::Writer::Writer(), and PNMFileTypeBMP::Writer::Writer().


The documentation for this class was generated from the following files:
Generated on Fri May 2 00:54:06 2003 for Panda by doxygen1.3