1 //---------------------------------------------------------------------------- 2 // Anti-Grain Geometry (AGG) - Version 2.5 3 // A high quality rendering engine for C++ 4 // Copyright (C) 2002-2006 Maxim Shemanarev 5 // Contact: mcseem@antigrain.com 6 // mcseemagg@yahoo.com 7 // http://antigrain.com 8 // 9 // AGG is free software; you can redistribute it and/or 10 // modify it under the terms of the GNU General Public License 11 // as published by the Free Software Foundation; either version 2 12 // of the License, or (at your option) any later version. 13 // 14 // AGG is distributed in the hope that it will be useful, 15 // but WITHOUT ANY WARRANTY; without even the implied warranty of 16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 // GNU General Public License for more details. 18 // 19 // You should have received a copy of the GNU General Public License 20 // along with AGG; if not, write to the Free Software 21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 22 // MA 02110-1301, USA. 23 //---------------------------------------------------------------------------- 24 // 25 // Adaptation for 32-bit screen coordinates (scanline32_bin) has been sponsored by 26 // Liberty Technology Systems, Inc., visit http://lib-sys.com 27 // 28 // Liberty Technology Systems, Inc. is the provider of 29 // PostScript and PDF technology for software developers. 30 // 31 //---------------------------------------------------------------------------- 32 33 #ifndef AGG_SCANLINE_BIN_INCLUDED 34 #define AGG_SCANLINE_BIN_INCLUDED 35 36 #include "agg_array.h" 37 38 namespace agg 39 { 40 41 //=============================================================scanline_bin 42 // 43 // This is binary scaline container which supports the interface 44 // used in the rasterizer::render(). See description of agg_scanline_u8 45 // for details. 46 // 47 //------------------------------------------------------------------------ 48 class scanline_bin 49 { 50 public: 51 typedef int32 coord_type; 52 53 struct span 54 { 55 int16 x; 56 int16 len; 57 }; 58 59 typedef const span* const_iterator; 60 61 //-------------------------------------------------------------------- scanline_bin()62 scanline_bin() : 63 m_last_x(0x7FFFFFF0), 64 m_spans(), 65 m_cur_span(0) 66 { 67 } 68 69 //-------------------------------------------------------------------- reset(int min_x,int max_x)70 void reset(int min_x, int max_x) 71 { 72 unsigned max_len = max_x - min_x + 3; 73 if(max_len > m_spans.size()) 74 { 75 m_spans.resize(max_len); 76 } 77 m_last_x = 0x7FFFFFF0; 78 m_cur_span = &m_spans[0]; 79 } 80 81 //-------------------------------------------------------------------- add_cell(int x,unsigned)82 void add_cell(int x, unsigned) 83 { 84 if(x == m_last_x+1) 85 { 86 m_cur_span->len++; 87 } 88 else 89 { 90 ++m_cur_span; 91 m_cur_span->x = (int16)x; 92 m_cur_span->len = 1; 93 } 94 m_last_x = x; 95 } 96 97 //-------------------------------------------------------------------- add_span(int x,unsigned len,unsigned)98 void add_span(int x, unsigned len, unsigned) 99 { 100 if(x == m_last_x+1) 101 { 102 m_cur_span->len = (int16)(m_cur_span->len + len); 103 } 104 else 105 { 106 ++m_cur_span; 107 m_cur_span->x = (int16)x; 108 m_cur_span->len = (int16)len; 109 } 110 m_last_x = x + len - 1; 111 } 112 113 //-------------------------------------------------------------------- add_cells(int x,unsigned len,const void *)114 void add_cells(int x, unsigned len, const void*) 115 { 116 add_span(x, len, 0); 117 } 118 119 //-------------------------------------------------------------------- finalize(int y)120 void finalize(int y) 121 { 122 m_y = y; 123 } 124 125 //-------------------------------------------------------------------- reset_spans()126 void reset_spans() 127 { 128 m_last_x = 0x7FFFFFF0; 129 m_cur_span = &m_spans[0]; 130 } 131 132 //-------------------------------------------------------------------- y()133 int y() const { return m_y; } num_spans()134 unsigned num_spans() const { return unsigned(m_cur_span - &m_spans[0]); } begin()135 const_iterator begin() const { return &m_spans[1]; } 136 137 private: 138 scanline_bin(const scanline_bin&); 139 const scanline_bin operator = (const scanline_bin&); 140 141 int m_last_x; 142 int m_y; 143 pod_array<span> m_spans; 144 span* m_cur_span; 145 }; 146 147 148 149 150 151 152 //===========================================================scanline32_bin 153 class scanline32_bin 154 { 155 public: 156 typedef int32 coord_type; 157 158 //-------------------------------------------------------------------- 159 struct span 160 { spanspan161 span() {} spanspan162 span(coord_type x_, coord_type len_) : x(x_), len(len_) {} 163 164 coord_type x; 165 coord_type len; 166 }; 167 typedef pod_bvector<span, 4> span_array_type; 168 169 170 //-------------------------------------------------------------------- 171 class const_iterator 172 { 173 public: const_iterator(const span_array_type & spans)174 const_iterator(const span_array_type& spans) : 175 m_spans(spans), 176 m_span_idx(0) 177 {} 178 179 const span& operator*() const { return m_spans[m_span_idx]; } 180 const span* operator->() const { return &m_spans[m_span_idx]; } 181 182 void operator ++ () { ++m_span_idx; } 183 184 private: 185 const span_array_type& m_spans; 186 unsigned m_span_idx; 187 }; 188 189 190 //-------------------------------------------------------------------- scanline32_bin()191 scanline32_bin() : m_max_len(0), m_last_x(0x7FFFFFF0) {} 192 193 //-------------------------------------------------------------------- reset(int min_x,int max_x)194 void reset(int min_x, int max_x) 195 { 196 m_last_x = 0x7FFFFFF0; 197 m_spans.remove_all(); 198 } 199 200 //-------------------------------------------------------------------- add_cell(int x,unsigned)201 void add_cell(int x, unsigned) 202 { 203 if(x == m_last_x+1) 204 { 205 m_spans.last().len++; 206 } 207 else 208 { 209 m_spans.add(span(coord_type(x), 1)); 210 } 211 m_last_x = x; 212 } 213 214 //-------------------------------------------------------------------- add_span(int x,unsigned len,unsigned)215 void add_span(int x, unsigned len, unsigned) 216 { 217 if(x == m_last_x+1) 218 { 219 m_spans.last().len += coord_type(len); 220 } 221 else 222 { 223 m_spans.add(span(coord_type(x), coord_type(len))); 224 } 225 m_last_x = x + len - 1; 226 } 227 228 //-------------------------------------------------------------------- add_cells(int x,unsigned len,const void *)229 void add_cells(int x, unsigned len, const void*) 230 { 231 add_span(x, len, 0); 232 } 233 234 //-------------------------------------------------------------------- finalize(int y)235 void finalize(int y) 236 { 237 m_y = y; 238 } 239 240 //-------------------------------------------------------------------- reset_spans()241 void reset_spans() 242 { 243 m_last_x = 0x7FFFFFF0; 244 m_spans.remove_all(); 245 } 246 247 //-------------------------------------------------------------------- y()248 int y() const { return m_y; } num_spans()249 unsigned num_spans() const { return m_spans.size(); } begin()250 const_iterator begin() const { return const_iterator(m_spans); } 251 252 private: 253 scanline32_bin(const scanline32_bin&); 254 const scanline32_bin operator = (const scanline32_bin&); 255 256 unsigned m_max_len; 257 int m_last_x; 258 int m_y; 259 span_array_type m_spans; 260 }; 261 262 263 264 265 266 } 267 268 269 #endif 270