Skip to content

Commit 1b937a4

Browse files
committed
Make cell_block_limit non-hard-coded
1 parent 7766ebe commit 1b937a4

5 files changed

+58
-54
lines changed

extern/agg24/include/agg_rasterizer_cells_aa.h

+48-44
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
// Anti-Grain Geometry - Version 2.4
33
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
44
//
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.
77
// This software is provided "as is" without express or implied
88
// warranty, and with no claim as to its suitability for any purpose.
99
//
1010
//----------------------------------------------------------------------------
1111
//
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
1414
// libray - in producing this work. See http://www.freetype.org for details.
1515
//
1616
//----------------------------------------------------------------------------
@@ -19,16 +19,17 @@
1919
// http://www.antigrain.com
2020
//----------------------------------------------------------------------------
2121
//
22-
// Adaptation for 32-bit screen coordinates has been sponsored by
22+
// Adaptation for 32-bit screen coordinates has been sponsored by
2323
// Liberty Technology Systems, Inc., visit http://lib-sys.com
2424
//
2525
// Liberty Technology Systems, Inc. is the provider of
2626
// PostScript and PDF technology for software developers.
27-
//
27+
//
2828
//----------------------------------------------------------------------------
2929
#ifndef AGG_RASTERIZER_CELLS_AA_INCLUDED
3030
#define AGG_RASTERIZER_CELLS_AA_INCLUDED
3131

32+
#include <stdexcept>
3233
#include <string.h>
3334
#include <math.h>
3435
#include "agg_math.h"
@@ -48,8 +49,7 @@ namespace agg
4849
cell_block_shift = 12,
4950
cell_block_size = 1 << cell_block_shift,
5051
cell_block_mask = cell_block_size - 1,
51-
cell_block_pool = 256,
52-
cell_block_limit = 1024
52+
cell_block_pool = 256
5353
};
5454

5555
struct sorted_y
@@ -63,7 +63,7 @@ namespace agg
6363
typedef rasterizer_cells_aa<Cell> self_type;
6464

6565
~rasterizer_cells_aa();
66-
rasterizer_cells_aa();
66+
rasterizer_cells_aa(unsigned cell_block_limit=1024);
6767

6868
void reset();
6969
void style(const cell_type& style_cell);
@@ -76,19 +76,19 @@ namespace agg
7676

7777
void sort_cells();
7878

79-
unsigned total_cells() const
79+
unsigned total_cells() const
8080
{
8181
return m_num_cells;
8282
}
8383

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;
8787
}
8888

8989
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;
9292
}
9393

9494
bool sorted() const { return m_sorted; }
@@ -101,12 +101,13 @@ namespace agg
101101
void add_curr_cell();
102102
void render_hline(int ey, int x1, int y1, int x2, int y2);
103103
void allocate_block();
104-
104+
105105
private:
106106
unsigned m_num_blocks;
107107
unsigned m_max_blocks;
108108
unsigned m_curr_block;
109109
unsigned m_num_cells;
110+
unsigned m_cell_block_limit;
110111
cell_type** m_cells;
111112
cell_type* m_curr_cell_ptr;
112113
pod_vector<cell_type*> m_sorted_cells;
@@ -124,7 +125,7 @@ namespace agg
124125

125126

126127
//------------------------------------------------------------------------
127-
template<class Cell>
128+
template<class Cell>
128129
rasterizer_cells_aa<Cell>::~rasterizer_cells_aa()
129130
{
130131
if(m_num_blocks)
@@ -140,12 +141,13 @@ namespace agg
140141
}
141142

142143
//------------------------------------------------------------------------
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) :
145146
m_num_blocks(0),
146147
m_max_blocks(0),
147148
m_curr_block(0),
148149
m_num_cells(0),
150+
m_cell_block_limit(cell_block_limit),
149151
m_cells(0),
150152
m_curr_cell_ptr(0),
151153
m_sorted_cells(),
@@ -161,10 +163,10 @@ namespace agg
161163
}
162164

163165
//------------------------------------------------------------------------
164-
template<class Cell>
166+
template<class Cell>
165167
void rasterizer_cells_aa<Cell>::reset()
166168
{
167-
m_num_cells = 0;
169+
m_num_cells = 0;
168170
m_curr_block = 0;
169171
m_curr_cell.initial();
170172
m_style_cell.initial();
@@ -176,14 +178,16 @@ namespace agg
176178
}
177179

178180
//------------------------------------------------------------------------
179-
template<class Cell>
181+
template<class Cell>
180182
AGG_INLINE void rasterizer_cells_aa<Cell>::add_curr_cell()
181183
{
182184
if(m_curr_cell.area | m_curr_cell.cover)
183185
{
184186
if((m_num_cells & cell_block_mask) == 0)
185187
{
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+
}
187191
allocate_block();
188192
}
189193
*m_curr_cell_ptr++ = m_curr_cell;
@@ -192,7 +196,7 @@ namespace agg
192196
}
193197

194198
//------------------------------------------------------------------------
195-
template<class Cell>
199+
template<class Cell>
196200
AGG_INLINE void rasterizer_cells_aa<Cell>::set_curr_cell(int x, int y)
197201
{
198202
if(m_curr_cell.not_equal(x, y, m_style_cell))
@@ -207,9 +211,9 @@ namespace agg
207211
}
208212

209213
//------------------------------------------------------------------------
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,
213217
int x2, int y2)
214218
{
215219
int ex1 = x1 >> poly_subpixel_shift;
@@ -305,14 +309,14 @@ namespace agg
305309
}
306310

307311
//------------------------------------------------------------------------
308-
template<class Cell>
312+
template<class Cell>
309313
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);
312316
}
313317

314318
//------------------------------------------------------------------------
315-
template<class Cell>
319+
template<class Cell>
316320
void rasterizer_cells_aa<Cell>::line(int x1, int y1, int x2, int y2)
317321
{
318322
enum dx_limit_e { dx_limit = 16384 << poly_subpixel_shift };
@@ -358,7 +362,7 @@ namespace agg
358362

359363
//Vertical line - we have to calculate start and end cells,
360364
//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
362366
//cell, so, we don't have to call render_hline().
363367
incr = 1;
364368
if(dx == 0)
@@ -463,15 +467,15 @@ namespace agg
463467
}
464468

465469
//------------------------------------------------------------------------
466-
template<class Cell>
470+
template<class Cell>
467471
void rasterizer_cells_aa<Cell>::allocate_block()
468472
{
469473
if(m_curr_block >= m_num_blocks)
470474
{
471475
if(m_num_blocks >= m_max_blocks)
472476
{
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 +
475479
cell_block_pool);
476480

477481
if(m_cells)
@@ -483,7 +487,7 @@ namespace agg
483487
m_max_blocks += cell_block_pool;
484488
}
485489

486-
m_cells[m_num_blocks++] =
490+
m_cells[m_num_blocks++] =
487491
pod_allocator<cell_type>::allocate(cell_block_size);
488492

489493
}
@@ -513,7 +517,7 @@ namespace agg
513517
void qsort_cells(Cell** start, unsigned num)
514518
{
515519
Cell** stack[80];
516-
Cell*** top;
520+
Cell*** top;
517521
Cell** limit;
518522
Cell** base;
519523

@@ -538,7 +542,7 @@ namespace agg
538542
i = base + 1;
539543
j = limit - 1;
540544

541-
// now ensure that *i <= *base <= *j
545+
// now ensure that *i <= *base <= *j
542546
if((*j)->x < (*i)->x)
543547
{
544548
swap_cells(i, j);
@@ -619,7 +623,7 @@ namespace agg
619623

620624

621625
//------------------------------------------------------------------------
622-
template<class Cell>
626+
template<class Cell>
623627
void rasterizer_cells_aa<Cell>::sort_cells()
624628
{
625629
if(m_sorted) return; //Perform sort only the first time.
@@ -636,9 +640,9 @@ namespace agg
636640
//for(unsigned nc = 0; nc < m_num_cells; nc++)
637641
//{
638642
// 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 ||
642646
// cell->y > m_max_y)
643647
// {
644648
// cell = cell; // Breakpoint here
@@ -661,7 +665,7 @@ namespace agg
661665
cell_ptr = *block_ptr++;
662666
i = (nb > cell_block_size) ? cell_block_size : nb;
663667
nb -= i;
664-
while(i--)
668+
while(i--)
665669
{
666670
m_sorted_y[cell_ptr->y - m_min_y].start++;
667671
++cell_ptr;
@@ -693,7 +697,7 @@ namespace agg
693697
++cell_ptr;
694698
}
695699
}
696-
700+
697701
// Finally arrange the X-arrays
698702
for(i = 0; i < m_sorted_y.size(); i++)
699703
{

extern/agg24/include/agg_rasterizer_compound_aa.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ namespace agg
109109
};
110110

111111
//--------------------------------------------------------------------
112-
rasterizer_compound_aa() :
113-
m_outline(),
112+
rasterizer_compound_aa(unsigned cell_block_limit=1024) :
113+
m_outline(cell_block_limit),
114114
m_clipper(),
115115
m_filling_rule(fill_non_zero),
116116
m_layer_order(layer_direct),

extern/agg24/include/agg_rasterizer_scanline_aa.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ namespace agg
9393
};
9494

9595
//--------------------------------------------------------------------
96-
rasterizer_scanline_aa() :
97-
m_outline(),
96+
rasterizer_scanline_aa(unsigned cell_block_limit=1024) :
97+
m_outline(cell_block_limit),
9898
m_clipper(),
9999
m_filling_rule(fill_non_zero),
100100
m_auto_close(true),
@@ -107,9 +107,9 @@ namespace agg
107107
}
108108

109109
//--------------------------------------------------------------------
110-
template<class GammaF>
111-
rasterizer_scanline_aa(const GammaF& gamma_function) :
112-
m_outline(),
110+
template<class GammaF>
111+
rasterizer_scanline_aa(const GammaF& gamma_function, unsigned cell_block_limit) :
112+
m_outline(cell_block_limit),
113113
m_clipper(m_outline),
114114
m_filling_rule(fill_non_zero),
115115
m_auto_close(true),

extern/agg24/include/agg_rasterizer_scanline_aa_nogamma.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ namespace agg
121121
};
122122

123123
//--------------------------------------------------------------------
124-
rasterizer_scanline_aa_nogamma() :
125-
m_outline(),
124+
rasterizer_scanline_aa_nogamma(unsigned cell_block_limit=1024) :
125+
m_outline(cell_block_limit),
126126
m_clipper(),
127127
m_filling_rule(fill_non_zero),
128128
m_auto_close(true),

src/_backend_agg.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ RendererAgg::RendererAgg(unsigned int width, unsigned int height, double dpi)
4646
rendererBase(),
4747
rendererAA(),
4848
rendererBin(),
49-
theRasterizer(),
49+
theRasterizer(4096),
5050
lastclippath(NULL),
5151
_fill_color(agg::rgba(1, 1, 1, 0))
5252
{

0 commit comments

Comments
 (0)