@@ -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+
278288template <class R >
279289void
280290RendererAgg::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 ();
0 commit comments