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_PIXFMT_AMASK_ADAPTOR_INCLUDED 00026 #define AGG_PIXFMT_AMASK_ADAPTOR_INCLUDED 00027 00028 00029 #include <string.h> 00030 #include "agg_array.h" 00031 #include "agg_rendering_buffer.h" 00032 00033 00034 namespace agg 00035 { 00036 //==================================================pixfmt_amask_adaptor 00037 template<class PixFmt, class AlphaMask> class pixfmt_amask_adaptor 00038 { 00039 public: 00040 typedef PixFmt pixfmt_type; 00041 typedef typename pixfmt_type::color_type color_type; 00042 typedef typename pixfmt_type::row_data row_data; 00043 typedef AlphaMask amask_type; 00044 typedef typename amask_type::cover_type cover_type; 00045 00046 private: 00047 enum span_extra_tail_e { span_extra_tail = 256 }; 00048 00049 void realloc_span(unsigned len) 00050 { 00051 if(len > m_span.size()) 00052 { 00053 m_span.resize(len + span_extra_tail); 00054 } 00055 } 00056 00057 void init_span(unsigned len) 00058 { 00059 realloc_span(len); 00060 memset(&m_span[0], amask_type::cover_full, len * sizeof(cover_type)); 00061 } 00062 00063 void init_span(unsigned len, const cover_type* covers) 00064 { 00065 realloc_span(len); 00066 memcpy(&m_span[0], covers, len * sizeof(cover_type)); 00067 } 00068 00069 00070 public: 00071 pixfmt_amask_adaptor(pixfmt_type& pixf, const amask_type& mask) : 00072 m_pixf(&pixf), m_mask(&mask), m_span() 00073 {} 00074 00075 void attach_pixfmt(pixfmt_type& pixf) { m_pixf = &pixf; } 00076 void attach_alpha_mask(const amask_type& mask) { m_mask = &mask; } 00077 00078 //-------------------------------------------------------------------- 00079 template<class PixFmt2> 00080 bool attach_pixfmt(PixFmt2& pixf, int x1, int y1, int x2, int y2) 00081 { 00082 return m_pixf->attach(pixf, x1, y1, x2, y2); 00083 } 00084 00085 //-------------------------------------------------------------------- 00086 unsigned width() const { return m_pixf->width(); } 00087 unsigned height() const { return m_pixf->height(); } 00088 00089 //-------------------------------------------------------------------- 00090 color_type pixel(int x, int y) 00091 { 00092 return m_pixf->pixel(x, y); 00093 } 00094 00095 //-------------------------------------------------------------------- 00096 void copy_pixel(int x, int y, const color_type& c) 00097 { 00098 m_pixf->blend_pixel(x, y, c, m_mask->pixel(x, y)); 00099 } 00100 00101 //-------------------------------------------------------------------- 00102 void blend_pixel(int x, int y, const color_type& c, cover_type cover) 00103 { 00104 m_pixf->blend_pixel(x, y, c, m_mask->combine_pixel(x, y, cover)); 00105 } 00106 00107 //-------------------------------------------------------------------- 00108 void copy_hline(int x, int y, 00109 unsigned len, 00110 const color_type& c) 00111 { 00112 realloc_span(len); 00113 m_mask->fill_hspan(x, y, &m_span[0], len); 00114 m_pixf->blend_solid_hspan(x, y, len, c, &m_span[0]); 00115 } 00116 00117 //-------------------------------------------------------------------- 00118 void blend_hline(int x, int y, 00119 unsigned len, 00120 const color_type& c, 00121 cover_type cover) 00122 { 00123 init_span(len); 00124 m_mask->combine_hspan(x, y, &m_span[0], len); 00125 m_pixf->blend_solid_hspan(x, y, len, c, &m_span[0]); 00126 } 00127 00128 //-------------------------------------------------------------------- 00129 void copy_vline(int x, int y, 00130 unsigned len, 00131 const color_type& c) 00132 { 00133 realloc_span(len); 00134 m_mask->fill_vspan(x, y, &m_span[0], len); 00135 m_pixf->blend_solid_vspan(x, y, len, c, &m_span[0]); 00136 } 00137 00138 //-------------------------------------------------------------------- 00139 void blend_vline(int x, int y, 00140 unsigned len, 00141 const color_type& c, 00142 cover_type cover) 00143 { 00144 init_span(len); 00145 m_mask->combine_vspan(x, y, &m_span[0], len); 00146 m_pixf->blend_solid_vspan(x, y, len, c, &m_span[0]); 00147 } 00148 00149 //-------------------------------------------------------------------- 00150 void copy_from(const rendering_buffer& from, 00151 int xdst, int ydst, 00152 int xsrc, int ysrc, 00153 unsigned len) 00154 { 00155 m_pixf->copy_from(from, xdst, ydst, xsrc, ysrc, len); 00156 } 00157 00158 00159 //-------------------------------------------------------------------- 00160 void blend_solid_hspan(int x, int y, 00161 unsigned len, 00162 const color_type& c, 00163 const cover_type* covers) 00164 { 00165 init_span(len, covers); 00166 m_mask->combine_hspan(x, y, &m_span[0], len); 00167 m_pixf->blend_solid_hspan(x, y, len, c, &m_span[0]); 00168 } 00169 00170 00171 //-------------------------------------------------------------------- 00172 void blend_solid_vspan(int x, int y, 00173 unsigned len, 00174 const color_type& c, 00175 const cover_type* covers) 00176 { 00177 init_span(len, covers); 00178 m_mask->combine_vspan(x, y, &m_span[0], len); 00179 m_pixf->blend_solid_vspan(x, y, len, c, &m_span[0]); 00180 } 00181 00182 00183 //-------------------------------------------------------------------- 00184 void copy_color_hspan(int x, int y, unsigned len, const color_type* colors) 00185 { 00186 realloc_span(len); 00187 m_mask->fill_hspan(x, y, &m_span[0], len); 00188 m_pixf->blend_color_hspan(x, y, len, colors, &m_span[0], cover_full); 00189 } 00190 00191 //-------------------------------------------------------------------- 00192 void copy_color_vspan(int x, int y, unsigned len, const color_type* colors) 00193 { 00194 realloc_span(len); 00195 m_mask->fill_vspan(x, y, &m_span[0], len); 00196 m_pixf->blend_color_vspan(x, y, len, colors, &m_span[0], cover_full); 00197 } 00198 00199 //-------------------------------------------------------------------- 00200 void blend_color_hspan(int x, int y, 00201 unsigned len, 00202 const color_type* colors, 00203 const cover_type* covers, 00204 cover_type cover = cover_full) 00205 { 00206 if(covers) 00207 { 00208 init_span(len, covers); 00209 m_mask->combine_hspan(x, y, &m_span[0], len); 00210 } 00211 else 00212 { 00213 realloc_span(len); 00214 m_mask->fill_hspan(x, y, &m_span[0], len); 00215 } 00216 m_pixf->blend_color_hspan(x, y, len, colors, &m_span[0], cover); 00217 } 00218 00219 00220 //-------------------------------------------------------------------- 00221 void blend_color_vspan(int x, int y, 00222 unsigned len, 00223 const color_type* colors, 00224 const cover_type* covers, 00225 cover_type cover = cover_full) 00226 { 00227 if(covers) 00228 { 00229 init_span(len, covers); 00230 m_mask->combine_vspan(x, y, &m_span[0], len); 00231 } 00232 else 00233 { 00234 realloc_span(len); 00235 m_mask->fill_vspan(x, y, &m_span[0], len); 00236 } 00237 m_pixf->blend_color_vspan(x, y, len, colors, &m_span[0], cover); 00238 } 00239 00240 private: 00241 pixfmt_type* m_pixf; 00242 const amask_type* m_mask; 00243 pod_array<cover_type> m_span; 00244 }; 00245 00246 } 00247 00248 #endif 00249