| 1 |
//---------------------------------------------------------------------------- |
| 2 |
// Anti-Grain Geometry - Version 2.4 |
| 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: [email protected] |
| 12 |
// [email protected] |
| 13 |
// http://www.antigrain.com |
| 14 |
//---------------------------------------------------------------------------- |
| 15 |
// |
| 16 |
// class rendering_buffer_dynarow |
| 17 |
// |
| 18 |
//---------------------------------------------------------------------------- |
| 19 |
|
| 20 |
#ifndef AGG_RENDERING_BUFFER_DYNAROW_INCLUDED |
| 21 |
#define AGG_RENDERING_BUFFER_DYNAROW_INCLUDED |
| 22 |
|
| 23 |
#include "agg_array.h" |
| 24 |
|
| 25 |
namespace agg |
| 26 |
{ |
| 27 |
|
| 28 |
//===============================================rendering_buffer_dynarow |
| 29 |
// Rendering buffer class with dynamic allocation of the rows. |
| 30 |
// The rows are allocated as needed when requesting for span_ptr(). |
| 31 |
// The class automatically calculates min_x and max_x for each row. |
| 32 |
// Generally it's more efficient to use this class as a temporary buffer |
| 33 |
// for rendering a few lines and then to blend it with another buffer. |
| 34 |
// |
| 35 |
class rendering_buffer_dynarow |
| 36 |
{ |
| 37 |
public: |
| 38 |
typedef row_info<int8u> row_data; |
| 39 |
|
| 40 |
//------------------------------------------------------------------- |
| 41 |
~rendering_buffer_dynarow() |
| 42 |
{ |
| 43 |
init(0,0,0); |
| 44 |
} |
| 45 |
|
| 46 |
//------------------------------------------------------------------- |
| 47 |
rendering_buffer_dynarow() : |
| 48 |
m_rows(), |
| 49 |
m_width(0), |
| 50 |
m_height(0), |
| 51 |
m_byte_width(0) |
| 52 |
{ |
| 53 |
} |
| 54 |
|
| 55 |
// Allocate and clear the buffer |
| 56 |
//-------------------------------------------------------------------- |
| 57 |
rendering_buffer_dynarow(unsigned width, unsigned height, |
| 58 |
unsigned byte_width) : |
| 59 |
m_rows(height), |
| 60 |
m_width(width), |
| 61 |
m_height(height), |
| 62 |
m_byte_width(byte_width) |
| 63 |
{ |
| 64 |
memset(&m_rows[0], 0, sizeof(row_data) * height); |
| 65 |
} |
| 66 |
|
| 67 |
// Allocate and clear the buffer |
| 68 |
//-------------------------------------------------------------------- |
| 69 |
void init(unsigned width, unsigned height, unsigned byte_width) |
| 70 |
{ |
| 71 |
unsigned i; |
| 72 |
for(i = 0; i < m_height; ++i) |
| 73 |
{ |
| 74 |
pod_allocator<int8u>::deallocate((int8u*)m_rows[i].ptr, m_byte_width); |
| 75 |
} |
| 76 |
if(width && height) |
| 77 |
{ |
| 78 |
m_width = width; |
| 79 |
m_height = height; |
| 80 |
m_byte_width = byte_width; |
| 81 |
m_rows.resize(height); |
| 82 |
memset(&m_rows[0], 0, sizeof(row_data) * height); |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
//-------------------------------------------------------------------- |
| 87 |
unsigned width() const { return m_width; } |
| 88 |
unsigned height() const { return m_height; } |
| 89 |
unsigned byte_width() const { return m_byte_width; } |
| 90 |
|
| 91 |
// The main function used for rendering. Returns pointer to the |
| 92 |
// pre-allocated span. Memory for the row is allocated as needed. |
| 93 |
//-------------------------------------------------------------------- |
| 94 |
int8u* row_ptr(int x, int y, unsigned len) |
| 95 |
{ |
| 96 |
row_data* r = &m_rows[y]; |
| 97 |
int x2 = x + len - 1; |
| 98 |
if(r->ptr) |
| 99 |
{ |
| 100 |
if(x < r->x1) { r->x1 = x; } |
| 101 |
if(x2 > r->x2) { r->x2 = x2; } |
| 102 |
} |
| 103 |
else |
| 104 |
{ |
| 105 |
int8u* p = pod_allocator<int8u>::allocate(m_byte_width); |
| 106 |
r->ptr = p; |
| 107 |
r->x1 = x; |
| 108 |
r->x2 = x2; |
| 109 |
memset(p, 0, m_byte_width); |
| 110 |
} |
| 111 |
return (int8u*)r->ptr; |
| 112 |
} |
| 113 |
|
| 114 |
//-------------------------------------------------------------------- |
| 115 |
const int8u* row_ptr(int y) const { return m_rows[y].ptr; } |
| 116 |
int8u* row_ptr(int y) { return row_ptr(0, y, m_width); } |
| 117 |
row_data row (int y) const { return m_rows[y]; } |
| 118 |
|
| 119 |
private: |
| 120 |
//-------------------------------------------------------------------- |
| 121 |
// Prohibit copying |
| 122 |
rendering_buffer_dynarow(const rendering_buffer_dynarow&); |
| 123 |
const rendering_buffer_dynarow& operator = (const rendering_buffer_dynarow&); |
| 124 |
|
| 125 |
private: |
| 126 |
//-------------------------------------------------------------------- |
| 127 |
pod_array<row_data> m_rows; // Pointers to each row of the buffer |
| 128 |
unsigned m_width; // Width in pixels |
| 129 |
unsigned m_height; // Height in pixels |
| 130 |
unsigned m_byte_width; // Width in bytes |
| 131 |
}; |
| 132 |
|
| 133 |
|
| 134 |
} |
| 135 |
|
| 136 |
|
| 137 |
#endif |