update dev300-m58
[ooovba.git] / agg / inc / agg_rendering_buffer.h
blobfc5a941dfd05dedeab84ba187844a07c7e32922f
1 //----------------------------------------------------------------------------
2 // Anti-Grain Geometry - Version 2.3
3 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4 //
5 // Permission to copy, use, modify, sell and distribute this software
6 // is granted provided this copyright notice appears in all copies.
7 // This software is provided "as is" without express or implied
8 // warranty, and with no claim as to its suitability for any purpose.
9 //
10 //----------------------------------------------------------------------------
11 // Contact: mcseem@antigrain.com
12 // mcseemagg@yahoo.com
13 // http://www.antigrain.com
14 //----------------------------------------------------------------------------
16 // class rendering_buffer
18 //----------------------------------------------------------------------------
20 #ifndef AGG_RENDERING_BUFFER_INCLUDED
21 #define AGG_RENDERING_BUFFER_INCLUDED
23 #include "agg_basics.h"
25 namespace agg
28 //==========================================================row_ptr_cache
29 template<class T> class row_ptr_cache
31 public:
32 //--------------------------------------------------------------------
33 struct row_data
35 int x1, x2;
36 const int8u* ptr;
37 row_data() {}
38 row_data(int x1_, int x2_, const int8u* ptr_) :
39 x1(x1_), x2(x2_), ptr(ptr_) {}
42 //-------------------------------------------------------------------
43 ~row_ptr_cache()
45 delete [] m_rows;
48 //-------------------------------------------------------------------
49 row_ptr_cache() :
50 m_buf(0),
51 m_rows(0),
52 m_width(0),
53 m_height(0),
54 m_stride(0),
55 m_max_height(0)
59 //--------------------------------------------------------------------
60 row_ptr_cache(T* _buf, unsigned _width, unsigned _height, int _stride) :
61 m_buf(0),
62 m_rows(0),
63 m_width(0),
64 m_height(0),
65 m_stride(0),
66 m_max_height(0)
68 attach(_buf, _width, _height, _stride);
71 //--------------------------------------------------------------------
72 void attach(T* _buf, unsigned _width, unsigned _height, int _stride)
74 m_buf = _buf;
75 m_width = _width;
76 m_height = _height;
77 m_stride = _stride;
78 if(_height > m_max_height)
80 delete [] m_rows;
81 m_rows = new T* [m_max_height = _height];
84 T* row_ptr = m_buf;
86 if(_stride < 0)
88 row_ptr = m_buf - int(_height - 1) * _stride;
91 T** _rows = m_rows;
93 while(_height--)
95 *_rows++ = row_ptr;
96 row_ptr += _stride;
100 //--------------------------------------------------------------------
101 const T* buf() const { return m_buf; }
102 unsigned width() const { return m_width; }
103 unsigned height() const { return m_height; }
104 int stride() const { return m_stride; }
105 unsigned stride_abs() const
107 return (m_stride < 0) ?
108 unsigned(-m_stride) :
109 unsigned(m_stride);
112 //--------------------------------------------------------------------
113 T* row(unsigned y) { return m_rows[y]; }
114 const T* row(unsigned y) const { return m_rows[y]; }
116 T* next_row(void* p) { return (T*)p + m_stride; }
117 const T* next_row(const void* p) const { return (T*)p + m_stride; }
119 T const* const* rows() const { return m_rows; }
121 //--------------------------------------------------------------------
122 void copy_from(const row_ptr_cache<T>& mtx)
124 unsigned h = height();
125 if(mtx.height() < h) h = mtx.height();
127 unsigned l = stride_abs();
128 if(mtx.stride_abs() < l) l = mtx.stride_abs();
130 l *= sizeof(T);
132 unsigned y;
133 for (y = 0; y < h; y++)
135 memcpy(row(y), mtx.row(y), l);
139 //--------------------------------------------------------------------
140 void clear(T value)
142 unsigned y;
143 for(y = 0; y < height(); y++)
145 T* p = row(y);
146 unsigned x;
147 for(x = 0; x < stride_abs(); x++)
149 *p++ = value;
155 private:
156 //--------------------------------------------------------------------
157 // Prohibit copying
158 row_ptr_cache(const row_ptr_cache<T>&);
159 const row_ptr_cache<T>& operator = (const row_ptr_cache<T>&);
161 private:
162 //--------------------------------------------------------------------
163 T* m_buf; // Pointer to renrdering buffer
164 T** m_rows; // Pointers to each row of the buffer
165 unsigned m_width; // Width in pixels
166 unsigned m_height; // Height in pixels
167 int m_stride; // Number of bytes per row. Can be < 0
168 unsigned m_max_height; // The maximal height (currently allocated)
173 //========================================================rendering_buffer
174 typedef row_ptr_cache<int8u> rendering_buffer;
179 #endif