23class EXPCL_PANDA_PNMIMAGE PNMTransparentBrush :
public PNMBrush {
25 PNMTransparentBrush() :
28 virtual void draw(
PNMImage &,
int,
int,
float) {
31 virtual void fill(
PNMImage &,
int,
int,
int,
int,
int) {
36class EXPCL_PANDA_PNMIMAGE PNMPixelBrush :
public PNMBrush {
38 PNMPixelBrush(
const LColorf &color) :
39 PNMBrush(0.5, 0.5), _color(color) { }
45class EXPCL_PANDA_PNMIMAGE PNMSetPixelBrush :
public PNMPixelBrush {
47 PNMSetPixelBrush(
const LColorf &color) : PNMPixelBrush(color) { }
49 virtual void draw(
PNMImage &image,
int x,
int y,
float pixel_scale) {
57 virtual void fill(
PNMImage &image,
int xfrom,
int xto,
int y,
60 xfrom = max(xfrom, 0);
62 for (
int x = xfrom; x <= xto; ++x) {
70class EXPCL_PANDA_PNMIMAGE PNMBlendPixelBrush :
public PNMPixelBrush {
72 PNMBlendPixelBrush(
const LColorf &color) : PNMPixelBrush(color) { }
74 virtual void draw(
PNMImage &image,
int x,
int y,
float pixel_scale) {
77 image.
blend(x, y, _color[0], _color[1], _color[2], _color[3] * pixel_scale);
81 virtual void fill(
PNMImage &image,
int xfrom,
int xto,
int y,
84 xfrom = max(xfrom, 0);
86 for (
int x = xfrom; x <= xto; ++x) {
87 image.
blend(x, y, _color[0], _color[1], _color[2], _color[3]);
94class EXPCL_PANDA_PNMIMAGE PNMDarkenPixelBrush :
public PNMPixelBrush {
96 PNMDarkenPixelBrush(
const LColorf &color) : PNMPixelBrush(color) { }
98 virtual void draw(
PNMImage &image,
int x,
int y,
float pixel_scale) {
102 LColorf p = (_color - 1.0f) * pixel_scale + 1.0f;
107 virtual void fill(
PNMImage &image,
int xfrom,
int xto,
int y,
110 xfrom = max(xfrom, 0);
112 for (
int x = xfrom; x <= xto; ++x) {
120class EXPCL_PANDA_PNMIMAGE PNMLightenPixelBrush :
public PNMPixelBrush {
122 PNMLightenPixelBrush(
const LColorf &color) : PNMPixelBrush(color) { }
124 virtual void draw(
PNMImage &image,
int x,
int y,
float pixel_scale) {
128 image.
get_xel_a(x, y).fmax(_color * pixel_scale));
132 virtual void fill(
PNMImage &image,
int xfrom,
int xto,
int y,
135 xfrom = max(xfrom, 0);
137 for (
int x = xfrom; x <= xto; ++x) {
146class EXPCL_PANDA_PNMIMAGE PNMImageBrush :
public PNMBrush {
148 PNMImageBrush(
const PNMImage &image,
float xc,
float yc) :
154 virtual void fill(
PNMImage &image,
int xfrom,
int xto,
int y,
157 xfrom = max(xfrom, 0);
160 int x_pat = (xfrom + xo) % _image.get_x_size();
161 int y_pat = (y + yo) % _image.get_y_size();
165 do_scanline(image, x, y, x_pat, y_pat, xto - x + 1, 1);
167 x += _image.get_x_size() - x_pat;
169 do_scanline(image, x, y, 0, y_pat, xto - x + 1, 1);
170 x += _image.get_x_size();
175 virtual void do_scanline(
PNMImage &image,
int xto,
int yto,
176 int xfrom,
int yfrom,
int x_size,
int y_size)=0;
182class EXPCL_PANDA_PNMIMAGE PNMSetImageBrush :
public PNMImageBrush {
184 PNMSetImageBrush(
const PNMImage &image,
float xc,
float yc) :
185 PNMImageBrush(image, xc, yc) { }
187 virtual void draw(
PNMImage &image,
int x,
int y,
float pixel_scale) {
188 if (pixel_scale >= 0.5) {
193 virtual void do_scanline(
PNMImage &image,
int xto,
int yto,
194 int xfrom,
int yfrom,
int x_size,
int y_size) {
195 image.
copy_sub_image(_image, xto, yto, xfrom, yfrom, x_size, y_size);
200class EXPCL_PANDA_PNMIMAGE PNMBlendImageBrush :
public PNMImageBrush {
202 PNMBlendImageBrush(
const PNMImage &image,
float xc,
float yc) :
203 PNMImageBrush(image, xc, yc) { }
205 virtual void draw(
PNMImage &image,
int x,
int y,
float pixel_scale) {
209 virtual void do_scanline(
PNMImage &image,
int xto,
int yto,
210 int xfrom,
int yfrom,
int x_size,
int y_size) {
216class EXPCL_PANDA_PNMIMAGE PNMDarkenImageBrush :
public PNMImageBrush {
218 PNMDarkenImageBrush(
const PNMImage &image,
float xc,
float yc) :
219 PNMImageBrush(image, xc, yc) { }
221 virtual void draw(
PNMImage &image,
int x,
int y,
float pixel_scale) {
225 virtual void do_scanline(
PNMImage &image,
int xto,
int yto,
226 int xfrom,
int yfrom,
int x_size,
int y_size) {
232class EXPCL_PANDA_PNMIMAGE PNMLightenImageBrush :
public PNMImageBrush {
234 PNMLightenImageBrush(
const PNMImage &image,
float xc,
float yc) :
235 PNMImageBrush(image, xc, yc) { }
237 virtual void draw(
PNMImage &image,
int x,
int y,
float pixel_scale) {
241 virtual void do_scanline(
PNMImage &image,
int xto,
int yto,
242 int xfrom,
int yfrom,
int x_size,
int y_size) {
260 return new PNMTransparentBrush();
268make_pixel(
const LColorf &color, PNMBrush::BrushEffect effect) {
271 return new PNMSetPixelBrush(color);
274 return new PNMBlendPixelBrush(color);
277 return new PNMDarkenPixelBrush(color);
280 return new PNMLightenPixelBrush(color);
284 <<
"**Invalid BrushEffect (" << (int)effect <<
")**\n";
285 return new PNMSetPixelBrush(color);
293make_spot(
const LColorf &color,
float radius,
bool fuzzy,
294 BrushEffect effect) {
303 bg.set(color[0], color[1], color[2], 0.0f);
316 <<
"**Invalid BrushEffect (" << (int)effect <<
")**\n";
319 int size = (int)cceil(radius * 2.0f);
320 float half_size = (float)size * 0.5f;
322 float r = half_size / radius;
325 spot.render_spot(color, bg, 0.0f, r);
327 spot.render_spot(color, bg, r, r);
329 return make_image(spot, half_size, half_size, effect);
340make_image(
const PNMImage &image,
float xc,
float yc,
341 PNMBrush::BrushEffect effect) {
344 return new PNMSetImageBrush(image, xc, yc);
347 return new PNMBlendImageBrush(image, xc, yc);
350 return new PNMDarkenImageBrush(image, xc, yc);
353 return new PNMLightenImageBrush(image, xc, yc);
357 <<
"**Invalid BrushEffect (" << (int)effect <<
")**\n";
358 return new PNMSetImageBrush(image, xc, yc);
This class is used to control the shape and color of the drawing operations performed by a PNMPainter...
The name of this class derives from the fact that we originally implemented it as a layer on top of t...
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 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_xel_a(int x, int y, const LColorf &value)
Changes the RGBA color at the indicated pixel.
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 blend(int x, int y, const LRGBColorf &val, float alpha)
Smoothly blends the indicated pixel value in with whatever was already in the image,...
LColorf get_xel_a(int x, int y) const
Returns the RGBA color at the indicated pixel.
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...
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.