Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c7af6e1

Browse files
committed
Don't allocate the clipping path buffers unless we need them.
svn path=/branches/transforms/; revision=4763
1 parent 2209689 commit c7af6e1

2 files changed

Lines changed: 29 additions & 17 deletions

File tree

src/_backend_agg.cpp

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -239,27 +239,22 @@ RendererAgg::RendererAgg(unsigned int width, unsigned int height, double dpi,
239239
height(height),
240240
dpi(dpi),
241241
NUMBYTES(width*height*4),
242+
alphaBuffer(NULL),
243+
alphaMaskRenderingBuffer(NULL),
244+
alphaMask(NULL),
245+
pixfmtAlphaMask(NULL),
246+
rendererBaseAlphaMask(NULL),
247+
rendererAlphaMask(NULL),
248+
scanlineAlphaMask(NULL),
242249
debug(debug)
243250
{
244251
_VERBOSE("RendererAgg::RendererAgg");
245252
unsigned stride(width*4);
246253

247-
248254
pixBuffer = new agg::int8u[NUMBYTES];
249255
renderingBuffer = new agg::rendering_buffer;
250256
renderingBuffer->attach(pixBuffer, width, height, stride);
251257

252-
alphaBuffer = new agg::int8u[NUMBYTES];
253-
alphaMaskRenderingBuffer = new agg::rendering_buffer;
254-
alphaMaskRenderingBuffer->attach(alphaBuffer, width, height, stride);
255-
alphaMask = new alpha_mask_type(*alphaMaskRenderingBuffer);
256-
257-
pixfmtAlphaMask = new agg::pixfmt_gray8(*alphaMaskRenderingBuffer);
258-
rendererBaseAlphaMask = new renderer_base_alpha_mask_type(*pixfmtAlphaMask);
259-
rendererAlphaMask = new renderer_alpha_mask_type(*rendererBaseAlphaMask);
260-
scanlineAlphaMask = new agg::scanline_p8();
261-
262-
263258
slineP8 = new scanline_p8;
264259
slineBin = new scanline_bin;
265260

@@ -275,6 +270,21 @@ RendererAgg::RendererAgg(unsigned int width, unsigned int height, double dpi,
275270

276271
};
277272

273+
void RendererAgg::create_alpha_buffers() {
274+
if (!alphaBuffer) {
275+
unsigned stride(width*4);
276+
alphaBuffer = new agg::int8u[NUMBYTES];
277+
alphaMaskRenderingBuffer = new agg::rendering_buffer;
278+
alphaMaskRenderingBuffer->attach(alphaBuffer, width, height, stride);
279+
alphaMask = new alpha_mask_type(*alphaMaskRenderingBuffer);
280+
281+
pixfmtAlphaMask = new agg::pixfmt_gray8(*alphaMaskRenderingBuffer);
282+
rendererBaseAlphaMask = new renderer_base_alpha_mask_type(*pixfmtAlphaMask);
283+
rendererAlphaMask = new renderer_alpha_mask_type(*rendererBaseAlphaMask);
284+
scanlineAlphaMask = new agg::scanline_p8();
285+
}
286+
}
287+
278288
template<class R>
279289
void
280290
RendererAgg::set_clipbox(const Py::Object& cliprect, R rasterizer) {
@@ -442,6 +452,7 @@ bool RendererAgg::render_clippath(const Py::Object& clippath, const agg::trans_a
442452
if (has_clippath &&
443453
(clippath.ptr() != lastclippath.ptr() ||
444454
clippath_trans != lastclippath_transform)) {
455+
create_alpha_buffers();
445456
agg::trans_affine trans(clippath_trans);
446457
trans *= agg::trans_affine_scaling(1.0, -1.0);
447458
trans *= agg::trans_affine_translation(0.0, (double)height);
@@ -617,7 +628,7 @@ class font_to_rgba
617628
_color(color) {
618629
}
619630

620-
void generate(color_type* output_span, int x, int y, unsigned len)
631+
inline void generate(color_type* output_span, int x, int y, unsigned len)
621632
{
622633
_allocator.allocate(len);
623634
child_color_type* input_span = _allocator.span();

src/_backend_agg.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class SafeSnap {
7777
SafeSnap() : first(true), xsnap(0.0), lastx(0.0), lastxsnap(0.0),
7878
ysnap(0.0), lasty(0.0), lastysnap(0.0) {}
7979
SnapData snap (const float& x, const float& y);
80-
80+
8181
private:
8282
bool first;
8383
float xsnap, lastx, lastxsnap, ysnap, lasty, lastysnap;
@@ -87,7 +87,7 @@ class SafeSnap {
8787
// a class in the swig wrapper
8888
class BufferRegion : public Py::PythonExtension<BufferRegion> {
8989
public:
90-
BufferRegion(const agg::rect_i &r, bool freemem=true) :
90+
BufferRegion(const agg::rect_i &r, bool freemem=true) :
9191
rect(r), freemem(freemem) {
9292
width = r.x2 - r.x1;
9393
height = r.y2 - r.y1;
@@ -99,7 +99,7 @@ class BufferRegion : public Py::PythonExtension<BufferRegion> {
9999
int width;
100100
int height;
101101
int stride;
102-
102+
103103
bool freemem;
104104

105105
Py::Object to_string(const Py::Tuple &args);
@@ -151,7 +151,7 @@ class GCAgg {
151151

152152

153153
//struct AMRenderer {
154-
//
154+
//
155155
//}
156156

157157
// the renderer
@@ -246,6 +246,7 @@ class RendererAgg: public Py::PythonExtension<RendererAgg> {
246246
const Py::SeqBase<Py::Int>& antialiaseds);
247247

248248
private:
249+
void create_alpha_buffers();
249250
Py::Object lastclippath;
250251
agg::trans_affine lastclippath_transform;
251252
};

0 commit comments

Comments
 (0)