1 //----------------------------------------------------------------------------
2 // Anti-Grain Geometry - Version 2.4
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_array.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 //-------------------------------------------------------------------
52 //--------------------------------------------------------------------
53 row_ptr_cache(T
* buf
, unsigned width
, unsigned height
, int stride
) :
60 attach(buf
, width
, height
, stride
);
63 //--------------------------------------------------------------------
64 void attach(T
* buf
, unsigned width
, unsigned height
, int stride
)
70 if(height
> m_rows
.size())
72 m_rows
.resize(height
);
79 row_ptr
= m_buf
- int(height
- 1) * stride
;
82 T
** rows
= &m_rows
[0];
91 //--------------------------------------------------------------------
92 T
* buf() { return m_buf
; }
93 const T
* buf() const { return m_buf
; }
94 unsigned width() const { return m_width
; }
95 unsigned height() const { return m_height
; }
96 int stride() const { return m_stride
; }
97 unsigned stride_abs() const
99 return (m_stride
< 0) ? unsigned(-m_stride
) : unsigned(m_stride
);
102 //--------------------------------------------------------------------
103 T
* row_ptr(int, int y
, unsigned) { return m_rows
[y
]; }
104 T
* row_ptr(int y
) { return m_rows
[y
]; }
105 const T
* row_ptr(int y
) const { return m_rows
[y
]; }
106 row_data
row (int y
) const { return row_data(0, m_width
-1, m_rows
[y
]); }
108 //--------------------------------------------------------------------
109 T
const* const* rows() const { return &m_rows
[0]; }
111 //--------------------------------------------------------------------
112 template<class RenBuf
>
113 void copy_from(const RenBuf
& src
)
115 unsigned h
= height();
116 if(src
.height() < h
) h
= src
.height();
118 unsigned l
= stride_abs();
119 if(src
.stride_abs() < l
) l
= src
.stride_abs();
124 unsigned w
= width();
125 for (y
= 0; y
< h
; y
++)
127 memcpy(row_ptr(0, y
, w
), src
.row_ptr(y
), l
);
131 //--------------------------------------------------------------------
135 unsigned w
= width();
136 unsigned stride
= stride_abs();
137 for(y
= 0; y
< height(); y
++)
139 T
* p
= row_ptr(0, y
, w
);
141 for(x
= 0; x
< stride
; x
++)
149 //--------------------------------------------------------------------
150 T
* m_buf
; // Pointer to renrdering buffer
151 pod_array
<T
*> m_rows
; // Pointers to each row of the buffer
152 unsigned m_width
; // Width in pixels
153 unsigned m_height
; // Height in pixels
154 int m_stride
; // Number of bytes per row. Can be < 0
159 //========================================================rendering_buffer
160 typedef row_ptr_cache
<int8u
> rendering_buffer
;