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 // Adaptation for 32-bit screen coordinates (scanline32_bin) has been sponsored by 00026 // Liberty Technology Systems, Inc., visit http://lib-sys.com 00027 // 00028 // Liberty Technology Systems, Inc. is the provider of 00029 // PostScript and PDF technology for software developers. 00030 // 00031 //---------------------------------------------------------------------------- 00032 00033 #ifndef AGG_SCANLINE_BIN_INCLUDED 00034 #define AGG_SCANLINE_BIN_INCLUDED 00035 00036 #include "agg_array.h" 00037 00038 namespace agg 00039 { 00040 00041 //=============================================================scanline_bin 00042 // 00043 // This is binary scaline container which supports the interface 00044 // used in the rasterizer::render(). See description of agg_scanline_u8 00045 // for details. 00046 // 00047 //------------------------------------------------------------------------ 00048 class scanline_bin 00049 { 00050 public: 00051 typedef int32 coord_type; 00052 00053 struct span 00054 { 00055 int16 x; 00056 int16 len; 00057 }; 00058 00059 typedef const span* const_iterator; 00060 00061 //-------------------------------------------------------------------- 00062 scanline_bin() : 00063 m_last_x(0x7FFFFFF0), 00064 m_spans(), 00065 m_cur_span(0) 00066 { 00067 } 00068 00069 //-------------------------------------------------------------------- 00070 void reset(int min_x, int max_x) 00071 { 00072 unsigned max_len = max_x - min_x + 3; 00073 if(max_len > m_spans.size()) 00074 { 00075 m_spans.resize(max_len); 00076 } 00077 m_last_x = 0x7FFFFFF0; 00078 m_cur_span = &m_spans[0]; 00079 } 00080 00081 //-------------------------------------------------------------------- 00082 void add_cell(int x, unsigned) 00083 { 00084 if(x == m_last_x+1) 00085 { 00086 m_cur_span->len++; 00087 } 00088 else 00089 { 00090 ++m_cur_span; 00091 m_cur_span->x = (int16)x; 00092 m_cur_span->len = 1; 00093 } 00094 m_last_x = x; 00095 } 00096 00097 //-------------------------------------------------------------------- 00098 void add_span(int x, unsigned len, unsigned) 00099 { 00100 if(x == m_last_x+1) 00101 { 00102 m_cur_span->len = (int16)(m_cur_span->len + len); 00103 } 00104 else 00105 { 00106 ++m_cur_span; 00107 m_cur_span->x = (int16)x; 00108 m_cur_span->len = (int16)len; 00109 } 00110 m_last_x = x + len - 1; 00111 } 00112 00113 //-------------------------------------------------------------------- 00114 void add_cells(int x, unsigned len, const void*) 00115 { 00116 add_span(x, len, 0); 00117 } 00118 00119 //-------------------------------------------------------------------- 00120 void finalize(int y) 00121 { 00122 m_y = y; 00123 } 00124 00125 //-------------------------------------------------------------------- 00126 void reset_spans() 00127 { 00128 m_last_x = 0x7FFFFFF0; 00129 m_cur_span = &m_spans[0]; 00130 } 00131 00132 //-------------------------------------------------------------------- 00133 int y() const { return m_y; } 00134 unsigned num_spans() const { return unsigned(m_cur_span - &m_spans[0]); } 00135 const_iterator begin() const { return &m_spans[1]; } 00136 00137 private: 00138 scanline_bin(const scanline_bin&); 00139 const scanline_bin operator = (const scanline_bin&); 00140 00141 int m_last_x; 00142 int m_y; 00143 pod_array<span> m_spans; 00144 span* m_cur_span; 00145 }; 00146 00147 00148 00149 00150 00151 00152 //===========================================================scanline32_bin 00153 class scanline32_bin 00154 { 00155 public: 00156 typedef int32 coord_type; 00157 00158 //-------------------------------------------------------------------- 00159 struct span 00160 { 00161 span() {} 00162 span(coord_type x_, coord_type len_) : x(x_), len(len_) {} 00163 00164 coord_type x; 00165 coord_type len; 00166 }; 00167 typedef pod_bvector<span, 4> span_array_type; 00168 00169 00170 //-------------------------------------------------------------------- 00171 class const_iterator 00172 { 00173 public: 00174 const_iterator(const span_array_type& spans) : 00175 m_spans(spans), 00176 m_span_idx(0) 00177 {} 00178 00179 const span& operator*() const { return m_spans[m_span_idx]; } 00180 const span* operator->() const { return &m_spans[m_span_idx]; } 00181 00182 void operator ++ () { ++m_span_idx; } 00183 00184 private: 00185 const span_array_type& m_spans; 00186 unsigned m_span_idx; 00187 }; 00188 00189 00190 //-------------------------------------------------------------------- 00191 scanline32_bin() : m_max_len(0), m_last_x(0x7FFFFFF0) {} 00192 00193 //-------------------------------------------------------------------- 00194 void reset(int min_x, int max_x) 00195 { 00196 m_last_x = 0x7FFFFFF0; 00197 m_spans.remove_all(); 00198 } 00199 00200 //-------------------------------------------------------------------- 00201 void add_cell(int x, unsigned) 00202 { 00203 if(x == m_last_x+1) 00204 { 00205 m_spans.last().len++; 00206 } 00207 else 00208 { 00209 m_spans.add(span(coord_type(x), 1)); 00210 } 00211 m_last_x = x; 00212 } 00213 00214 //-------------------------------------------------------------------- 00215 void add_span(int x, unsigned len, unsigned) 00216 { 00217 if(x == m_last_x+1) 00218 { 00219 m_spans.last().len += coord_type(len); 00220 } 00221 else 00222 { 00223 m_spans.add(span(coord_type(x), coord_type(len))); 00224 } 00225 m_last_x = x + len - 1; 00226 } 00227 00228 //-------------------------------------------------------------------- 00229 void add_cells(int x, unsigned len, const void*) 00230 { 00231 add_span(x, len, 0); 00232 } 00233 00234 //-------------------------------------------------------------------- 00235 void finalize(int y) 00236 { 00237 m_y = y; 00238 } 00239 00240 //-------------------------------------------------------------------- 00241 void reset_spans() 00242 { 00243 m_last_x = 0x7FFFFFF0; 00244 m_spans.remove_all(); 00245 } 00246 00247 //-------------------------------------------------------------------- 00248 int y() const { return m_y; } 00249 unsigned num_spans() const { return m_spans.size(); } 00250 const_iterator begin() const { return const_iterator(m_spans); } 00251 00252 private: 00253 scanline32_bin(const scanline32_bin&); 00254 const scanline32_bin operator = (const scanline32_bin&); 00255 00256 unsigned m_max_len; 00257 int m_last_x; 00258 int m_y; 00259 span_array_type m_spans; 00260 }; 00261 00262 00263 00264 00265 00266 } 00267 00268 00269 #endif