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: mcseem@antigrain.com 13 // mcseemagg@yahoo.com 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 agg 24 { 25 class rendering_buffer 26 { 27 public: 28 struct row_data { 29 int x1, x2; 30 const int8u* ptr; row_datarow_data31 row_data() {} row_datarow_data32 row_data(int x1_, int x2_, const int8u* ptr_) : 33 x1(x1_), x2(x2_), ptr(ptr_) {} 34 }; 35 struct span_data { 36 int x; 37 unsigned len; 38 int8u* ptr; span_dataspan_data39 span_data() {} span_dataspan_data40 span_data(int) : x(0), len(0), ptr(0) {} span_dataspan_data41 span_data(int x_, unsigned len_, int8u* ptr_) : 42 x(x_), len(len_), ptr(ptr_) {} 43 }; ~rendering_buffer()44 ~rendering_buffer() 45 { 46 FX_Free(m_rows); 47 } rendering_buffer()48 rendering_buffer() : 49 m_buf(0), 50 m_rows(0), 51 m_width(0), 52 m_height(0), 53 m_stride(0), 54 m_max_height(0) 55 { 56 } rendering_buffer(int8u * buf,unsigned width,unsigned height,int stride)57 rendering_buffer(int8u* buf, unsigned width, unsigned height, int stride) : 58 m_buf(0), 59 m_rows(0), 60 m_width(0), 61 m_height(0), 62 m_stride(0), 63 m_max_height(0) 64 { 65 attach(buf, width, height, stride); 66 } attach(int8u * buf,unsigned width,unsigned height,int stride)67 void attach(int8u* buf, unsigned width, unsigned height, int stride) 68 { 69 m_buf = buf; 70 m_width = width; 71 m_height = height; 72 m_stride = stride; 73 if(height > m_max_height) { 74 FX_Free(m_rows); 75 m_rows = FX_Alloc(int8u*, m_max_height = height); 76 } 77 int8u* row_ptr = m_buf; 78 if(stride < 0) { 79 row_ptr = m_buf - int(height - 1) * stride; 80 } 81 int8u** rows = m_rows; 82 while(height--) { 83 *rows++ = row_ptr; 84 row_ptr += stride; 85 } 86 } buf()87 int8u* buf() 88 { 89 return m_buf; 90 } buf()91 const int8u* buf() const 92 { 93 return m_buf; 94 } width()95 unsigned width() const 96 { 97 return m_width; 98 } height()99 unsigned height() const 100 { 101 return m_height; 102 } stride()103 int stride() const 104 { 105 return m_stride; 106 } stride_abs()107 unsigned stride_abs() const 108 { 109 return (m_stride < 0) ? 110 unsigned(-m_stride) : 111 unsigned(m_stride); 112 } row(unsigned y)113 int8u* row(unsigned y) 114 { 115 return m_rows[y]; 116 } row(unsigned y)117 const int8u* row(unsigned y) const 118 { 119 return m_rows[y]; 120 } next_row(void * p)121 int8u* next_row(void* p) 122 { 123 return (int8u*)p + m_stride; 124 } next_row(const void * p)125 const int8u* next_row(const void* p) const 126 { 127 return (int8u*)p + m_stride; 128 } rows()129 int8u const* const* rows() const 130 { 131 return m_rows; 132 } 133 private: 134 rendering_buffer(const rendering_buffer&); 135 const rendering_buffer& operator = (const rendering_buffer&); 136 private: 137 int8u* m_buf; 138 int8u** m_rows; 139 unsigned m_width; 140 unsigned m_height; 141 int m_stride; 142 unsigned m_max_height; 143 }; 144 } 145 #endif 146