19 #ifndef AGG_ALPHA_MASK_U8_INCLUDED 20 #define AGG_ALPHA_MASK_U8_INCLUDED 23 #include "agg_basics.h" 24 #include "agg_rendering_buffer.h" 31 static unsigned calculate(
const int8u* p) {
return *p; }
36 template<
unsigned R,
unsigned G,
unsigned B>
39 static unsigned calculate(
const int8u* p)
41 return (p[R]*77 + p[G]*150 + p[B]*29) >> 8;
46 template<
unsigned Step=1,
unsigned Offset=0,
class MaskF=one_component_mask_u8>
50 typedef int8u cover_type;
64 MaskF& mask_function() {
return m_mask_function; }
65 const MaskF& mask_function()
const {
return m_mask_function; }
69 cover_type pixel(
int x,
int y)
const 71 if(x >= 0 && y >= 0 &&
72 x < (
int)m_rbuf->width() &&
73 y < (int)m_rbuf->height())
75 return (cover_type)m_mask_function.calculate(
76 m_rbuf->row_ptr(y) + x * Step + Offset);
82 cover_type combine_pixel(
int x,
int y, cover_type val)
const 84 if(x >= 0 && y >= 0 &&
85 x < (
int)m_rbuf->width() &&
86 y < (int)m_rbuf->height())
88 return (cover_type)((cover_full + val *
89 m_mask_function.calculate(
90 m_rbuf->row_ptr(y) + x * Step + Offset)) >>
98 void fill_hspan(
int x,
int y, cover_type* dst,
int num_pix)
const 100 int xmax = m_rbuf->width() - 1;
101 int ymax = m_rbuf->height() - 1;
104 cover_type* covers = dst;
106 if(y < 0 || y > ymax)
108 std::memset(dst, 0, num_pix *
sizeof(cover_type));
117 std::memset(dst, 0, num_pix *
sizeof(cover_type));
120 std::memset(covers, 0, -x *
sizeof(cover_type));
127 int rest = x + count - xmax - 1;
131 std::memset(dst, 0, num_pix *
sizeof(cover_type));
134 std::memset(covers + count, 0, rest *
sizeof(cover_type));
137 const int8u* mask = m_rbuf->row_ptr(y) + x * Step + Offset;
140 *covers++ = (cover_type)m_mask_function.calculate(mask);
148 void combine_hspan(
int x,
int y, cover_type* dst,
int num_pix)
const 150 int xmax = m_rbuf->width() - 1;
151 int ymax = m_rbuf->height() - 1;
154 cover_type* covers = dst;
156 if(y < 0 || y > ymax)
158 std::memset(dst, 0, num_pix *
sizeof(cover_type));
167 std::memset(dst, 0, num_pix *
sizeof(cover_type));
170 std::memset(covers, 0, -x *
sizeof(cover_type));
177 int rest = x + count - xmax - 1;
181 std::memset(dst, 0, num_pix *
sizeof(cover_type));
184 std::memset(covers + count, 0, rest *
sizeof(cover_type));
187 const int8u* mask = m_rbuf->row_ptr(y) + x * Step + Offset;
190 *covers = (cover_type)((cover_full + (*covers) *
191 m_mask_function.calculate(mask)) >>
200 void fill_vspan(
int x,
int y, cover_type* dst,
int num_pix)
const 202 int xmax = m_rbuf->width() - 1;
203 int ymax = m_rbuf->height() - 1;
206 cover_type* covers = dst;
208 if(x < 0 || x > xmax)
210 std::memset(dst, 0, num_pix *
sizeof(cover_type));
219 std::memset(dst, 0, num_pix *
sizeof(cover_type));
222 std::memset(covers, 0, -y *
sizeof(cover_type));
229 int rest = y + count - ymax - 1;
233 std::memset(dst, 0, num_pix *
sizeof(cover_type));
236 std::memset(covers + count, 0, rest *
sizeof(cover_type));
239 const int8u* mask = m_rbuf->row_ptr(y) + x * Step + Offset;
242 *covers++ = (cover_type)m_mask_function.calculate(mask);
243 mask += m_rbuf->stride();
249 void combine_vspan(
int x,
int y, cover_type* dst,
int num_pix)
const 251 int xmax = m_rbuf->width() - 1;
252 int ymax = m_rbuf->height() - 1;
255 cover_type* covers = dst;
257 if(x < 0 || x > xmax)
259 std::memset(dst, 0, num_pix *
sizeof(cover_type));
268 std::memset(dst, 0, num_pix *
sizeof(cover_type));
271 std::memset(covers, 0, -y *
sizeof(cover_type));
278 int rest = y + count - ymax - 1;
282 std::memset(dst, 0, num_pix *
sizeof(cover_type));
285 std::memset(covers + count, 0, rest *
sizeof(cover_type));
288 const int8u* mask = m_rbuf->row_ptr(y) + x * Step + Offset;
291 *covers = (cover_type)((cover_full + (*covers) *
292 m_mask_function.calculate(mask)) >>
295 mask += m_rbuf->stride();
303 const self_type& operator = (
const self_type&);
306 MaskF m_mask_function;
350 template<
unsigned Step=1,
unsigned Offset=0,
class MaskF=one_component_mask_u8>
354 typedef int8u cover_type;
368 MaskF& mask_function() {
return m_mask_function; }
369 const MaskF& mask_function()
const {
return m_mask_function; }
373 cover_type pixel(
int x,
int y)
const 375 return (cover_type)m_mask_function.calculate(
376 m_rbuf->row_ptr(y) + x * Step + Offset);
381 cover_type combine_pixel(
int x,
int y, cover_type val)
const 383 return (cover_type)((cover_full + val *
384 m_mask_function.calculate(
385 m_rbuf->row_ptr(y) + x * Step + Offset)) >>
391 void fill_hspan(
int x,
int y, cover_type* dst,
int num_pix)
const 393 const int8u* mask = m_rbuf->row_ptr(y) + x * Step + Offset;
396 *dst++ = (cover_type)m_mask_function.calculate(mask);
405 void combine_hspan(
int x,
int y, cover_type* dst,
int num_pix)
const 407 const int8u* mask = m_rbuf->row_ptr(y) + x * Step + Offset;
410 *dst = (cover_type)((cover_full + (*dst) *
411 m_mask_function.calculate(mask)) >>
421 void fill_vspan(
int x,
int y, cover_type* dst,
int num_pix)
const 423 const int8u* mask = m_rbuf->row_ptr(y) + x * Step + Offset;
426 *dst++ = (cover_type)m_mask_function.calculate(mask);
427 mask += m_rbuf->stride();
434 void combine_vspan(
int x,
int y, cover_type* dst,
int num_pix)
const 436 const int8u* mask = m_rbuf->row_ptr(y) + x * Step + Offset;
439 *dst = (cover_type)((cover_full + (*dst) *
440 m_mask_function.calculate(mask)) >>
443 mask += m_rbuf->stride();
450 const self_type& operator = (
const self_type&);
453 MaskF m_mask_function;