Anti-Grain Geometry - AGG (libagg)
2.5
|
00001 //---------------------------------------------------------------------------- 00002 // Anti-Grain Geometry (AGG) - Version 2.5 00003 // A high quality rendering engine for C++ 00004 // Copyright (C) 2002-2006 Maxim Shemanarev 00005 // Contact: mcseem@antigrain.com 00006 // mcseemagg@yahoo.com 00007 // http://antigrain.com 00008 // 00009 // AGG is free software; you can redistribute it and/or 00010 // modify it under the terms of the GNU General Public License 00011 // as published by the Free Software Foundation; either version 2 00012 // of the License, or (at your option) any later version. 00013 // 00014 // AGG is distributed in the hope that it will be useful, 00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 // GNU General Public License for more details. 00018 // 00019 // You should have received a copy of the GNU General Public License 00020 // along with AGG; if not, write to the Free Software 00021 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00022 // MA 02110-1301, USA. 00023 //---------------------------------------------------------------------------- 00024 00025 #ifndef AGG_PATTERN_FILTERS_RGBA8_INCLUDED 00026 #define AGG_PATTERN_FILTERS_RGBA8_INCLUDED 00027 00028 #include "agg_basics.h" 00029 #include "agg_line_aa_basics.h" 00030 #include "agg_color_rgba.h" 00031 00032 00033 namespace agg 00034 { 00035 00036 //=======================================================pattern_filter_nn 00037 template<class ColorT> struct pattern_filter_nn 00038 { 00039 typedef ColorT color_type; 00040 static unsigned dilation() { return 0; } 00041 00042 static void AGG_INLINE pixel_low_res(color_type const* const* buf, 00043 color_type* p, int x, int y) 00044 { 00045 *p = buf[y][x]; 00046 } 00047 00048 static void AGG_INLINE pixel_high_res(color_type const* const* buf, 00049 color_type* p, int x, int y) 00050 { 00051 *p = buf[y >> line_subpixel_shift] 00052 [x >> line_subpixel_shift]; 00053 } 00054 }; 00055 00056 typedef pattern_filter_nn<rgba8> pattern_filter_nn_rgba8; 00057 typedef pattern_filter_nn<rgba16> pattern_filter_nn_rgba16; 00058 00059 00060 //===========================================pattern_filter_bilinear_rgba 00061 template<class ColorT> struct pattern_filter_bilinear_rgba 00062 { 00063 typedef ColorT color_type; 00064 typedef typename color_type::value_type value_type; 00065 typedef typename color_type::calc_type calc_type; 00066 00067 00068 static unsigned dilation() { return 1; } 00069 00070 static AGG_INLINE void pixel_low_res(color_type const* const* buf, 00071 color_type* p, int x, int y) 00072 { 00073 *p = buf[y][x]; 00074 } 00075 00076 static AGG_INLINE void pixel_high_res(color_type const* const* buf, 00077 color_type* p, int x, int y) 00078 { 00079 calc_type r, g, b, a; 00080 r = g = b = a = line_subpixel_scale * line_subpixel_scale / 2; 00081 00082 calc_type weight; 00083 int x_lr = x >> line_subpixel_shift; 00084 int y_lr = y >> line_subpixel_shift; 00085 00086 x &= line_subpixel_mask; 00087 y &= line_subpixel_mask; 00088 const color_type* ptr = buf[y_lr] + x_lr; 00089 00090 weight = (line_subpixel_scale - x) * 00091 (line_subpixel_scale - y); 00092 r += weight * ptr->r; 00093 g += weight * ptr->g; 00094 b += weight * ptr->b; 00095 a += weight * ptr->a; 00096 00097 ++ptr; 00098 00099 weight = x * (line_subpixel_scale - y); 00100 r += weight * ptr->r; 00101 g += weight * ptr->g; 00102 b += weight * ptr->b; 00103 a += weight * ptr->a; 00104 00105 ptr = buf[y_lr + 1] + x_lr; 00106 00107 weight = (line_subpixel_scale - x) * y; 00108 r += weight * ptr->r; 00109 g += weight * ptr->g; 00110 b += weight * ptr->b; 00111 a += weight * ptr->a; 00112 00113 ++ptr; 00114 00115 weight = x * y; 00116 r += weight * ptr->r; 00117 g += weight * ptr->g; 00118 b += weight * ptr->b; 00119 a += weight * ptr->a; 00120 00121 p->r = (value_type)(r >> line_subpixel_shift * 2); 00122 p->g = (value_type)(g >> line_subpixel_shift * 2); 00123 p->b = (value_type)(b >> line_subpixel_shift * 2); 00124 p->a = (value_type)(a >> line_subpixel_shift * 2); 00125 } 00126 }; 00127 00128 typedef pattern_filter_bilinear_rgba<rgba8> pattern_filter_bilinear_rgba8; 00129 typedef pattern_filter_bilinear_rgba<rgba16> pattern_filter_bilinear_rgba16; 00130 } 00131 00132 #endif