Panda3D
Loading...
Searching...
No Matches
pnmImage.h
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file pnmImage.h
10 * @author drose
11 * @date 2000-06-14
12 */
13
14#ifndef PNMIMAGE_H
15#define PNMIMAGE_H
16
17#include "pandabase.h"
18
19#include "pnmImageHeader.h"
20#include "pnmBrush.h"
21#include "stackedPerlinNoise2.h"
22#include "convert_srgb.h"
23#include "luse.h"
24
25class PNMReader;
26class PNMWriter;
27class PNMFileType;
28
29/**
30 * The name of this class derives from the fact that we originally implemented
31 * it as a layer on top of the "pnm library", based on netpbm, which was built
32 * to implement pbm, pgm, and pbm files, and is the underlying support of a
33 * number of public-domain image file converters. Nowadays we are no longer
34 * derived directly from the pnm library, mainly to allow support of C++
35 * iostreams instead of the C stdio FILE interface.
36 *
37 * Conceptually, a PNMImage is a two-dimensional array of xels, which are the
38 * PNM-defined generic pixel type. Each xel may have a red, green, and blue
39 * component, or (if the image is grayscale) a gray component. The image may
40 * be read in, the individual xels manipulated, and written out again, or a
41 * black image may be constructed from scratch.
42 *
43 * A PNMImage has a color space and a maxval, the combination of which defines
44 * how a floating-point linear color value is encoded as an integer value in
45 * memory. The functions ending in _val operate on encoded colors, whereas
46 * the regular ones work with linear floating-point values. All operations
47 * are color space correct unless otherwise specified.
48 *
49 * The image is of size XSize() by YSize() xels, numbered from top to bottom,
50 * left to right, beginning at zero.
51 *
52 * Files can be specified by filename, or by an iostream pointer. The
53 * filename "-" refers to stdin or stdout.
54 *
55 * This class is not inherently thread-safe; use it from a single thread or
56 * protect access using a mutex.
57 */
58class EXPCL_PANDA_PNMIMAGE PNMImage : public PNMImageHeader {
59PUBLISHED:
60 INLINE PNMImage();
61 explicit PNMImage(const Filename &filename, PNMFileType *type = nullptr);
62 INLINE explicit PNMImage(int x_size, int y_size, int num_channels = 3,
63 xelval maxval = 255, PNMFileType *type = nullptr,
64 ColorSpace color_space = CS_linear);
65 INLINE PNMImage(const PNMImage &copy);
66 INLINE void operator = (const PNMImage &copy);
67
68 INLINE ~PNMImage();
69
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;
73 INLINE xelval to_alpha_val(float input_value) const;
74 INLINE LRGBColorf from_val(const xel &input_value) const;
75 INLINE float from_val(xelval input_value) const;
76 INLINE float from_alpha_val(xelval input_value) const;
77
78 void clear();
79 void clear(int x_size, int y_size, int num_channels = 3,
80 xelval maxval = 255, PNMFileType *type = nullptr,
81 ColorSpace color_space = CS_linear);
82
83 void copy_from(const PNMImage &copy);
84 void copy_channel(const PNMImage &copy, int src_channel, int dest_channel);
85 void copy_channel_bits(const PNMImage &copy, int src_channel, int dest_channel, xelval src_mask, int right_shift);
86 void copy_header_from(const PNMImageHeader &header);
87 void take_from(PNMImage &orig);
88
89 INLINE void fill(float red, float green, float blue);
90 INLINE void fill(float gray = 0.0);
91
92 void fill_val(xelval red, xelval green, xelval blue);
93 INLINE void fill_val(xelval gray = 0);
94
95 INLINE void alpha_fill(float alpha = 0.0);
96 void alpha_fill_val(xelval alpha = 0);
97
98 INLINE void set_read_size(int x_size, int y_size);
99 INLINE void clear_read_size();
100 INLINE bool has_read_size() const;
101 INLINE int get_read_x_size() const;
102 INLINE int get_read_y_size() const;
103 INLINE ColorSpace get_color_space() const;
104
105 BLOCKING bool read(const Filename &filename, PNMFileType *type = nullptr,
106 bool report_unknown_type = true);
107 BLOCKING bool read(std::istream &data, const std::string &filename = std::string(),
108 PNMFileType *type = nullptr,
109 bool report_unknown_type = true);
110 BLOCKING bool read(PNMReader *reader);
111
112 BLOCKING bool write(const Filename &filename, PNMFileType *type = nullptr) const;
113 BLOCKING bool write(std::ostream &data, const std::string &filename = std::string(),
114 PNMFileType *type = nullptr) const;
115 BLOCKING bool write(PNMWriter *writer) const;
116
117 INLINE bool is_valid() const;
118
119 INLINE void set_num_channels(int num_channels);
120 void set_color_type(ColorType color_type);
121 void set_color_space(ColorSpace color_space);
122
123 INLINE void add_alpha();
124 INLINE void remove_alpha();
125 INLINE void make_grayscale();
126 void make_grayscale(float rc, float gc, float bc);
127 INLINE void make_rgb();
128
129 BLOCKING void premultiply_alpha();
130 BLOCKING void unpremultiply_alpha();
131
132 BLOCKING void reverse_rows();
133 BLOCKING void flip(bool flip_x, bool flip_y, bool transpose);
134
135 BLOCKING void set_maxval(xelval maxval);
136
137 // The *_val() functions return or set the color values in the range
138 // [0..get_maxval()]. This range may be different for different images!
139 // Use the corresponding functions (without _val()) to work in the
140 // normalized range [0..1]. These return values in the image's stored color
141 // space.
142
143 INLINE xel &get_xel_val(int x, int y);
144 INLINE xel get_xel_val(int x, int y) const;
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);
148
149 INLINE xelval get_red_val(int x, int y) const;
150 INLINE xelval get_green_val(int x, int y) const;
151 INLINE xelval get_blue_val(int x, int y) const;
152 INLINE xelval get_gray_val(int x, int y) const;
153 INLINE xelval get_alpha_val(int x, int y) const;
154
155 INLINE void set_red_val(int x, int y, xelval r);
156 INLINE void set_green_val(int x, int y, xelval g);
157 INLINE void set_blue_val(int x, int y, xelval b);
158 INLINE void set_gray_val(int x, int y, xelval gray);
159 INLINE void set_alpha_val(int x, int y, xelval a);
160
161 xelval get_channel_val(int x, int y, int channel) const;
162 void set_channel_val(int x, int y, int channel, xelval value);
163 float get_channel(int x, int y, int channel) const;
164 void set_channel(int x, int y, int channel, float value);
165
166 PixelSpec get_pixel(int x, int y) const;
167 void set_pixel(int x, int y, const PixelSpec &pixel);
168
169 // The corresponding get_xel(), set_xel(), get_red(), etc. functions
170 // automatically scale their values by get_maxval() into the range [0..1],
171 // and into the linear color space.
172
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);
177
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);
181
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;
187
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);
193
194 INLINE float get_bright(int x, int y) const;
195 INLINE float get_bright(int x, int y, float rc, float gc,
196 float bc) const;
197 INLINE float get_bright(int x, int y, float rc, float gc,
198 float bc, float ac) const;
199
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);
202
203 void copy_sub_image(const PNMImage &copy, int xto, int yto,
204 int xfrom = 0, int yfrom = 0,
205 int x_size = -1, int y_size = -1);
206 void blend_sub_image(const PNMImage &copy, int xto, int yto,
207 int xfrom = 0, int yfrom = 0,
208 int x_size = -1, int y_size = -1,
209 float pixel_scale = 1.0);
210 void add_sub_image(const PNMImage &copy, int xto, int yto,
211 int xfrom = 0, int yfrom = 0,
212 int x_size = -1, int y_size = -1,
213 float pixel_scale = 1.0);
214 void mult_sub_image(const PNMImage &copy, int xto, int yto,
215 int xfrom = 0, int yfrom = 0,
216 int x_size = -1, int y_size = -1,
217 float pixel_scale = 1.0);
218 void darken_sub_image(const PNMImage &copy, int xto, int yto,
219 int xfrom = 0, int yfrom = 0,
220 int x_size = -1, int y_size = -1,
221 float pixel_scale = 1.0);
222 void lighten_sub_image(const PNMImage &copy, int xto, int yto,
223 int xfrom = 0, int yfrom = 0,
224 int x_size = -1, int y_size = -1,
225 float pixel_scale = 1.0);
226 void threshold(const PNMImage &select_image, int channel, float threshold,
227 const PNMImage &lt, const PNMImage &ge);
228 BLOCKING void fill_distance_inside(const PNMImage &mask, float threshold, int radius, bool shrink_from_border);
229 BLOCKING void fill_distance_outside(const PNMImage &mask, float threshold, int radius);
230
231 void indirect_1d_lookup(const PNMImage &index_image, int channel,
232 const PNMImage &pixel_values);
233
234 void rescale(float min_val, float max_val);
235
236 void copy_channel(const PNMImage &copy, 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);
239
240 void render_spot(const LColorf &fg, const LColorf &bg,
241 float min_radius, float max_radius);
242
243 void expand_border(int left, int right, int bottom, int top,
244 const LColorf &color);
245
246 // The bodies for the non-inline *_filter() functions can be found in the
247 // file pnm-image-filter.cxx.
248
249 BLOCKING INLINE void box_filter(float radius = 1.0);
250 BLOCKING INLINE void gaussian_filter(float radius = 1.0);
251
252 BLOCKING void unfiltered_stretch_from(const PNMImage &copy);
253 BLOCKING void box_filter_from(float radius, const PNMImage &copy);
254 BLOCKING void gaussian_filter_from(float radius, const PNMImage &copy);
255 BLOCKING void quick_filter_from(const PNMImage &copy,
256 int xborder = 0, int yborder = 0);
257
258 void make_histogram(Histogram &hist);
259 void quantize(size_t max_colors);
260 BLOCKING void perlin_noise_fill(float sx, float sy, int table_size = 256,
261 unsigned long seed = 0);
263
264 void remix_channels(const LMatrix4 &conv);
265 BLOCKING INLINE void gamma_correct(float from_gamma, float to_gamma);
266 BLOCKING INLINE void gamma_correct_alpha(float from_gamma, float to_gamma);
267 BLOCKING INLINE void apply_exponent(float gray_exponent);
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);
271
272 LRGBColorf get_average_xel() const;
273 LColorf get_average_xel_a() const;
274 float get_average_gray() const;
275
276 void do_fill_distance(int xi, int yi, int d);
277
278PUBLISHED:
279 // Provides an accessor for reading or writing the contents of one row of
280 // the image in-place.
281 class EXPCL_PANDA_PNMIMAGE Row {
282 PUBLISHED:
283 INLINE size_t size() const;
284 INLINE LColorf operator[](int x) const;
285#ifdef HAVE_PYTHON
286 INLINE void __setitem__(int x, const LColorf &v);
287#endif
288 INLINE xel &get_xel_val(int x);
289 INLINE void set_xel_val(int x, const xel &v);
290 INLINE xelval get_alpha_val(int x) const;
291 INLINE void set_alpha_val(int x, xelval v);
292
293 public:
294 INLINE Row(PNMImage &image, int y);
295
296 private:
297 PNMImage &_image;
298 int _y;
299 };
300
301 // Provides an accessor for reading the contents of one row of the image in-
302 // place.
303 class EXPCL_PANDA_PNMIMAGE CRow {
304 PUBLISHED:
305 INLINE size_t size() const;
306 INLINE LColorf operator[](int x) const;
307 INLINE xel get_xel_val(int x) const;
308 INLINE xelval get_alpha_val(int x) const;
309
310 public:
311 INLINE CRow(const PNMImage &image, int y);
312
313 private:
314 const PNMImage &_image;
315 int _y;
316 };
317
318 INLINE Row operator [] (int y);
319 INLINE CRow operator [] (int y) const;
320
321public:
322 // Know what you are doing if you access the underlying data arrays
323 // directly.
324 INLINE xel *get_array();
325 INLINE const xel *get_array() const;
326 INLINE xelval *get_alpha_array();
327 INLINE const xelval *get_alpha_array() const;
328
329 INLINE xel *take_array();
330 INLINE xelval *take_alpha_array();
331 void set_array(xel *array);
332 void set_alpha_array(xelval *alpha);
333
334private:
335 INLINE void allocate_array();
336 INLINE void allocate_alpha();
337
338 INLINE xel *row(int row) const;
339 INLINE xelval *alpha_row(int row) const;
340
341 INLINE void setup_sub_image(const PNMImage &copy, int &xto, int &yto,
342 int &xfrom, int &yfrom, int &x_size, int &y_size,
343 int &xmin, int &ymin, int &xmax, int &ymax);
344
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);
348
349 void setup_rc();
350 void setup_encoding();
351
352 void r_quantize(pmap<xel, xel> &color_map, size_t max_colors,
353 xel *colors, size_t num_colors);
354
355PUBLISHED:
356 PNMImage operator ~() const;
357
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);
372
373private:
374 friend class Row;
375 friend class Texture;
376
377 xel *_array;
378 xelval *_alpha;
379 float _default_rc, _default_gc, _default_bc;
380
381 int _read_x_size, _read_y_size;
382 bool _has_read_size;
383
384 // The reciprocal of _maxval, as an optimization for from_val.
385 float _inv_maxval;
386
387 // These method pointers contain the implementation for to_val and from_val,
388 // respectively, dependent on the maxval and color space.
389 ColorSpace _color_space;
390
391 // The following enum determines which code path we should take in the
392 // set_xel and get_xel methods.
393 enum XelEncoding {
394 XE_generic,
395 XE_generic_alpha,
396 XE_generic_sRGB,
397 XE_generic_sRGB_alpha,
398 XE_uchar_sRGB,
399 XE_uchar_sRGB_alpha,
400 XE_uchar_sRGB_sse2,
401 XE_uchar_sRGB_alpha_sse2,
402 XE_scRGB,
403 XE_scRGB_alpha
404 } _xel_encoding;
405};
406
407#include "pnmImage.I"
408
409#endif
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
This is the base class of a family of classes that represent particular image file types that PNMImag...
Definition pnmFileType.h:32
get_color_space
Returns the color space that the image is encoded in, or CS_unspecified if unknown.
size_t size() const
Get the number of pixels in the row.
Definition pnmImage.I:1050
xel get_xel_val(int x) const
Fetch the pixel at the given column in the row.
Definition pnmImage.I:1066
LColorf operator[](int x) const
Fetch the RGB value at the given column in the row.
Definition pnmImage.I:1058
xelval get_alpha_val(int x) const
Fetch the alpha value at the given column in the row.
Definition pnmImage.I:1074
void set_alpha_val(int x, xelval v)
Set the alpha value at the given column in the row.
Definition pnmImage.I:1034
xel & get_xel_val(int x)
Fetch the pixel at the given column in the row.
Definition pnmImage.I:1010
size_t size() const
Get the number of pixels in the row.
Definition pnmImage.I:983
void set_xel_val(int x, const xel &v)
Set the pixel at the given column in the row.
Definition pnmImage.I:1018
xelval get_alpha_val(int x) const
Fetch the alpha value at the given column in the row.
Definition pnmImage.I:1026
LColorf operator[](int x) const
Fetch the RGB value at the given column in the row.
Definition pnmImage.I:991
void clear()
Frees all memory allocated for the image, and clears all its parameters (size, color,...
Definition pnmImage.cxx:48
xel & get_xel_val(int x, int y)
Returns the RGB color at the indicated pixel.
Definition pnmImage.I:398
void set_xel_val(int x, int y, const xel &value)
Changes the RGB color at the indicated pixel.
Definition pnmImage.I:419
void set_read_size(int x_size, int y_size)
Specifies the size to we'd like to scale the image upon reading it.
Definition pnmImage.I:288
void set_maxval(xelval maxval)
Rescales the image to the indicated maxval.
Definition pnmImage.cxx:794
xelval get_channel_val(int x, int y, int channel) const
Returns the nth component color at the indicated pixel.
Definition pnmImage.cxx:837
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 &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 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.
Definition pnmImage.cxx:715
void set_blue(int x, int y, float b)
Sets the blue component color only at the indicated pixel.
Definition pnmImage.I:836
void set_blue_val(int x, int y, xelval b)
Sets the blue component color only at the indicated pixel.
Definition pnmImage.I:530
void premultiply_alpha()
Converts an image in-place to its "premultiplied" form, where, for every pixel in the image,...
Definition pnmImage.cxx:639
void fill_val(xelval red, xelval green, xelval blue)
Sets the entire image (except the alpha channel) to the given color.
Definition pnmImage.cxx:244
void alpha_fill(float alpha=0.0)
Sets the entire alpha channel to the given level.
Definition pnmImage.I:272
void gaussian_filter_from(float radius, const PNMImage &copy)
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.
Definition pnmImage.I:559
xelval get_green_val(int x, int y) const
Returns the green component color at the indicated pixel.
Definition pnmImage.I:462
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.
Definition pnmImage.I:380
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 th...
void set_green(int x, int y, float g)
Sets the green component color only at the indicated pixel.
Definition pnmImage.I:827
xel * take_array()
Returns the underlying PNMImage array and removes it from the PNMImage.
Definition pnmImage.I:1135
float get_blue(int x, int y) const
Returns the blue component color at the indicated pixel.
Definition pnmImage.I:788
float get_alpha(int x, int y) const
Returns the alpha component color at the indicated pixel.
Definition pnmImage.I:809
LRGBColorf get_xel(int x, int y) const
Returns the RGB color at the indicated pixel.
Definition pnmImage.I:569
void set_xel_a(int x, int y, const LColorf &value)
Changes the RGBA color at the indicated pixel.
Definition pnmImage.I:675
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.
Definition pnmImage.cxx:904
LRGBColorf from_val(const xel &input_value) const
A handy function to scale non-alpha values from [0..get_maxval()] to [0..1].
Definition pnmImage.I:171
void set_color_space(ColorSpace color_space)
Converts the colors in the image to the indicated color space.
Definition pnmImage.cxx:534
float get_gray(int x, int y) const
Returns the gray component color at the indicated pixel.
Definition pnmImage.I:799
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 ...
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.
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 destinat...
void remove_alpha()
Removes the image's alpha channel, if it exists.
Definition pnmImage.I:371
xelval clamp_val(int input_value) const
A handy function to clamp values to [0..get_maxval()].
Definition pnmImage.I:70
void fill(float red, float green, float blue)
Sets the entire image (except the alpha channel) to the given color.
Definition pnmImage.I:246
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,...
Definition pnmImage.I:900
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.
Definition pnmImage.I:608
void set_num_channels(int num_channels)
Changes the number of channels associated with the image.
Definition pnmImage.I:353
void make_rgb()
Converts the image from grayscale to RGB.
Definition pnmImage.I:389
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.
Definition pnmImage.cxx:988
void set_gray(int x, int y, float gray)
Sets the gray component color at the indicated pixel.
Definition pnmImage.I:849
xelval to_alpha_val(float input_value) const
A handy function to scale alpha values from [0..1] to [0..get_maxval()].
Definition pnmImage.I:162
void set_color_type(ColorType color_type)
Translates the image to or from grayscale, color, or four-color mode.
Definition pnmImage.cxx:478
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 o...
Definition pnmImage.cxx:154
void set_gray_val(int x, int y, xelval gray)
Sets the gray component color at the indicated pixel.
Definition pnmImage.I:545
xelval get_alpha_val(int x, int y) const
Returns the alpha component color at the indicated pixel.
Definition pnmImage.I:494
void set_red(int x, int y, float r)
Sets the red component color only at the indicated pixel.
Definition pnmImage.I:818
void copy_header_from(const PNMImageHeader &header)
Copies just the header information into this image.
Definition pnmImage.cxx:200
void take_from(PNMImage &orig)
Move the contents of the other image into this one, and empty the other image.
Definition pnmImage.cxx:224
void box_filter(float radius=1.0)
This flavor of box_filter() will apply the filter over the entire image without resizing or copying; ...
Definition pnmImage.I:909
void reverse_rows()
Performs an in-place reversal of the row (y) data.
Definition pnmImage.cxx:685
float get_bright(int x, int y) const
Returns the linear brightness of the given xel, as a linearized float in the range 0....
Definition pnmImage.I:869
bool has_read_size() const
Returns true if set_read_size() has been called.
Definition pnmImage.I:306
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 &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,...
void set_channel_val(int x, int y, int channel, xelval value)
Sets the nth component color at the indicated pixel.
Definition pnmImage.cxx:868
void set_green_val(int x, int y, xelval g)
Sets the green component color only at the indicated pixel.
Definition pnmImage.I:518
void unfiltered_stretch_from(const PNMImage &copy)
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.
Definition pnmImage.I:342
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 &copy)
Makes this image become a copy of the other image.
Definition pnmImage.cxx:105
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].
Definition pnmImage.I:238
xelval get_blue_val(int x, int y) const
Returns the blue component color at the indicated pixel.
Definition pnmImage.I:472
float get_green(int x, int y) const
Returns the green component color at the indicated pixel.
Definition pnmImage.I:779
void unpremultiply_alpha()
Converts an image in-place to its "straight alpha" form (presumably from a "premultiplied" form),...
Definition pnmImage.cxx:663
bool read(const Filename &filename, PNMFileType *type=nullptr, bool report_unknown_type=true)
Reads the indicated image filename.
Definition pnmImage.cxx:278
LRGBColorf get_average_xel() const
Returns the average color of all of the pixels in the image.
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...
void gaussian_filter(float radius=1.0)
This flavor of gaussian_filter() will apply the filter over the entire image without resizing or copy...
Definition pnmImage.I:918
xel * get_array()
Directly access the underlying PNMImage array.
Definition pnmImage.I:1098
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.
Definition pnmImage.I:452
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.
Definition pnmImage.I:579
void set_red_val(int x, int y, xelval r)
Sets the red component color only at the indicated pixel.
Definition pnmImage.I:506
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...
Definition pnmImage.I:324
void box_filter_from(float radius, const PNMImage &copy)
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,...
Definition pnmImage.I:928
void set_channel(int x, int y, int channel, float value)
Sets the nth component color at the indicated pixel.
Definition pnmImage.cxx:935
xelval * take_alpha_array()
Returns the underlying PNMImage array and removes it from the PNMImage.
Definition pnmImage.I:1148
xel to_val(const LRGBColorf &input_value) const
A handy function to scale non-alpha values from [0..1] to [0..get_maxval()].
Definition pnmImage.I:79
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,...
Definition pnmImage.I:938
PixelSpec get_pixel(int x, int y) const
Returns the (r, g, b, a) pixel value at the indicated pixel, using a PixelSpec object.
Definition pnmImage.cxx:968
xelval get_gray_val(int x, int y) const
Returns the gray component color at the indicated pixel.
Definition pnmImage.I:484
void set_alpha(int x, int y, float a)
Sets the alpha component color only at the indicated pixel.
Definition pnmImage.I:859
void apply_exponent(float gray_exponent)
Adjusts each channel of the image by raising the corresponding component value to the indicated expon...
Definition pnmImage.I:947
void clear_read_size()
Undoes the effect of a previous call to set_read_size().
Definition pnmImage.I:298
void add_alpha()
Adds an alpha channel to the image, if it does not already have one.
Definition pnmImage.I:363
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 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.
Definition pnmImage.I:1115
bool write(const Filename &filename, PNMFileType *type=nullptr) const
Writes the image to the indicated filename.
Definition pnmImage.cxx:385
void alpha_fill_val(xelval alpha=0)
Sets the entire alpha channel to the given level.
Definition pnmImage.cxx:258
void copy_channel(const PNMImage &copy, int src_channel, int dest_channel)
Copies a channel from one image into another.
Definition pnmImage.cxx:121
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...
Definition pnmImage.I:315
float get_red(int x, int y) const
Returns the red component color at the indicated pixel.
Definition pnmImage.I:770
This is an abstract base class that defines the interface for reading image files of various types.
Definition pnmReader.h:27
This is an abstract base class that defines the interface for writing image files of various types.
Definition pnmWriter.h:27
Implements a multi-layer PerlinNoise, with one or more high-frequency noise functions added to a lowe...
STL class.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.