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_RENDERER_MCLIP_INCLUDED 00026 #define AGG_RENDERER_MCLIP_INCLUDED 00027 00028 #include "agg_basics.h" 00029 #include "agg_array.h" 00030 #include "agg_renderer_base.h" 00031 00032 namespace agg 00033 { 00034 00035 //----------------------------------------------------------renderer_mclip 00036 template<class PixelFormat> class renderer_mclip 00037 { 00038 public: 00039 typedef PixelFormat pixfmt_type; 00040 typedef typename pixfmt_type::color_type color_type; 00041 typedef typename pixfmt_type::row_data row_data; 00042 typedef renderer_base<pixfmt_type> base_ren_type; 00043 00044 //-------------------------------------------------------------------- 00045 explicit renderer_mclip(pixfmt_type& pixf) : 00046 m_ren(pixf), 00047 m_curr_cb(0), 00048 m_bounds(m_ren.xmin(), m_ren.ymin(), m_ren.xmax(), m_ren.ymax()) 00049 {} 00050 void attach(pixfmt_type& pixf) 00051 { 00052 m_ren.attach(pixf); 00053 reset_clipping(true); 00054 } 00055 00056 //-------------------------------------------------------------------- 00057 const pixfmt_type& ren() const { return m_ren.ren(); } 00058 pixfmt_type& ren() { return m_ren.ren(); } 00059 00060 //-------------------------------------------------------------------- 00061 unsigned width() const { return m_ren.width(); } 00062 unsigned height() const { return m_ren.height(); } 00063 00064 //-------------------------------------------------------------------- 00065 const rect_i& clip_box() const { return m_ren.clip_box(); } 00066 int xmin() const { return m_ren.xmin(); } 00067 int ymin() const { return m_ren.ymin(); } 00068 int xmax() const { return m_ren.xmax(); } 00069 int ymax() const { return m_ren.ymax(); } 00070 00071 //-------------------------------------------------------------------- 00072 const rect_i& bounding_clip_box() const { return m_bounds; } 00073 int bounding_xmin() const { return m_bounds.x1; } 00074 int bounding_ymin() const { return m_bounds.y1; } 00075 int bounding_xmax() const { return m_bounds.x2; } 00076 int bounding_ymax() const { return m_bounds.y2; } 00077 00078 //-------------------------------------------------------------------- 00079 void first_clip_box() 00080 { 00081 m_curr_cb = 0; 00082 if(m_clip.size()) 00083 { 00084 const rect_i& cb = m_clip[0]; 00085 m_ren.clip_box_naked(cb.x1, cb.y1, cb.x2, cb.y2); 00086 } 00087 } 00088 00089 //-------------------------------------------------------------------- 00090 bool next_clip_box() 00091 { 00092 if(++m_curr_cb < m_clip.size()) 00093 { 00094 const rect_i& cb = m_clip[m_curr_cb]; 00095 m_ren.clip_box_naked(cb.x1, cb.y1, cb.x2, cb.y2); 00096 return true; 00097 } 00098 return false; 00099 } 00100 00101 //-------------------------------------------------------------------- 00102 void reset_clipping(bool visibility) 00103 { 00104 m_ren.reset_clipping(visibility); 00105 m_clip.remove_all(); 00106 m_curr_cb = 0; 00107 m_bounds = m_ren.clip_box(); 00108 } 00109 00110 //-------------------------------------------------------------------- 00111 void add_clip_box(int x1, int y1, int x2, int y2) 00112 { 00113 rect_i cb(x1, y1, x2, y2); 00114 cb.normalize(); 00115 if(cb.clip(rect_i(0, 0, width() - 1, height() - 1))) 00116 { 00117 m_clip.add(cb); 00118 if(cb.x1 < m_bounds.x1) m_bounds.x1 = cb.x1; 00119 if(cb.y1 < m_bounds.y1) m_bounds.y1 = cb.y1; 00120 if(cb.x2 > m_bounds.x2) m_bounds.x2 = cb.x2; 00121 if(cb.y2 > m_bounds.y2) m_bounds.y2 = cb.y2; 00122 } 00123 } 00124 00125 //-------------------------------------------------------------------- 00126 void clear(const color_type& c) 00127 { 00128 m_ren.clear(c); 00129 } 00130 00131 //-------------------------------------------------------------------- 00132 void copy_pixel(int x, int y, const color_type& c) 00133 { 00134 first_clip_box(); 00135 do 00136 { 00137 if(m_ren.inbox(x, y)) 00138 { 00139 m_ren.ren().copy_pixel(x, y, c); 00140 break; 00141 } 00142 } 00143 while(next_clip_box()); 00144 } 00145 00146 //-------------------------------------------------------------------- 00147 void blend_pixel(int x, int y, const color_type& c, cover_type cover) 00148 { 00149 first_clip_box(); 00150 do 00151 { 00152 if(m_ren.inbox(x, y)) 00153 { 00154 m_ren.ren().blend_pixel(x, y, c, cover); 00155 break; 00156 } 00157 } 00158 while(next_clip_box()); 00159 } 00160 00161 //-------------------------------------------------------------------- 00162 color_type pixel(int x, int y) const 00163 { 00164 if(m_ren.inbox(x, y)) 00165 { 00166 return m_ren.ren().pixel(x, y); 00167 } 00168 return color_type::no_color(); 00169 } 00170 00171 //-------------------------------------------------------------------- 00172 void copy_hline(int x1, int y, int x2, const color_type& c) 00173 { 00174 first_clip_box(); 00175 do 00176 { 00177 m_ren.copy_hline(x1, y, x2, c); 00178 } 00179 while(next_clip_box()); 00180 } 00181 00182 //-------------------------------------------------------------------- 00183 void copy_vline(int x, int y1, int y2, const color_type& c) 00184 { 00185 first_clip_box(); 00186 do 00187 { 00188 m_ren.copy_vline(x, y1, y2, c); 00189 } 00190 while(next_clip_box()); 00191 } 00192 00193 //-------------------------------------------------------------------- 00194 void blend_hline(int x1, int y, int x2, 00195 const color_type& c, cover_type cover) 00196 { 00197 first_clip_box(); 00198 do 00199 { 00200 m_ren.blend_hline(x1, y, x2, c, cover); 00201 } 00202 while(next_clip_box()); 00203 } 00204 00205 //-------------------------------------------------------------------- 00206 void blend_vline(int x, int y1, int y2, 00207 const color_type& c, cover_type cover) 00208 { 00209 first_clip_box(); 00210 do 00211 { 00212 m_ren.blend_vline(x, y1, y2, c, cover); 00213 } 00214 while(next_clip_box()); 00215 } 00216 00217 //-------------------------------------------------------------------- 00218 void copy_bar(int x1, int y1, int x2, int y2, const color_type& c) 00219 { 00220 first_clip_box(); 00221 do 00222 { 00223 m_ren.copy_bar(x1, y1, x2, y2, c); 00224 } 00225 while(next_clip_box()); 00226 } 00227 00228 //-------------------------------------------------------------------- 00229 void blend_bar(int x1, int y1, int x2, int y2, 00230 const color_type& c, cover_type cover) 00231 { 00232 first_clip_box(); 00233 do 00234 { 00235 m_ren.blend_bar(x1, y1, x2, y2, c, cover); 00236 } 00237 while(next_clip_box()); 00238 } 00239 00240 //-------------------------------------------------------------------- 00241 void blend_solid_hspan(int x, int y, int len, 00242 const color_type& c, const cover_type* covers) 00243 { 00244 first_clip_box(); 00245 do 00246 { 00247 m_ren.blend_solid_hspan(x, y, len, c, covers); 00248 } 00249 while(next_clip_box()); 00250 } 00251 00252 //-------------------------------------------------------------------- 00253 void blend_solid_vspan(int x, int y, int len, 00254 const color_type& c, const cover_type* covers) 00255 { 00256 first_clip_box(); 00257 do 00258 { 00259 m_ren.blend_solid_vspan(x, y, len, c, covers); 00260 } 00261 while(next_clip_box()); 00262 } 00263 00264 00265 //-------------------------------------------------------------------- 00266 void copy_color_hspan(int x, int y, int len, const color_type* colors) 00267 { 00268 first_clip_box(); 00269 do 00270 { 00271 m_ren.copy_color_hspan(x, y, len, colors); 00272 } 00273 while(next_clip_box()); 00274 } 00275 00276 //-------------------------------------------------------------------- 00277 void blend_color_hspan(int x, int y, int len, 00278 const color_type* colors, 00279 const cover_type* covers, 00280 cover_type cover = cover_full) 00281 { 00282 first_clip_box(); 00283 do 00284 { 00285 m_ren.blend_color_hspan(x, y, len, colors, covers, cover); 00286 } 00287 while(next_clip_box()); 00288 } 00289 00290 //-------------------------------------------------------------------- 00291 void blend_color_vspan(int x, int y, int len, 00292 const color_type* colors, 00293 const cover_type* covers, 00294 cover_type cover = cover_full) 00295 { 00296 first_clip_box(); 00297 do 00298 { 00299 m_ren.blend_color_vspan(x, y, len, colors, covers, cover); 00300 } 00301 while(next_clip_box()); 00302 } 00303 00304 //-------------------------------------------------------------------- 00305 void copy_from(const rendering_buffer& from, 00306 const rect_i* rc=0, 00307 int x_to=0, 00308 int y_to=0) 00309 { 00310 first_clip_box(); 00311 do 00312 { 00313 m_ren.copy_from(from, rc, x_to, y_to); 00314 } 00315 while(next_clip_box()); 00316 } 00317 00318 //-------------------------------------------------------------------- 00319 template<class SrcPixelFormatRenderer> 00320 void blend_from(const SrcPixelFormatRenderer& src, 00321 const rect_i* rect_src_ptr = 0, 00322 int dx = 0, 00323 int dy = 0, 00324 cover_type cover = cover_full) 00325 { 00326 first_clip_box(); 00327 do 00328 { 00329 m_ren.blend_from(src, rect_src_ptr, dx, dy, cover); 00330 } 00331 while(next_clip_box()); 00332 } 00333 00334 00335 private: 00336 renderer_mclip(const renderer_mclip<PixelFormat>&); 00337 const renderer_mclip<PixelFormat>& 00338 operator = (const renderer_mclip<PixelFormat>&); 00339 00340 base_ren_type m_ren; 00341 pod_bvector<rect_i, 4> m_clip; 00342 unsigned m_curr_cb; 00343 rect_i m_bounds; 00344 }; 00345 00346 00347 } 00348 00349 #endif