1 2 //---------------------------------------------------------------------------- 3 // Anti-Grain Geometry - Version 2.3 4 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com) 5 // 6 // Permission to copy, use, modify, sell and distribute this software 7 // is granted provided this copyright notice appears in all copies. 8 // This software is provided "as is" without express or implied 9 // warranty, and with no claim as to its suitability for any purpose. 10 // 11 //---------------------------------------------------------------------------- 12 // Contact: mcseem@antigrain.com 13 // mcseemagg@yahoo.com 14 // http://www.antigrain.com 15 //---------------------------------------------------------------------------- 16 // 17 // Adaptation for 32-bit screen coordinates (scanline32_u) has been sponsored by 18 // Liberty Technology Systems, Inc., visit http://lib-sys.com 19 // 20 // Liberty Technology Systems, Inc. is the provider of 21 // PostScript and PDF technology for software developers. 22 // 23 //---------------------------------------------------------------------------- 24 #ifndef AGG_SCANLINE_U_INCLUDED 25 #define AGG_SCANLINE_U_INCLUDED 26 #include "agg_array.h" 27 namespace pdfium 28 { 29 namespace agg 30 { 31 template<class CoverT> class scanline_u 32 { 33 public: 34 typedef scanline_u<CoverT> self_type; 35 typedef CoverT cover_type; 36 typedef int16 coord_type; 37 struct span { 38 coord_type x; 39 coord_type len; 40 cover_type* covers; 41 }; 42 typedef span* iterator; 43 typedef const span* const_iterator; ~scanline_u()44 ~scanline_u() 45 { 46 FX_Free(m_spans); 47 FX_Free(m_covers); 48 } scanline_u()49 scanline_u() : 50 m_min_x(0), 51 m_max_len(0), 52 m_last_x(0x7FFFFFF0), 53 m_covers(0), 54 m_spans(0), 55 m_cur_span(0) 56 {} reset(int min_x,int max_x)57 void reset(int min_x, int max_x) 58 { 59 unsigned max_len = max_x - min_x + 2; 60 if(max_len > m_max_len) { 61 FX_Free(m_spans); 62 FX_Free(m_covers); 63 m_covers = FX_Alloc( cover_type , max_len); 64 m_spans = FX_Alloc( span , max_len); 65 m_max_len = max_len; 66 } 67 m_last_x = 0x7FFFFFF0; 68 m_min_x = min_x; 69 m_cur_span = m_spans; 70 } add_cell(int x,unsigned cover)71 void add_cell(int x, unsigned cover) 72 { 73 x -= m_min_x; 74 m_covers[x] = (cover_type)cover; 75 if(x == m_last_x + 1) { 76 m_cur_span->len++; 77 } else { 78 m_cur_span++; 79 m_cur_span->x = (coord_type)(x + m_min_x); 80 m_cur_span->len = 1; 81 m_cur_span->covers = m_covers + x; 82 } 83 m_last_x = x; 84 } add_cells(int x,unsigned len,const CoverT * covers)85 void add_cells(int x, unsigned len, const CoverT* covers) 86 { 87 x -= m_min_x; 88 memcpy(m_covers + x, covers, len * sizeof(CoverT)); 89 if(x == m_last_x + 1) { 90 m_cur_span->len += (coord_type)len; 91 } else { 92 m_cur_span++; 93 m_cur_span->x = (coord_type)(x + m_min_x); 94 m_cur_span->len = (coord_type)len; 95 m_cur_span->covers = m_covers + x; 96 } 97 m_last_x = x + len - 1; 98 } add_span(int x,unsigned len,unsigned cover)99 void add_span(int x, unsigned len, unsigned cover) 100 { 101 x -= m_min_x; 102 memset(m_covers + x, cover, len); 103 if(x == m_last_x + 1) { 104 m_cur_span->len += (coord_type)len; 105 } else { 106 m_cur_span++; 107 m_cur_span->x = (coord_type)(x + m_min_x); 108 m_cur_span->len = (coord_type)len; 109 m_cur_span->covers = m_covers + x; 110 } 111 m_last_x = x + len - 1; 112 } finalize(int y)113 void finalize(int y) 114 { 115 m_y = y; 116 } reset_spans()117 void reset_spans() 118 { 119 m_last_x = 0x7FFFFFF0; 120 m_cur_span = m_spans; 121 } y()122 int y() const 123 { 124 return m_y; 125 } num_spans()126 unsigned num_spans() const 127 { 128 return unsigned(m_cur_span - m_spans); 129 } begin()130 const_iterator begin() const 131 { 132 return m_spans + 1; 133 } begin()134 iterator begin() 135 { 136 return m_spans + 1; 137 } 138 private: 139 scanline_u(const self_type&); 140 const self_type& operator = (const self_type&); 141 private: 142 int m_min_x; 143 unsigned m_max_len; 144 int m_last_x; 145 int m_y; 146 cover_type* m_covers; 147 span* m_spans; 148 span* m_cur_span; 149 }; 150 typedef scanline_u<int8u> scanline_u8; 151 } 152 } // namespace pdfium 153 #endif 154