diff options
author | bubnikv <bubnikv@gmail.com> | 2019-02-07 14:06:51 +0300 |
---|---|---|
committer | bubnikv <bubnikv@gmail.com> | 2019-02-07 14:06:51 +0300 |
commit | 9b15908a47af12658d6563cddac334505e27b60a (patch) | |
tree | 33f6e8bf44d1da66df4c009b3236b22eb93eb34d /src/agg/agg_pixfmt_rgb.h | |
parent | a2478b7faa7ad07d4fe0341897e9b6e7657aa92e (diff) |
WIP: SVG import & rasterization
Updated AntiGrain (agg) library to 2.5
Added agg_svg library from AntiGrain 2.5
added src/slic3r/Utils/SVGImport.cpp/hpp
Diffstat (limited to 'src/agg/agg_pixfmt_rgb.h')
-rw-r--r-- | src/agg/agg_pixfmt_rgb.h | 716 |
1 files changed, 295 insertions, 421 deletions
diff --git a/src/agg/agg_pixfmt_rgb.h b/src/agg/agg_pixfmt_rgb.h index 6fa8772ce..48947178b 100644 --- a/src/agg/agg_pixfmt_rgb.h +++ b/src/agg/agg_pixfmt_rgb.h @@ -1,16 +1,25 @@ //---------------------------------------------------------------------------- -// Anti-Grain Geometry - Version 2.4 -// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com) -// -// Permission to copy, use, modify, sell and distribute this software -// is granted provided this copyright notice appears in all copies. -// This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. -// -//---------------------------------------------------------------------------- +// Anti-Grain Geometry (AGG) - Version 2.5 +// A high quality rendering engine for C++ +// Copyright (C) 2002-2006 Maxim Shemanarev // Contact: mcseem@antigrain.com // mcseemagg@yahoo.com -// http://www.antigrain.com +// http://antigrain.com +// +// AGG is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// AGG is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with AGG; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +// MA 02110-1301, USA. //---------------------------------------------------------------------------- // // Adaptation for high precision colors has been sponsored by @@ -25,7 +34,8 @@ #define AGG_PIXFMT_RGB_INCLUDED #include <string.h> -#include "agg_pixfmt_base.h" +#include "agg_basics.h" +#include "agg_color_rgba.h" #include "agg_rendering_buffer.h" namespace agg @@ -73,73 +83,66 @@ namespace agg //=========================================================blender_rgb - template<class ColorT, class Order> - struct blender_rgb + template<class ColorT, class Order> struct blender_rgb { typedef ColorT color_type; typedef Order order_type; typedef typename color_type::value_type value_type; typedef typename color_type::calc_type calc_type; - typedef typename color_type::long_type long_type; - - // Blend pixels using the non-premultiplied form of Alvy-Ray Smith's - // compositing function. Since the render buffer is opaque we skip the - // initial premultiply and final demultiply. + enum base_scale_e { base_shift = color_type::base_shift }; //-------------------------------------------------------------------- static AGG_INLINE void blend_pix(value_type* p, - value_type cr, value_type cg, value_type cb, value_type alpha, cover_type cover) - { - blend_pix(p, cr, cg, cb, color_type::mult_cover(alpha, cover)); - } - - //-------------------------------------------------------------------- - static AGG_INLINE void blend_pix(value_type* p, - value_type cr, value_type cg, value_type cb, value_type alpha) + unsigned cr, unsigned cg, unsigned cb, + unsigned alpha, + unsigned cover=0) { - p[Order::R] = color_type::lerp(p[Order::R], cr, alpha); - p[Order::G] = color_type::lerp(p[Order::G], cg, alpha); - p[Order::B] = color_type::lerp(p[Order::B], cb, alpha); + p[Order::R] += (value_type)(((cr - p[Order::R]) * alpha) >> base_shift); + p[Order::G] += (value_type)(((cg - p[Order::G]) * alpha) >> base_shift); + p[Order::B] += (value_type)(((cb - p[Order::B]) * alpha) >> base_shift); } }; + //======================================================blender_rgb_pre - template<class ColorT, class Order> - struct blender_rgb_pre + template<class ColorT, class Order> struct blender_rgb_pre { typedef ColorT color_type; typedef Order order_type; typedef typename color_type::value_type value_type; typedef typename color_type::calc_type calc_type; - typedef typename color_type::long_type long_type; - - // Blend pixels using the premultiplied form of Alvy-Ray Smith's - // compositing function. + enum base_scale_e { base_shift = color_type::base_shift }; //-------------------------------------------------------------------- static AGG_INLINE void blend_pix(value_type* p, - value_type cr, value_type cg, value_type cb, value_type alpha, cover_type cover) + unsigned cr, unsigned cg, unsigned cb, + unsigned alpha, + unsigned cover) { - blend_pix(p, - color_type::mult_cover(cr, cover), - color_type::mult_cover(cg, cover), - color_type::mult_cover(cb, cover), - color_type::mult_cover(alpha, cover)); + alpha = color_type::base_mask - alpha; + cover = (cover + 1) << (base_shift - 8); + p[Order::R] = (value_type)((p[Order::R] * alpha + cr * cover) >> base_shift); + p[Order::G] = (value_type)((p[Order::G] * alpha + cg * cover) >> base_shift); + p[Order::B] = (value_type)((p[Order::B] * alpha + cb * cover) >> base_shift); } //-------------------------------------------------------------------- static AGG_INLINE void blend_pix(value_type* p, - value_type cr, value_type cg, value_type cb, value_type alpha) + unsigned cr, unsigned cg, unsigned cb, + unsigned alpha) { - p[Order::R] = color_type::prelerp(p[Order::R], cr, alpha); - p[Order::G] = color_type::prelerp(p[Order::G], cg, alpha); - p[Order::B] = color_type::prelerp(p[Order::B], cb, alpha); + alpha = color_type::base_mask - alpha; + p[Order::R] = (value_type)(((p[Order::R] * alpha) >> base_shift) + cr); + p[Order::G] = (value_type)(((p[Order::G] * alpha) >> base_shift) + cg); + p[Order::B] = (value_type)(((p[Order::B] * alpha) >> base_shift) + cb); } + }; + + //===================================================blender_rgb_gamma - template<class ColorT, class Order, class Gamma> - class blender_rgb_gamma : public blender_base<ColorT, Order> + template<class ColorT, class Order, class Gamma> class blender_rgb_gamma { public: typedef ColorT color_type; @@ -147,7 +150,7 @@ namespace agg typedef Gamma gamma_type; typedef typename color_type::value_type value_type; typedef typename color_type::calc_type calc_type; - typedef typename color_type::long_type long_type; + enum base_scale_e { base_shift = color_type::base_shift }; //-------------------------------------------------------------------- blender_rgb_gamma() : m_gamma(0) {} @@ -155,34 +158,29 @@ namespace agg //-------------------------------------------------------------------- AGG_INLINE void blend_pix(value_type* p, - value_type cr, value_type cg, value_type cb, value_type alpha, cover_type cover) - { - blend_pix(p, cr, cg, cb, color_type::mult_cover(alpha, cover)); - } - - //-------------------------------------------------------------------- - AGG_INLINE void blend_pix(value_type* p, - value_type cr, value_type cg, value_type cb, value_type alpha) + unsigned cr, unsigned cg, unsigned cb, + unsigned alpha, + unsigned cover=0) { calc_type r = m_gamma->dir(p[Order::R]); calc_type g = m_gamma->dir(p[Order::G]); calc_type b = m_gamma->dir(p[Order::B]); - p[Order::R] = m_gamma->inv(color_type::downscale((m_gamma->dir(cr) - r) * alpha) + r); - p[Order::G] = m_gamma->inv(color_type::downscale((m_gamma->dir(cg) - g) * alpha) + g); - p[Order::B] = m_gamma->inv(color_type::downscale((m_gamma->dir(cb) - b) * alpha) + b); + p[Order::R] = m_gamma->inv((((m_gamma->dir(cr) - r) * alpha) >> base_shift) + r); + p[Order::G] = m_gamma->inv((((m_gamma->dir(cg) - g) * alpha) >> base_shift) + g); + p[Order::B] = m_gamma->inv((((m_gamma->dir(cb) - b) * alpha) >> base_shift) + b); } - + private: const gamma_type* m_gamma; }; + + //==================================================pixfmt_alpha_blend_rgb - template<class Blender, class RenBuf, unsigned Step, unsigned Offset = 0> - class pixfmt_alpha_blend_rgb + template<class Blender, class RenBuf> class pixfmt_alpha_blend_rgb { public: - typedef pixfmt_rgb_tag pixfmt_category; typedef RenBuf rbuf_type; typedef Blender blender_type; typedef typename rbuf_type::row_data row_data; @@ -190,125 +188,56 @@ namespace agg typedef typename blender_type::order_type order_type; typedef typename color_type::value_type value_type; typedef typename color_type::calc_type calc_type; - enum - { - num_components = 3, - pix_step = Step, - pix_offset = Offset, - pix_width = sizeof(value_type) * pix_step - }; - struct pixel_type + enum base_scale_e { - value_type c[num_components]; - - void set(value_type r, value_type g, value_type b) - { - c[order_type::R] = r; - c[order_type::G] = g; - c[order_type::B] = b; - } - - void set(const color_type& color) - { - set(color.r, color.g, color.b); - } - - void get(value_type& r, value_type& g, value_type& b) const - { - r = c[order_type::R]; - g = c[order_type::G]; - b = c[order_type::B]; - } - - color_type get() const - { - return color_type( - c[order_type::R], - c[order_type::G], - c[order_type::B]); - } - - pixel_type* next() - { - return (pixel_type*)(c + pix_step); - } - - const pixel_type* next() const - { - return (const pixel_type*)(c + pix_step); - } - - pixel_type* advance(int n) - { - return (pixel_type*)(c + n * pix_step); - } - - const pixel_type* advance(int n) const - { - return (const pixel_type*)(c + n * pix_step); - } + base_shift = color_type::base_shift, + base_scale = color_type::base_scale, + base_mask = color_type::base_mask, + pix_width = sizeof(value_type) * 3 }; private: //-------------------------------------------------------------------- - AGG_INLINE void blend_pix(pixel_type* p, - value_type r, value_type g, value_type b, value_type a, - unsigned cover) - { - m_blender.blend_pix(p->c, r, g, b, a, cover); - } - - //-------------------------------------------------------------------- - AGG_INLINE void blend_pix(pixel_type* p, - value_type r, value_type g, value_type b, value_type a) - { - m_blender.blend_pix(p->c, r, g, b, a); - } - - //-------------------------------------------------------------------- - AGG_INLINE void blend_pix(pixel_type* p, const color_type& c, unsigned cover) - { - m_blender.blend_pix(p->c, c.r, c.g, c.b, c.a, cover); - } - - //-------------------------------------------------------------------- - AGG_INLINE void blend_pix(pixel_type* p, const color_type& c) - { - m_blender.blend_pix(p->c, c.r, c.g, c.b, c.a); - } - - //-------------------------------------------------------------------- - AGG_INLINE void copy_or_blend_pix(pixel_type* p, const color_type& c, unsigned cover) + AGG_INLINE void copy_or_blend_pix(value_type* p, + const color_type& c, + unsigned cover) { - if (!c.is_transparent()) + if (c.a) { - if (c.is_opaque() && cover == cover_mask) + calc_type alpha = (calc_type(c.a) * (cover + 1)) >> 8; + if(alpha == base_mask) { - p->set(c); + p[order_type::R] = c.r; + p[order_type::G] = c.g; + p[order_type::B] = c.b; } else { - blend_pix(p, c, cover); + m_blender.blend_pix(p, c.r, c.g, c.b, alpha, cover); } } } //-------------------------------------------------------------------- - AGG_INLINE void copy_or_blend_pix(pixel_type* p, const color_type& c) + AGG_INLINE void copy_or_blend_pix(value_type* p, + const color_type& c) { - if (!c.is_transparent()) + if (c.a) { - if (c.is_opaque()) + if(c.a == base_mask) { - p->set(c); + p[order_type::R] = c.r; + p[order_type::G] = c.g; + p[order_type::B] = c.b; } else { - blend_pix(p, c); + m_blender.blend_pix(p, c.r, c.g, c.b, c.a); } } } + public: //-------------------------------------------------------------------- explicit pixfmt_alpha_blend_rgb(rbuf_type& rb) : @@ -321,7 +250,7 @@ namespace agg bool attach(PixFmt& pixf, int x1, int y1, int x2, int y2) { rect_i r(x1, y1, x2, y2); - if (r.clip(rect_i(0, 0, pixf.width()-1, pixf.height()-1))) + if(r.clip(rect_i(0, 0, pixf.width()-1, pixf.height()-1))) { int stride = pixf.stride(); m_rbuf->attach(pixf.pix_ptr(r.x1, stride < 0 ? r.y2 : r.y1), @@ -349,91 +278,59 @@ namespace agg //-------------------------------------------------------------------- AGG_INLINE int8u* pix_ptr(int x, int y) { - return m_rbuf->row_ptr(y) + sizeof(value_type) * (x * pix_step + pix_offset); + return m_rbuf->row_ptr(y) + x * pix_width; } AGG_INLINE const int8u* pix_ptr(int x, int y) const { - return m_rbuf->row_ptr(y) + sizeof(value_type) * (x * pix_step + pix_offset); - } - - // Return pointer to pixel value, forcing row to be allocated. - AGG_INLINE pixel_type* pix_value_ptr(int x, int y, unsigned len) - { - return (pixel_type*)(m_rbuf->row_ptr(x, y, len) + sizeof(value_type) * (x * pix_step + pix_offset)); - } - - // Return pointer to pixel value, or null if row not allocated. - AGG_INLINE const pixel_type* pix_value_ptr(int x, int y) const - { - int8u* p = m_rbuf->row_ptr(y); - return p ? (pixel_type*)(p + sizeof(value_type) * (x * pix_step + pix_offset)) : 0; - } - - // Get pixel pointer from raw buffer pointer. - AGG_INLINE static pixel_type* pix_value_ptr(void* p) - { - return (pixel_type*)((value_type*)p + pix_offset); - } - - // Get pixel pointer from raw buffer pointer. - AGG_INLINE static const pixel_type* pix_value_ptr(const void* p) - { - return (const pixel_type*)((const value_type*)p + pix_offset); - } - - //-------------------------------------------------------------------- - AGG_INLINE static void write_plain_color(void* p, color_type c) - { - // RGB formats are implicitly premultiplied. - c.premultiply(); - pix_value_ptr(p)->set(c); - } - - //-------------------------------------------------------------------- - AGG_INLINE static color_type read_plain_color(const void* p) - { - return pix_value_ptr(p)->get(); + return m_rbuf->row_ptr(y) + x * pix_width; } //-------------------------------------------------------------------- AGG_INLINE static void make_pix(int8u* p, const color_type& c) { - ((pixel_type*)p)->set(c); + ((value_type*)p)[order_type::R] = c.r; + ((value_type*)p)[order_type::G] = c.g; + ((value_type*)p)[order_type::B] = c.b; } //-------------------------------------------------------------------- AGG_INLINE color_type pixel(int x, int y) const { - if (const pixel_type* p = pix_value_ptr(x, y)) - { - return p->get(); - } - return color_type::no_color(); + value_type* p = (value_type*)m_rbuf->row_ptr(y) + x + x + x; + return color_type(p[order_type::R], + p[order_type::G], + p[order_type::B]); } //-------------------------------------------------------------------- AGG_INLINE void copy_pixel(int x, int y, const color_type& c) { - pix_value_ptr(x, y, 1)->set(c); + value_type* p = (value_type*)m_rbuf->row_ptr(x, y, 1) + x + x + x; + p[order_type::R] = c.r; + p[order_type::G] = c.g; + p[order_type::B] = c.b; } //-------------------------------------------------------------------- AGG_INLINE void blend_pixel(int x, int y, const color_type& c, int8u cover) { - copy_or_blend_pix(pix_value_ptr(x, y, 1), c, cover); + copy_or_blend_pix((value_type*)m_rbuf->row_ptr(x, y, 1) + x + x + x, c, cover); } + //-------------------------------------------------------------------- AGG_INLINE void copy_hline(int x, int y, unsigned len, const color_type& c) { - pixel_type* p = pix_value_ptr(x, y, len); + value_type* p = (value_type*)m_rbuf->row_ptr(x, y, len) + x + x + x; do { - p->set(c); - p = p->next(); + p[order_type::R] = c.r; + p[order_type::G] = c.g; + p[order_type::B] = c.b; + p += 3; } while(--len); } @@ -446,38 +343,47 @@ namespace agg { do { - pix_value_ptr(x, y++, 1)->set(c); + value_type* p = (value_type*) + m_rbuf->row_ptr(x, y++, 1) + x + x + x; + p[order_type::R] = c.r; + p[order_type::G] = c.g; + p[order_type::B] = c.b; } - while (--len); + while(--len); } + //-------------------------------------------------------------------- void blend_hline(int x, int y, unsigned len, const color_type& c, int8u cover) { - if (!c.is_transparent()) + if (c.a) { - pixel_type* p = pix_value_ptr(x, y, len); + value_type* p = (value_type*) + m_rbuf->row_ptr(x, y, len) + x + x + x; - if (c.is_opaque() && cover == cover_mask) + calc_type alpha = (calc_type(c.a) * (calc_type(cover) + 1)) >> 8; + if(alpha == base_mask) { do { - p->set(c); - p = p->next(); + p[order_type::R] = c.r; + p[order_type::G] = c.g; + p[order_type::B] = c.b; + p += 3; } - while (--len); + while(--len); } else { do { - blend_pix(p, c, cover); - p = p->next(); + m_blender.blend_pix(p, c.r, c.g, c.b, alpha, cover); + p += 3; } - while (--len); + while(--len); } } } @@ -489,51 +395,66 @@ namespace agg const color_type& c, int8u cover) { - if (!c.is_transparent()) + if (c.a) { - if (c.is_opaque() && cover == cover_mask) + value_type* p; + calc_type alpha = (calc_type(c.a) * (cover + 1)) >> 8; + if(alpha == base_mask) { do { - pix_value_ptr(x, y++, 1)->set(c); + p = (value_type*) + m_rbuf->row_ptr(x, y++, 1) + x + x + x; + + p[order_type::R] = c.r; + p[order_type::G] = c.g; + p[order_type::B] = c.b; } - while (--len); + while(--len); } else { do { - blend_pix(pix_value_ptr(x, y++, 1), c, cover); + p = (value_type*) + m_rbuf->row_ptr(x, y++, 1) + x + x + x; + + m_blender.blend_pix(p, c.r, c.g, c.b, alpha, cover); } - while (--len); + while(--len); } } } + //-------------------------------------------------------------------- void blend_solid_hspan(int x, int y, unsigned len, const color_type& c, const int8u* covers) { - if (!c.is_transparent()) + if (c.a) { - pixel_type* p = pix_value_ptr(x, y, len); + value_type* p = (value_type*) + m_rbuf->row_ptr(x, y, len) + x + x + x; do { - if (c.is_opaque() && *covers == cover_mask) + calc_type alpha = (calc_type(c.a) * (calc_type(*covers) + 1)) >> 8; + if(alpha == base_mask) { - p->set(c); + p[order_type::R] = c.r; + p[order_type::G] = c.g; + p[order_type::B] = c.b; } else { - blend_pix(p, c, *covers); + m_blender.blend_pix(p, c.r, c.g, c.b, alpha, *covers); } - p = p->next(); + p += 3; ++covers; } - while (--len); + while(--len); } } @@ -544,39 +465,48 @@ namespace agg const color_type& c, const int8u* covers) { - if (!c.is_transparent()) + if (c.a) { do { - pixel_type* p = pix_value_ptr(x, y++, 1); + value_type* p = (value_type*) + m_rbuf->row_ptr(x, y++, 1) + x + x + x; - if (c.is_opaque() && *covers == cover_mask) + calc_type alpha = (calc_type(c.a) * (calc_type(*covers) + 1)) >> 8; + if(alpha == base_mask) { - p->set(c); + p[order_type::R] = c.r; + p[order_type::G] = c.g; + p[order_type::B] = c.b; } else { - blend_pix(p, c, *covers); + m_blender.blend_pix(p, c.r, c.g, c.b, alpha, *covers); } ++covers; } - while (--len); + while(--len); } } + //-------------------------------------------------------------------- void copy_color_hspan(int x, int y, unsigned len, const color_type* colors) { - pixel_type* p = pix_value_ptr(x, y, len); + value_type* p = (value_type*) + m_rbuf->row_ptr(x, y, len) + x + x + x; do { - p->set(*colors++); - p = p->next(); + p[order_type::R] = colors->r; + p[order_type::G] = colors->g; + p[order_type::B] = colors->b; + ++colors; + p += 3; } - while (--len); + while(--len); } @@ -587,11 +517,17 @@ namespace agg { do { - pix_value_ptr(x, y++, 1)->set(*colors++); + value_type* p = (value_type*) + m_rbuf->row_ptr(x, y++, 1) + x + x + x; + p[order_type::R] = colors->r; + p[order_type::G] = colors->g; + p[order_type::B] = colors->b; + ++colors; } - while (--len); + while(--len); } + //-------------------------------------------------------------------- void blend_color_hspan(int x, int y, unsigned len, @@ -599,40 +535,43 @@ namespace agg const int8u* covers, int8u cover) { - pixel_type* p = pix_value_ptr(x, y, len); + value_type* p = (value_type*) + m_rbuf->row_ptr(x, y, len) + x + x + x; - if (covers) + if(covers) { do { copy_or_blend_pix(p, *colors++, *covers++); - p = p->next(); + p += 3; } - while (--len); + while(--len); } else { - if (cover == cover_mask) + if(cover == 255) { do { copy_or_blend_pix(p, *colors++); - p = p->next(); + p += 3; } - while (--len); + while(--len); } else { do { copy_or_blend_pix(p, *colors++, cover); - p = p->next(); + p += 3; } - while (--len); + while(--len); } } } + + //-------------------------------------------------------------------- void blend_color_vspan(int x, int y, unsigned len, @@ -640,31 +579,41 @@ namespace agg const int8u* covers, int8u cover) { - if (covers) + value_type* p; + if(covers) { do { - copy_or_blend_pix(pix_value_ptr(x, y++, 1), *colors++, *covers++); + p = (value_type*) + m_rbuf->row_ptr(x, y++, 1) + x + x + x; + + copy_or_blend_pix(p, *colors++, *covers++); } - while (--len); + while(--len); } else { - if (cover == cover_mask) + if(cover == 255) { do { - copy_or_blend_pix(pix_value_ptr(x, y++, 1), *colors++); + p = (value_type*) + m_rbuf->row_ptr(x, y++, 1) + x + x + x; + + copy_or_blend_pix(p, *colors++); } - while (--len); + while(--len); } else { do { - copy_or_blend_pix(pix_value_ptr(x, y++, 1), *colors++, cover); + p = (value_type*) + m_rbuf->row_ptr(x, y++, 1) + x + x + x; + + copy_or_blend_pix(p, *colors++, cover); } - while (--len); + while(--len); } } } @@ -672,19 +621,21 @@ namespace agg //-------------------------------------------------------------------- template<class Function> void for_each_pixel(Function f) { - for (unsigned y = 0; y < height(); ++y) + unsigned y; + for(y = 0; y < height(); ++y) { row_data r = m_rbuf->row(y); - if (r.ptr) + if(r.ptr) { unsigned len = r.x2 - r.x1 + 1; - pixel_type* p = pix_value_ptr(r.x1, y, len); + value_type* p = (value_type*) + m_rbuf->row_ptr(r.x1, y, len) + r.x1 * 3; do { - f(p->c); - p = p->next(); + f(p); + p += 3; } - while (--len); + while(--len); } } } @@ -708,7 +659,8 @@ namespace agg int xsrc, int ysrc, unsigned len) { - if (const int8u* p = from.row_ptr(ysrc)) + const int8u* p = from.row_ptr(ysrc); + if(p) { memmove(m_rbuf->row_ptr(xdst, ydst, len) + xdst * pix_width, p + xsrc * pix_width, @@ -716,8 +668,8 @@ namespace agg } } + //-------------------------------------------------------------------- - // Blend from an RGBA surface. template<class SrcPixelFormatRenderer> void blend_from(const SrcPixelFormatRenderer& from, int xdst, int ydst, @@ -725,55 +677,61 @@ namespace agg unsigned len, int8u cover) { - typedef typename SrcPixelFormatRenderer::pixel_type src_pixel_type; typedef typename SrcPixelFormatRenderer::order_type src_order; - if (const src_pixel_type* psrc = from.pix_value_ptr(xsrc, ysrc)) + const value_type* psrc = (const value_type*)from.row_ptr(ysrc); + if(psrc) { - pixel_type* pdst = pix_value_ptr(xdst, ydst, len); + psrc += xsrc * 4; + value_type* pdst = + (value_type*)m_rbuf->row_ptr(xdst, ydst, len) + xdst * 3; - if (cover == cover_mask) + if(cover == 255) { do { - value_type alpha = psrc->c[src_order::A]; - if (alpha <= color_type::empty_value()) + value_type alpha = psrc[src_order::A]; + if(alpha) { - if (alpha >= color_type::full_value()) + if(alpha == base_mask) { - pdst->c[order_type::R] = psrc->c[src_order::R]; - pdst->c[order_type::G] = psrc->c[src_order::G]; - pdst->c[order_type::B] = psrc->c[src_order::B]; + pdst[order_type::R] = psrc[src_order::R]; + pdst[order_type::G] = psrc[src_order::G]; + pdst[order_type::B] = psrc[src_order::B]; } else { - blend_pix(pdst, - psrc->c[src_order::R], - psrc->c[src_order::G], - psrc->c[src_order::B], - alpha); + m_blender.blend_pix(pdst, + psrc[src_order::R], + psrc[src_order::G], + psrc[src_order::B], + alpha); } } - psrc = psrc->next(); - pdst = pdst->next(); + psrc += 4; + pdst += 3; } while(--len); } else { + color_type color; do { - copy_or_blend_pix(pdst, psrc->get(), cover); - psrc = psrc->next(); - pdst = pdst->next(); + color.r = psrc[src_order::R]; + color.g = psrc[src_order::G]; + color.b = psrc[src_order::B]; + color.a = psrc[src_order::A]; + copy_or_blend_pix(pdst, color, cover); + psrc += 4; + pdst += 3; } - while (--len); + while(--len); } } } //-------------------------------------------------------------------- - // Blend from single color, using grayscale surface as alpha channel. template<class SrcPixelFormatRenderer> void blend_from_color(const SrcPixelFormatRenderer& from, const color_type& color, @@ -782,26 +740,25 @@ namespace agg unsigned len, int8u cover) { - typedef typename SrcPixelFormatRenderer::pixel_type src_pixel_type; - typedef typename SrcPixelFormatRenderer::color_type src_color_type; - - if (const src_pixel_type* psrc = from.pix_value_ptr(xsrc, ysrc)) + typedef typename SrcPixelFormatRenderer::value_type src_value_type; + const src_value_type* psrc = (src_value_type*)from.row_ptr(ysrc); + if(psrc) { - pixel_type* pdst = pix_value_ptr(xdst, ydst, len); - + value_type* pdst = + (value_type*)m_rbuf->row_ptr(xdst, ydst, len) + xdst * 3; do { - copy_or_blend_pix(pdst, color, src_color_type::scale_cover(cover, psrc->c[0])); - psrc = psrc->next(); - pdst = pdst->next(); + copy_or_blend_pix(pdst, + color, + (*psrc * cover + base_mask) >> base_shift); + ++psrc; + pdst += 3; } - while (--len); + while(--len); } } //-------------------------------------------------------------------- - // Blend from color table, using grayscale surface as indexes into table. - // Obviously, this only works for integer value types. template<class SrcPixelFormatRenderer> void blend_from_lut(const SrcPixelFormatRenderer& from, const color_type* color_lut, @@ -810,20 +767,22 @@ namespace agg unsigned len, int8u cover) { - typedef typename SrcPixelFormatRenderer::pixel_type src_pixel_type; - - if (const src_pixel_type* psrc = from.pix_value_ptr(xsrc, ysrc)) + typedef typename SrcPixelFormatRenderer::value_type src_value_type; + const src_value_type* psrc = (src_value_type*)from.row_ptr(ysrc); + if(psrc) { - pixel_type* pdst = pix_value_ptr(xdst, ydst, len); + value_type* pdst = + (value_type*)m_rbuf->row_ptr(xdst, ydst, len) + xdst * 3; - if (cover == cover_mask) + if(cover == 255) { do { - const color_type& color = color_lut[psrc->c[0]]; - blend_pix(pdst, color); - psrc = psrc->next(); - pdst = pdst->next(); + const color_type& color = color_lut[*psrc]; + m_blender.blend_pix(pdst, + color.r, color.g, color.b, color.a); + ++psrc; + pdst += 3; } while(--len); } @@ -831,9 +790,9 @@ namespace agg { do { - copy_or_blend_pix(pdst, color_lut[psrc->c[0]], cover); - psrc = psrc->next(); - pdst = pdst->next(); + copy_or_blend_pix(pdst, color_lut[*psrc], cover); + ++psrc; + pdst += 3; } while(--len); } @@ -844,98 +803,24 @@ namespace agg rbuf_type* m_rbuf; Blender m_blender; }; - - //----------------------------------------------------------------------- - typedef blender_rgb<rgba8, order_rgb> blender_rgb24; - typedef blender_rgb<rgba8, order_bgr> blender_bgr24; - typedef blender_rgb<srgba8, order_rgb> blender_srgb24; - typedef blender_rgb<srgba8, order_bgr> blender_sbgr24; - typedef blender_rgb<rgba16, order_rgb> blender_rgb48; - typedef blender_rgb<rgba16, order_bgr> blender_bgr48; - typedef blender_rgb<rgba32, order_rgb> blender_rgb96; - typedef blender_rgb<rgba32, order_bgr> blender_bgr96; - - typedef blender_rgb_pre<rgba8, order_rgb> blender_rgb24_pre; - typedef blender_rgb_pre<rgba8, order_bgr> blender_bgr24_pre; - typedef blender_rgb_pre<srgba8, order_rgb> blender_srgb24_pre; - typedef blender_rgb_pre<srgba8, order_bgr> blender_sbgr24_pre; - typedef blender_rgb_pre<rgba16, order_rgb> blender_rgb48_pre; - typedef blender_rgb_pre<rgba16, order_bgr> blender_bgr48_pre; - typedef blender_rgb_pre<rgba32, order_rgb> blender_rgb96_pre; - typedef blender_rgb_pre<rgba32, order_bgr> blender_bgr96_pre; - - typedef pixfmt_alpha_blend_rgb<blender_rgb24, rendering_buffer, 3> pixfmt_rgb24; - typedef pixfmt_alpha_blend_rgb<blender_bgr24, rendering_buffer, 3> pixfmt_bgr24; - typedef pixfmt_alpha_blend_rgb<blender_srgb24, rendering_buffer, 3> pixfmt_srgb24; - typedef pixfmt_alpha_blend_rgb<blender_sbgr24, rendering_buffer, 3> pixfmt_sbgr24; - typedef pixfmt_alpha_blend_rgb<blender_rgb48, rendering_buffer, 3> pixfmt_rgb48; - typedef pixfmt_alpha_blend_rgb<blender_bgr48, rendering_buffer, 3> pixfmt_bgr48; - typedef pixfmt_alpha_blend_rgb<blender_rgb96, rendering_buffer, 3> pixfmt_rgb96; - typedef pixfmt_alpha_blend_rgb<blender_bgr96, rendering_buffer, 3> pixfmt_bgr96; - - typedef pixfmt_alpha_blend_rgb<blender_rgb24_pre, rendering_buffer, 3> pixfmt_rgb24_pre; - typedef pixfmt_alpha_blend_rgb<blender_bgr24_pre, rendering_buffer, 3> pixfmt_bgr24_pre; - typedef pixfmt_alpha_blend_rgb<blender_srgb24_pre, rendering_buffer, 3> pixfmt_srgb24_pre; - typedef pixfmt_alpha_blend_rgb<blender_sbgr24_pre, rendering_buffer, 3> pixfmt_sbgr24_pre; - typedef pixfmt_alpha_blend_rgb<blender_rgb48_pre, rendering_buffer, 3> pixfmt_rgb48_pre; - typedef pixfmt_alpha_blend_rgb<blender_bgr48_pre, rendering_buffer, 3> pixfmt_bgr48_pre; - typedef pixfmt_alpha_blend_rgb<blender_rgb96_pre, rendering_buffer, 3> pixfmt_rgb96_pre; - typedef pixfmt_alpha_blend_rgb<blender_bgr96_pre, rendering_buffer, 3> pixfmt_bgr96_pre; - - typedef pixfmt_alpha_blend_rgb<blender_rgb24, rendering_buffer, 4, 0> pixfmt_rgbx32; - typedef pixfmt_alpha_blend_rgb<blender_rgb24, rendering_buffer, 4, 1> pixfmt_xrgb32; - typedef pixfmt_alpha_blend_rgb<blender_bgr24, rendering_buffer, 4, 1> pixfmt_xbgr32; - typedef pixfmt_alpha_blend_rgb<blender_bgr24, rendering_buffer, 4, 0> pixfmt_bgrx32; - typedef pixfmt_alpha_blend_rgb<blender_srgb24, rendering_buffer, 4, 0> pixfmt_srgbx32; - typedef pixfmt_alpha_blend_rgb<blender_srgb24, rendering_buffer, 4, 1> pixfmt_sxrgb32; - typedef pixfmt_alpha_blend_rgb<blender_sbgr24, rendering_buffer, 4, 1> pixfmt_sxbgr32; - typedef pixfmt_alpha_blend_rgb<blender_sbgr24, rendering_buffer, 4, 0> pixfmt_sbgrx32; - typedef pixfmt_alpha_blend_rgb<blender_rgb48, rendering_buffer, 4, 0> pixfmt_rgbx64; - typedef pixfmt_alpha_blend_rgb<blender_rgb48, rendering_buffer, 4, 1> pixfmt_xrgb64; - typedef pixfmt_alpha_blend_rgb<blender_bgr48, rendering_buffer, 4, 1> pixfmt_xbgr64; - typedef pixfmt_alpha_blend_rgb<blender_bgr48, rendering_buffer, 4, 0> pixfmt_bgrx64; - typedef pixfmt_alpha_blend_rgb<blender_rgb96, rendering_buffer, 4, 0> pixfmt_rgbx128; - typedef pixfmt_alpha_blend_rgb<blender_rgb96, rendering_buffer, 4, 1> pixfmt_xrgb128; - typedef pixfmt_alpha_blend_rgb<blender_bgr96, rendering_buffer, 4, 1> pixfmt_xbgr128; - typedef pixfmt_alpha_blend_rgb<blender_bgr96, rendering_buffer, 4, 0> pixfmt_bgrx128; - - typedef pixfmt_alpha_blend_rgb<blender_rgb24_pre, rendering_buffer, 4, 0> pixfmt_rgbx32_pre; - typedef pixfmt_alpha_blend_rgb<blender_rgb24_pre, rendering_buffer, 4, 1> pixfmt_xrgb32_pre; - typedef pixfmt_alpha_blend_rgb<blender_bgr24_pre, rendering_buffer, 4, 1> pixfmt_xbgr32_pre; - typedef pixfmt_alpha_blend_rgb<blender_bgr24_pre, rendering_buffer, 4, 0> pixfmt_bgrx32_pre; - typedef pixfmt_alpha_blend_rgb<blender_srgb24_pre, rendering_buffer, 4, 0> pixfmt_srgbx32_pre; - typedef pixfmt_alpha_blend_rgb<blender_srgb24_pre, rendering_buffer, 4, 1> pixfmt_sxrgb32_pre; - typedef pixfmt_alpha_blend_rgb<blender_sbgr24_pre, rendering_buffer, 4, 1> pixfmt_sxbgr32_pre; - typedef pixfmt_alpha_blend_rgb<blender_sbgr24_pre, rendering_buffer, 4, 0> pixfmt_sbgrx32_pre; - typedef pixfmt_alpha_blend_rgb<blender_rgb48_pre, rendering_buffer, 4, 0> pixfmt_rgbx64_pre; - typedef pixfmt_alpha_blend_rgb<blender_rgb48_pre, rendering_buffer, 4, 1> pixfmt_xrgb64_pre; - typedef pixfmt_alpha_blend_rgb<blender_bgr48_pre, rendering_buffer, 4, 1> pixfmt_xbgr64_pre; - typedef pixfmt_alpha_blend_rgb<blender_bgr48_pre, rendering_buffer, 4, 0> pixfmt_bgrx64_pre; - typedef pixfmt_alpha_blend_rgb<blender_rgb96_pre, rendering_buffer, 4, 0> pixfmt_rgbx128_pre; - typedef pixfmt_alpha_blend_rgb<blender_rgb96_pre, rendering_buffer, 4, 1> pixfmt_xrgb128_pre; - typedef pixfmt_alpha_blend_rgb<blender_bgr96_pre, rendering_buffer, 4, 1> pixfmt_xbgr128_pre; - typedef pixfmt_alpha_blend_rgb<blender_bgr96_pre, rendering_buffer, 4, 0> pixfmt_bgrx128_pre; - + + typedef pixfmt_alpha_blend_rgb<blender_rgb<rgba8, order_rgb>, rendering_buffer> pixfmt_rgb24; //----pixfmt_rgb24 + typedef pixfmt_alpha_blend_rgb<blender_rgb<rgba8, order_bgr>, rendering_buffer> pixfmt_bgr24; //----pixfmt_bgr24 + typedef pixfmt_alpha_blend_rgb<blender_rgb<rgba16, order_rgb>, rendering_buffer> pixfmt_rgb48; //----pixfmt_rgb48 + typedef pixfmt_alpha_blend_rgb<blender_rgb<rgba16, order_bgr>, rendering_buffer> pixfmt_bgr48; //----pixfmt_bgr48 + + typedef pixfmt_alpha_blend_rgb<blender_rgb_pre<rgba8, order_rgb>, rendering_buffer> pixfmt_rgb24_pre; //----pixfmt_rgb24_pre + typedef pixfmt_alpha_blend_rgb<blender_rgb_pre<rgba8, order_bgr>, rendering_buffer> pixfmt_bgr24_pre; //----pixfmt_bgr24_pre + typedef pixfmt_alpha_blend_rgb<blender_rgb_pre<rgba16, order_rgb>, rendering_buffer> pixfmt_rgb48_pre; //----pixfmt_rgb48_pre + typedef pixfmt_alpha_blend_rgb<blender_rgb_pre<rgba16, order_bgr>, rendering_buffer> pixfmt_bgr48_pre; //----pixfmt_bgr48_pre //-----------------------------------------------------pixfmt_rgb24_gamma template<class Gamma> class pixfmt_rgb24_gamma : - public pixfmt_alpha_blend_rgb<blender_rgb_gamma<rgba8, order_rgb, Gamma>, rendering_buffer, 3> + public pixfmt_alpha_blend_rgb<blender_rgb_gamma<rgba8, order_rgb, Gamma>, rendering_buffer> { public: pixfmt_rgb24_gamma(rendering_buffer& rb, const Gamma& g) : - pixfmt_alpha_blend_rgb<blender_rgb_gamma<rgba8, order_rgb, Gamma>, rendering_buffer, 3>(rb) - { - this->blender().gamma(g); - } - }; - - //-----------------------------------------------------pixfmt_srgb24_gamma - template<class Gamma> class pixfmt_srgb24_gamma : - public pixfmt_alpha_blend_rgb<blender_rgb_gamma<srgba8, order_rgb, Gamma>, rendering_buffer, 3> - { - public: - pixfmt_srgb24_gamma(rendering_buffer& rb, const Gamma& g) : - pixfmt_alpha_blend_rgb<blender_rgb_gamma<srgba8, order_rgb, Gamma>, rendering_buffer, 3>(rb) + pixfmt_alpha_blend_rgb<blender_rgb_gamma<rgba8, order_rgb, Gamma>, rendering_buffer>(rb) { this->blender().gamma(g); } @@ -943,23 +828,11 @@ namespace agg //-----------------------------------------------------pixfmt_bgr24_gamma template<class Gamma> class pixfmt_bgr24_gamma : - public pixfmt_alpha_blend_rgb<blender_rgb_gamma<rgba8, order_bgr, Gamma>, rendering_buffer, 3> + public pixfmt_alpha_blend_rgb<blender_rgb_gamma<rgba8, order_bgr, Gamma>, rendering_buffer> { public: pixfmt_bgr24_gamma(rendering_buffer& rb, const Gamma& g) : - pixfmt_alpha_blend_rgb<blender_rgb_gamma<rgba8, order_bgr, Gamma>, rendering_buffer, 3>(rb) - { - this->blender().gamma(g); - } - }; - - //-----------------------------------------------------pixfmt_sbgr24_gamma - template<class Gamma> class pixfmt_sbgr24_gamma : - public pixfmt_alpha_blend_rgb<blender_rgb_gamma<srgba8, order_bgr, Gamma>, rendering_buffer, 3> - { - public: - pixfmt_sbgr24_gamma(rendering_buffer& rb, const Gamma& g) : - pixfmt_alpha_blend_rgb<blender_rgb_gamma<srgba8, order_bgr, Gamma>, rendering_buffer, 3>(rb) + pixfmt_alpha_blend_rgb<blender_rgb_gamma<rgba8, order_bgr, Gamma>, rendering_buffer>(rb) { this->blender().gamma(g); } @@ -967,11 +840,11 @@ namespace agg //-----------------------------------------------------pixfmt_rgb48_gamma template<class Gamma> class pixfmt_rgb48_gamma : - public pixfmt_alpha_blend_rgb<blender_rgb_gamma<rgba16, order_rgb, Gamma>, rendering_buffer, 3> + public pixfmt_alpha_blend_rgb<blender_rgb_gamma<rgba16, order_rgb, Gamma>, rendering_buffer> { public: pixfmt_rgb48_gamma(rendering_buffer& rb, const Gamma& g) : - pixfmt_alpha_blend_rgb<blender_rgb_gamma<rgba16, order_rgb, Gamma>, rendering_buffer, 3>(rb) + pixfmt_alpha_blend_rgb<blender_rgb_gamma<rgba16, order_rgb, Gamma>, rendering_buffer>(rb) { this->blender().gamma(g); } @@ -979,16 +852,17 @@ namespace agg //-----------------------------------------------------pixfmt_bgr48_gamma template<class Gamma> class pixfmt_bgr48_gamma : - public pixfmt_alpha_blend_rgb<blender_rgb_gamma<rgba16, order_bgr, Gamma>, rendering_buffer, 3> + public pixfmt_alpha_blend_rgb<blender_rgb_gamma<rgba16, order_bgr, Gamma>, rendering_buffer> { public: pixfmt_bgr48_gamma(rendering_buffer& rb, const Gamma& g) : - pixfmt_alpha_blend_rgb<blender_rgb_gamma<rgba16, order_bgr, Gamma>, rendering_buffer, 3>(rb) + pixfmt_alpha_blend_rgb<blender_rgb_gamma<rgba16, order_bgr, Gamma>, rendering_buffer>(rb) { this->blender().gamma(g); } }; - + + } #endif |