25 #ifndef __SYNFIG_BRUSH_H
26 #define __SYNFIG_BRUSH_H
30 #include <synfig/surface.h>
46 float ,
float ,
float ,
49 float = 1.0,
float = 0.0,
56 float * color_r,
float * color_g,
float * color_b,
float * color_a
57 ) { *color_r = 0.f; *color_g = 0.f; *color_b = 0.f; *color_a = 0.f; };
89 float color_r,
float color_g,
float color_b,
90 float opaque,
float hardness = 0.5,
91 float alpha_eraser = 1.0,
92 float aspect_ratio = 1.0,
float angle = 0.0,
95 if (
surface == NULL)
return false;
100 float cs = cosf(angle/180.f*(
float)PI);
101 float sn = sinf(angle/180.f*(
float)PI);
104 if (aspect_ratio < 1.0) aspect_ratio = 1.0;
105 if (hardness > 1.0) hardness = 1.0;
106 if (hardness < 0.0) hardness = 0.0;
107 float maxr = fabsf(radius);
108 int x0 = (int)(x - maxr - 1.f);
109 int x1 = (int)(x + maxr + 1.f);
110 int y0 = (int)(y - maxr - 1.f);
111 int y1 = (int)(y + maxr + 1.f);
118 int l = x0 < 0 ? x0 : 0;
119 int t = y0 < 0 ? y0 : 0;
132 synfig::Surface::pen p(
surface->get_pen(-l, -t));
137 x -= (float)l; y -= (float)t;
142 bool erase = alpha_eraser < 1.0;
143 for(
int py = y0; py <= y1; py++)
145 for(
int px = x0; px <= x1; px++)
147 float dx = (float)px - x;
148 float dy = (float)py - y;
149 float dyr = (dy*cs-dx*sn)*aspect_ratio;
150 float dxr = (dy*sn+dx*cs);
151 float dd = (dyr*dyr + dxr*dxr) / (radius*radius);
154 float opa = dd < hardness
155 ? dd + 1-(dd/hardness)
156 : hardness/(1-hardness)*(1-dd);
158 synfig::Color &c = (*surface)[py][px];
161 c.set_a(c.get_a()*(1.0 - (1.0 - alpha_eraser)*opa));
165 float sum_alpha = opa + c.get_a();
166 if (sum_alpha > 1.0) sum_alpha = 1.0;
167 float inv_opa = sum_alpha - opa;
168 c.set_r(c.get_r()*inv_opa + color_r*opa);
169 c.set_g(c.get_g()*inv_opa + color_g*opa);
170 c.set_b(c.get_b()*inv_opa + color_b*opa);
183 float * color_r,
float * color_g,
float * color_b,
float * color_a
186 *color_r = 0.f; *color_g = 0.f; *color_b = 0.f; *color_a = 0.f;
193 synfig::Color c =
surface->cubic_sample(x, y);
194 *color_r = c.get_r();
195 *color_g = c.get_g();
196 *color_b = c.get_b();
197 *color_a = c.get_a();