incubator-ooo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r1184758 [15/17] - in /incubator/ooo/trunk/main: ./ agg/inc/ agg/source/ solenv/config/
Date Sun, 16 Oct 2011 04:13:21 GMT
Modified: incubator/ooo/trunk/main/agg/inc/agg_span_image_filter_rgba.h
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/agg/inc/agg_span_image_filter_rgba.h?rev=1184758&r1=1184757&r2=1184758&view=diff
==============================================================================
--- incubator/ooo/trunk/main/agg/inc/agg_span_image_filter_rgba.h (original)
+++ incubator/ooo/trunk/main/agg/inc/agg_span_image_filter_rgba.h Sun Oct 16 04:13:16 2011
@@ -1,5 +1,5 @@
 //----------------------------------------------------------------------------
-// Anti-Grain Geometry - Version 2.3
+// 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 
@@ -20,10 +20,6 @@
 // PostScript and PDF technology for software developers.
 // 
 //----------------------------------------------------------------------------
-//
-// classes span_image_filter_rgba32*
-//
-//----------------------------------------------------------------------------
 #ifndef AGG_SPAN_IMAGE_FILTER_RGBA_INCLUDED
 #define AGG_SPAN_IMAGE_FILTER_RGBA_INCLUDED
 
@@ -35,149 +31,204 @@
 namespace agg
 {
 
-    //=============================================span_image_filter_rgba_nn
-    template<class ColorT,
-             class Order, 
-             class Interpolator,
-             class Allocator = span_allocator<ColorT> > 
+    //==============================================span_image_filter_rgba_nn
+    template<class Source, class Interpolator> 
     class span_image_filter_rgba_nn : 
-    public span_image_filter<ColorT, Interpolator, Allocator>
+    public span_image_filter<Source, Interpolator>
     {
     public:
-        typedef ColorT color_type;
-        typedef Order order_type;
+        typedef Source source_type;
+        typedef typename source_type::color_type color_type;
+        typedef typename source_type::order_type order_type;
         typedef Interpolator interpolator_type;
-        typedef Allocator alloc_type;
-        typedef span_image_filter<color_type, interpolator_type, alloc_type> base_type;
+        typedef span_image_filter<source_type, interpolator_type> base_type;
         typedef typename color_type::value_type value_type;
         typedef typename color_type::calc_type calc_type;
-        enum
+        enum base_scale_e
         {
             base_shift = color_type::base_shift,
             base_mask  = color_type::base_mask
         };
 
         //--------------------------------------------------------------------
-        span_image_filter_rgba_nn(alloc_type& alloc) : base_type(alloc) {}
+        span_image_filter_rgba_nn() {}
+        span_image_filter_rgba_nn(source_type& src, 
+                                  interpolator_type& inter) :
+            base_type(src, inter, 0) 
+        {}
 
         //--------------------------------------------------------------------
-        span_image_filter_rgba_nn(alloc_type& alloc,
-                                  const rendering_buffer& src, 
-                                  const color_type& back_color,
-                                  interpolator_type& inter) :
-            base_type(alloc, src, back_color, inter, 0) 
+        void generate(color_type* span, int x, int y, unsigned len)
+        {
+            base_type::interpolator().begin(x + base_type::filter_dx_dbl(), 
+                                            y + base_type::filter_dy_dbl(), len);
+            do
+            {
+                base_type::interpolator().coordinates(&x, &y);
+                const value_type* fg_ptr = (const value_type*)
+                    base_type::source().span(x >> image_subpixel_shift, 
+                                             y >> image_subpixel_shift, 
+                                             1);
+                span->r = fg_ptr[order_type::R];
+                span->g = fg_ptr[order_type::G];
+                span->b = fg_ptr[order_type::B];
+                span->a = fg_ptr[order_type::A];
+                ++span;
+                ++base_type::interpolator();
+
+            } while(--len);
+        }
+    };
+
+
+
+    //=========================================span_image_filter_rgba_bilinear
+    template<class Source, class Interpolator> 
+    class span_image_filter_rgba_bilinear : 
+    public span_image_filter<Source, Interpolator>
+    {
+    public:
+        typedef Source source_type;
+        typedef typename source_type::color_type color_type;
+        typedef typename source_type::order_type order_type;
+        typedef Interpolator interpolator_type;
+        typedef span_image_filter<source_type, interpolator_type> base_type;
+        typedef typename color_type::value_type value_type;
+        typedef typename color_type::calc_type calc_type;
+        enum base_scale_e
+        {
+            base_shift = color_type::base_shift,
+            base_mask  = color_type::base_mask
+        };
+
+        //--------------------------------------------------------------------
+        span_image_filter_rgba_bilinear() {}
+        span_image_filter_rgba_bilinear(source_type& src, 
+                                        interpolator_type& inter) :
+            base_type(src, inter, 0) 
         {}
 
+
         //--------------------------------------------------------------------
-        color_type* generate(int x, int y, unsigned len)
+        void generate(color_type* span, int x, int y, unsigned len)
         {
             base_type::interpolator().begin(x + base_type::filter_dx_dbl(), 
                                             y + base_type::filter_dy_dbl(), len);
 
             calc_type fg[4];
-
             const value_type *fg_ptr;
-            color_type* span = base_type::allocator().span();
-
-            int maxx = base_type::source_image().width() - 1;
-            int maxy = base_type::source_image().height() - 1;
 
             do
             {
-                base_type::interpolator().coordinates(&x, &y);
+                int x_hr;
+                int y_hr;
 
-                x >>= image_subpixel_shift;
-                y >>= image_subpixel_shift;
+                base_type::interpolator().coordinates(&x_hr, &y_hr);
 
-                if(x >= 0    && y >= 0 &&
-                   x <= maxx && y <= maxy) 
-                {
-                    fg_ptr = (const value_type*)base_type::source_image().row(y) + (x << 2);
-                    fg[0] = *fg_ptr++;
-                    fg[1] = *fg_ptr++;
-                    fg[2] = *fg_ptr++;
-                    fg[3] = *fg_ptr++;
-                }
-                else
-                {
-                   fg[order_type::R] = base_type::background_color().r;
-                   fg[order_type::G] = base_type::background_color().g;
-                   fg[order_type::B] = base_type::background_color().b;
-                   fg[order_type::A] = base_type::background_color().a;
-                }
+                x_hr -= base_type::filter_dx_int();
+                y_hr -= base_type::filter_dy_int();
+
+                int x_lr = x_hr >> image_subpixel_shift;
+                int y_lr = y_hr >> image_subpixel_shift;
+
+                unsigned weight;
+
+                fg[0] = 
+                fg[1] = 
+                fg[2] = 
+                fg[3] = image_subpixel_scale * image_subpixel_scale / 2;
+
+                x_hr &= image_subpixel_mask;
+                y_hr &= image_subpixel_mask;
+
+                fg_ptr = (const value_type*)base_type::source().span(x_lr, y_lr, 2);
+                weight = (image_subpixel_scale - x_hr) * 
+                         (image_subpixel_scale - y_hr);
+                fg[0] += weight * *fg_ptr++;
+                fg[1] += weight * *fg_ptr++;
+                fg[2] += weight * *fg_ptr++;
+                fg[3] += weight * *fg_ptr;
+
+                fg_ptr = (const value_type*)base_type::source().next_x();
+                weight = x_hr * (image_subpixel_scale - y_hr);
+                fg[0] += weight * *fg_ptr++;
+                fg[1] += weight * *fg_ptr++;
+                fg[2] += weight * *fg_ptr++;
+                fg[3] += weight * *fg_ptr;
+
+                fg_ptr = (const value_type*)base_type::source().next_y();
+                weight = (image_subpixel_scale - x_hr) * y_hr;
+                fg[0] += weight * *fg_ptr++;
+                fg[1] += weight * *fg_ptr++;
+                fg[2] += weight * *fg_ptr++;
+                fg[3] += weight * *fg_ptr;
+
+                fg_ptr = (const value_type*)base_type::source().next_x();
+                weight = x_hr * y_hr;
+                fg[0] += weight * *fg_ptr++;
+                fg[1] += weight * *fg_ptr++;
+                fg[2] += weight * *fg_ptr++;
+                fg[3] += weight * *fg_ptr;
+
+                span->r = value_type(fg[order_type::R] >> (image_subpixel_shift * 2));
+                span->g = value_type(fg[order_type::G] >> (image_subpixel_shift * 2));
+                span->b = value_type(fg[order_type::B] >> (image_subpixel_shift * 2));
+                span->a = value_type(fg[order_type::A] >> (image_subpixel_shift * 2));
 
-                span->r = fg[order_type::R];
-                span->g = fg[order_type::G];
-                span->b = fg[order_type::B];
-                span->a = fg[order_type::A];
                 ++span;
                 ++base_type::interpolator();
 
             } while(--len);
-
-            return base_type::allocator().span();
         }
-
     };
 
 
-
-
-
-
-
-    //=======================================span_image_filter_rgba_bilinear
-    template<class ColorT,
-             class Order, 
-             class Interpolator,
-             class Allocator = span_allocator<ColorT> > 
-    class span_image_filter_rgba_bilinear : 
-    public span_image_filter<ColorT, Interpolator, Allocator>
+    //====================================span_image_filter_rgba_bilinear_clip
+    template<class Source, class Interpolator> 
+    class span_image_filter_rgba_bilinear_clip : 
+    public span_image_filter<Source, Interpolator>
     {
     public:
-        typedef ColorT color_type;
-        typedef Order order_type;
+        typedef Source source_type;
+        typedef typename source_type::color_type color_type;
+        typedef typename source_type::order_type order_type;
         typedef Interpolator interpolator_type;
-        typedef Allocator alloc_type;
-        typedef span_image_filter<color_type, interpolator_type, alloc_type> base_type;
+        typedef span_image_filter<source_type, interpolator_type> base_type;
         typedef typename color_type::value_type value_type;
         typedef typename color_type::calc_type calc_type;
-        enum
+        enum base_scale_e
         {
             base_shift = color_type::base_shift,
             base_mask  = color_type::base_mask
         };
 
         //--------------------------------------------------------------------
-        span_image_filter_rgba_bilinear(alloc_type& alloc) : base_type(alloc) {}
-
-        //--------------------------------------------------------------------
-        span_image_filter_rgba_bilinear(alloc_type& alloc,
-                                        const rendering_buffer& src, 
-                                        const color_type& back_color,
-                                        interpolator_type& inter) :
-            base_type(alloc, src, back_color, inter, 0) 
+        span_image_filter_rgba_bilinear_clip() {}
+        span_image_filter_rgba_bilinear_clip(source_type& src, 
+                                             const color_type& back_color,
+                                             interpolator_type& inter) :
+            base_type(src, inter, 0),
+            m_back_color(back_color)
         {}
+        const color_type& background_color() const { return m_back_color; }
+        void background_color(const color_type& v)   { m_back_color = v; }
 
 
         //--------------------------------------------------------------------
-        color_type* generate(int x, int y, unsigned len)
+        void generate(color_type* span, int x, int y, unsigned len)
         {
             base_type::interpolator().begin(x + base_type::filter_dx_dbl(), 
                                             y + base_type::filter_dy_dbl(), len);
 
             calc_type fg[4];
-            value_type back_r = base_type::background_color().r;
-            value_type back_g = base_type::background_color().g;
-            value_type back_b = base_type::background_color().b;
-            value_type back_a = base_type::background_color().a;
+            value_type back_r = m_back_color.r;
+            value_type back_g = m_back_color.g;
+            value_type back_b = m_back_color.b;
+            value_type back_a = m_back_color.a;
 
             const value_type *fg_ptr;
-
-            color_type* span = base_type::allocator().span();
-
-            int maxx = base_type::source_image().width() - 1;
-            int maxy = base_type::source_image().height() - 1;
+            int maxx = base_type::source().width() - 1;
+            int maxy = base_type::source().height() - 1;
 
             do
             {
@@ -200,29 +251,32 @@ namespace agg
                     fg[0] = 
                     fg[1] = 
                     fg[2] = 
-                    fg[3] = image_subpixel_size * image_subpixel_size / 2;
+                    fg[3] = image_subpixel_scale * image_subpixel_scale / 2;
 
                     x_hr &= image_subpixel_mask;
                     y_hr &= image_subpixel_mask;
 
-                    fg_ptr = (const value_type*)base_type::source_image().row(y_lr) + (x_lr << 2);
+                    fg_ptr = (const value_type*)
+                        base_type::source().row_ptr(y_lr) + (x_lr << 2);
 
-                    weight = (image_subpixel_size - x_hr) * 
-                             (image_subpixel_size - y_hr);
+                    weight = (image_subpixel_scale - x_hr) * 
+                             (image_subpixel_scale - y_hr);
                     fg[0] += weight * *fg_ptr++;
                     fg[1] += weight * *fg_ptr++;
                     fg[2] += weight * *fg_ptr++;
                     fg[3] += weight * *fg_ptr++;
 
-                    weight = x_hr * (image_subpixel_size - y_hr);
+                    weight = x_hr * (image_subpixel_scale - y_hr);
                     fg[0] += weight * *fg_ptr++;
                     fg[1] += weight * *fg_ptr++;
                     fg[2] += weight * *fg_ptr++;
                     fg[3] += weight * *fg_ptr++;
 
-                    fg_ptr = (const value_type*)base_type::source_image().next_row(fg_ptr - 8);
+                    ++y_lr;
+                    fg_ptr = (const value_type*)
+                        base_type::source().row_ptr(y_lr) + (x_lr << 2);
 
-                    weight = (image_subpixel_size - x_hr) * y_hr;
+                    weight = (image_subpixel_scale - x_hr) * y_hr;
                     fg[0] += weight * *fg_ptr++;
                     fg[1] += weight * *fg_ptr++;
                     fg[2] += weight * *fg_ptr++;
@@ -254,17 +308,19 @@ namespace agg
                         fg[0] = 
                         fg[1] = 
                         fg[2] = 
-                        fg[3] = image_subpixel_size * image_subpixel_size / 2;
+                        fg[3] = image_subpixel_scale * image_subpixel_scale / 2;
 
                         x_hr &= image_subpixel_mask;
                         y_hr &= image_subpixel_mask;
 
-                        weight = (image_subpixel_size - x_hr) * 
-                                 (image_subpixel_size - y_hr);
+                        weight = (image_subpixel_scale - x_hr) * 
+                                 (image_subpixel_scale - y_hr);
                         if(x_lr >= 0    && y_lr >= 0 &&
                            x_lr <= maxx && y_lr <= maxy)
                         {
-                            fg_ptr = (const value_type*)base_type::source_image().row(y_lr) + (x_lr << 2);
+                            fg_ptr = (const value_type*)
+                                base_type::source().row_ptr(y_lr) + (x_lr << 2);
+
                             fg[0] += weight * *fg_ptr++;
                             fg[1] += weight * *fg_ptr++;
                             fg[2] += weight * *fg_ptr++;
@@ -280,11 +336,13 @@ namespace agg
 
                         x_lr++;
 
-                        weight = x_hr * (image_subpixel_size - y_hr);
+                        weight = x_hr * (image_subpixel_scale - y_hr);
                         if(x_lr >= 0    && y_lr >= 0 &&
                            x_lr <= maxx && y_lr <= maxy)
                         {
-                            fg_ptr = (const value_type*)base_type::source_image().row(y_lr) + (x_lr << 2);
+                            fg_ptr = (const value_type*)
+                                base_type::source().row_ptr(y_lr) + (x_lr << 2);
+
                             fg[0] += weight * *fg_ptr++;
                             fg[1] += weight * *fg_ptr++;
                             fg[2] += weight * *fg_ptr++;
@@ -301,11 +359,13 @@ namespace agg
                         x_lr--;
                         y_lr++;
 
-                        weight = (image_subpixel_size - x_hr) * y_hr;
+                        weight = (image_subpixel_scale - x_hr) * y_hr;
                         if(x_lr >= 0    && y_lr >= 0 &&
                            x_lr <= maxx && y_lr <= maxy)
                         {
-                            fg_ptr = (const value_type*)base_type::source_image().row(y_lr) + (x_lr << 2);
+                            fg_ptr = (const value_type*)
+                                base_type::source().row_ptr(y_lr) + (x_lr << 2);
+
                             fg[0] += weight * *fg_ptr++;
                             fg[1] += weight * *fg_ptr++;
                             fg[2] += weight * *fg_ptr++;
@@ -325,7 +385,9 @@ namespace agg
                         if(x_lr >= 0    && y_lr >= 0 &&
                            x_lr <= maxx && y_lr <= maxy)
                         {
-                            fg_ptr = (const value_type*)base_type::source_image().row(y_lr) + (x_lr << 2);
+                            fg_ptr = (const value_type*)
+                                base_type::source().row_ptr(y_lr) + (x_lr << 2);
+
                             fg[0] += weight * *fg_ptr++;
                             fg[1] += weight * *fg_ptr++;
                             fg[2] += weight * *fg_ptr++;
@@ -354,74 +416,53 @@ namespace agg
                 ++base_type::interpolator();
 
             } while(--len);
-
-            return base_type::allocator().span();
         }
+    private:
+        color_type m_back_color;
     };
 
 
-
-
-
-
-
-    //=======================================span_image_filter_rgba_2x2
-    template<class ColorT,
-             class Order, 
-             class Interpolator,
-             class Allocator = span_allocator<ColorT> > 
+    //==============================================span_image_filter_rgba_2x2
+    template<class Source, class Interpolator> 
     class span_image_filter_rgba_2x2 : 
-    public span_image_filter<ColorT, Interpolator, Allocator>
+    public span_image_filter<Source, Interpolator>
     {
     public:
-        typedef ColorT color_type;
-        typedef Order order_type;
+        typedef Source source_type;
+        typedef typename source_type::color_type color_type;
+        typedef typename source_type::order_type order_type;
         typedef Interpolator interpolator_type;
-        typedef Allocator alloc_type;
-        typedef span_image_filter<color_type, interpolator_type, alloc_type> base_type;
+        typedef span_image_filter<source_type, interpolator_type> base_type;
         typedef typename color_type::value_type value_type;
         typedef typename color_type::calc_type calc_type;
-        enum
+        enum base_scale_e
         {
             base_shift = color_type::base_shift,
             base_mask  = color_type::base_mask
         };
 
         //--------------------------------------------------------------------
-        span_image_filter_rgba_2x2(alloc_type& alloc) : base_type(alloc) {}
-
-        //--------------------------------------------------------------------
-        span_image_filter_rgba_2x2(alloc_type& alloc,
-                                   const rendering_buffer& src, 
-                                   const color_type& back_color,
+        span_image_filter_rgba_2x2() {}
+        span_image_filter_rgba_2x2(source_type& src, 
                                    interpolator_type& inter,
                                    const image_filter_lut& filter) :
-            base_type(alloc, src, back_color, inter, &filter) 
+            base_type(src, inter, &filter) 
         {}
 
 
         //--------------------------------------------------------------------
-        color_type* generate(int x, int y, unsigned len)
+        void generate(color_type* span, int x, int y, unsigned len)
         {
             base_type::interpolator().begin(x + base_type::filter_dx_dbl(), 
                                             y + base_type::filter_dy_dbl(), len);
 
             calc_type fg[4];
-            value_type back_r = base_type::background_color().r;
-            value_type back_g = base_type::background_color().g;
-            value_type back_b = base_type::background_color().b;
-            value_type back_a = base_type::background_color().a;
 
             const value_type *fg_ptr;
-
-            color_type* span = base_type::allocator().span();
             const int16* weight_array = base_type::filter().weight_array() + 
                                         ((base_type::filter().diameter()/2 - 1) << 
                                           image_subpixel_shift);
 
-            int maxx = base_type::source_image().width() - 1;
-            int maxy = base_type::source_image().height() - 1;
-
             do
             {
                 int x_hr;
@@ -436,181 +477,60 @@ namespace agg
                 int y_lr = y_hr >> image_subpixel_shift;
 
                 unsigned weight;
-                fg[0] = fg[1] = fg[2] = fg[3] = image_filter_size / 2;
-
-                if(x_lr >= 0    && y_lr >= 0 &&
-                   x_lr <  maxx && y_lr <  maxy) 
-                {
-                    x_hr &= image_subpixel_mask;
-                    y_hr &= image_subpixel_mask;
-
-                    fg_ptr = (const value_type*)base_type::source_image().row(y_lr) + (x_lr << 2);
-
-                    weight = (weight_array[x_hr + image_subpixel_size] * 
-                              weight_array[y_hr + image_subpixel_size] + 
-                              image_filter_size / 2) >> 
-                              image_filter_shift;
-                    fg[0] += weight * *fg_ptr++;
-                    fg[1] += weight * *fg_ptr++;
-                    fg[2] += weight * *fg_ptr++;
-                    fg[3] += weight * *fg_ptr++;
-
-                    weight = (weight_array[x_hr] * 
-                              weight_array[y_hr + image_subpixel_size] + 
-                              image_filter_size / 2) >> 
-                              image_filter_shift;
-                    fg[0] += weight * *fg_ptr++;
-                    fg[1] += weight * *fg_ptr++;
-                    fg[2] += weight * *fg_ptr++;
-                    fg[3] += weight * *fg_ptr++;
-
-                    fg_ptr = (const value_type*)base_type::source_image().next_row(fg_ptr - 8);
-
-                    weight = (weight_array[x_hr + image_subpixel_size] * 
-                              weight_array[y_hr] + 
-                              image_filter_size / 2) >> 
-                              image_filter_shift;
-                    fg[0] += weight * *fg_ptr++;
-                    fg[1] += weight * *fg_ptr++;
-                    fg[2] += weight * *fg_ptr++;
-                    fg[3] += weight * *fg_ptr++;
-
-                    weight = (weight_array[x_hr] * 
-                              weight_array[y_hr] + 
-                              image_filter_size / 2) >> 
-                              image_filter_shift;
-                    fg[0] += weight * *fg_ptr++;
-                    fg[1] += weight * *fg_ptr++;
-                    fg[2] += weight * *fg_ptr++;
-                    fg[3] += weight * *fg_ptr++;
-
-                    fg[0] >>= image_filter_shift;
-                    fg[1] >>= image_filter_shift;
-                    fg[2] >>= image_filter_shift;
-                    fg[3] >>= image_filter_shift;
-
-                    if(fg[order_type::A] > base_mask)         fg[order_type::A] = base_mask;
-                    if(fg[order_type::R] > fg[order_type::A]) fg[order_type::R] = fg[order_type::A];
-                    if(fg[order_type::G] > fg[order_type::A]) fg[order_type::G] = fg[order_type::A];
-                    if(fg[order_type::B] > fg[order_type::A]) fg[order_type::B] = fg[order_type::A];
-                }
-                else
-                {
-                    if(x_lr < -1   || y_lr < -1 ||
-                       x_lr > maxx || y_lr > maxy)
-                    {
-                        fg[order_type::R] = back_r;
-                        fg[order_type::G] = back_g;
-                        fg[order_type::B] = back_b;
-                        fg[order_type::A] = back_a;
-                    }
-                    else
-                    {
-                        x_hr &= image_subpixel_mask;
-                        y_hr &= image_subpixel_mask;
-
-                        weight = (weight_array[x_hr + image_subpixel_size] * 
-                                  weight_array[y_hr + image_subpixel_size] + 
-                                  image_filter_size / 2) >> 
-                                  image_filter_shift;
-                        if(x_lr >= 0    && y_lr >= 0 &&
-                           x_lr <= maxx && y_lr <= maxy)
-                        {
-                            fg_ptr = (const value_type*)base_type::source_image().row(y_lr) + (x_lr << 2);
-                            fg[0] += weight * *fg_ptr++;
-                            fg[1] += weight * *fg_ptr++;
-                            fg[2] += weight * *fg_ptr++;
-                            fg[3] += weight * *fg_ptr++;
-                        }
-                        else
-                        {
-                            fg[order_type::R] += back_r * weight;
-                            fg[order_type::G] += back_g * weight;
-                            fg[order_type::B] += back_b * weight;
-                            fg[order_type::A] += back_a * weight;
-                        }
-
-                        x_lr++;
-
-                        weight = (weight_array[x_hr] * 
-                                  weight_array[y_hr + image_subpixel_size] + 
-                                  image_filter_size / 2) >> 
-                                  image_filter_shift;
-                        if(x_lr >= 0    && y_lr >= 0 &&
-                           x_lr <= maxx && y_lr <= maxy)
-                        {
-                            fg_ptr = (const value_type*)base_type::source_image().row(y_lr) + (x_lr << 2);
-                            fg[0] += weight * *fg_ptr++;
-                            fg[1] += weight * *fg_ptr++;
-                            fg[2] += weight * *fg_ptr++;
-                            fg[3] += weight * *fg_ptr++;
-                        }
-                        else
-                        {
-                            fg[order_type::R] += back_r * weight;
-                            fg[order_type::G] += back_g * weight;
-                            fg[order_type::B] += back_b * weight;
-                            fg[order_type::A] += back_a * weight;
-                        }
-
-                        x_lr--;
-                        y_lr++;
+                fg[0] = fg[1] = fg[2] = fg[3] = image_filter_scale / 2;
 
-                        weight = (weight_array[x_hr + image_subpixel_size] * 
-                                  weight_array[y_hr] + 
-                                  image_filter_size / 2) >> 
-                                  image_filter_shift;
-                        if(x_lr >= 0    && y_lr >= 0 &&
-                           x_lr <= maxx && y_lr <= maxy)
-                        {
-                            fg_ptr = (const value_type*)base_type::source_image().row(y_lr) + (x_lr << 2);
-                            fg[0] += weight * *fg_ptr++;
-                            fg[1] += weight * *fg_ptr++;
-                            fg[2] += weight * *fg_ptr++;
-                            fg[3] += weight * *fg_ptr++;
-                        }
-                        else
-                        {
-                            fg[order_type::R] += back_r * weight;
-                            fg[order_type::G] += back_g * weight;
-                            fg[order_type::B] += back_b * weight;
-                            fg[order_type::A] += back_a * weight;
-                        }
-
-                        x_lr++;
-
-                        weight = (weight_array[x_hr] * 
-                                  weight_array[y_hr] + 
-                                  image_filter_size / 2) >> 
-                                  image_filter_shift;
-                        if(x_lr >= 0    && y_lr >= 0 &&
-                           x_lr <= maxx && y_lr <= maxy)
-                        {
-                            fg_ptr = (const value_type*)base_type::source_image().row(y_lr) + (x_lr << 2);
-                            fg[0] += weight * *fg_ptr++;
-                            fg[1] += weight * *fg_ptr++;
-                            fg[2] += weight * *fg_ptr++;
-                            fg[3] += weight * *fg_ptr++;
-                        }
-                        else
-                        {
-                            fg[order_type::R] += back_r * weight;
-                            fg[order_type::G] += back_g * weight;
-                            fg[order_type::B] += back_b * weight;
-                            fg[order_type::A] += back_a * weight;
-                        }
+                x_hr &= image_subpixel_mask;
+                y_hr &= image_subpixel_mask;
 
-                        fg[0] >>= image_filter_shift;
-                        fg[1] >>= image_filter_shift;
-                        fg[2] >>= image_filter_shift;
-                        fg[3] >>= image_filter_shift;
-
-                        if(fg[order_type::A] > base_mask)         fg[order_type::A] = base_mask;
-                        if(fg[order_type::R] > fg[order_type::A]) fg[order_type::R] = fg[order_type::A];
-                        if(fg[order_type::G] > fg[order_type::A]) fg[order_type::G] = fg[order_type::A];
-                        if(fg[order_type::B] > fg[order_type::A]) fg[order_type::B] = fg[order_type::A];
-                    }
-                }
+                fg_ptr = (const value_type*)base_type::source().span(x_lr, y_lr, 2);
+                weight = (weight_array[x_hr + image_subpixel_scale] * 
+                          weight_array[y_hr + image_subpixel_scale] + 
+                          image_filter_scale / 2) >> 
+                          image_filter_shift;
+                fg[0] += weight * *fg_ptr++;
+                fg[1] += weight * *fg_ptr++;
+                fg[2] += weight * *fg_ptr++;
+                fg[3] += weight * *fg_ptr;
+
+                fg_ptr = (const value_type*)base_type::source().next_x();
+                weight = (weight_array[x_hr] * 
+                          weight_array[y_hr + image_subpixel_scale] + 
+                          image_filter_scale / 2) >> 
+                          image_filter_shift;
+                fg[0] += weight * *fg_ptr++;
+                fg[1] += weight * *fg_ptr++;
+                fg[2] += weight * *fg_ptr++;
+                fg[3] += weight * *fg_ptr;
+
+                fg_ptr = (const value_type*)base_type::source().next_y();
+                weight = (weight_array[x_hr + image_subpixel_scale] * 
+                          weight_array[y_hr] + 
+                          image_filter_scale / 2) >> 
+                          image_filter_shift;
+                fg[0] += weight * *fg_ptr++;
+                fg[1] += weight * *fg_ptr++;
+                fg[2] += weight * *fg_ptr++;
+                fg[3] += weight * *fg_ptr;
+
+                fg_ptr = (const value_type*)base_type::source().next_x();
+                weight = (weight_array[x_hr] * 
+                          weight_array[y_hr] + 
+                          image_filter_scale / 2) >> 
+                          image_filter_shift;
+                fg[0] += weight * *fg_ptr++;
+                fg[1] += weight * *fg_ptr++;
+                fg[2] += weight * *fg_ptr++;
+                fg[3] += weight * *fg_ptr;
+
+                fg[0] >>= image_filter_shift;
+                fg[1] >>= image_filter_shift;
+                fg[2] >>= image_filter_shift;
+                fg[3] >>= image_filter_shift;
+
+                if(fg[order_type::A] > base_mask)         fg[order_type::A] = base_mask;
+                if(fg[order_type::R] > fg[order_type::A]) fg[order_type::R] = fg[order_type::A];
+                if(fg[order_type::G] > fg[order_type::A]) fg[order_type::G] = fg[order_type::A];
+                if(fg[order_type::B] > fg[order_type::A]) fg[order_type::B] = fg[order_type::A];
 
                 span->r = (value_type)fg[order_type::R];
                 span->g = (value_type)fg[order_type::G];
@@ -620,86 +540,51 @@ namespace agg
                 ++base_type::interpolator();
 
             } while(--len);
-
-            return base_type::allocator().span();
         }
     };
 
 
 
-
-
-
-
-
-
-
-
-
-
-    //================================================span_image_filter_rgba
-    template<class ColorT,
-             class Order, 
-             class Interpolator,
-             class Allocator = span_allocator<ColorT> > 
+    //==================================================span_image_filter_rgba
+    template<class Source, class Interpolator> 
     class span_image_filter_rgba : 
-    public span_image_filter<ColorT, Interpolator, Allocator>
+    public span_image_filter<Source, Interpolator>
     {
     public:
-        typedef ColorT color_type;
-        typedef Order order_type;
+        typedef Source source_type;
+        typedef typename source_type::color_type color_type;
+        typedef typename source_type::order_type order_type;
         typedef Interpolator interpolator_type;
-        typedef Allocator alloc_type;
-        typedef span_image_filter<color_type, interpolator_type, alloc_type> base_type;
+        typedef span_image_filter<source_type, interpolator_type> base_type;
         typedef typename color_type::value_type value_type;
         typedef typename color_type::calc_type calc_type;
-        enum
+        enum base_scale_e
         {
             base_shift = color_type::base_shift,
             base_mask  = color_type::base_mask
         };
 
         //--------------------------------------------------------------------
-        span_image_filter_rgba(alloc_type& alloc) : base_type(alloc) {}
-
-        //--------------------------------------------------------------------
-        span_image_filter_rgba(alloc_type& alloc,
-                               const rendering_buffer& src, 
-                               const color_type& back_color,
+        span_image_filter_rgba() {}
+        span_image_filter_rgba(source_type& src, 
                                interpolator_type& inter,
                                const image_filter_lut& filter) :
-            base_type(alloc, src, back_color, inter, &filter) 
+            base_type(src, inter, &filter) 
         {}
 
         //--------------------------------------------------------------------
-        color_type* generate(int x, int y, unsigned len)
+        void generate(color_type* span, int x, int y, unsigned len)
         {
             base_type::interpolator().begin(x + base_type::filter_dx_dbl(), 
                                             y + base_type::filter_dy_dbl(), len);
 
             int fg[4];
-
-            value_type back_r = base_type::background_color().r;
-            value_type back_g = base_type::background_color().g;
-            value_type back_b = base_type::background_color().b;
-            value_type back_a = base_type::background_color().a;
-
             const value_type *fg_ptr;
 
-            unsigned   diameter     = base_type::filter().diameter();
-            int        start        = base_type::filter().start();
-            int        start1       = start - 1;
+            unsigned     diameter     = base_type::filter().diameter();
+            int          start        = base_type::filter().start();
             const int16* weight_array = base_type::filter().weight_array();
 
-            unsigned step_back = diameter << 2;
-            color_type* span = base_type::allocator().span();
-
-            int maxx = base_type::source_image().width() + start - 2;
-            int maxy = base_type::source_image().height() + start - 2;
-
-            int maxx2 = base_type::source_image().width() - start - 1;
-            int maxy2 = base_type::source_image().height() - start - 1;
-
             int x_count; 
             int weight_y;
 
@@ -716,142 +601,313 @@ namespace agg
                 int x_lr = x_hr >> image_subpixel_shift;
                 int y_lr = y_hr >> image_subpixel_shift;
 
-                fg[0] = fg[1] = fg[2] = fg[3] = image_filter_size / 2;
+                fg[0] = fg[1] = fg[2] = fg[3] = image_filter_scale / 2;
 
                 int x_fract = x_hr & image_subpixel_mask;
                 unsigned y_count = diameter;
 
-                if(x_lr >= -start && y_lr >= -start &&
-                   x_lr <= maxx   && y_lr <= maxy) 
+                y_hr = image_subpixel_mask - (y_hr & image_subpixel_mask);
+                fg_ptr = (const value_type*)base_type::source().span(x_lr + start, 
+                                                                     y_lr + start, 
+                                                                     diameter);
+                for(;;)
                 {
-                    y_hr = image_subpixel_mask - (y_hr & image_subpixel_mask);
-                    fg_ptr = (const value_type*)base_type::source_image().row(y_lr + start) + ((x_lr + start) << 2);
-                    do
+                    x_count  = diameter;
+                    weight_y = weight_array[y_hr];
+                    x_hr = image_subpixel_mask - x_fract;
+                    for(;;)
                     {
-                        x_count = diameter;
-                        weight_y = weight_array[y_hr];
-                        x_hr = image_subpixel_mask - x_fract;
+                        int weight = (weight_y * weight_array[x_hr] + 
+                                     image_filter_scale / 2) >> 
+                                     image_filter_shift;
+
+                        fg[0] += weight * *fg_ptr++;
+                        fg[1] += weight * *fg_ptr++;
+                        fg[2] += weight * *fg_ptr++;
+                        fg[3] += weight * *fg_ptr;
+
+                        if(--x_count == 0) break;
+                        x_hr  += image_subpixel_scale;
+                        fg_ptr = (const value_type*)base_type::source().next_x();
+                    }
 
-                        do
-                        {
-                            int weight = (weight_y * weight_array[x_hr] + 
-                                         image_filter_size / 2) >> 
-                                         image_filter_shift;
-            
-                            fg[0] += *fg_ptr++ * weight;
-                            fg[1] += *fg_ptr++ * weight;
-                            fg[2] += *fg_ptr++ * weight;
-                            fg[3] += *fg_ptr++ * weight;
-
-                            x_hr += image_subpixel_size;
-
-                        } while(--x_count);
-
-                        y_hr += image_subpixel_size;
-                        fg_ptr = (const value_type*)base_type::source_image().next_row(fg_ptr - step_back);
-
-                    } while(--y_count);
-
-                    fg[0] >>= image_filter_shift;
-                    fg[1] >>= image_filter_shift;
-                    fg[2] >>= image_filter_shift;
-                    fg[3] >>= image_filter_shift;
-
-                    if(fg[0] < 0) fg[0] = 0;
-                    if(fg[1] < 0) fg[1] = 0;
-                    if(fg[2] < 0) fg[2] = 0;
-                    if(fg[3] < 0) fg[3] = 0;
-
-                    if(fg[order_type::A] > base_mask)         fg[order_type::A] = base_mask;
-                    if(fg[order_type::R] > fg[order_type::A]) fg[order_type::R] = fg[order_type::A];
-                    if(fg[order_type::G] > fg[order_type::A]) fg[order_type::G] = fg[order_type::A];
-                    if(fg[order_type::B] > fg[order_type::A]) fg[order_type::B] = fg[order_type::A];
+                    if(--y_count == 0) break;
+                    y_hr  += image_subpixel_scale;
+                    fg_ptr = (const value_type*)base_type::source().next_y();
                 }
-                else
+
+                fg[0] >>= image_filter_shift;
+                fg[1] >>= image_filter_shift;
+                fg[2] >>= image_filter_shift;
+                fg[3] >>= image_filter_shift;
+
+                if(fg[0] < 0) fg[0] = 0;
+                if(fg[1] < 0) fg[1] = 0;
+                if(fg[2] < 0) fg[2] = 0;
+                if(fg[3] < 0) fg[3] = 0;
+
+                if(fg[order_type::A] > base_mask)         fg[order_type::A] = base_mask;
+                if(fg[order_type::R] > fg[order_type::A]) fg[order_type::R] = fg[order_type::A];
+                if(fg[order_type::G] > fg[order_type::A]) fg[order_type::G] = fg[order_type::A];
+                if(fg[order_type::B] > fg[order_type::A]) fg[order_type::B] = fg[order_type::A];
+
+                span->r = (value_type)fg[order_type::R];
+                span->g = (value_type)fg[order_type::G];
+                span->b = (value_type)fg[order_type::B];
+                span->a = (value_type)fg[order_type::A];
+                ++span;
+                ++base_type::interpolator();
+
+            } while(--len);
+        }
+    };
+
+
+
+    //========================================span_image_resample_rgba_affine
+    template<class Source> 
+    class span_image_resample_rgba_affine : 
+    public span_image_resample_affine<Source>
+    {
+    public:
+        typedef Source source_type;
+        typedef typename source_type::color_type color_type;
+        typedef typename source_type::order_type order_type;
+        typedef span_image_resample_affine<source_type> base_type;
+        typedef typename base_type::interpolator_type interpolator_type;
+        typedef typename color_type::value_type value_type;
+        typedef typename color_type::long_type long_type;
+        enum base_scale_e
+        {
+            base_shift      = color_type::base_shift,
+            base_mask       = color_type::base_mask,
+            downscale_shift = image_filter_shift
+        };
+
+        //--------------------------------------------------------------------
+        span_image_resample_rgba_affine() {}
+        span_image_resample_rgba_affine(source_type& src, 
+                                        interpolator_type& inter,
+                                        const image_filter_lut& filter) :
+            base_type(src, inter, filter) 
+        {}
+
+
+        //--------------------------------------------------------------------
+        void generate(color_type* span, int x, int y, unsigned len)
+        {
+            base_type::interpolator().begin(x + base_type::filter_dx_dbl(), 
+                                            y + base_type::filter_dy_dbl(), len);
+
+            long_type fg[4];
+
+            int diameter     = base_type::filter().diameter();
+            int filter_scale = diameter << image_subpixel_shift;
+            int radius_x     = (diameter * base_type::m_rx) >> 1;
+            int radius_y     = (diameter * base_type::m_ry) >> 1;
+            int len_x_lr     = 
+                (diameter * base_type::m_rx + image_subpixel_mask) >> 
+                    image_subpixel_shift;
+
+            const int16* weight_array = base_type::filter().weight_array();
+
+            do
+            {
+                base_type::interpolator().coordinates(&x, &y);
+
+                x += base_type::filter_dx_int() - radius_x;
+                y += base_type::filter_dy_int() - radius_y;
+
+                fg[0] = fg[1] = fg[2] = fg[3] = image_filter_scale / 2;
+
+                int y_lr = y >> image_subpixel_shift;
+                int y_hr = ((image_subpixel_mask - (y & image_subpixel_mask)) * 
+                                base_type::m_ry_inv) >> 
+                                    image_subpixel_shift;
+                int total_weight = 0;
+                int x_lr = x >> image_subpixel_shift;
+                int x_hr = ((image_subpixel_mask - (x & image_subpixel_mask)) * 
+                                base_type::m_rx_inv) >> 
+                                    image_subpixel_shift;
+
+                int x_hr2 = x_hr;
+                const value_type* fg_ptr = 
+                    (const value_type*)base_type::source().span(x_lr, y_lr, len_x_lr);
+                for(;;)
                 {
-                    if(x_lr < start1 || y_lr < start1 ||
-                       x_lr > maxx2  || y_lr > maxy2) 
+                    int weight_y = weight_array[y_hr];
+                    x_hr = x_hr2;
+                    for(;;)
                     {
-                        fg[order_type::R] = back_r;
-                        fg[order_type::G] = back_g;
-                        fg[order_type::B] = back_b;
-                        fg[order_type::A] = back_a;
+                        int weight = (weight_y * weight_array[x_hr] + 
+                                     image_filter_scale / 2) >> 
+                                     downscale_shift;
+
+                        fg[0] += *fg_ptr++ * weight;
+                        fg[1] += *fg_ptr++ * weight;
+                        fg[2] += *fg_ptr++ * weight;
+                        fg[3] += *fg_ptr++ * weight;
+                        total_weight += weight;
+                        x_hr  += base_type::m_rx_inv;
+                        if(x_hr >= filter_scale) break;
+                        fg_ptr = (const value_type*)base_type::source().next_x();
                     }
-                    else
-                    {
-                        y_lr = (y >> image_subpixel_shift) + start;
-                        y_hr = image_subpixel_mask - (y_hr & image_subpixel_mask);
+                    y_hr += base_type::m_ry_inv;
+                    if(y_hr >= filter_scale) break;
+                    fg_ptr = (const value_type*)base_type::source().next_y();
+                }
 
-                        do
-                        {
-                            x_count = diameter;
-                            weight_y = weight_array[y_hr];
-                            x_lr = (x >> image_subpixel_shift) + start;
-                            x_hr = image_subpixel_mask - x_fract;
-
-                            do
-                            {
-                                int weight = (weight_y * weight_array[x_hr] + 
-                                             image_filter_size / 2) >> 
-                                             image_filter_shift;
-
-                                if(x_lr >= 0 && y_lr >= 0 && 
-                                   x_lr < int(base_type::source_image().width()) && 
-                                   y_lr < int(base_type::source_image().height()))
-                                {
-                                    fg_ptr = (const value_type*)base_type::source_image().row(y_lr) + (x_lr << 2);
-                                    fg[0] += *fg_ptr++ * weight;
-                                    fg[1] += *fg_ptr++ * weight;
-                                    fg[2] += *fg_ptr++ * weight;
-                                    fg[3] += *fg_ptr++ * weight;
-                                }
-                                else
-                                {
-                                    fg[order_type::R] += back_r * weight;
-                                    fg[order_type::G] += back_g * weight;
-                                    fg[order_type::B] += back_b * weight;
-                                    fg[order_type::A] += back_a * weight;
-                                }
-                                x_hr += image_subpixel_size;
-                                x_lr++;
-
-                            } while(--x_count);
-
-                            y_hr += image_subpixel_size;
-                            y_lr++;
-
-                        } while(--y_count);
-
-
-                        fg[0] >>= image_filter_shift;
-                        fg[1] >>= image_filter_shift;
-                        fg[2] >>= image_filter_shift;
-                        fg[3] >>= image_filter_shift;
-
-                        if(fg[0] < 0) fg[0] = 0;
-                        if(fg[1] < 0) fg[1] = 0;
-                        if(fg[2] < 0) fg[2] = 0;
-                        if(fg[3] < 0) fg[3] = 0;
-
-                        if(fg[order_type::A] > base_mask)         fg[order_type::A] = base_mask;
-                        if(fg[order_type::R] > fg[order_type::A]) fg[order_type::R] = fg[order_type::A];
-                        if(fg[order_type::G] > fg[order_type::A]) fg[order_type::G] = fg[order_type::A];
-                        if(fg[order_type::B] > fg[order_type::A]) fg[order_type::B] = fg[order_type::A];
+                fg[0] /= total_weight;
+                fg[1] /= total_weight;
+                fg[2] /= total_weight;
+                fg[3] /= total_weight;
+
+                if(fg[0] < 0) fg[0] = 0;
+                if(fg[1] < 0) fg[1] = 0;
+                if(fg[2] < 0) fg[2] = 0;
+                if(fg[3] < 0) fg[3] = 0;
+
+                if(fg[order_type::A] > base_mask)         fg[order_type::A] = base_mask;
+                if(fg[order_type::R] > fg[order_type::A]) fg[order_type::R] = fg[order_type::A];
+                if(fg[order_type::G] > fg[order_type::A]) fg[order_type::G] = fg[order_type::A];
+                if(fg[order_type::B] > fg[order_type::A]) fg[order_type::B] = fg[order_type::A];
+
+                span->r = (value_type)fg[order_type::R];
+                span->g = (value_type)fg[order_type::G];
+                span->b = (value_type)fg[order_type::B];
+                span->a = (value_type)fg[order_type::A];
+
+                ++span;
+                ++base_type::interpolator();
+            } while(--len);
+        }
+    };
+
+
+
+    //==============================================span_image_resample_rgba
+    template<class Source, class Interpolator>
+    class span_image_resample_rgba : 
+    public span_image_resample<Source, Interpolator>
+    {
+    public:
+        typedef Source source_type;
+        typedef typename source_type::color_type color_type;
+        typedef typename source_type::order_type order_type;
+        typedef Interpolator interpolator_type;
+        typedef span_image_resample<source_type, interpolator_type> base_type;
+        typedef typename color_type::value_type value_type;
+        typedef typename color_type::long_type long_type;
+        enum base_scale_e
+        {
+            base_shift = color_type::base_shift,
+            base_mask  = color_type::base_mask,
+            downscale_shift = image_filter_shift
+        };
+
+        //--------------------------------------------------------------------
+        span_image_resample_rgba() {}
+        span_image_resample_rgba(source_type& src, 
+                                 interpolator_type& inter,
+                                 const image_filter_lut& filter) :
+            base_type(src, inter, filter)
+        {}
+
+        //--------------------------------------------------------------------
+        void generate(color_type* span, int x, int y, unsigned len)
+        {
+            base_type::interpolator().begin(x + base_type::filter_dx_dbl(), 
+                                            y + base_type::filter_dy_dbl(), len);
+            long_type fg[4];
+
+            int diameter = base_type::filter().diameter();
+            int filter_scale = diameter << image_subpixel_shift;
+
+            const int16* weight_array = base_type::filter().weight_array();
+            do
+            {
+                int rx;
+                int ry;
+                int rx_inv = image_subpixel_scale;
+                int ry_inv = image_subpixel_scale;
+                base_type::interpolator().coordinates(&x,  &y);
+                base_type::interpolator().local_scale(&rx, &ry);
+                base_type::adjust_scale(&rx, &ry);
+
+                rx_inv = image_subpixel_scale * image_subpixel_scale / rx;
+                ry_inv = image_subpixel_scale * image_subpixel_scale / ry;
+
+                int radius_x = (diameter * rx) >> 1;
+                int radius_y = (diameter * ry) >> 1;
+                int len_x_lr = 
+                    (diameter * rx + image_subpixel_mask) >> 
+                        image_subpixel_shift;
+
+                x += base_type::filter_dx_int() - radius_x;
+                y += base_type::filter_dy_int() - radius_y;
+
+                fg[0] = fg[1] = fg[2] = fg[3] = image_filter_scale / 2;
+
+                int y_lr = y >> image_subpixel_shift;
+                int y_hr = ((image_subpixel_mask - (y & image_subpixel_mask)) * 
+                               ry_inv) >> 
+                                   image_subpixel_shift;
+                int total_weight = 0;
+                int x_lr = x >> image_subpixel_shift;
+                int x_hr = ((image_subpixel_mask - (x & image_subpixel_mask)) * 
+                               rx_inv) >> 
+                                   image_subpixel_shift;
+                int x_hr2 = x_hr;
+                const value_type* fg_ptr = 
+                    (const value_type*)base_type::source().span(x_lr, y_lr, len_x_lr);
+
+                for(;;)
+                {
+                    int weight_y = weight_array[y_hr];
+                    x_hr = x_hr2;
+                    for(;;)
+                    {
+                        int weight = (weight_y * weight_array[x_hr] + 
+                                     image_filter_scale / 2) >> 
+                                     downscale_shift;
+                        fg[0] += *fg_ptr++ * weight;
+                        fg[1] += *fg_ptr++ * weight;
+                        fg[2] += *fg_ptr++ * weight;
+                        fg[3] += *fg_ptr++ * weight;
+                        total_weight += weight;
+                        x_hr  += rx_inv;
+                        if(x_hr >= filter_scale) break;
+                        fg_ptr = (const value_type*)base_type::source().next_x();
                     }
+                    y_hr += ry_inv;
+                    if(y_hr >= filter_scale) break;
+                    fg_ptr = (const value_type*)base_type::source().next_y();
                 }
 
-                span->r = fg[order_type::R];
-                span->g = fg[order_type::G];
-                span->b = fg[order_type::B];
-                span->a = fg[order_type::A];
+                fg[0] /= total_weight;
+                fg[1] /= total_weight;
+                fg[2] /= total_weight;
+                fg[3] /= total_weight;
+
+                if(fg[0] < 0) fg[0] = 0;
+                if(fg[1] < 0) fg[1] = 0;
+                if(fg[2] < 0) fg[2] = 0;
+                if(fg[3] < 0) fg[3] = 0;
+
+                if(fg[order_type::A] > base_mask)         fg[order_type::A] = base_mask;
+                if(fg[order_type::R] > fg[order_type::R]) fg[order_type::R] = fg[order_type::R];
+                if(fg[order_type::G] > fg[order_type::G]) fg[order_type::G] = fg[order_type::G];
+                if(fg[order_type::B] > fg[order_type::B]) fg[order_type::B] = fg[order_type::B];
+
+                span->r = (value_type)fg[order_type::R];
+                span->g = (value_type)fg[order_type::G];
+                span->b = (value_type)fg[order_type::B];
+                span->a = (value_type)fg[order_type::A];
+
                 ++span;
                 ++base_type::interpolator();
-
             } while(--len);
-
-            return base_type::allocator().span();
         }
-
     };
 
 

Modified: incubator/ooo/trunk/main/agg/inc/agg_span_interpolator_adaptor.h
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/agg/inc/agg_span_interpolator_adaptor.h?rev=1184758&r1=1184757&r2=1184758&view=diff
==============================================================================
--- incubator/ooo/trunk/main/agg/inc/agg_span_interpolator_adaptor.h (original)
+++ incubator/ooo/trunk/main/agg/inc/agg_span_interpolator_adaptor.h Sun Oct 16 04:13:16 2011
@@ -1,5 +1,5 @@
 //----------------------------------------------------------------------------
-// Anti-Grain Geometry - Version 2.3
+// 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 

Modified: incubator/ooo/trunk/main/agg/inc/agg_span_interpolator_linear.h
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/agg/inc/agg_span_interpolator_linear.h?rev=1184758&r1=1184757&r2=1184758&view=diff
==============================================================================
--- incubator/ooo/trunk/main/agg/inc/agg_span_interpolator_linear.h (original)
+++ incubator/ooo/trunk/main/agg/inc/agg_span_interpolator_linear.h Sun Oct 16 04:13:16 2011
@@ -1,5 +1,5 @@
 //----------------------------------------------------------------------------
-// Anti-Grain Geometry - Version 2.3
+// 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 
@@ -30,10 +30,10 @@ namespace agg
     public:
         typedef Transformer trans_type;
 
-        enum
+        enum subpixel_scale_e
         {
             subpixel_shift = SubpixelShift,
-            subpixel_size  = 1 << subpixel_shift
+            subpixel_scale  = 1 << subpixel_shift
         };
 
         //--------------------------------------------------------------------
@@ -59,14 +59,14 @@ namespace agg
             tx = x;
             ty = y;
             m_trans->transform(&tx, &ty);
-            int x1 = int(tx * subpixel_size);
-            int y1 = int(ty * subpixel_size);
+            int x1 = iround(tx * subpixel_scale);
+            int y1 = iround(ty * subpixel_scale);
 
             tx = x + len;
             ty = y;
             m_trans->transform(&tx, &ty);
-            int x2 = int(tx * subpixel_size);
-            int y2 = int(ty * subpixel_size);
+            int x2 = iround(tx * subpixel_scale);
+            int y2 = iround(ty * subpixel_scale);
 
             m_li_x = dda2_line_interpolator(x1, x2, len);
             m_li_y = dda2_line_interpolator(y1, y2, len);
@@ -76,8 +76,8 @@ namespace agg
         void resynchronize(double xe, double ye, unsigned len)
         {
             m_trans->transform(&xe, &ye);
-            m_li_x = dda2_line_interpolator(m_li_x.y(), int(xe * subpixel_size), len);
-            m_li_y = dda2_line_interpolator(m_li_y.y(), int(ye * subpixel_size), len);
+            m_li_x = dda2_line_interpolator(m_li_x.y(), iround(xe * subpixel_scale), len);
+            m_li_y = dda2_line_interpolator(m_li_y.y(), iround(ye * subpixel_scale), len);
         }
     
         //----------------------------------------------------------------
@@ -112,10 +112,10 @@ namespace agg
     public:
         typedef Transformer trans_type;
 
-        enum
+        enum subpixel_scale_e
         {
             subpixel_shift = SubpixelShift,
-            subpixel_size  = 1 << subpixel_shift
+            subpixel_scale = 1 << subpixel_shift
         };
 
 
@@ -162,7 +162,7 @@ namespace agg
             double tx;
             double ty;
             m_pos   = 1;
-            m_src_x = int(x * subpixel_size) + subpixel_size;
+            m_src_x = iround(x * subpixel_scale) + subpixel_scale;
             m_src_y = y;
             m_len   = len;
 
@@ -170,15 +170,15 @@ namespace agg
             tx = x;
             ty = y;
             m_trans->transform(&tx, &ty);
-            int x1 = int(tx * subpixel_size);
-            int y1 = int(ty * subpixel_size);
+            int x1 = iround(tx * subpixel_scale);
+            int y1 = iround(ty * subpixel_scale);
 
             tx = x + len;
             ty = y;
             m_trans->transform(&tx, &ty);
 
-            m_li_x = dda2_line_interpolator(x1, int(tx * subpixel_size), len);
-            m_li_y = dda2_line_interpolator(y1, int(ty * subpixel_size), len);
+            m_li_x = dda2_line_interpolator(x1, iround(tx * subpixel_scale), len);
+            m_li_y = dda2_line_interpolator(y1, iround(ty * subpixel_scale), len);
         }
 
         //----------------------------------------------------------------
@@ -190,14 +190,14 @@ namespace agg
             {
                 unsigned len = m_len;
                 if(len > m_subdiv_size) len = m_subdiv_size;
-                double tx = double(m_src_x) / double(subpixel_size) + len;
+                double tx = double(m_src_x) / double(subpixel_scale) + len;
                 double ty = m_src_y;
                 m_trans->transform(&tx, &ty);
-                m_li_x = dda2_line_interpolator(m_li_x.y(), int(tx * subpixel_size), len);
-                m_li_y = dda2_line_interpolator(m_li_y.y(), int(ty * subpixel_size), len);
+                m_li_x = dda2_line_interpolator(m_li_x.y(), iround(tx * subpixel_scale), len);
+                m_li_y = dda2_line_interpolator(m_li_y.y(), iround(ty * subpixel_scale), len);
                 m_pos = 0;
             }
-            m_src_x += subpixel_size;
+            m_src_x += subpixel_scale;
             ++m_pos;
             --m_len;
         }

Modified: incubator/ooo/trunk/main/agg/inc/agg_span_interpolator_persp.h
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/agg/inc/agg_span_interpolator_persp.h?rev=1184758&r1=1184757&r2=1184758&view=diff
==============================================================================
--- incubator/ooo/trunk/main/agg/inc/agg_span_interpolator_persp.h (original)
+++ incubator/ooo/trunk/main/agg/inc/agg_span_interpolator_persp.h Sun Oct 16 04:13:16 2011
@@ -1,5 +1,5 @@
 //----------------------------------------------------------------------------
-// Anti-Grain Geometry - Version 2.3
+// 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 
@@ -30,10 +30,10 @@ namespace agg
     public:
         typedef trans_perspective trans_type;
         typedef trans_perspective::iterator_x iterator_type;
-        enum
+        enum subpixel_scale_e
         {
             subpixel_shift = SubpixelShift,
-            subpixel_size  = 1 << subpixel_shift
+            subpixel_scale = 1 << subpixel_shift
         };
 
         //--------------------------------------------------------------------
@@ -112,19 +112,19 @@ namespace agg
 
             double dx;
             double dy;
-            const double delta = 1/double(subpixel_size);
+            const double delta = 1/double(subpixel_scale);
             dx = xt + delta;
             dy = yt;
             m_trans_inv.transform(&dx, &dy);
             dx -= x;
             dy -= y;
-            int sx1 = int(subpixel_size/sqrt(dx*dx + dy*dy)) >> subpixel_shift;
+            int sx1 = uround(subpixel_scale/sqrt(dx*dx + dy*dy)) >> subpixel_shift;
             dx = xt;
             dy = yt + delta;
             m_trans_inv.transform(&dx, &dy);
             dx -= x;
             dy -= y;
-            int sy1 = int(subpixel_size/sqrt(dx*dx + dy*dy)) >> subpixel_shift;
+            int sy1 = uround(subpixel_scale/sqrt(dx*dx + dy*dy)) >> subpixel_shift;
 
             x += len;
             xt = x;
@@ -136,13 +136,13 @@ namespace agg
             m_trans_inv.transform(&dx, &dy);
             dx -= x;
             dy -= y;
-            int sx2 = int(subpixel_size/sqrt(dx*dx + dy*dy)) >> subpixel_shift;
+            int sx2 = uround(subpixel_scale/sqrt(dx*dx + dy*dy)) >> subpixel_shift;
             dx = xt;
             dy = yt + delta;
             m_trans_inv.transform(&dx, &dy);
             dx -= x;
             dy -= y;
-            int sy2 = int(subpixel_size/sqrt(dx*dx + dy*dy)) >> subpixel_shift;
+            int sy2 = uround(subpixel_scale/sqrt(dx*dx + dy*dy)) >> subpixel_shift;
 
             m_scale_x = dda2_line_interpolator(sx1, sx2, len);
             m_scale_y = dda2_line_interpolator(sy1, sy2, len);
@@ -161,7 +161,7 @@ namespace agg
             double yt = ye;
             m_trans_dir.transform(&xt, &yt);
 
-            const double delta = 1/double(subpixel_size);
+            const double delta = 1/double(subpixel_scale);
             double dx;
             double dy;
 
@@ -171,7 +171,7 @@ namespace agg
             m_trans_inv.transform(&dx, &dy);
             dx -= xe;
             dy -= ye;
-            int sx2 = int(subpixel_size/sqrt(dx*dx + dy*dy)) >> subpixel_shift;
+            int sx2 = uround(subpixel_scale/sqrt(dx*dx + dy*dy)) >> subpixel_shift;
 
             // Calculate scale by Y at x2,y2
             dx = xt;
@@ -179,7 +179,7 @@ namespace agg
             m_trans_inv.transform(&dx, &dy);
             dx -= xe;
             dy -= ye;
-            int sy2 = int(subpixel_size/sqrt(dx*dx + dy*dy)) >> subpixel_shift;
+            int sy2 = uround(subpixel_scale/sqrt(dx*dx + dy*dy)) >> subpixel_shift;
 
             // Initialize the interpolators
             m_scale_x = dda2_line_interpolator(sx1, sx2, len);
@@ -199,8 +199,8 @@ namespace agg
         //----------------------------------------------------------------
         void coordinates(int* x, int* y) const
         {
-            *x = int(m_iterator.x * subpixel_size + 0.5);
-            *y = int(m_iterator.y * subpixel_size + 0.5);
+            *x = iround(m_iterator.x * subpixel_scale);
+            *y = iround(m_iterator.y * subpixel_scale);
         }
 
         //----------------------------------------------------------------
@@ -240,10 +240,10 @@ namespace agg
     {
     public:
         typedef trans_perspective trans_type;
-        enum
+        enum subpixel_scale_e
         {
             subpixel_shift = SubpixelShift,
-            subpixel_size  = 1 << subpixel_shift
+            subpixel_scale = 1 << subpixel_shift
         };
 
         //--------------------------------------------------------------------
@@ -320,12 +320,12 @@ namespace agg
             double xt = x;
             double yt = y;
             m_trans_dir.transform(&xt, &yt);
-            int x1 = int(xt * subpixel_size);
-            int y1 = int(yt * subpixel_size);
+            int x1 = iround(xt * subpixel_scale);
+            int y1 = iround(yt * subpixel_scale);
 
             double dx;
             double dy;
-            const double delta = 1/double(subpixel_size);
+            const double delta = 1/double(subpixel_scale);
 
             // Calculate scale by X at x1,y1
             dx = xt + delta;
@@ -333,7 +333,7 @@ namespace agg
             m_trans_inv.transform(&dx, &dy);
             dx -= x;
             dy -= y;
-            int sx1 = int(subpixel_size/sqrt(dx*dx + dy*dy)) >> subpixel_shift;
+            int sx1 = uround(subpixel_scale/sqrt(dx*dx + dy*dy)) >> subpixel_shift;
 
             // Calculate scale by Y at x1,y1
             dx = xt;
@@ -341,15 +341,15 @@ namespace agg
             m_trans_inv.transform(&dx, &dy);
             dx -= x;
             dy -= y;
-            int sy1 = int(subpixel_size/sqrt(dx*dx + dy*dy)) >> subpixel_shift;
+            int sy1 = uround(subpixel_scale/sqrt(dx*dx + dy*dy)) >> subpixel_shift;
 
             // Calculate transformed coordinates at x2,y2 
             x += len;
             xt = x;
             yt = y;
             m_trans_dir.transform(&xt, &yt);
-            int x2 = int(xt * subpixel_size);
-            int y2 = int(yt * subpixel_size);
+            int x2 = iround(xt * subpixel_scale);
+            int y2 = iround(yt * subpixel_scale);
 
             // Calculate scale by X at x2,y2
             dx = xt + delta;
@@ -357,7 +357,7 @@ namespace agg
             m_trans_inv.transform(&dx, &dy);
             dx -= x;
             dy -= y;
-            int sx2 = int(subpixel_size/sqrt(dx*dx + dy*dy)) >> subpixel_shift;
+            int sx2 = uround(subpixel_scale/sqrt(dx*dx + dy*dy)) >> subpixel_shift;
 
             // Calculate scale by Y at x2,y2
             dx = xt;
@@ -365,7 +365,7 @@ namespace agg
             m_trans_inv.transform(&dx, &dy);
             dx -= x;
             dy -= y;
-            int sy2 = int(subpixel_size/sqrt(dx*dx + dy*dy)) >> subpixel_shift;
+            int sy2 = uround(subpixel_scale/sqrt(dx*dx + dy*dy)) >> subpixel_shift;
 
             // Initialize the interpolators
             m_coord_x = dda2_line_interpolator(x1,  x2,  len);
@@ -388,10 +388,10 @@ namespace agg
             double xt = xe;
             double yt = ye;
             m_trans_dir.transform(&xt, &yt);
-            int x2 = int(xt * subpixel_size);
-            int y2 = int(yt * subpixel_size);
+            int x2 = iround(xt * subpixel_scale);
+            int y2 = iround(yt * subpixel_scale);
 
-            const double delta = 1/double(subpixel_size);
+            const double delta = 1/double(subpixel_scale);
             double dx;
             double dy;
 
@@ -401,7 +401,7 @@ namespace agg
             m_trans_inv.transform(&dx, &dy);
             dx -= xe;
             dy -= ye;
-            int sx2 = int(subpixel_size/sqrt(dx*dx + dy*dy)) >> subpixel_shift;
+            int sx2 = uround(subpixel_scale/sqrt(dx*dx + dy*dy)) >> subpixel_shift;
 
             // Calculate scale by Y at x2,y2
             dx = xt;
@@ -409,7 +409,7 @@ namespace agg
             m_trans_inv.transform(&dx, &dy);
             dx -= xe;
             dy -= ye;
-            int sy2 = int(subpixel_size/sqrt(dx*dx + dy*dy)) >> subpixel_shift;
+            int sy2 = uround(subpixel_scale/sqrt(dx*dx + dy*dy)) >> subpixel_shift;
 
             // Initialize the interpolators
             m_coord_x = dda2_line_interpolator(x1,  x2,  len);

Modified: incubator/ooo/trunk/main/agg/inc/agg_span_interpolator_trans.h
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/agg/inc/agg_span_interpolator_trans.h?rev=1184758&r1=1184757&r2=1184758&view=diff
==============================================================================
--- incubator/ooo/trunk/main/agg/inc/agg_span_interpolator_trans.h (original)
+++ incubator/ooo/trunk/main/agg/inc/agg_span_interpolator_trans.h Sun Oct 16 04:13:16 2011
@@ -1,5 +1,5 @@
 //----------------------------------------------------------------------------
-// Anti-Grain Geometry - Version 2.3
+// 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 
@@ -31,10 +31,10 @@ namespace agg
     {
     public:
         typedef Transformer trans_type;
-        enum
+        enum subpixel_scale_e
         {
             subpixel_shift = SubpixelShift,
-            subpixel_size  = 1 << subpixel_shift
+            subpixel_scale = 1 << subpixel_shift
         };
 
         //--------------------------------------------------------------------
@@ -57,13 +57,8 @@ namespace agg
             m_x = x;
             m_y = y;
             m_trans->transform(&x, &y);
-            m_ix = int(x * subpixel_size);
-            m_iy = int(y * subpixel_size);
-        }
-
-        //----------------------------------------------------------------
-        void next(double, double, unsigned)
-        {
+            m_ix = iround(x * subpixel_scale);
+            m_iy = iround(y * subpixel_scale);
         }
 
         //----------------------------------------------------------------
@@ -73,8 +68,8 @@ namespace agg
             double x = m_x;
             double y = m_y;
             m_trans->transform(&x, &y);
-            m_ix = int(x * subpixel_size);
-            m_iy = int(y * subpixel_size);
+            m_ix = iround(x * subpixel_scale);
+            m_iy = iround(y * subpixel_scale);
         }
 
         //----------------------------------------------------------------

Added: incubator/ooo/trunk/main/agg/inc/agg_span_pattern_gray.h
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/agg/inc/agg_span_pattern_gray.h?rev=1184758&view=auto
==============================================================================
--- incubator/ooo/trunk/main/agg/inc/agg_span_pattern_gray.h (added)
+++ incubator/ooo/trunk/main/agg/inc/agg_span_pattern_gray.h Sun Oct 16 04:13:16 2011
@@ -0,0 +1,93 @@
+//----------------------------------------------------------------------------
+// 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.
+//
+//----------------------------------------------------------------------------
+// Contact: mcseem@antigrain.com
+//          mcseemagg@yahoo.com
+//          http://www.antigrain.com
+//----------------------------------------------------------------------------
+//
+// Adaptation for high precision colors has been sponsored by 
+// Liberty Technology Systems, Inc., visit http://lib-sys.com
+//
+// Liberty Technology Systems, Inc. is the provider of
+// PostScript and PDF technology for software developers.
+// 
+//----------------------------------------------------------------------------
+
+
+#ifndef AGG_SPAN_PATTERN_GRAY_INCLUDED
+#define AGG_SPAN_PATTERN_GRAY_INCLUDED
+
+#include "agg_basics.h"
+
+namespace agg
+{
+
+    //=======================================================span_pattern_gray
+    template<class Source> class span_pattern_gray
+    {
+    public:
+        typedef Source source_type;
+        typedef typename source_type::color_type color_type;
+        typedef typename color_type::value_type value_type;
+        typedef typename color_type::calc_type calc_type;
+
+        //--------------------------------------------------------------------
+        span_pattern_gray() {}
+        span_pattern_gray(source_type& src, 
+                          unsigned offset_x, unsigned offset_y) :
+            m_src(&src),
+            m_offset_x(offset_x),
+            m_offset_y(offset_y),
+            m_alpha(color_type::base_mask)
+        {}
+
+        //--------------------------------------------------------------------
+        void   attach(source_type& v)      { m_src = &v; }
+               source_type& source()       { return *m_src; }
+        const  source_type& source() const { return *m_src; }
+
+        //--------------------------------------------------------------------
+        void       offset_x(unsigned v) { m_offset_x = v; }
+        void       offset_y(unsigned v) { m_offset_y = v; }
+        unsigned   offset_x() const { return m_offset_x; }
+        unsigned   offset_y() const { return m_offset_y; }
+        void       alpha(value_type v) { m_alpha = v; }
+        value_type alpha() const { return m_alpha; }
+
+        //--------------------------------------------------------------------
+        void prepare() {}
+        void generate(color_type* span, int x, int y, unsigned len)
+        {   
+            x += m_offset_x;
+            y += m_offset_y;
+            const value_type* p = (const value_type*)m_src->span(x, y, len);
+            do
+            {
+                span->v = *p;
+                span->a = m_alpha;
+                p = m_src->next_x();
+                ++span;
+            }
+            while(--len);
+        }
+
+    private:
+        source_type* m_src;
+        unsigned     m_offset_x;
+        unsigned     m_offset_y;
+        value_type   m_alpha;
+
+    };
+
+}
+
+#endif
+

Modified: incubator/ooo/trunk/main/agg/inc/agg_span_pattern_rgb.h
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/agg/inc/agg_span_pattern_rgb.h?rev=1184758&r1=1184757&r2=1184758&view=diff
==============================================================================
--- incubator/ooo/trunk/main/agg/inc/agg_span_pattern_rgb.h (original)
+++ incubator/ooo/trunk/main/agg/inc/agg_span_pattern_rgb.h Sun Oct 16 04:13:16 2011
@@ -1,5 +1,5 @@
 //----------------------------------------------------------------------------
-// Anti-Grain Geometry - Version 2.3
+// 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 
@@ -26,138 +26,69 @@
 #define AGG_SPAN_PATTERN_RGB_INCLUDED
 
 #include "agg_basics.h"
-#include "agg_pixfmt_rgb.h"
-#include "agg_span_pattern.h"
 
 namespace agg
 {
-    //=======================================================span_pattern_rgb
-    template<class ColorT,
-             class Order, 
-             class WrapModeX,
-             class WrapModeY,
-             class Allocator = span_allocator<ColorT> > 
-    class span_pattern_rgb : public span_pattern_base<ColorT, Allocator>
+
+    //========================================================span_pattern_rgb
+    template<class Source> class span_pattern_rgb
     {
     public:
-        typedef ColorT color_type;
-        typedef Order order_type;
-        typedef Allocator alloc_type;
-        typedef span_pattern_base<color_type, alloc_type> base_type;
+        typedef Source source_type;
+        typedef typename source_type::color_type color_type;
+        typedef typename source_type::order_type order_type;
         typedef typename color_type::value_type value_type;
         typedef typename color_type::calc_type calc_type;
-        enum
-        {
-            base_shift = color_type::base_shift,
-            base_mask  = color_type::base_mask
-        };
 
         //--------------------------------------------------------------------
-        span_pattern_rgb(alloc_type& alloc) : 
-            base_type(alloc), 
-            m_wrap_mode_x(1),
-            m_wrap_mode_y(1)
+        span_pattern_rgb() {}
+        span_pattern_rgb(source_type& src, 
+                         unsigned offset_x, unsigned offset_y) :
+            m_src(&src),
+            m_offset_x(offset_x),
+            m_offset_y(offset_y),
+            m_alpha(color_type::base_mask)
         {}
 
-        //----------------------------------------------------------------
-        span_pattern_rgb(alloc_type& alloc,
-                         const rendering_buffer& src, 
-                         unsigned offset_x, 
-                         unsigned offset_y,
-                         value_type alpha = base_mask) :
-            base_type(alloc, src, offset_x, offset_y, alpha),
-            m_wrap_mode_x(src.width()),
-            m_wrap_mode_y(src.height())
-        {}
+        //--------------------------------------------------------------------
+        void   attach(source_type& v)      { m_src = &v; }
+               source_type& source()       { return *m_src; }
+        const  source_type& source() const { return *m_src; }
 
-        //-------------------------------------------------------------------
-        void source_image(const rendering_buffer& src) 
-        { 
-            base_type::source_image(src);
-            m_wrap_mode_x = WrapModeX(src.width());
-            m_wrap_mode_y = WrapModeY(src.height());
-        }
+        //--------------------------------------------------------------------
+        void       offset_x(unsigned v) { m_offset_x = v; }
+        void       offset_y(unsigned v) { m_offset_y = v; }
+        unsigned   offset_x() const { return m_offset_x; }
+        unsigned   offset_y() const { return m_offset_y; }
+        void       alpha(value_type v) { m_alpha = v; }
+        value_type alpha() const { return m_alpha; }
 
         //--------------------------------------------------------------------
-        color_type* generate(int x, int y, unsigned len)
+        void prepare() {}
+        void generate(color_type* span, int x, int y, unsigned len)
         {   
-            color_type* span = base_type::allocator().span();
-            unsigned sx = m_wrap_mode_x(base_type::offset_x() + x);
-            const value_type* row_ptr = 
-                (const value_type*)base_type::source_image().row(
-                    m_wrap_mode_y(
-                        base_type::offset_y() + y));
+            x += m_offset_x;
+            y += m_offset_y;
+            const value_type* p = (const value_type*)m_src->span(x, y, len);
             do
             {
-                const value_type* p = row_ptr + sx + sx + sx;
                 span->r = p[order_type::R];
                 span->g = p[order_type::G];
                 span->b = p[order_type::B];
-                span->a = base_type::alpha_int();
-                sx = ++m_wrap_mode_x;
+                span->a = m_alpha;
+                p = m_src->next_x();
                 ++span;
             }
             while(--len);
-            return base_type::allocator().span();
         }
 
     private:
-        WrapModeX m_wrap_mode_x;
-        WrapModeY m_wrap_mode_y;
-    };
-
-
-
-/*
-    //=========================================================span_pattern_rgb
-    template<class ColorT, class Order, class Allocator = span_allocator<ColorT> >
-    class span_pattern_rgb : public span_pattern<rgba8, int8u, Allocator>
-    {
-    public:
-        typedef Allocator alloc_type;
-        typedef rgba8 color_type;
-        typedef span_pattern<color_type, int8u, alloc_type> base_type;
-
-        //--------------------------------------------------------------------
-        span_pattern_rgb24(alloc_type& alloc) : base_type(alloc) {}
-
-        //----------------------------------------------------------------
-        span_pattern_rgb24(alloc_type& alloc,
-                           const rendering_buffer& src, 
-                           unsigned offset_x, unsigned offset_y, 
-                           int8u alpha = 255) :
-            base_type(alloc, src, offset_x, offset_y, alpha)
-        {}
+        source_type* m_src;
+        unsigned     m_offset_x;
+        unsigned     m_offset_y;
+        value_type   m_alpha;
 
-
-        //--------------------------------------------------------------------
-        color_type* generate(int x, int y, unsigned len)
-        {   
-            color_type* span = base_type::allocator().span();
-            unsigned sx = (base_type::offset_x() + x) % base_type::source_image().width();
-            unsigned wp = base_type::source_image().width() * 3;
-            const int8u* p = base_type::source_image().row((base_type::offset_y() + y) % base_type::source_image().height());
-            p += sx * 3;
-            do
-            {
-                span->r = p[Order::R];
-                span->g = p[Order::G];
-                span->b = p[Order::B];
-                span->a = base_type::alpha();
-                p += 3;
-                ++sx;
-                ++span;
-                if(sx >= base_type::source_image().width())
-                {
-                    sx -= base_type::source_image().width();
-                    p -= wp;
-                }
-            }
-            while(--len);
-            return base_type::allocator().span();
-        }
     };
-*/
 
 }
 

Modified: incubator/ooo/trunk/main/agg/inc/agg_span_pattern_rgba.h
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/agg/inc/agg_span_pattern_rgba.h?rev=1184758&r1=1184757&r2=1184758&view=diff
==============================================================================
--- incubator/ooo/trunk/main/agg/inc/agg_span_pattern_rgba.h (original)
+++ incubator/ooo/trunk/main/agg/inc/agg_span_pattern_rgba.h Sun Oct 16 04:13:16 2011
@@ -1,5 +1,5 @@
 //----------------------------------------------------------------------------
-// Anti-Grain Geometry - Version 2.3
+// 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 
@@ -26,83 +26,66 @@
 #define AGG_SPAN_PATTERN_RGBA_INCLUDED
 
 #include "agg_basics.h"
-#include "agg_pixfmt_rgba.h"
-#include "agg_span_pattern.h"
 
 namespace agg
 {
 
     //======================================================span_pattern_rgba
-    template<class ColorT,
-             class Order, 
-             class WrapModeX,
-             class WrapModeY,
-             class Allocator = span_allocator<ColorT> > 
-    class span_pattern_rgba : public span_pattern_base<ColorT, Allocator>
+    template<class Source> class span_pattern_rgba
     {
     public:
-        typedef ColorT color_type;
-        typedef Order order_type;
-        typedef Allocator alloc_type;
-        typedef span_pattern_base<color_type, alloc_type> base_type;
+        typedef Source source_type;
+        typedef typename source_type::color_type color_type;
+        typedef typename source_type::order_type order_type;
         typedef typename color_type::value_type value_type;
         typedef typename color_type::calc_type calc_type;
-        enum
-        {
-            base_shift = color_type::base_shift,
-            base_mask  = color_type::base_mask
-        };
 
         //--------------------------------------------------------------------
-        span_pattern_rgba(alloc_type& alloc) : 
-            base_type(alloc), 
-            m_wrap_mode_x(1),
-            m_wrap_mode_y(1)
-        {}
-
-        //----------------------------------------------------------------
-        span_pattern_rgba(alloc_type& alloc,
-                          const rendering_buffer& src, 
+        span_pattern_rgba() {}
+        span_pattern_rgba(source_type& src, 
                           unsigned offset_x, unsigned offset_y) :
-            base_type(alloc, src, offset_x, offset_y, 0),
-            m_wrap_mode_x(src.width()),
-            m_wrap_mode_y(src.height())
+            m_src(&src),
+            m_offset_x(offset_x),
+            m_offset_y(offset_y)
         {}
 
-        //-------------------------------------------------------------------
-        void source_image(const rendering_buffer& src) 
-        { 
-            base_type::source_image(src);
-            m_wrap_mode_x = WrapModeX(src.width());
-            m_wrap_mode_y = WrapModeY(src.height());
-        }
+        //--------------------------------------------------------------------
+        void   attach(source_type& v)      { m_src = &v; }
+               source_type& source()       { return *m_src; }
+        const  source_type& source() const { return *m_src; }
 
         //--------------------------------------------------------------------
-        color_type* generate(int x, int y, unsigned len)
+        void       offset_x(unsigned v) { m_offset_x = v; }
+        void       offset_y(unsigned v) { m_offset_y = v; }
+        unsigned   offset_x() const { return m_offset_x; }
+        unsigned   offset_y() const { return m_offset_y; }
+        void       alpha(value_type) {}
+        value_type alpha() const { return 0; }
+
+        //--------------------------------------------------------------------
+        void prepare() {}
+        void generate(color_type* span, int x, int y, unsigned len)
         {   
-            color_type* span = base_type::allocator().span();
-            unsigned sx = m_wrap_mode_x(base_type::offset_x() + x);
-            const value_type* row_ptr = 
-                (const value_type*)base_type::source_image().row(
-                    m_wrap_mode_y(
-                        base_type::offset_y() + y));
+            x += m_offset_x;
+            y += m_offset_y;
+            const value_type* p = (const value_type*)m_src->span(x, y, len);
             do
             {
-                const value_type* p = row_ptr + (sx << 2);
                 span->r = p[order_type::R];
                 span->g = p[order_type::G];
                 span->b = p[order_type::B];
                 span->a = p[order_type::A];
-                sx = ++m_wrap_mode_x;
+                p = (const value_type*)m_src->next_x();
                 ++span;
             }
             while(--len);
-            return base_type::allocator().span();
         }
 
     private:
-        WrapModeX m_wrap_mode_x;
-        WrapModeY m_wrap_mode_y;
+        source_type* m_src;
+        unsigned     m_offset_x;
+        unsigned     m_offset_y;
+
     };
 
 }



Mime
View raw message