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
#ifndef AGG_IMAGE_ACCESSORS_INCLUDED
17
#define AGG_IMAGE_ACCESSORS_INCLUDED
19
#include "agg_basics.h"
24
//-----------------------------------------------------image_accessor_clip
25
template<class PixFmt> class image_accessor_clip
28
typedef PixFmt pixfmt_type;
29
typedef typename pixfmt_type::color_type color_type;
30
typedef typename pixfmt_type::order_type order_type;
31
typedef typename pixfmt_type::value_type value_type;
32
enum pix_width_e { pix_width = pixfmt_type::pix_width };
34
image_accessor_clip() {}
35
explicit image_accessor_clip(const pixfmt_type& pixf,
36
const color_type& bk) :
39
pixfmt_type::make_pix(m_bk_buf, bk);
42
void attach(const pixfmt_type& pixf)
47
void background_color(const color_type& bk)
49
pixfmt_type::make_pix(m_bk_buf, bk);
53
AGG_INLINE const int8u* pixel() const
55
if(m_y >= 0 && m_y < (int)m_pixf->height() &&
56
m_x >= 0 && m_x < (int)m_pixf->width())
58
return m_pixf->pix_ptr(m_x, m_y);
64
AGG_INLINE const int8u* span(int x, int y, unsigned len)
68
if(y >= 0 && y < (int)m_pixf->height() &&
69
x >= 0 && x+(int)len <= (int)m_pixf->width())
71
return m_pix_ptr = m_pixf->pix_ptr(x, y);
77
AGG_INLINE const int8u* next_x()
79
if(m_pix_ptr) return m_pix_ptr += pix_width;
84
AGG_INLINE const int8u* next_y()
89
m_y >= 0 && m_y < (int)m_pixf->height())
91
return m_pix_ptr = m_pixf->pix_ptr(m_x, m_y);
98
const pixfmt_type* m_pixf;
101
const int8u* m_pix_ptr;
107
//--------------------------------------------------image_accessor_no_clip
108
template<class PixFmt> class image_accessor_no_clip
111
typedef PixFmt pixfmt_type;
112
typedef typename pixfmt_type::color_type color_type;
113
typedef typename pixfmt_type::order_type order_type;
114
typedef typename pixfmt_type::value_type value_type;
115
enum pix_width_e { pix_width = pixfmt_type::pix_width };
117
image_accessor_no_clip() {}
118
explicit image_accessor_no_clip(const pixfmt_type& pixf) :
122
void attach(const pixfmt_type& pixf)
127
AGG_INLINE const int8u* span(int x, int y, unsigned)
131
return m_pix_ptr = m_pixf->pix_ptr(x, y);
134
AGG_INLINE const int8u* next_x()
136
return m_pix_ptr += pix_width;
139
AGG_INLINE const int8u* next_y()
142
return m_pix_ptr = m_pixf->pix_ptr(m_x, m_y);
146
const pixfmt_type* m_pixf;
148
const int8u* m_pix_ptr;
154
//----------------------------------------------------image_accessor_clone
155
template<class PixFmt> class image_accessor_clone
158
typedef PixFmt pixfmt_type;
159
typedef typename pixfmt_type::color_type color_type;
160
typedef typename pixfmt_type::order_type order_type;
161
typedef typename pixfmt_type::value_type value_type;
162
enum pix_width_e { pix_width = pixfmt_type::pix_width };
164
image_accessor_clone() {}
165
explicit image_accessor_clone(const pixfmt_type& pixf) :
169
void attach(const pixfmt_type& pixf)
175
AGG_INLINE const int8u* pixel() const
177
register int x = m_x;
178
register int y = m_y;
181
if(x >= (int)m_pixf->width()) x = m_pixf->width() - 1;
182
if(y >= (int)m_pixf->height()) y = m_pixf->height() - 1;
183
return m_pixf->pix_ptr(x, y);
187
AGG_INLINE const int8u* span(int x, int y, unsigned len)
191
if(y >= 0 && y < (int)m_pixf->height() &&
192
x >= 0 && x+len <= (int)m_pixf->width())
194
return m_pix_ptr = m_pixf->pix_ptr(x, y);
200
AGG_INLINE const int8u* next_x()
202
if(m_pix_ptr) return m_pix_ptr += pix_width;
207
AGG_INLINE const int8u* next_y()
212
m_y >= 0 && m_y < (int)m_pixf->height())
214
return m_pix_ptr = m_pixf->pix_ptr(m_x, m_y);
221
const pixfmt_type* m_pixf;
223
const int8u* m_pix_ptr;
230
//-----------------------------------------------------image_accessor_wrap
231
template<class PixFmt, class WrapX, class WrapY> class image_accessor_wrap
234
typedef PixFmt pixfmt_type;
235
typedef typename pixfmt_type::color_type color_type;
236
typedef typename pixfmt_type::order_type order_type;
237
typedef typename pixfmt_type::value_type value_type;
238
enum pix_width_e { pix_width = pixfmt_type::pix_width };
240
image_accessor_wrap() {}
241
explicit image_accessor_wrap(const pixfmt_type& pixf) :
243
m_wrap_x(pixf.width()),
244
m_wrap_y(pixf.height())
247
void attach(const pixfmt_type& pixf)
252
AGG_INLINE const int8u* span(int x, int y, unsigned)
255
m_row_ptr = m_pixf->row_ptr(m_wrap_y(y));
256
return m_row_ptr + m_wrap_x(x) * pix_width;
259
AGG_INLINE const int8u* next_x()
262
return m_row_ptr + x * pix_width;
265
AGG_INLINE const int8u* next_y()
267
m_row_ptr = m_pixf->row_ptr(++m_wrap_y);
268
return m_row_ptr + m_wrap_x(m_x) * pix_width;
272
const pixfmt_type* m_pixf;
273
const int8u* m_row_ptr;
282
//--------------------------------------------------------wrap_mode_repeat
283
class wrap_mode_repeat
286
wrap_mode_repeat() {}
287
wrap_mode_repeat(unsigned size) :
289
m_add(size * (0x3FFFFFFF / size)),
293
AGG_INLINE unsigned operator() (int v)
295
return m_value = (unsigned(v) + m_add) % m_size;
298
AGG_INLINE unsigned operator++ ()
301
if(m_value >= m_size) m_value = 0;
311
//---------------------------------------------------wrap_mode_repeat_pow2
312
class wrap_mode_repeat_pow2
315
wrap_mode_repeat_pow2() {}
316
wrap_mode_repeat_pow2(unsigned size) : m_value(0)
319
while(m_mask < size) m_mask = (m_mask << 1) | 1;
322
AGG_INLINE unsigned operator() (int v)
324
return m_value = unsigned(v) & m_mask;
326
AGG_INLINE unsigned operator++ ()
329
if(m_value > m_mask) m_value = 0;
338
//----------------------------------------------wrap_mode_repeat_auto_pow2
339
class wrap_mode_repeat_auto_pow2
342
wrap_mode_repeat_auto_pow2() {}
343
wrap_mode_repeat_auto_pow2(unsigned size) :
345
m_add(size * (0x3FFFFFFF / size)),
346
m_mask((m_size & (m_size-1)) ? 0 : m_size-1),
350
AGG_INLINE unsigned operator() (int v)
352
if(m_mask) return m_value = unsigned(v) & m_mask;
353
return m_value = (unsigned(v) + m_add) % m_size;
355
AGG_INLINE unsigned operator++ ()
358
if(m_value >= m_size) m_value = 0;
370
//-------------------------------------------------------wrap_mode_reflect
371
class wrap_mode_reflect
374
wrap_mode_reflect() {}
375
wrap_mode_reflect(unsigned size) :
378
m_add(m_size2 * (0x3FFFFFFF / m_size2)),
382
AGG_INLINE unsigned operator() (int v)
384
m_value = (unsigned(v) + m_add) % m_size2;
385
if(m_value >= m_size) return m_size2 - m_value - 1;
389
AGG_INLINE unsigned operator++ ()
392
if(m_value >= m_size2) m_value = 0;
393
if(m_value >= m_size) return m_size2 - m_value - 1;
405
//--------------------------------------------------wrap_mode_reflect_pow2
406
class wrap_mode_reflect_pow2
409
wrap_mode_reflect_pow2() {}
410
wrap_mode_reflect_pow2(unsigned size) : m_value(0)
416
m_mask = (m_mask << 1) | 1;
420
AGG_INLINE unsigned operator() (int v)
422
m_value = unsigned(v) & m_mask;
423
if(m_value >= m_size) return m_mask - m_value;
426
AGG_INLINE unsigned operator++ ()
430
if(m_value >= m_size) return m_mask - m_value;
441
//---------------------------------------------wrap_mode_reflect_auto_pow2
442
class wrap_mode_reflect_auto_pow2
445
wrap_mode_reflect_auto_pow2() {}
446
wrap_mode_reflect_auto_pow2(unsigned size) :
449
m_add(m_size2 * (0x3FFFFFFF / m_size2)),
450
m_mask((m_size2 & (m_size2-1)) ? 0 : m_size2-1),
454
AGG_INLINE unsigned operator() (int v)
456
m_value = m_mask ? unsigned(v) & m_mask :
457
(unsigned(v) + m_add) % m_size2;
458
if(m_value >= m_size) return m_size2 - m_value - 1;
461
AGG_INLINE unsigned operator++ ()
464
if(m_value >= m_size2) m_value = 0;
465
if(m_value >= m_size) return m_size2 - m_value - 1;
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
#ifndef AGG_IMAGE_ACCESSORS_INCLUDED
17
#define AGG_IMAGE_ACCESSORS_INCLUDED
19
#include "agg_basics.h"
24
//-----------------------------------------------------image_accessor_clip
25
template<class PixFmt> class image_accessor_clip
28
typedef PixFmt pixfmt_type;
29
typedef typename pixfmt_type::color_type color_type;
30
typedef typename pixfmt_type::order_type order_type;
31
typedef typename pixfmt_type::value_type value_type;
32
enum pix_width_e { pix_width = pixfmt_type::pix_width };
34
image_accessor_clip() {}
35
explicit image_accessor_clip(pixfmt_type& pixf,
36
const color_type& bk) :
39
pixfmt_type::make_pix(m_bk_buf, bk);
42
void attach(pixfmt_type& pixf)
47
void background_color(const color_type& bk)
49
pixfmt_type::make_pix(m_bk_buf, bk);
53
AGG_INLINE const int8u* pixel() const
55
if(m_y >= 0 && m_y < (int)m_pixf->height() &&
56
m_x >= 0 && m_x < (int)m_pixf->width())
58
return m_pixf->pix_ptr(m_x, m_y);
64
AGG_INLINE const int8u* span(int x, int y, unsigned len)
68
if(y >= 0 && y < (int)m_pixf->height() &&
69
x >= 0 && x+(int)len <= (int)m_pixf->width())
71
return m_pix_ptr = m_pixf->pix_ptr(x, y);
77
AGG_INLINE const int8u* next_x()
79
if(m_pix_ptr) return m_pix_ptr += pix_width;
84
AGG_INLINE const int8u* next_y()
89
m_y >= 0 && m_y < (int)m_pixf->height())
91
return m_pix_ptr = m_pixf->pix_ptr(m_x, m_y);
98
const pixfmt_type* m_pixf;
99
int8u m_bk_buf[pix_width];
101
const int8u* m_pix_ptr;
107
//--------------------------------------------------image_accessor_no_clip
108
template<class PixFmt> class image_accessor_no_clip
111
typedef PixFmt pixfmt_type;
112
typedef typename pixfmt_type::color_type color_type;
113
typedef typename pixfmt_type::order_type order_type;
114
typedef typename pixfmt_type::value_type value_type;
115
enum pix_width_e { pix_width = pixfmt_type::pix_width };
117
image_accessor_no_clip() {}
118
explicit image_accessor_no_clip(pixfmt_type& pixf) :
122
void attach(pixfmt_type& pixf)
127
AGG_INLINE const int8u* span(int x, int y, unsigned)
131
return m_pix_ptr = m_pixf->pix_ptr(x, y);
134
AGG_INLINE const int8u* next_x()
136
return m_pix_ptr += pix_width;
139
AGG_INLINE const int8u* next_y()
142
return m_pix_ptr = m_pixf->pix_ptr(m_x, m_y);
146
const pixfmt_type* m_pixf;
148
const int8u* m_pix_ptr;
154
//----------------------------------------------------image_accessor_clone
155
template<class PixFmt> class image_accessor_clone
158
typedef PixFmt pixfmt_type;
159
typedef typename pixfmt_type::color_type color_type;
160
typedef typename pixfmt_type::order_type order_type;
161
typedef typename pixfmt_type::value_type value_type;
162
enum pix_width_e { pix_width = pixfmt_type::pix_width };
164
image_accessor_clone() {}
165
explicit image_accessor_clone(pixfmt_type& pixf) :
169
void attach(pixfmt_type& pixf)
175
AGG_INLINE const int8u* pixel() const
181
if(x >= (int)m_pixf->width()) x = m_pixf->width() - 1;
182
if(y >= (int)m_pixf->height()) y = m_pixf->height() - 1;
183
return m_pixf->pix_ptr(x, y);
187
AGG_INLINE const int8u* span(int x, int y, unsigned len)
191
if(y >= 0 && y < (int)m_pixf->height() &&
192
x >= 0 && x+len <= (int)m_pixf->width())
194
return m_pix_ptr = m_pixf->pix_ptr(x, y);
200
AGG_INLINE const int8u* next_x()
202
if(m_pix_ptr) return m_pix_ptr += pix_width;
207
AGG_INLINE const int8u* next_y()
212
m_y >= 0 && m_y < (int)m_pixf->height())
214
return m_pix_ptr = m_pixf->pix_ptr(m_x, m_y);
221
const pixfmt_type* m_pixf;
223
const int8u* m_pix_ptr;
230
//-----------------------------------------------------image_accessor_wrap
231
template<class PixFmt, class WrapX, class WrapY> class image_accessor_wrap
234
typedef PixFmt pixfmt_type;
235
typedef typename pixfmt_type::color_type color_type;
236
typedef typename pixfmt_type::order_type order_type;
237
typedef typename pixfmt_type::value_type value_type;
238
enum pix_width_e { pix_width = pixfmt_type::pix_width };
240
image_accessor_wrap() {}
241
explicit image_accessor_wrap(pixfmt_type& pixf) :
243
m_wrap_x(pixf.width()),
244
m_wrap_y(pixf.height())
247
void attach(pixfmt_type& pixf)
252
AGG_INLINE const int8u* span(int x, int y, unsigned)
255
m_row_ptr = m_pixf->pix_ptr(0, m_wrap_y(y));
256
return m_row_ptr + m_wrap_x(x) * pix_width;
259
AGG_INLINE const int8u* next_x()
262
return m_row_ptr + x * pix_width;
265
AGG_INLINE const int8u* next_y()
267
m_row_ptr = m_pixf->pix_ptr(0, ++m_wrap_y);
268
return m_row_ptr + m_wrap_x(m_x) * pix_width;
272
const pixfmt_type* m_pixf;
273
const int8u* m_row_ptr;
282
//--------------------------------------------------------wrap_mode_repeat
283
class wrap_mode_repeat
286
wrap_mode_repeat() {}
287
wrap_mode_repeat(unsigned size) :
289
m_add(size * (0x3FFFFFFF / size)),
293
AGG_INLINE unsigned operator() (int v)
295
return m_value = (unsigned(v) + m_add) % m_size;
298
AGG_INLINE unsigned operator++ ()
301
if(m_value >= m_size) m_value = 0;
311
//---------------------------------------------------wrap_mode_repeat_pow2
312
class wrap_mode_repeat_pow2
315
wrap_mode_repeat_pow2() {}
316
wrap_mode_repeat_pow2(unsigned size) : m_value(0)
319
while(m_mask < size) m_mask = (m_mask << 1) | 1;
322
AGG_INLINE unsigned operator() (int v)
324
return m_value = unsigned(v) & m_mask;
326
AGG_INLINE unsigned operator++ ()
329
if(m_value > m_mask) m_value = 0;
338
//----------------------------------------------wrap_mode_repeat_auto_pow2
339
class wrap_mode_repeat_auto_pow2
342
wrap_mode_repeat_auto_pow2() {}
343
wrap_mode_repeat_auto_pow2(unsigned size) :
345
m_add(size * (0x3FFFFFFF / size)),
346
m_mask((m_size & (m_size-1)) ? 0 : m_size-1),
350
AGG_INLINE unsigned operator() (int v)
352
if(m_mask) return m_value = unsigned(v) & m_mask;
353
return m_value = (unsigned(v) + m_add) % m_size;
355
AGG_INLINE unsigned operator++ ()
358
if(m_value >= m_size) m_value = 0;
370
//-------------------------------------------------------wrap_mode_reflect
371
class wrap_mode_reflect
374
wrap_mode_reflect() {}
375
wrap_mode_reflect(unsigned size) :
378
m_add(m_size2 * (0x3FFFFFFF / m_size2)),
382
AGG_INLINE unsigned operator() (int v)
384
m_value = (unsigned(v) + m_add) % m_size2;
385
if(m_value >= m_size) return m_size2 - m_value - 1;
389
AGG_INLINE unsigned operator++ ()
392
if(m_value >= m_size2) m_value = 0;
393
if(m_value >= m_size) return m_size2 - m_value - 1;
405
//--------------------------------------------------wrap_mode_reflect_pow2
406
class wrap_mode_reflect_pow2
409
wrap_mode_reflect_pow2() {}
410
wrap_mode_reflect_pow2(unsigned size) : m_value(0)
416
m_mask = (m_mask << 1) | 1;
420
AGG_INLINE unsigned operator() (int v)
422
m_value = unsigned(v) & m_mask;
423
if(m_value >= m_size) return m_mask - m_value;
426
AGG_INLINE unsigned operator++ ()
430
if(m_value >= m_size) return m_mask - m_value;
441
//---------------------------------------------wrap_mode_reflect_auto_pow2
442
class wrap_mode_reflect_auto_pow2
445
wrap_mode_reflect_auto_pow2() {}
446
wrap_mode_reflect_auto_pow2(unsigned size) :
449
m_add(m_size2 * (0x3FFFFFFF / m_size2)),
450
m_mask((m_size2 & (m_size2-1)) ? 0 : m_size2-1),
454
AGG_INLINE unsigned operator() (int v)
456
m_value = m_mask ? unsigned(v) & m_mask :
457
(unsigned(v) + m_add) % m_size2;
458
if(m_value >= m_size) return m_size2 - m_value - 1;
461
AGG_INLINE unsigned operator++ ()
464
if(m_value >= m_size2) m_value = 0;
465
if(m_value >= m_size) return m_size2 - m_value - 1;