00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef AGG_RENDERING_BUFFER_INCLUDED
00021 #define AGG_RENDERING_BUFFER_INCLUDED
00022
00023 #include "agg_basics.h"
00024
00025 namespace agg
00026 {
00027
00028
00029 template<class T> class row_ptr_cache
00030 {
00031 public:
00032
00033 struct row_data
00034 {
00035 int x1, x2;
00036 const int8u* ptr;
00037 row_data() {}
00038 row_data(int x1_, int x2_, const int8u* ptr_) :
00039 x1(x1_), x2(x2_), ptr(ptr_) {}
00040 };
00041
00042
00043 ~row_ptr_cache()
00044 {
00045 delete [] m_rows;
00046 }
00047
00048
00049 row_ptr_cache() :
00050 m_buf(0),
00051 m_rows(0),
00052 m_width(0),
00053 m_height(0),
00054 m_stride(0),
00055 m_max_height(0)
00056 {
00057 }
00058
00059
00060 row_ptr_cache(T* buf, unsigned width, unsigned height, int stride) :
00061 m_buf(0),
00062 m_rows(0),
00063 m_width(0),
00064 m_height(0),
00065 m_stride(0),
00066 m_max_height(0)
00067 {
00068 attach(buf, width, height, stride);
00069 }
00070
00071
00072 void attach(T* buf, unsigned width, unsigned height, int stride)
00073 {
00074 m_buf = buf;
00075 m_width = width;
00076 m_height = height;
00077 m_stride = stride;
00078 if(height > m_max_height)
00079 {
00080 delete [] m_rows;
00081 m_rows = new T* [m_max_height = height];
00082 }
00083
00084 T* row_ptr = m_buf;
00085
00086 if(stride < 0)
00087 {
00088 row_ptr = m_buf - int(height - 1) * stride;
00089 }
00090
00091 T** rows = m_rows;
00092
00093 while(height--)
00094 {
00095 *rows++ = row_ptr;
00096 row_ptr += stride;
00097 }
00098 }
00099
00100
00101 const T* buf() const { return m_buf; }
00102 unsigned width() const { return m_width; }
00103 unsigned height() const { return m_height; }
00104 int stride() const { return m_stride; }
00105 unsigned stride_abs() const
00106 {
00107 return (m_stride < 0) ?
00108 unsigned(-m_stride) :
00109 unsigned(m_stride);
00110 }
00111
00112
00113 T* row(unsigned y) { return m_rows[y]; }
00114 const T* row(unsigned y) const { return m_rows[y]; }
00115 T const* const* rows() const { return m_rows; }
00116
00117
00118 void copy_from(const row_ptr_cache<T>& mtx)
00119 {
00120 unsigned h = height();
00121 if(mtx.height() < h) h = mtx.height();
00122
00123 unsigned l = stride_abs();
00124 if(mtx.stride_abs() < l) l = mtx.stride_abs();
00125
00126 l *= sizeof(T);
00127
00128 unsigned y;
00129 for (y = 0; y < h; y++)
00130 {
00131 memcpy(row(y), mtx.row(y), l);
00132 }
00133 }
00134
00135
00136 void clear(T value)
00137 {
00138 unsigned y;
00139 for(y = 0; y < height(); y++)
00140 {
00141 T* p = row(y);
00142 unsigned x;
00143 for(x = 0; x < stride_abs(); x++)
00144 {
00145 *p++ = value;
00146 }
00147 }
00148 }
00149
00150
00151 private:
00152
00153
00154 row_ptr_cache(const row_ptr_cache<T>&);
00155 const row_ptr_cache<T>& operator = (const row_ptr_cache<T>&);
00156
00157 private:
00158
00159 T* m_buf;
00160 T** m_rows;
00161 unsigned m_width;
00162 unsigned m_height;
00163 int m_stride;
00164 unsigned m_max_height;
00165 };
00166
00167
00168
00169
00170 typedef row_ptr_cache<int8u> rendering_buffer;
00171
00172 }
00173
00174
00175 #endif