blob: 1db31c3e314003bc5e89b550b8383d7574140d3e [file] [log] [blame]
John Abd-El-Malek5110c472014-05-17 22:33:34 -07001
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"
Lei Zhang0b36f362020-10-02 23:45:07 +000027namespace pdfium
28{
John Abd-El-Malek5110c472014-05-17 22:33:34 -070029namespace agg
30{
Tom Sepez6fc8cbb2015-04-14 13:50:34 -070031template<class CoverT> class scanline_u
John Abd-El-Malek5110c472014-05-17 22:33:34 -070032{
33public:
34 typedef scanline_u<CoverT> self_type;
35 typedef CoverT cover_type;
36 typedef int16 coord_type;
Tom Sepez6fc8cbb2015-04-14 13:50:34 -070037 struct span {
John Abd-El-Malek5110c472014-05-17 22:33:34 -070038 coord_type x;
39 coord_type len;
40 cover_type* covers;
41 };
42 typedef span* iterator;
43 typedef const span* const_iterator;
44 ~scanline_u()
45 {
46 FX_Free(m_spans);
47 FX_Free(m_covers);
48 }
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 {}
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 }
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 }
85 void add_cells(int x, unsigned len, const CoverT* covers)
86 {
87 x -= m_min_x;
Dan Sinclair1c5d0b42017-04-03 15:05:11 -040088 memcpy(m_covers + x, covers, len * sizeof(CoverT));
John Abd-El-Malek5110c472014-05-17 22:33:34 -070089 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 }
99 void add_span(int x, unsigned len, unsigned cover)
100 {
101 x -= m_min_x;
Dan Sinclair1c5d0b42017-04-03 15:05:11 -0400102 memset(m_covers + x, cover, len);
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700103 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 }
113 void finalize(int y)
114 {
115 m_y = y;
116 }
117 void reset_spans()
118 {
119 m_last_x = 0x7FFFFFF0;
120 m_cur_span = m_spans;
121 }
122 int y() const
123 {
124 return m_y;
125 }
126 unsigned num_spans() const
127 {
128 return unsigned(m_cur_span - m_spans);
129 }
130 const_iterator begin() const
131 {
132 return m_spans + 1;
133 }
134 iterator begin()
135 {
136 return m_spans + 1;
137 }
138private:
139 scanline_u(const self_type&);
140 const self_type& operator = (const self_type&);
141private:
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};
150typedef scanline_u<int8u> scanline_u8;
151}
Lei Zhang0b36f362020-10-02 23:45:07 +0000152} // namespace pdfium
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700153#endif