1130803Smarcel//----------------------------------------------------------------------------
2130803Smarcel// Anti-Grain Geometry - Version 2.4
3130803Smarcel// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4130803Smarcel//
5130803Smarcel// Permission to copy, use, modify, sell and distribute this software
6130803Smarcel// is granted provided this copyright notice appears in all copies.
7130803Smarcel// This software is provided "as is" without express or implied
8130803Smarcel// warranty, and with no claim as to its suitability for any purpose.
9130803Smarcel//
10130803Smarcel//----------------------------------------------------------------------------
11130803Smarcel// Contact: mcseem@antigrain.com
12130803Smarcel//          mcseemagg@yahoo.com
13130803Smarcel//          http://www.antigrain.com
14130803Smarcel//----------------------------------------------------------------------------
15130803Smarcel#ifndef AGG_PATTERN_FILTERS_RGBA8_INCLUDED
16130803Smarcel#define AGG_PATTERN_FILTERS_RGBA8_INCLUDED
17130803Smarcel
18130803Smarcel#include "agg_basics.h"
19130803Smarcel#include "agg_line_aa_basics.h"
20130803Smarcel#include "agg_color_rgba.h"
21130803Smarcel
22130803Smarcel
23130803Smarcelnamespace agg
24130803Smarcel{
25130803Smarcel
26130803Smarcel    //=======================================================pattern_filter_nn
27130803Smarcel    template<class ColorT> struct pattern_filter_nn
28130803Smarcel    {
29130803Smarcel        typedef ColorT color_type;
30130803Smarcel        static unsigned dilation() { return 0; }
31130803Smarcel
32130803Smarcel        static void AGG_INLINE pixel_low_res(color_type const* const* buf,
33130803Smarcel                                             color_type* p, int x, int y)
34130803Smarcel        {
35130803Smarcel            *p = buf[y][x];
36130803Smarcel        }
37130803Smarcel
38130803Smarcel        static void AGG_INLINE pixel_high_res(color_type const* const* buf,
39130803Smarcel                                              color_type* p, int x, int y)
40130803Smarcel        {
41130803Smarcel            *p = buf[y >> line_subpixel_shift]
42130803Smarcel                    [x >> line_subpixel_shift];
43130803Smarcel        }
44130803Smarcel    };
45130803Smarcel
46130803Smarcel    typedef pattern_filter_nn<rgba8>  pattern_filter_nn_rgba8;
47130803Smarcel    typedef pattern_filter_nn<rgba16> pattern_filter_nn_rgba16;
48130803Smarcel
49130803Smarcel
50130803Smarcel    //===========================================pattern_filter_bilinear_rgba
51130803Smarcel    template<class ColorT> struct pattern_filter_bilinear_rgba
52130803Smarcel    {
53130803Smarcel        typedef ColorT color_type;
54130803Smarcel        typedef typename color_type::value_type value_type;
55130803Smarcel        typedef typename color_type::calc_type calc_type;
56130803Smarcel
57130803Smarcel
58130803Smarcel        static unsigned dilation() { return 1; }
59130803Smarcel
60130803Smarcel        static AGG_INLINE void pixel_low_res(color_type const* const* buf,
61130803Smarcel                                             color_type* p, int x, int y)
62130803Smarcel        {
63130803Smarcel            *p = buf[y][x];
64130803Smarcel        }
65130803Smarcel
66130803Smarcel        static AGG_INLINE void pixel_high_res(color_type const* const* buf,
67130803Smarcel                                              color_type* p, int x, int y)
68130803Smarcel        {
69130803Smarcel            calc_type r, g, b, a;
70130803Smarcel            r = g = b = a = line_subpixel_scale * line_subpixel_scale / 2;
71
72            calc_type weight;
73            int x_lr = x >> line_subpixel_shift;
74            int y_lr = y >> line_subpixel_shift;
75
76            x &= line_subpixel_mask;
77            y &= line_subpixel_mask;
78            const color_type* ptr = buf[y_lr] + x_lr;
79
80            weight = (line_subpixel_scale - x) *
81                     (line_subpixel_scale - y);
82            r += weight * ptr->r;
83            g += weight * ptr->g;
84            b += weight * ptr->b;
85            a += weight * ptr->a;
86
87            ++ptr;
88
89            weight = x * (line_subpixel_scale - y);
90            r += weight * ptr->r;
91            g += weight * ptr->g;
92            b += weight * ptr->b;
93            a += weight * ptr->a;
94
95            ptr = buf[y_lr + 1] + x_lr;
96
97            weight = (line_subpixel_scale - x) * y;
98            r += weight * ptr->r;
99            g += weight * ptr->g;
100            b += weight * ptr->b;
101            a += weight * ptr->a;
102
103            ++ptr;
104
105            weight = x * y;
106            r += weight * ptr->r;
107            g += weight * ptr->g;
108            b += weight * ptr->b;
109            a += weight * ptr->a;
110
111            p->r = (value_type)(r >> line_subpixel_shift * 2);
112            p->g = (value_type)(g >> line_subpixel_shift * 2);
113            p->b = (value_type)(b >> line_subpixel_shift * 2);
114            p->a = (value_type)(a >> line_subpixel_shift * 2);
115        }
116    };
117
118    typedef pattern_filter_bilinear_rgba<rgba8>  pattern_filter_bilinear_rgba8;
119    typedef pattern_filter_bilinear_rgba<rgba16> pattern_filter_bilinear_rgba16;
120}
121
122#endif
123