2
2
// Anti-Grain Geometry - Version 2.4
3
3
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
4
//
5
- // Permission to copy, use, modify, sell and distribute this software
6
- // is granted provided this copyright notice appears in all copies.
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
7
// This software is provided "as is" without express or implied
8
8
// warranty, and with no claim as to its suitability for any purpose.
9
9
//
10
10
// ----------------------------------------------------------------------------
11
11
//
12
- // The author gratefully acknowleges the support of David Turner,
13
- // Robert Wilhelm, and Werner Lemberg - the authors of the FreeType
12
+ // The author gratefully acknowleges the support of David Turner,
13
+ // Robert Wilhelm, and Werner Lemberg - the authors of the FreeType
14
14
// libray - in producing this work. See http://www.freetype.org for details.
15
15
//
16
16
// ----------------------------------------------------------------------------
19
19
// http://www.antigrain.com
20
20
// ----------------------------------------------------------------------------
21
21
//
22
- // Adaptation for 32-bit screen coordinates has been sponsored by
22
+ // Adaptation for 32-bit screen coordinates has been sponsored by
23
23
// Liberty Technology Systems, Inc., visit http://lib-sys.com
24
24
//
25
25
// Liberty Technology Systems, Inc. is the provider of
26
26
// PostScript and PDF technology for software developers.
27
- //
27
+ //
28
28
// ----------------------------------------------------------------------------
29
29
#ifndef AGG_RASTERIZER_CELLS_AA_INCLUDED
30
30
#define AGG_RASTERIZER_CELLS_AA_INCLUDED
31
31
32
+ #include < stdexcept>
32
33
#include < string.h>
33
34
#include < math.h>
34
35
#include " agg_math.h"
@@ -48,8 +49,7 @@ namespace agg
48
49
cell_block_shift = 12 ,
49
50
cell_block_size = 1 << cell_block_shift,
50
51
cell_block_mask = cell_block_size - 1 ,
51
- cell_block_pool = 256 ,
52
- cell_block_limit = 1024
52
+ cell_block_pool = 256
53
53
};
54
54
55
55
struct sorted_y
@@ -63,7 +63,7 @@ namespace agg
63
63
typedef rasterizer_cells_aa<Cell> self_type;
64
64
65
65
~rasterizer_cells_aa ();
66
- rasterizer_cells_aa ();
66
+ rasterizer_cells_aa (unsigned cell_block_limit= 1024 );
67
67
68
68
void reset ();
69
69
void style (const cell_type& style_cell);
@@ -76,19 +76,19 @@ namespace agg
76
76
77
77
void sort_cells ();
78
78
79
- unsigned total_cells () const
79
+ unsigned total_cells () const
80
80
{
81
81
return m_num_cells;
82
82
}
83
83
84
- unsigned scanline_num_cells (unsigned y) const
85
- {
86
- return m_sorted_y[y - m_min_y].num ;
84
+ unsigned scanline_num_cells (unsigned y) const
85
+ {
86
+ return m_sorted_y[y - m_min_y].num ;
87
87
}
88
88
89
89
const cell_type* const * scanline_cells (unsigned y) const
90
- {
91
- return m_sorted_cells.data () + m_sorted_y[y - m_min_y].start ;
90
+ {
91
+ return m_sorted_cells.data () + m_sorted_y[y - m_min_y].start ;
92
92
}
93
93
94
94
bool sorted () const { return m_sorted; }
@@ -101,12 +101,13 @@ namespace agg
101
101
void add_curr_cell ();
102
102
void render_hline (int ey, int x1, int y1, int x2, int y2);
103
103
void allocate_block ();
104
-
104
+
105
105
private:
106
106
unsigned m_num_blocks;
107
107
unsigned m_max_blocks;
108
108
unsigned m_curr_block;
109
109
unsigned m_num_cells;
110
+ unsigned m_cell_block_limit;
110
111
cell_type** m_cells;
111
112
cell_type* m_curr_cell_ptr;
112
113
pod_vector<cell_type*> m_sorted_cells;
@@ -124,7 +125,7 @@ namespace agg
124
125
125
126
126
127
// ------------------------------------------------------------------------
127
- template <class Cell >
128
+ template <class Cell >
128
129
rasterizer_cells_aa<Cell>::~rasterizer_cells_aa ()
129
130
{
130
131
if (m_num_blocks)
@@ -140,12 +141,13 @@ namespace agg
140
141
}
141
142
142
143
// ------------------------------------------------------------------------
143
- template <class Cell >
144
- rasterizer_cells_aa<Cell>::rasterizer_cells_aa() :
144
+ template <class Cell >
145
+ rasterizer_cells_aa<Cell>::rasterizer_cells_aa(unsigned cell_block_limit ) :
145
146
m_num_blocks (0 ),
146
147
m_max_blocks(0 ),
147
148
m_curr_block(0 ),
148
149
m_num_cells(0 ),
150
+ m_cell_block_limit(cell_block_limit),
149
151
m_cells(0 ),
150
152
m_curr_cell_ptr(0 ),
151
153
m_sorted_cells(),
@@ -161,10 +163,10 @@ namespace agg
161
163
}
162
164
163
165
// ------------------------------------------------------------------------
164
- template <class Cell >
166
+ template <class Cell >
165
167
void rasterizer_cells_aa<Cell>::reset()
166
168
{
167
- m_num_cells = 0 ;
169
+ m_num_cells = 0 ;
168
170
m_curr_block = 0 ;
169
171
m_curr_cell.initial ();
170
172
m_style_cell.initial ();
@@ -176,14 +178,16 @@ namespace agg
176
178
}
177
179
178
180
// ------------------------------------------------------------------------
179
- template <class Cell >
181
+ template <class Cell >
180
182
AGG_INLINE void rasterizer_cells_aa<Cell>::add_curr_cell()
181
183
{
182
184
if (m_curr_cell.area | m_curr_cell.cover )
183
185
{
184
186
if ((m_num_cells & cell_block_mask) == 0 )
185
187
{
186
- if (m_num_blocks >= cell_block_limit) return ;
188
+ if (m_num_blocks >= m_cell_block_limit) {
189
+ throw std::overflow_error (" Exceeded cell block limit" );
190
+ }
187
191
allocate_block ();
188
192
}
189
193
*m_curr_cell_ptr++ = m_curr_cell;
@@ -192,7 +196,7 @@ namespace agg
192
196
}
193
197
194
198
// ------------------------------------------------------------------------
195
- template <class Cell >
199
+ template <class Cell >
196
200
AGG_INLINE void rasterizer_cells_aa<Cell>::set_curr_cell(int x, int y)
197
201
{
198
202
if (m_curr_cell.not_equal (x, y, m_style_cell))
@@ -207,9 +211,9 @@ namespace agg
207
211
}
208
212
209
213
// ------------------------------------------------------------------------
210
- template <class Cell >
211
- AGG_INLINE void rasterizer_cells_aa<Cell>::render_hline(int ey,
212
- int x1, int y1,
214
+ template <class Cell >
215
+ AGG_INLINE void rasterizer_cells_aa<Cell>::render_hline(int ey,
216
+ int x1, int y1,
213
217
int x2, int y2)
214
218
{
215
219
int ex1 = x1 >> poly_subpixel_shift;
@@ -305,14 +309,14 @@ namespace agg
305
309
}
306
310
307
311
// ------------------------------------------------------------------------
308
- template <class Cell >
312
+ template <class Cell >
309
313
AGG_INLINE void rasterizer_cells_aa<Cell>::style(const cell_type& style_cell)
310
- {
311
- m_style_cell.style (style_cell);
314
+ {
315
+ m_style_cell.style (style_cell);
312
316
}
313
317
314
318
// ------------------------------------------------------------------------
315
- template <class Cell >
319
+ template <class Cell >
316
320
void rasterizer_cells_aa<Cell>::line(int x1, int y1, int x2, int y2)
317
321
{
318
322
enum dx_limit_e { dx_limit = 16384 << poly_subpixel_shift };
@@ -358,7 +362,7 @@ namespace agg
358
362
359
363
// Vertical line - we have to calculate start and end cells,
360
364
// and then - the common values of the area and coverage for
361
- // all cells of the line. We know exactly there's only one
365
+ // all cells of the line. We know exactly there's only one
362
366
// cell, so, we don't have to call render_hline().
363
367
incr = 1 ;
364
368
if (dx == 0 )
@@ -463,15 +467,15 @@ namespace agg
463
467
}
464
468
465
469
// ------------------------------------------------------------------------
466
- template <class Cell >
470
+ template <class Cell >
467
471
void rasterizer_cells_aa<Cell>::allocate_block()
468
472
{
469
473
if (m_curr_block >= m_num_blocks)
470
474
{
471
475
if (m_num_blocks >= m_max_blocks)
472
476
{
473
- cell_type** new_cells =
474
- pod_allocator<cell_type*>::allocate (m_max_blocks +
477
+ cell_type** new_cells =
478
+ pod_allocator<cell_type*>::allocate (m_max_blocks +
475
479
cell_block_pool);
476
480
477
481
if (m_cells)
@@ -483,7 +487,7 @@ namespace agg
483
487
m_max_blocks += cell_block_pool;
484
488
}
485
489
486
- m_cells[m_num_blocks++] =
490
+ m_cells[m_num_blocks++] =
487
491
pod_allocator<cell_type>::allocate (cell_block_size);
488
492
489
493
}
@@ -513,7 +517,7 @@ namespace agg
513
517
void qsort_cells (Cell** start, unsigned num)
514
518
{
515
519
Cell** stack[80 ];
516
- Cell*** top;
520
+ Cell*** top;
517
521
Cell** limit;
518
522
Cell** base;
519
523
@@ -538,7 +542,7 @@ namespace agg
538
542
i = base + 1 ;
539
543
j = limit - 1 ;
540
544
541
- // now ensure that *i <= *base <= *j
545
+ // now ensure that *i <= *base <= *j
542
546
if ((*j)->x < (*i)->x )
543
547
{
544
548
swap_cells (i, j);
@@ -619,7 +623,7 @@ namespace agg
619
623
620
624
621
625
// ------------------------------------------------------------------------
622
- template <class Cell >
626
+ template <class Cell >
623
627
void rasterizer_cells_aa<Cell>::sort_cells()
624
628
{
625
629
if (m_sorted) return ; // Perform sort only the first time.
@@ -636,9 +640,9 @@ namespace agg
636
640
// for(unsigned nc = 0; nc < m_num_cells; nc++)
637
641
// {
638
642
// cell_type* cell = m_cells[nc >> cell_block_shift] + (nc & cell_block_mask);
639
- // if(cell->x < m_min_x ||
640
- // cell->y < m_min_y ||
641
- // cell->x > m_max_x ||
643
+ // if(cell->x < m_min_x ||
644
+ // cell->y < m_min_y ||
645
+ // cell->x > m_max_x ||
642
646
// cell->y > m_max_y)
643
647
// {
644
648
// cell = cell; // Breakpoint here
@@ -661,7 +665,7 @@ namespace agg
661
665
cell_ptr = *block_ptr++;
662
666
i = (nb > cell_block_size) ? cell_block_size : nb;
663
667
nb -= i;
664
- while (i--)
668
+ while (i--)
665
669
{
666
670
m_sorted_y[cell_ptr->y - m_min_y].start ++;
667
671
++cell_ptr;
@@ -693,7 +697,7 @@ namespace agg
693
697
++cell_ptr;
694
698
}
695
699
}
696
-
700
+
697
701
// Finally arrange the X-arrays
698
702
for (i = 0 ; i < m_sorted_y.size (); i++)
699
703
{
0 commit comments