58class EXPCL_PANDA_PNMIMAGE PNMImage :
public PNMImageHeader {
62 INLINE
explicit PNMImage(
int x_size,
int y_size,
int num_channels = 3,
64 ColorSpace color_space = CS_linear);
65 INLINE PNMImage(
const PNMImage ©);
66 INLINE
void operator = (
const PNMImage ©);
70 INLINE xelval
clamp_val(
int input_value)
const;
71 INLINE xel
to_val(
const LRGBColorf &input_value)
const;
72 INLINE xelval
to_val(
float input_value)
const;
74 INLINE LRGBColorf
from_val(
const xel &input_value)
const;
75 INLINE
float from_val(xelval input_value)
const;
79 void clear(
int x_size,
int y_size,
int num_channels = 3,
81 ColorSpace color_space = CS_linear);
84 void copy_channel(
const PNMImage ©,
int src_channel,
int dest_channel);
85 void copy_channel_bits(
const PNMImage ©,
int src_channel,
int dest_channel, xelval src_mask,
int right_shift);
89 INLINE
void fill(
float red,
float green,
float blue);
90 INLINE
void fill(
float gray = 0.0);
92 void fill_val(xelval red, xelval green, xelval blue);
93 INLINE
void fill_val(xelval gray = 0);
106 bool report_unknown_type =
true);
107 BLOCKING
bool read(std::istream &data,
const std::string &filename = std::string(),
109 bool report_unknown_type =
true);
113 BLOCKING
bool write(std::ostream &data,
const std::string &filename = std::string(),
133 BLOCKING
void flip(
bool flip_x,
bool flip_y,
bool transpose);
145 INLINE
void set_xel_val(
int x,
int y,
const xel &value);
146 INLINE
void set_xel_val(
int x,
int y, xelval r, xelval g, xelval b);
147 INLINE
void set_xel_val(
int x,
int y, xelval gray);
163 float get_channel(
int x,
int y,
int channel)
const;
164 void set_channel(
int x,
int y,
int channel,
float value);
173 INLINE LRGBColorf
get_xel(
int x,
int y)
const;
174 INLINE
void set_xel(
int x,
int y,
const LRGBColorf &value);
175 INLINE
void set_xel(
int x,
int y,
float r,
float g,
float b);
176 INLINE
void set_xel(
int x,
int y,
float gray);
178 INLINE LColorf
get_xel_a(
int x,
int y)
const;
179 INLINE
void set_xel_a(
int x,
int y,
const LColorf &value);
180 INLINE
void set_xel_a(
int x,
int y,
float r,
float g,
float b,
float a);
182 INLINE
float get_red(
int x,
int y)
const;
183 INLINE
float get_green(
int x,
int y)
const;
184 INLINE
float get_blue(
int x,
int y)
const;
185 INLINE
float get_gray(
int x,
int y)
const;
186 INLINE
float get_alpha(
int x,
int y)
const;
188 INLINE
void set_red(
int x,
int y,
float r);
189 INLINE
void set_green(
int x,
int y,
float g);
190 INLINE
void set_blue(
int x,
int y,
float b);
191 INLINE
void set_gray(
int x,
int y,
float gray);
192 INLINE
void set_alpha(
int x,
int y,
float a);
195 INLINE
float get_bright(
int x,
int y,
float rc,
float gc,
197 INLINE
float get_bright(
int x,
int y,
float rc,
float gc,
198 float bc,
float ac)
const;
200 INLINE
void blend(
int x,
int y,
const LRGBColorf &val,
float alpha);
201 void blend(
int x,
int y,
float r,
float g,
float b,
float alpha);
204 int xfrom = 0,
int yfrom = 0,
205 int x_size = -1,
int y_size = -1);
207 int xfrom = 0,
int yfrom = 0,
208 int x_size = -1,
int y_size = -1,
209 float pixel_scale = 1.0);
211 int xfrom = 0,
int yfrom = 0,
212 int x_size = -1,
int y_size = -1,
213 float pixel_scale = 1.0);
215 int xfrom = 0,
int yfrom = 0,
216 int x_size = -1,
int y_size = -1,
217 float pixel_scale = 1.0);
219 int xfrom = 0,
int yfrom = 0,
220 int x_size = -1,
int y_size = -1,
221 float pixel_scale = 1.0);
223 int xfrom = 0,
int yfrom = 0,
224 int x_size = -1,
int y_size = -1,
225 float pixel_scale = 1.0);
227 const PNMImage <,
const PNMImage &ge);
232 const PNMImage &pixel_values);
234 void rescale(
float min_val,
float max_val);
236 void copy_channel(
const PNMImage ©,
int xto,
int yto,
int cto,
237 int xfrom = 0,
int yfrom = 0,
int cfrom = 0,
238 int x_size = -1,
int y_size = -1);
240 void render_spot(
const LColorf &fg,
const LColorf &bg,
241 float min_radius,
float max_radius);
244 const LColorf &color);
249 BLOCKING INLINE
void box_filter(
float radius = 1.0);
256 int xborder = 0,
int yborder = 0);
261 unsigned long seed = 0);
265 BLOCKING INLINE
void gamma_correct(
float from_gamma,
float to_gamma);
268 BLOCKING INLINE
void apply_exponent(
float gray_exponent,
float alpha_exponent);
269 BLOCKING INLINE
void apply_exponent(
float red_exponent,
float green_exponent,
float blue_exponent);
270 BLOCKING
void apply_exponent(
float red_exponent,
float green_exponent,
float blue_exponent,
float alpha_exponent);
281 class EXPCL_PANDA_PNMIMAGE Row {
283 INLINE
size_t size()
const;
286 INLINE
void __setitem__(
int x,
const LColorf &v);
294 INLINE Row(PNMImage &image,
int y);
303 class EXPCL_PANDA_PNMIMAGE CRow {
305 INLINE
size_t size()
const;
311 INLINE CRow(
const PNMImage &image,
int y);
314 const PNMImage &_image;
318 INLINE
Row operator [] (
int y);
319 INLINE
CRow operator [] (
int y)
const;
335 INLINE
void allocate_array();
336 INLINE
void allocate_alpha();
338 INLINE xel *row(
int row)
const;
339 INLINE xelval *alpha_row(
int row)
const;
341 INLINE
void setup_sub_image(
const PNMImage ©,
int &xto,
int &yto,
342 int &xfrom,
int &yfrom,
int &x_size,
int &y_size,
343 int &xmin,
int &ymin,
int &xmax,
int &ymax);
345 INLINE
static void compute_spot_pixel(LColorf &c,
float d2,
346 float min_radius,
float max_radius,
347 const LColorf &fg,
const LColorf &bg);
350 void setup_encoding();
352 void r_quantize(pmap<xel, xel> &color_map,
size_t max_colors,
353 xel *colors,
size_t num_colors);
356 PNMImage operator ~()
const;
358 INLINE PNMImage operator + (
const PNMImage &other)
const;
359 INLINE PNMImage operator + (
const LColorf &other)
const;
360 INLINE PNMImage operator - (
const PNMImage &other)
const;
361 INLINE PNMImage operator - (
const LColorf &other)
const;
362 INLINE PNMImage operator * (
const PNMImage &other)
const;
363 INLINE PNMImage operator * (
float multiplier)
const;
364 INLINE PNMImage operator * (
const LColorf &other)
const;
365 void operator += (
const PNMImage &other);
366 void operator += (
const LColorf &other);
367 void operator -= (
const PNMImage &other);
368 void operator -= (
const LColorf &other);
369 void operator *= (
const PNMImage &other);
370 void operator *= (
float multiplier);
371 void operator *= (
const LColorf &other);
375 friend class Texture;
379 float _default_rc, _default_gc, _default_bc;
381 int _read_x_size, _read_y_size;
389 ColorSpace _color_space;
397 XE_generic_sRGB_alpha,
401 XE_uchar_sRGB_alpha_sse2,
The name of a file, such as a texture file or an Egg file.
This is the base class of a family of classes that represent particular image file types that PNMImag...
size_t size() const
Get the number of pixels in the row.
xel get_xel_val(int x) const
Fetch the pixel at the given column in the row.
LColorf operator[](int x) const
Fetch the RGB value at the given column in the row.
xelval get_alpha_val(int x) const
Fetch the alpha value at the given column in the row.
void set_alpha_val(int x, xelval v)
Set the alpha value at the given column in the row.
xel & get_xel_val(int x)
Fetch the pixel at the given column in the row.
size_t size() const
Get the number of pixels in the row.
void set_xel_val(int x, const xel &v)
Set the pixel at the given column in the row.
xelval get_alpha_val(int x) const
Fetch the alpha value at the given column in the row.
LColorf operator[](int x) const
Fetch the RGB value at the given column in the row.
void clear()
Frees all memory allocated for the image, and clears all its parameters (size, color,...
xel & get_xel_val(int x, int y)
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_read_size(int x_size, int y_size)
Specifies the size to we'd like to scale the image upon reading it.
void set_maxval(xelval maxval)
Rescales the image to the indicated maxval.
xelval get_channel_val(int x, int y, int channel) const
Returns the nth component color at the indicated pixel.
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.
void copy_sub_image(const PNMImage ©, 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 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.
void flip(bool flip_x, bool flip_y, bool transpose)
Reverses, transposes, and/or rotates the image in-place according to the specified parameters.
void set_blue(int x, int y, float b)
Sets the blue 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 premultiply_alpha()
Converts an image in-place to its "premultiplied" form, where, for every pixel in the image,...
void fill_val(xelval red, xelval green, xelval blue)
Sets the entire image (except the alpha channel) to the given color.
void alpha_fill(float alpha=0.0)
Sets the entire alpha channel to the given level.
void gaussian_filter_from(float radius, const PNMImage ©)
Makes a resized copy of the indicated image into this one using the indicated filter.
void set_alpha_val(int x, int y, xelval a)
Sets the alpha component color only at the indicated pixel.
xelval get_green_val(int x, int y) const
Returns the green component color at the indicated pixel.
float get_average_gray() const
Returns the average grayscale component of all of the pixels in the image.
void make_grayscale()
Converts the image from RGB to grayscale.
void blend_sub_image(const PNMImage ©, 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 th...
void set_green(int x, int y, float g)
Sets the green component color only at the indicated pixel.
xel * take_array()
Returns the underlying PNMImage array and removes it from the PNMImage.
float get_blue(int x, int y) const
Returns the blue component color at the indicated pixel.
float get_alpha(int x, int y) const
Returns the alpha component color at the indicated pixel.
LRGBColorf get_xel(int x, int y) const
Returns the RGB color at the indicated pixel.
void set_xel_a(int x, int y, const LColorf &value)
Changes the RGBA color at the indicated pixel.
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.
float get_channel(int x, int y, int channel) const
Returns the nth component color at the indicated pixel.
LRGBColorf from_val(const xel &input_value) const
A handy function to scale non-alpha values from [0..get_maxval()] to [0..1].
void set_color_space(ColorSpace color_space)
Converts the colors in the image to the indicated color space.
float get_gray(int x, int y) const
Returns the gray component color at the indicated pixel.
void threshold(const PNMImage &select_image, int channel, float threshold, const PNMImage <, const PNMImage &ge)
Selectively copies each pixel from either one source or another source, depending on the pixel value ...
void quick_filter_from(const PNMImage ©, int xborder=0, int yborder=0)
Resizes from the given image, with a fixed radius of 0.5.
void lighten_sub_image(const PNMImage ©, 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 destinat...
void remove_alpha()
Removes the image's alpha channel, if it exists.
xelval clamp_val(int input_value) const
A handy function to clamp values to [0..get_maxval()].
void fill(float red, float green, float blue)
Sets the entire image (except the alpha channel) to the given color.
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,...
void set_array(xel *array)
Replaces the underlying PNMImage array with the indicated pointer.
LColorf get_xel_a(int x, int y) const
Returns the RGBA color at the indicated pixel.
void set_num_channels(int num_channels)
Changes the number of channels associated with the image.
void make_rgb()
Converts the image from grayscale to RGB.
LColorf get_average_xel_a() const
Returns the average color of all of the pixels in the image, including the alpha channel.
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.
void set_gray(int x, int y, float gray)
Sets the gray component color at the indicated pixel.
xelval to_alpha_val(float input_value) const
A handy function to scale alpha values from [0..1] to [0..get_maxval()].
void set_color_type(ColorType color_type)
Translates the image to or from grayscale, color, or four-color mode.
void copy_channel_bits(const PNMImage ©, 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 o...
void set_gray_val(int x, int y, xelval gray)
Sets 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(int x, int y, float r)
Sets the red component color only at the indicated pixel.
void copy_header_from(const PNMImageHeader &header)
Copies just the header information into this image.
void take_from(PNMImage &orig)
Move the contents of the other image into this one, and empty the other image.
void box_filter(float radius=1.0)
This flavor of box_filter() will apply the filter over the entire image without resizing or copying; ...
void reverse_rows()
Performs an in-place reversal of the row (y) data.
float get_bright(int x, int y) const
Returns the linear brightness of the given xel, as a linearized float in the range 0....
bool has_read_size() const
Returns true if set_read_size() has been called.
void quantize(size_t max_colors)
Reduces the number of unique colors in the image to (at most) the given count.
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 distanc...
void add_sub_image(const PNMImage ©, 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,...
void set_channel_val(int x, int y, int channel, xelval value)
Sets the nth component color 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 unfiltered_stretch_from(const PNMImage ©)
Resizes from the indicated image into this one by performing a nearest- point sample.
bool is_valid() const
Returns true if the image has been read in or correctly initialized with a height and width.
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 c...
void copy_from(const PNMImage ©)
Makes this image become a copy of the other image.
void make_histogram(Histogram &hist)
Computes a histogram of the colors used in the image.
void set_alpha_array(xelval *alpha)
Replaces the underlying PNMImage alpha array with the indicated pointer.
float from_alpha_val(xelval input_value) const
A handy function to scale alpha values from [0..get_maxval()] to [0..1].
xelval get_blue_val(int x, int y) const
Returns the blue component color at the indicated pixel.
float get_green(int x, int y) const
Returns the green component color at the indicated pixel.
void unpremultiply_alpha()
Converts an image in-place to its "straight alpha" form (presumably from a "premultiplied" form),...
bool read(const Filename &filename, PNMFileType *type=nullptr, bool report_unknown_type=true)
Reads the indicated image filename.
LRGBColorf get_average_xel() const
Returns the average color of all of the pixels in the image.
void mult_sub_image(const PNMImage ©, 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...
void gaussian_filter(float radius=1.0)
This flavor of gaussian_filter() will apply the filter over the entire image without resizing or copy...
xel * get_array()
Directly access the underlying PNMImage array.
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 distanc...
xelval get_red_val(int x, int y) const
Returns the red component color at the indicated pixel.
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 ...
void set_xel(int x, int y, const LRGBColorf &value)
Changes the RGB 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.
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 oth...
void box_filter_from(float radius, const PNMImage ©)
Makes a resized copy of the indicated image into this one using the indicated filter.
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,...
void set_channel(int x, int y, int channel, float value)
Sets the nth component color at the indicated pixel.
xelval * take_alpha_array()
Returns the underlying PNMImage array and removes it from the PNMImage.
xel to_val(const LRGBColorf &input_value) const
A handy function to scale non-alpha values from [0..1] to [0..get_maxval()].
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...
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,...
PixelSpec get_pixel(int x, int y) const
Returns the (r, g, b, a) pixel value at the indicated pixel, using a PixelSpec object.
xelval get_gray_val(int x, int y) const
Returns the gray component color at the indicated pixel.
void set_alpha(int x, int y, float a)
Sets the alpha component color only at the indicated pixel.
void apply_exponent(float gray_exponent)
Adjusts each channel of the image by raising the corresponding component value to the indicated expon...
void clear_read_size()
Undoes the effect of a previous call to set_read_size().
void add_alpha()
Adds an alpha channel to the image, if it does not already have one.
void darken_sub_image(const PNMImage ©, 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 destinati...
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.
xelval * get_alpha_array()
Directly access the underlying PNMImage array of alpha values.
bool write(const Filename &filename, PNMFileType *type=nullptr) const
Writes the image to the indicated filename.
void alpha_fill_val(xelval alpha=0)
Sets the entire alpha channel to the given level.
void copy_channel(const PNMImage ©, int src_channel, int dest_channel)
Copies a channel from one image into another.
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 oth...
float get_red(int x, int y) const
Returns the red component color at the indicated pixel.
This is an abstract base class that defines the interface for reading image files of various types.
This is an abstract base class that defines the interface for writing image files of various types.
Implements a multi-layer PerlinNoise, with one or more high-frequency noise functions added to a lowe...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.