Revision: 6340
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6340&view=rev
Author: mdboom
Date: 2008-10-27 21:13:24 + (Mon, 27 Oct 2008)
Log Message:
---
Reduce heap allocation of objects. Be safer when forced to do heap allocation.
Remove some dead code.
Modified Paths:
--
trunk/matplotlib/src/_backend_agg.cpp
trunk/matplotlib/src/_backend_agg.h
Modified: trunk/matplotlib/src/_backend_agg.cpp
===
--- trunk/matplotlib/src/_backend_agg.cpp 2008-10-27 19:40:25 UTC (rev
6339)
+++ trunk/matplotlib/src/_backend_agg.cpp 2008-10-27 21:13:24 UTC (rev
6340)
@@ -263,63 +263,57 @@
height(height),
dpi(dpi),
NUMBYTES(width*height*4),
+ pixBuffer(NULL),
+ renderingBuffer(),
alphaBuffer(NULL),
- alphaMaskRenderingBuffer(NULL),
- alphaMask(NULL),
- pixfmtAlphaMask(NULL),
- rendererBaseAlphaMask(NULL),
- rendererAlphaMask(NULL),
- scanlineAlphaMask(NULL),
+ alphaMaskRenderingBuffer(),
+ alphaMask(alphaMaskRenderingBuffer),
+ pixfmtAlphaMask(alphaMaskRenderingBuffer),
+ rendererBaseAlphaMask(),
+ rendererAlphaMask(),
+ scanlineAlphaMask(),
+ slineP8(),
+ slineBin(),
+ pixFmt(),
+ rendererBase(),
+ rendererAA(),
+ rendererBin(),
+ theRasterizer(),
debug(debug)
{
_VERBOSE("RendererAgg::RendererAgg");
unsigned stride(width*4);
pixBuffer = new agg::int8u[NUMBYTES];
- renderingBuffer = new agg::rendering_buffer;
- renderingBuffer->attach(pixBuffer, width, height, stride);
-
- slineP8 = new scanline_p8;
- slineBin = new scanline_bin;
-
- pixFmt = new pixfmt(*renderingBuffer);
- rendererBase = new renderer_base(*pixFmt);
- rendererBase->clear(agg::rgba(1, 1, 1, 0));
-
- rendererAA = new renderer_aa(*rendererBase);
- rendererBin = new renderer_bin(*rendererBase);
- theRasterizer = new rasterizer();
- //theRasterizer->filling_rule(agg::fill_even_odd);
- //theRasterizer->filling_rule(agg::fill_non_zero);
-
+ renderingBuffer.attach(pixBuffer, width, height, stride);
+ pixFmt.attach(renderingBuffer);
+ rendererBase.attach(pixFmt);
+ rendererBase.clear(agg::rgba(1, 1, 1, 0));
+ rendererAA.attach(rendererBase);
+ rendererBin.attach(rendererBase);
}
void RendererAgg::create_alpha_buffers() {
if (!alphaBuffer) {
unsigned stride(width*4);
alphaBuffer = new agg::int8u[NUMBYTES];
-alphaMaskRenderingBuffer = new agg::rendering_buffer;
-alphaMaskRenderingBuffer->attach(alphaBuffer, width, height, stride);
-alphaMask = new alpha_mask_type(*alphaMaskRenderingBuffer);
-
-pixfmtAlphaMask = new agg::pixfmt_gray8(*alphaMaskRenderingBuffer);
-rendererBaseAlphaMask = new
renderer_base_alpha_mask_type(*pixfmtAlphaMask);
-rendererAlphaMask = new
renderer_alpha_mask_type(*rendererBaseAlphaMask);
-scanlineAlphaMask = new agg::scanline_p8();
+alphaMaskRenderingBuffer.attach(alphaBuffer, width, height, stride);
+rendererBaseAlphaMask.attach(pixfmtAlphaMask);
+rendererAlphaMask.attach(rendererBaseAlphaMask);
}
}
template
void
-RendererAgg::set_clipbox(const Py::Object& cliprect, R rasterizer) {
+RendererAgg::set_clipbox(const Py::Object& cliprect, R& rasterizer) {
//set the clip rectangle from the gc
_VERBOSE("RendererAgg::set_clipbox");
double l, b, r, t;
if (py_convert_bbox(cliprect.ptr(), l, b, r, t)) {
-rasterizer->clip_box(int(mpl_round(l)) + 1, height - int(mpl_round(b)),
-int(mpl_round(r)), height - int(mpl_round(t)));
+rasterizer.clip_box(int(mpl_round(l)) + 1, height - int(mpl_round(b)),
+int(mpl_round(r)), height - int(mpl_round(t)));
}
_VERBOSE("RendererAgg::set_clipbox done");
@@ -341,45 +335,6 @@
return face;
}
-SnapData
-SafeSnap::snap (const float& x, const float& y) {
- xsnap = (int)(x + 0.5f);
- ysnap = (int)(y + 0.5f);
-
- if ( first || ( (xsnap!=lastxsnap) || (ysnap!=lastysnap) ) ) {
-lastxsnap = xsnap;
-lastysnap = ysnap;
-lastx = x;
-lasty = y;
-first = false;
-return SnapData(true, xsnap, ysnap);
- }
-
- // ok both are equal and we need to do an offset
- if ( (x==lastx) && (y==lasty) ) {
-// no choice but to return equal coords; set newpoint = false
-lastxsnap = xsnap;
-lastysnap = ysnap;
-lastx = x;
-lasty = y;
-return SnapData(false, xsnap, ysnap);
- }
-
- // ok the real points are not identical but the rounded ones, so do
- // a one pixel offset
- if (x>lastx) xsnap += 1.;
- else if (xlasty) ysnap += 1.;
- else if (y
bool should_snap(Path& path, const agg::trans_affine& trans) {
// If this contains only straight horizontal or vertical lines, it should be
@@ -443,12 +398,17 @@
throw Py::MemoryError("RendererAgg::copy_from_bbox could not allocate
memory for buffer");
}
- agg::rendering_buffer rbuf;
- rbuf.attach(reg->data, reg->width, reg->he