xref: /aosp_15_r20/external/pdfium/third_party/agg23/agg_rendering_buffer.h (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
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: [email protected]
13 //          [email protected]
14 //          http://www.antigrain.com
15 //----------------------------------------------------------------------------
16 //
17 // class rendering_buffer
18 //
19 //----------------------------------------------------------------------------
20 #ifndef AGG_RENDERING_BUFFER_INCLUDED
21 #define AGG_RENDERING_BUFFER_INCLUDED
22 #include "agg_basics.h"
23 namespace pdfium
24 {
25 namespace agg
26 {
27 class rendering_buffer
28 {
29 public:
30     struct row_data  {
31         int x1, x2;
32         const int8u* ptr;
row_datarow_data33         row_data() {}
row_datarow_data34         row_data(int x1_, int x2_, const int8u* ptr_) :
35             x1(x1_), x2(x2_), ptr(ptr_) {}
36     };
37     struct span_data  {
38         int x;
39         unsigned len;
40         int8u* ptr;
span_dataspan_data41         span_data() {}
span_dataspan_data42         span_data(int) : x(0), len(0), ptr(0) {}
span_dataspan_data43         span_data(int x_, unsigned len_, int8u* ptr_) :
44             x(x_), len(len_), ptr(ptr_) {}
45     };
~rendering_buffer()46     ~rendering_buffer()
47     {
48         FX_Free(m_rows);
49     }
rendering_buffer()50     rendering_buffer() :
51         m_buf(0),
52         m_rows(0),
53         m_width(0),
54         m_height(0),
55         m_stride(0),
56         m_max_height(0)
57     {
58     }
rendering_buffer(int8u * buf,unsigned width,unsigned height,int stride)59     rendering_buffer(int8u* buf, unsigned width, unsigned height, int stride) :
60         m_buf(0),
61         m_rows(0),
62         m_width(0),
63         m_height(0),
64         m_stride(0),
65         m_max_height(0)
66     {
67         attach(buf, width, height, stride);
68     }
attach(int8u * buf,unsigned width,unsigned height,int stride)69     void attach(int8u* buf, unsigned width, unsigned height, int stride)
70     {
71         m_buf = buf;
72         m_width = width;
73         m_height = height;
74         m_stride = stride;
75         if(height > m_max_height) {
76             FX_Free(m_rows);
77             m_rows = FX_Alloc(int8u*, m_max_height = height);
78         }
79         int8u* row_ptr = m_buf;
80         if(stride < 0) {
81             row_ptr = m_buf - int(height - 1) * stride;
82         }
83         int8u** rows = m_rows;
84         while(height--) {
85             *rows++ = row_ptr;
86             row_ptr += stride;
87         }
88     }
buf()89     int8u* buf()
90     {
91         return m_buf;
92     }
buf()93     const int8u* buf()    const
94     {
95         return m_buf;
96     }
width()97     unsigned width()  const
98     {
99         return m_width;
100     }
height()101     unsigned height() const
102     {
103         return m_height;
104     }
stride()105     int      stride() const
106     {
107         return m_stride;
108     }
stride_abs()109     unsigned stride_abs() const
110     {
111         return (m_stride < 0) ?
112                unsigned(-m_stride) :
113                unsigned(m_stride);
114     }
row(unsigned y)115     int8u* row(unsigned y)
116     {
117         return m_rows[y];
118     }
row(unsigned y)119     const int8u* row(unsigned y) const
120     {
121         return m_rows[y];
122     }
next_row(void * p)123     int8u* next_row(void* p)
124     {
125         return (int8u*)p + m_stride;
126     }
next_row(const void * p)127     const int8u* next_row(const void* p) const
128     {
129         return (int8u*)p + m_stride;
130     }
rows()131     int8u const* const* rows() const
132     {
133         return m_rows;
134     }
135 private:
136     rendering_buffer(const rendering_buffer&);
137     const rendering_buffer& operator = (const rendering_buffer&);
138 private:
139     int8u*       m_buf;
140     int8u**      m_rows;
141     unsigned m_width;
142     unsigned m_height;
143     int      m_stride;
144     unsigned m_max_height;
145 };
146 }
147 }  // namespace pdfium
148 #endif
149