1 //----------------------------------------------------------------------------
2 // Anti-Grain Geometry - Version 2.3
3 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
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.
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"
28 //==========================================================row_ptr_cache
29 template<class T
> class row_ptr_cache
32 //--------------------------------------------------------------------
38 row_data(int x1_
, int x2_
, const int8u
* ptr_
) :
39 x1(x1_
), x2(x2_
), ptr(ptr_
) {}
42 //-------------------------------------------------------------------
48 //-------------------------------------------------------------------
59 //--------------------------------------------------------------------
60 row_ptr_cache(T
* _buf
, unsigned _width
, unsigned _height
, int _stride
) :
68 attach(_buf
, _width
, _height
, _stride
);
71 //--------------------------------------------------------------------
72 void attach(T
* _buf
, unsigned _width
, unsigned _height
, int _stride
)
78 if(_height
> m_max_height
)
81 m_rows
= new T
* [m_max_height
= _height
];
88 row_ptr
= m_buf
- int(_height
- 1) * _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
) :
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();
133 for (y
= 0; y
< h
; y
++)
135 memcpy(row(y
), mtx
.row(y
), l
);
139 //--------------------------------------------------------------------
143 for(y
= 0; y
< height(); y
++)
147 for(x
= 0; x
< stride_abs(); x
++)
156 //--------------------------------------------------------------------
158 row_ptr_cache(const row_ptr_cache
<T
>&);
159 const row_ptr_cache
<T
>& operator = (const row_ptr_cache
<T
>&);
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
;