1//---------------------------------------------------------------------------- 2// Anti-Grain Geometry - Version 2.4 3// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com) 4// 5// Permission to copy, use, modify, sell and distribute this software 6// is granted provided this copyright notice appears in all copies. 7// This software is provided "as is" without express or implied 8// warranty, and with no claim as to its suitability for any purpose. 9// 10//---------------------------------------------------------------------------- 11// Contact: mcseem@antigrain.com 12// mcseemagg@yahoo.com 13// http://www.antigrain.com 14//---------------------------------------------------------------------------- 15#ifndef AGG_PATTERN_FILTERS_RGBA8_INCLUDED 16#define AGG_PATTERN_FILTERS_RGBA8_INCLUDED 17 18#include "agg_basics.h" 19#include "agg_line_aa_basics.h" 20#include "agg_color_rgba.h" 21 22 23namespace agg 24{ 25 26 //=======================================================pattern_filter_nn 27 template<class ColorT> struct pattern_filter_nn 28 { 29 typedef ColorT color_type; 30 static unsigned dilation() { return 0; } 31 32 static void AGG_INLINE pixel_low_res(color_type const* const* buf, 33 color_type* p, int x, int y) 34 { 35 *p = buf[y][x]; 36 } 37 38 static void AGG_INLINE pixel_high_res(color_type const* const* buf, 39 color_type* p, int x, int y) 40 { 41 *p = buf[y >> line_subpixel_shift] 42 [x >> line_subpixel_shift]; 43 } 44 }; 45 46 typedef pattern_filter_nn<rgba8> pattern_filter_nn_rgba8; 47 typedef pattern_filter_nn<rgba16> pattern_filter_nn_rgba16; 48 49 50 //===========================================pattern_filter_bilinear_rgba 51 template<class ColorT> struct pattern_filter_bilinear_rgba 52 { 53 typedef ColorT color_type; 54 typedef typename color_type::value_type value_type; 55 typedef typename color_type::calc_type calc_type; 56 57 58 static unsigned dilation() { return 1; } 59 60 static AGG_INLINE void pixel_low_res(color_type const* const* buf, 61 color_type* p, int x, int y) 62 { 63 *p = buf[y][x]; 64 } 65 66 static AGG_INLINE void pixel_high_res(color_type const* const* buf, 67 color_type* p, int x, int y) 68 { 69 calc_type r, g, b, a; 70 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