~ubuntu-branches/ubuntu/lucid/agg/lucid-proposed

« back to all changes in this revision

Viewing changes to include/agg_rendering_buffer.h

  • Committer: Bazaar Package Importer
  • Author(s): Rene Engelhard
  • Date: 2005-11-29 02:02:41 UTC
  • Revision ID: james.westby@ubuntu.com-20051129020241-pmlxls0x6j2qv3nm
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//----------------------------------------------------------------------------
 
2
// Anti-Grain Geometry - Version 2.3
 
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: mcseem@antigrain.com
 
12
//          mcseemagg@yahoo.com
 
13
//          http://www.antigrain.com
 
14
//----------------------------------------------------------------------------
 
15
//
 
16
// class rendering_buffer
 
17
//
 
18
//----------------------------------------------------------------------------
 
19
 
 
20
#ifndef AGG_RENDERING_BUFFER_INCLUDED
 
21
#define AGG_RENDERING_BUFFER_INCLUDED
 
22
 
 
23
#include "agg_basics.h"
 
24
 
 
25
namespace agg
 
26
{
 
27
 
 
28
    //==========================================================row_ptr_cache
 
29
    template<class T> class row_ptr_cache
 
30
    {
 
31
    public:
 
32
        //--------------------------------------------------------------------
 
33
        struct row_data
 
34
        {
 
35
            int x1, x2;
 
36
            const int8u* ptr;
 
37
            row_data() {}
 
38
            row_data(int x1_, int x2_, const int8u* ptr_) : 
 
39
                x1(x1_), x2(x2_), ptr(ptr_) {}
 
40
        };
 
41
 
 
42
        //--------------------------------------------------------------------
 
43
        struct span_data
 
44
        {
 
45
            int x;
 
46
            unsigned len;
 
47
            int8u* ptr;
 
48
            span_data() {}
 
49
            span_data(int) : x(0), len(0), ptr(0) {}
 
50
            span_data(int x_, unsigned len_, int8u* ptr_) : 
 
51
                x(x_), len(len_), ptr(ptr_) {}
 
52
        };
 
53
 
 
54
        //-------------------------------------------------------------------
 
55
        ~row_ptr_cache()
 
56
        {
 
57
            delete [] m_rows;
 
58
        }
 
59
 
 
60
        //-------------------------------------------------------------------
 
61
        row_ptr_cache() :
 
62
            m_buf(0),
 
63
            m_rows(0),
 
64
            m_width(0),
 
65
            m_height(0),
 
66
            m_stride(0),
 
67
            m_max_height(0)
 
68
        {
 
69
        }
 
70
 
 
71
        //--------------------------------------------------------------------
 
72
        row_ptr_cache(T* buf, unsigned width, unsigned height, int stride) :
 
73
            m_buf(0),
 
74
            m_rows(0),
 
75
            m_width(0),
 
76
            m_height(0),
 
77
            m_stride(0),
 
78
            m_max_height(0)
 
79
        {
 
80
            attach(buf, width, height, stride);
 
81
        }
 
82
 
 
83
        //--------------------------------------------------------------------
 
84
        void attach(T* buf, unsigned width, unsigned height, int stride)
 
85
        {
 
86
            m_buf = buf;
 
87
            m_width = width;
 
88
            m_height = height;
 
89
            m_stride = stride;
 
90
            if(height > m_max_height)
 
91
            {
 
92
                delete [] m_rows;
 
93
                m_rows = new T* [m_max_height = height];
 
94
            }
 
95
 
 
96
            T* row_ptr = m_buf;
 
97
 
 
98
            if(stride < 0)
 
99
            {
 
100
                row_ptr = m_buf - int(height - 1) * stride;
 
101
            }
 
102
 
 
103
            T** rows = m_rows;
 
104
 
 
105
            while(height--)
 
106
            {
 
107
                *rows++ = row_ptr;
 
108
                row_ptr += stride;
 
109
            }
 
110
        }
 
111
 
 
112
        //--------------------------------------------------------------------
 
113
        T* buf() { return m_buf; }
 
114
        const T* buf()    const { return m_buf;    }
 
115
        unsigned width()  const { return m_width;  }
 
116
        unsigned height() const { return m_height; }
 
117
        int      stride() const { return m_stride; }
 
118
        unsigned stride_abs() const 
 
119
        {
 
120
            return (m_stride < 0) ? 
 
121
                unsigned(-m_stride) : 
 
122
                unsigned(m_stride); 
 
123
        }
 
124
 
 
125
        //--------------------------------------------------------------------
 
126
        T* row(unsigned y) { return m_rows[y]; }
 
127
        const T* row(unsigned y) const { return m_rows[y]; }
 
128
 
 
129
        T* next_row(void* p) { return (T*)p + m_stride; }
 
130
        const T* next_row(const void* p) const { return (T*)p + m_stride; }
 
131
 
 
132
        T const* const* rows() const { return m_rows; }
 
133
 
 
134
        //--------------------------------------------------------------------
 
135
        void copy_from(const row_ptr_cache<T>& mtx)
 
136
        {
 
137
            unsigned h = height();
 
138
            if(mtx.height() < h) h = mtx.height();
 
139
        
 
140
            unsigned l = stride_abs();
 
141
            if(mtx.stride_abs() < l) l = mtx.stride_abs();
 
142
        
 
143
            l *= sizeof(T);
 
144
 
 
145
            unsigned y;
 
146
            for (y = 0; y < h; y++)
 
147
            {
 
148
                memcpy(row(y), mtx.row(y), l);
 
149
            }
 
150
        }
 
151
 
 
152
        //--------------------------------------------------------------------
 
153
        void clear(T value)
 
154
        {
 
155
            unsigned y;
 
156
            for(y = 0; y < height(); y++)
 
157
            {
 
158
                T* p = row(y);
 
159
                unsigned x;
 
160
                for(x = 0; x < stride_abs(); x++)
 
161
                {
 
162
                    *p++ = value;
 
163
                }
 
164
            }
 
165
        }
 
166
 
 
167
 
 
168
    private:
 
169
        //--------------------------------------------------------------------
 
170
        // Prohibit copying
 
171
        row_ptr_cache(const row_ptr_cache<T>&);
 
172
        const row_ptr_cache<T>& operator = (const row_ptr_cache<T>&);
 
173
 
 
174
    private:
 
175
        //--------------------------------------------------------------------
 
176
        T*       m_buf;        // Pointer to renrdering buffer
 
177
        T**      m_rows;       // Pointers to each row of the buffer
 
178
        unsigned m_width;      // Width in pixels
 
179
        unsigned m_height;     // Height in pixels
 
180
        int      m_stride;     // Number of bytes per row. Can be < 0
 
181
        unsigned m_max_height; // The maximal height (currently allocated)
 
182
    };
 
183
 
 
184
 
 
185
 
 
186
    //========================================================rendering_buffer
 
187
    typedef row_ptr_cache<int8u> rendering_buffer;
 
188
 
 
189
}
 
190
 
 
191
 
 
192
#endif