From: <md...@us...> - 2007-09-04 19:52:26
|
Revision: 3778 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3778&view=rev Author: mdboom Date: 2007-09-04 12:52:23 -0700 (Tue, 04 Sep 2007) Log Message: ----------- Simplify and fix a memory leak. Modified Paths: -------------- trunk/matplotlib/src/ft2font.cpp trunk/matplotlib/src/ft2font.h Modified: trunk/matplotlib/src/ft2font.cpp =================================================================== --- trunk/matplotlib/src/ft2font.cpp 2007-09-04 19:29:45 UTC (rev 3777) +++ trunk/matplotlib/src/ft2font.cpp 2007-09-04 19:52:23 UTC (rev 3778) @@ -42,14 +42,14 @@ FT_Library _ft2Library; -FT2Image::FT2Image() : - _isDirty(true), - _buffer(NULL), - _width(0), _height(0), - _rgbCopy(NULL), - _rgbaCopy(NULL) { - _VERBOSE("FT2Image::FT2Image"); -} +// FT2Image::FT2Image() : +// _isDirty(true), +// _buffer(NULL), +// _width(0), _height(0), +// _rgbCopy(NULL), +// _rgbaCopy(NULL) { +// _VERBOSE("FT2Image::FT2Image"); +// } FT2Image::FT2Image(unsigned long width, unsigned long height) : _isDirty(true), @@ -65,75 +65,28 @@ _VERBOSE("FT2Image::~FT2Image"); delete [] _buffer; _buffer=NULL; + delete _rgbCopy; + delete _rgbaCopy; } void FT2Image::resize(unsigned long width, unsigned long height) { size_t numBytes = width*height; - if (_width != width || _height != height) { + if (width != _width || height != _height) { + if (numBytes > _width*_height) { + delete [] _buffer; + _buffer = new unsigned char [numBytes]; + } + _width = width; _height = height; - - delete [] _buffer; - _buffer = new unsigned char [numBytes]; } - for (size_t n=0; n<numBytes; n++) - _buffer[n] = 0; + memset(_buffer, 0, numBytes); _isDirty = true; } -char FT2Image::resize__doc__[] = -"resize(width, height)\n" -"\n" -"Resize the dimensions of the image (it is cleared in the process).\n" -; -Py::Object -FT2Image::py_resize(const Py::Tuple & args) { - _VERBOSE("FT2Image::resize"); - - args.verify_length(2); - - long x0 = Py::Int(args[0]); - long y0 = Py::Int(args[1]); - - resize(x0, y0); - - return Py::Object(); -} - -void FT2Image::clear() { - _VERBOSE("FT2Image::clear"); - - _width = 0; - _height = 0; - _isDirty = true; - delete [] _buffer; - _buffer = NULL; - if (_rgbCopy) { - delete _rgbCopy; - _rgbCopy = NULL; - } - if (_rgbaCopy) { - delete _rgbaCopy; - _rgbaCopy = NULL; - } -} -char FT2Image::clear__doc__[] = -"clear()\n" -"\n" -"Clear the contents of the image.\n" -; -Py::Object -FT2Image::py_clear(const Py::Tuple & args) { - args.verify_length(0); - - clear(); - - return Py::Object(); -} - void FT2Image::draw_bitmap( FT_Bitmap* bitmap, FT_Int x, @@ -345,9 +298,7 @@ unsigned char *dst = _rgbaCopy->_buffer; while (src != src_end) { - *dst++ = 0; - *dst++ = 0; - *dst++ = 0; + dst += 3; *dst++ = *src++; } } @@ -824,8 +775,7 @@ _VERBOSE("FT2Font::clear"); args.verify_length(0); - if (image) - image->clear(); + delete image; angle = 0.0; @@ -1194,11 +1144,9 @@ size_t width = (string_bbox.xMax-string_bbox.xMin) / 64 + 2; size_t height = (string_bbox.yMax-string_bbox.yMin) / 64 + 2; - if (!image) { - image = new FT2Image(width, height); - } else { - image->resize(width, height); - } + Py_XDECREF(image); + image = NULL; + image = new FT2Image(width, height); for ( size_t n = 0; n < glyphs.size(); n++ ) { @@ -1764,10 +1712,6 @@ behaviors().name("FT2Image"); behaviors().doc("FT2Image"); - add_varargs_method("clear", &FT2Image::py_clear, - FT2Image::clear__doc__); - add_varargs_method("resize", &FT2Image::py_resize, - FT2Image::resize__doc__); add_varargs_method("write_bitmap", &FT2Image::py_write_bitmap, FT2Image::write_bitmap__doc__); add_varargs_method("draw_rect", &FT2Image::py_draw_rect, Modified: trunk/matplotlib/src/ft2font.h =================================================================== --- trunk/matplotlib/src/ft2font.h 2007-09-04 19:29:45 UTC (rev 3777) +++ trunk/matplotlib/src/ft2font.h 2007-09-04 19:52:23 UTC (rev 3778) @@ -22,14 +22,12 @@ // the freetype string rendered into a width, height buffer class FT2Image : public Py::PythonExtension<FT2Image> { public: - FT2Image(); + // FT2Image(); FT2Image(unsigned long width, unsigned long height); ~FT2Image(); static void init_type(); - void resize(unsigned long width, unsigned long height); - void clear(); void draw_bitmap(FT_Bitmap* bitmap, FT_Int x, FT_Int y); void write_bitmap(const char* filename) const; void draw_rect(unsigned long x0, unsigned long y0, @@ -41,10 +39,6 @@ unsigned int get_height() const { return _height; }; const unsigned char *const get_buffer() const { return _buffer; }; - static char clear__doc__ []; - Py::Object py_clear(const Py::Tuple & args); - static char resize__doc__ []; - Py::Object py_resize(const Py::Tuple & args); static char write_bitmap__doc__ []; Py::Object py_write_bitmap(const Py::Tuple & args); static char draw_rect__doc__ []; @@ -71,6 +65,8 @@ void makeRgbCopy(); void makeRgbaCopy(); + + void resize(unsigned long width, unsigned long height); }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ef...@us...> - 2007-11-14 07:45:13
|
Revision: 4264 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4264&view=rev Author: efiring Date: 2007-11-13 23:45:12 -0800 (Tue, 13 Nov 2007) Log Message: ----------- A step towards a fast rectilinear pcolor version Modified Paths: -------------- trunk/matplotlib/src/_image.cpp trunk/matplotlib/src/_image.h Modified: trunk/matplotlib/src/_image.cpp =================================================================== --- trunk/matplotlib/src/_image.cpp 2007-11-14 04:03:46 UTC (rev 4263) +++ trunk/matplotlib/src/_image.cpp 2007-11-14 07:45:12 UTC (rev 4264) @@ -1403,8 +1403,8 @@ // Create output Image* imo = new Image; imo->rowsIn = rows; + imo->colsIn = cols; imo->rowsOut = rows; - imo->colsIn = cols; imo->colsOut = cols; size_t NUMBYTES(rows * cols * 4); agg::int8u *buffer = new agg::int8u[NUMBYTES]; @@ -1499,6 +1499,227 @@ return Py::asObject(imo); } +void _bin_indices(int *irows, int nrows, double *y, int ny, + double sc, double offs) +{ + int i; + if (sc*(y[ny-1] - y[0]) > 0) + { + int ii = 0; + int iilast = ny-1; + int iy0 = (int)floor(sc * (y[ii] - offs)); + int iy1 = (int)floor(sc * (y[ii+1] - offs)); + for (i=0; i<nrows && i<iy0; i++) { + irows[i] = -1; + } + for (; i<nrows; i++) { + while (i > iy1 && ii < iilast) { + ii++; + iy0 = iy1; + iy1 = (int)floor(sc * (y[ii+1] - offs)); + } + if (i >= iy0 && i <= iy1) irows[i] = ii; + else break; + } + for (; i<nrows; i++) { + irows[i] = -1; + } + } + else + { + int iilast = ny-1; + int ii = iilast; + int iy0 = (int)floor(sc * (y[ii] - offs)); + int iy1 = (int)floor(sc * (y[ii-1] - offs)); + for (i=0; i<nrows && i<iy0; i++) { + irows[i] = -1; + } + for (; i<nrows; i++) { + while (i > iy1 && ii > 1) { + ii--; + iy0 = iy1; + iy1 = (int)floor(sc * (y[ii-1] - offs)); + } + if (i >= iy0 && i <= iy1) irows[i] = ii-1; + else break; + } + for (; i<nrows; i++) { + irows[i] = -1; + } + } +} + +char __image_module_pcolor2__doc__[] = +"pcolor2(x, y, data, rows, cols, bounds, bg)\n" +"\n" +"Generate a pseudo-color image from data on a non-uniform grid\n" +"specified by its cell boundaries.\n" +"bounds = (x_left, x_right, y_bot, y_top)\n" +"bg = ndarray of 4 uint8 representing background rgba\n" +; +Py::Object +_image_module::pcolor2(const Py::Tuple& args) { + _VERBOSE("_image_module::pcolor2"); + + if (args.length() != 7) + throw Py::TypeError("Incorrect number of arguments (6 expected)"); + + Py::Object xp = args[0]; + Py::Object yp = args[1]; + Py::Object dp = args[2]; + int rows = Py::Int(args[3]); + int cols = Py::Int(args[4]); + Py::Tuple bounds = args[5]; + Py::Object bgp = args[6]; + + if (bounds.length() !=4) + throw Py::TypeError("Incorrect number of bounds (4 expected)"); + double x_left = Py::Float(bounds[0]); + double x_right = Py::Float(bounds[1]); + double y_bot = Py::Float(bounds[2]); + double y_top = Py::Float(bounds[3]); + + // Check we have something to output to + if (rows == 0 || cols ==0) + throw Py::ValueError("rows or cols is zero; there are no pixels"); + + // Get numpy arrays + PyArrayObject *x = (PyArrayObject *) PyArray_ContiguousFromObject(xp.ptr(), + PyArray_DOUBLE, 1, 1); + if (x == NULL) + throw Py::ValueError("x is of incorrect type (wanted 1D double)"); + PyArrayObject *y = (PyArrayObject *) PyArray_ContiguousFromObject(yp.ptr(), + PyArray_DOUBLE, 1, 1); + if (y == NULL) { + Py_XDECREF(x); + throw Py::ValueError("y is of incorrect type (wanted 1D double)"); + } + PyArrayObject *d = (PyArrayObject *) PyArray_ContiguousFromObject(dp.ptr(), + PyArray_UBYTE, 3, 3); + if (d == NULL) { + Py_XDECREF(x); + Py_XDECREF(y); + throw Py::ValueError("data is of incorrect type (wanted 3D uint8)"); + } + if (d->dimensions[2] != 4) { + Py_XDECREF(x); + Py_XDECREF(y); + Py_XDECREF(d); + throw Py::ValueError("data must be in RGBA format"); + } + + // Check dimensions match + int nx = x->dimensions[0]; + int ny = y->dimensions[0]; + if (nx != d->dimensions[1]+1 || ny != d->dimensions[0]+1) { + Py_XDECREF(x); + Py_XDECREF(y); + Py_XDECREF(d); + throw Py::ValueError("data and axis bin boundary dimensions are incompatible"); + } + + PyArrayObject *bg = (PyArrayObject *) PyArray_ContiguousFromObject(bgp.ptr(), + PyArray_UBYTE, 1, 1); + if (bg == NULL) { + Py_XDECREF(x); + Py_XDECREF(y); + Py_XDECREF(d); + throw Py::ValueError("bg is of incorrect type (wanted 1D uint8)"); + } + if (bg->dimensions[0] != 4) { + Py_XDECREF(x); + Py_XDECREF(y); + Py_XDECREF(d); + Py_XDECREF(bg); + throw Py::ValueError("bg must be in RGBA format"); + } + + + // Allocate memory for pointer arrays + int * irows = reinterpret_cast<int*>(PyMem_Malloc(sizeof(int)*rows)); + if (irows == NULL) { + Py_XDECREF(x); + Py_XDECREF(y); + Py_XDECREF(d); + Py_XDECREF(bg); + throw Py::MemoryError("Cannot allocate memory for lookup table"); + } + int * jcols = reinterpret_cast<int*>(PyMem_Malloc(sizeof(int*)*cols)); + if (jcols == NULL) { + Py_XDECREF(x); + Py_XDECREF(y); + Py_XDECREF(d); + Py_XDECREF(bg); + PyMem_Free(irows); + throw Py::MemoryError("Cannot allocate memory for lookup table"); + } + + // Create output + Image* imo = new Image; + imo->rowsIn = rows; + imo->rowsOut = rows; + imo->colsIn = cols; + imo->colsOut = cols; + size_t NUMBYTES(rows * cols * 4); + agg::int8u *buffer = new agg::int8u[NUMBYTES]; + if (buffer == NULL) { + Py_XDECREF(x); + Py_XDECREF(y); + Py_XDECREF(d); + Py_XDECREF(bg); + PyMem_Free(irows); + PyMem_Free(jcols); + throw Py::MemoryError("Could not allocate memory for image"); + } + + // Calculate the pointer arrays to map input x to output x + int i, j; + double *x0 = reinterpret_cast<double*>(x->data); + double *y0 = reinterpret_cast<double*>(y->data); + double sx = cols/(x_right - x_left); + double sy = rows/(y_top - y_bot); + _bin_indices(jcols, cols, x0, nx, sx, x_left); + _bin_indices(irows, rows, y0, ny, sy, y_bot); + + // Copy data to output buffer + agg::int8u * position = buffer; + unsigned char *start = reinterpret_cast<unsigned char*>(d->data); + unsigned char *bgptr = reinterpret_cast<unsigned char*>(bg->data); + int s0 = d->strides[0]; + int s1 = d->strides[1]; + + for (i=0; i<rows; i++) + { + for (j=0; j<cols; j++) + { + if (irows[i] == -1 || jcols[j] == -1) { + memcpy(position, bgptr, 4*sizeof(agg::int8u)); + } + else { + memcpy(position, (start + s0*irows[i] + s1*jcols[j]), + 4*sizeof(agg::int8u)); + } + position += 4; + } + } + + // Attach output buffer to output buffer + imo->rbufOut = new agg::rendering_buffer; + imo->bufferOut = buffer; + imo->rbufOut->attach(imo->bufferOut, imo->colsOut, imo->rowsOut, imo->colsOut * imo->BPP); + + Py_XDECREF(x); + Py_XDECREF(y); + Py_XDECREF(d); + Py_XDECREF(bg); + PyMem_Free(irows); + PyMem_Free(jcols); + + return Py::asObject(imo); +} + + + #if defined(_MSC_VER) DL_EXPORT(void) #elif defined(__cplusplus) @@ -1532,7 +1753,7 @@ d["SINC"] = Py::Int(Image::SINC); d["LANCZOS"] = Py::Int(Image::LANCZOS); d["BLACKMAN"] = Py::Int(Image::BLACKMAN); - + d["ASPECT_FREE"] = Py::Int(Image::ASPECT_FREE); d["ASPECT_PRESERVE"] = Py::Int(Image::ASPECT_PRESERVE); Modified: trunk/matplotlib/src/_image.h =================================================================== --- trunk/matplotlib/src/_image.h 2007-11-14 04:03:46 UTC (rev 4263) +++ trunk/matplotlib/src/_image.h 2007-11-14 07:45:12 UTC (rev 4264) @@ -134,6 +134,8 @@ "from_images"); add_varargs_method("pcolor", &_image_module::pcolor, "pcolor"); + add_varargs_method("pcolor2", &_image_module::pcolor2, + "pcolor2"); initialize( "The _image module" ); } @@ -145,11 +147,13 @@ Py::Object fromarray (const Py::Tuple &args); Py::Object fromarray2 (const Py::Tuple &args); Py::Object pcolor (const Py::Tuple &args); + Py::Object pcolor2 (const Py::Tuple &args); Py::Object readpng (const Py::Tuple &args); Py::Object from_images (const Py::Tuple &args); static char _image_module_fromarray__doc__[]; static char _image_module_pcolor__doc__[]; + static char _image_module_pcolor2__doc__[]; static char _image_module_fromarray2__doc__[]; static char _image_module_frombyte__doc__[]; static char _image_module_frombuffer__doc__[]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2007-11-20 18:25:38
|
Revision: 4396 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4396&view=rev Author: mdboom Date: 2007-11-20 10:25:33 -0800 (Tue, 20 Nov 2007) Log Message: ----------- Slight speed improvement in draw_quad_mesh. 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 2007-11-20 17:44:27 UTC (rev 4395) +++ trunk/matplotlib/src/_backend_agg.cpp 2007-11-20 18:25:33 UTC (rev 4396) @@ -956,8 +956,10 @@ return numIntersect; } -void RendererAgg::DrawQuadMesh(int meshWidth, int meshHeight, const agg::rgba8 colorArray[], const double xCoords[], const double yCoords[]) +void RendererAgg::DrawQuadMesh(int meshWidth, int meshHeight, void* colors_void, const double xCoords[], const double yCoords[]) { + PyArrayObject* colors = (PyArrayObject*)colors_void; + /* draw each quadrilateral */ // agg::renderer_primitives<agg::renderer_base<agg::pixfmt_rgba32> > lineRen(*rendererBase); int i = 0; @@ -992,18 +994,25 @@ //currTime = clock(); //timer2 += (clock() - currTime); //currTime = clock(); + size_t color_index = (i * meshWidth) + j; + agg::rgba color(*(double*)PyArray_GETPTR2(colors, color_index, 0), + *(double*)PyArray_GETPTR2(colors, color_index, 1), + *(double*)PyArray_GETPTR2(colors, color_index, 2), + *(double*)PyArray_GETPTR2(colors, color_index, 3)); + for(k = firstRow; k <= lastRow; k++) { numCol = inPolygon(k, xs, ys, col); - if (numCol >= 2) rendererBase->copy_hline(col[0], k, col[1] - 1, colorArray[(i * meshWidth) + j]); - if (numCol == 4) rendererBase->copy_hline(col[2], k, col[3] - 1, colorArray[(i * meshWidth) + j]); + + if (numCol >= 2) rendererBase->copy_hline(col[0], k, col[1] - 1, color); + if (numCol == 4) rendererBase->copy_hline(col[2], k, col[3] - 1, color); } } } return; } -void RendererAgg::DrawQuadMeshEdges(int meshWidth, int meshHeight, const agg::rgba8 colorArray[], const double xCoords[], const double yCoords[]) +void RendererAgg::DrawQuadMeshEdges(int meshWidth, int meshHeight, const double xCoords[], const double yCoords[]) { int i, j; agg::renderer_primitives<agg::renderer_base<agg::pixfmt_rgba32> > lineRen(*rendererBase); @@ -1027,7 +1036,6 @@ Py::Object RendererAgg::draw_quad_mesh(const Py::Tuple& args){ - //printf("#1: %d\n", clock()); Py::Object colorsi = args[2]; Py::Object xCoordsi = args[3]; @@ -1035,7 +1043,6 @@ int meshWidth = Py::Int(args[0]); int meshHeight = Py::Int(args[1]); int showedges = Py::Int(args[9]); - int numQuads = (meshWidth * meshHeight); PyArrayObject *colors = (PyArrayObject *) PyArray_ContiguousFromObject(colorsi.ptr(), PyArray_DOUBLE, 2, 2); PyArrayObject *xCoords = (PyArrayObject *) PyArray_ContiguousFromObject(xCoordsi.ptr(), PyArray_DOUBLE, 1, 1); PyArrayObject *yCoords = (PyArrayObject *) PyArray_ContiguousFromObject(yCoordsi.ptr(), PyArray_DOUBLE, 1, 1); @@ -1117,30 +1124,14 @@ /**** End of transformations ****/ - /* convert colors */ - double r; - double g; - double b; - double a; - int i; - agg::rgba8* colorArray = new agg::rgba8[numQuads]; - for(i=0; i < numQuads; i++) - { - r = *(double *)(colors -> data + i*(colors -> strides[0])); - g = *(double *)(colors -> data + i*(colors -> strides[0]) + (colors -> strides[1])); - b = *(double *)(colors -> data + i*(colors -> strides[0]) + 2*(colors -> strides[1])); - a = *(double *)(colors -> data + i*(colors -> strides[0]) + 3*(colors -> strides[1])); - colorArray[i] = agg::rgba8((int)(255.0 * r), (int)(255.0 * g), (int)(255.0 * b), (int)(255.0 * a)); - } - DrawQuadMesh(meshWidth, meshHeight, colorArray, &(newXCoords[0]), &(newYCoords[0])); + DrawQuadMesh(meshWidth, meshHeight, colors, &(newXCoords[0]), &(newYCoords[0])); if(showedges) - DrawQuadMeshEdges(meshWidth, meshHeight, colorArray, &(newXCoords[0]), &(newYCoords[0])); + DrawQuadMeshEdges(meshWidth, meshHeight, &(newXCoords[0]), &(newYCoords[0])); Py_XDECREF(xCoords); Py_XDECREF(yCoords); Py_XDECREF(colors); delete newXCoords; delete newYCoords; - delete colorArray; //printf("#2: %d\n", clock()); return Py::Object(); } Modified: trunk/matplotlib/src/_backend_agg.h =================================================================== --- trunk/matplotlib/src/_backend_agg.h 2007-11-20 17:44:27 UTC (rev 4395) +++ trunk/matplotlib/src/_backend_agg.h 2007-11-20 18:25:33 UTC (rev 4396) @@ -215,8 +215,8 @@ agg::rect bbox_to_rect( const Py::Object& o); double points_to_pixels( const Py::Object& points); double points_to_pixels_snapto( const Py::Object& points); - void DrawQuadMesh(int, int, const agg::rgba8[], const double[], const double[]); - void DrawQuadMeshEdges(int, int, const agg::rgba8[], const double[], const double[]); + void DrawQuadMesh(int, int, void* colors, const double[], const double[]); + void DrawQuadMeshEdges(int, int, const double[], const double[]); int intersectCheck(double, double, double, double, double, int*); int inPolygon(int, const double[4], const double[4], int[4]); void set_clip_from_bbox(const Py::Object& o); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2008-01-21 18:33:59
|
Revision: 4881 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4881&view=rev Author: mdboom Date: 2008-01-21 10:32:57 -0800 (Mon, 21 Jan 2008) Log Message: ----------- Fix memory leak in pcolor and pcolormesh. (Thanks Rob Hetland) Modified Paths: -------------- trunk/matplotlib/src/_backend_agg.cpp trunk/matplotlib/src/_path.cpp Modified: trunk/matplotlib/src/_backend_agg.cpp =================================================================== --- trunk/matplotlib/src/_backend_agg.cpp 2008-01-18 18:21:14 UTC (rev 4880) +++ trunk/matplotlib/src/_backend_agg.cpp 2008-01-21 18:32:57 UTC (rev 4881) @@ -1001,6 +1001,7 @@ for (i = 0; i < N; ++i) { typename PathGenerator::path_iterator path = path_generator(i); + if (Ntransforms) { trans = transforms[i % Ntransforms]; } else { @@ -1070,15 +1071,18 @@ } } } + + Py_XDECREF(offsets); + Py_XDECREF(facecolors); + Py_XDECREF(edgecolors); + return Py::Object(); } catch (...) { + printf("Exception!\n"); Py_XDECREF(offsets); Py_XDECREF(facecolors); Py_XDECREF(edgecolors); throw; } - - Py_XDECREF(offsets); - return Py::Object(); } @@ -1186,9 +1190,9 @@ public: typedef QuadMeshPathIterator path_iterator; - inline QuadMeshGenerator(size_t meshWidth, size_t meshHeight, const Py::Object& coordinates) : + inline QuadMeshGenerator(size_t meshWidth, size_t meshHeight, PyObject* coordinates) : m_meshWidth(meshWidth), m_meshHeight(meshHeight), m_coordinates(NULL) { - PyArrayObject* coordinates_array = (PyArrayObject*)PyArray_FromObject(coordinates.ptr(), PyArray_DOUBLE, 3, 3); + PyArrayObject* coordinates_array = (PyArrayObject*)PyArray_FromObject(coordinates, PyArray_DOUBLE, 3, 3); if (!coordinates_array) { throw Py::ValueError("Invalid coordinates array."); } @@ -1214,6 +1218,7 @@ _VERBOSE("RendererAgg::draw_quad_mesh"); args.verify_length(12); + //segments, trans, clipbox, colors, linewidths, antialiaseds agg::trans_affine master_transform = py_to_agg_transformation_matrix(args[0]); Py::Object cliprect = args[1]; @@ -1221,12 +1226,13 @@ agg::trans_affine clippath_trans = py_to_agg_transformation_matrix(args[3], false); size_t mesh_width = Py::Int(args[4]); size_t mesh_height = Py::Int(args[5]); - Py::Object coordinates = args[6]; + PyObject* coordinates = args[6].ptr(); Py::Object offsets_obj = args[7]; agg::trans_affine offset_trans = py_to_agg_transformation_matrix(args[8]); Py::Object facecolors_obj = args[9]; bool antialiased = (bool)Py::Int(args[10]); bool showedges = (bool)Py::Int(args[11]); + bool free_edgecolors = false; QuadMeshGenerator path_generator(mesh_width, mesh_height, coordinates); @@ -1242,12 +1248,14 @@ npy_intp dims[] = { 1, 4, 0 }; double data[] = { 0, 0, 0, 1 }; edgecolors_obj = PyArray_SimpleNewFromData(2, dims, PyArray_DOUBLE, (char*)data); + free_edgecolors = true; } else { if (antialiased) { edgecolors_obj = facecolors_obj; } else { npy_intp dims[] = { 0, 0 }; edgecolors_obj = PyArray_SimpleNew(1, dims, PyArray_DOUBLE); + free_edgecolors = true; } } @@ -1266,6 +1274,9 @@ linestyles_obj, antialiaseds); + if (free_edgecolors) + Py_XDECREF(edgecolors_obj.ptr()); + return Py::Object(); } Modified: trunk/matplotlib/src/_path.cpp =================================================================== --- trunk/matplotlib/src/_path.cpp 2008-01-18 18:21:14 UTC (rev 4880) +++ trunk/matplotlib/src/_path.cpp 2008-01-21 18:32:57 UTC (rev 4881) @@ -294,11 +294,17 @@ agg::trans_affine trans = py_to_agg_transformation_matrix(args[1], false); npy_intp extent_dims[] = { 2, 2, 0 }; - double* extents_data = new double[4]; + double* extents_data = NULL; double xm, ym; PyArrayObject* extents = NULL; try { + extents = (PyArrayObject*)PyArray_SimpleNew + (2, extent_dims, PyArray_DOUBLE); + if (extents == NULL) + throw Py::MemoryError("Could not allocate result array"); + extents_data = (double*)PyArray_DATA(extents); + extents_data[0] = std::numeric_limits<double>::infinity(); extents_data[1] = std::numeric_limits<double>::infinity(); extents_data[2] = -std::numeric_limits<double>::infinity(); @@ -307,16 +313,10 @@ ::get_path_extents(path, trans, &extents_data[0], &extents_data[1], &extents_data[2], &extents_data[3], &xm, &ym); - - extents = (PyArrayObject*)PyArray_SimpleNewFromData - (2, extent_dims, PyArray_DOUBLE, extents_data); } catch (...) { - if (extents) - Py_XDECREF(extents); - else - delete[] extents_data; + Py_XDECREF(extents); throw; } @@ -357,15 +357,27 @@ Py_XDECREF(input_minpos); npy_intp extent_dims[] = { 2, 2, 0 }; - double* extents_data = new double[4]; + double* extents_data = NULL; npy_intp minpos_dims[] = { 2, 0 }; - double* minpos_data = new double[2]; + double* minpos_data = NULL; PyArrayObject* extents = NULL; PyArrayObject* minpos = NULL; bool changed = false; try { + extents = (PyArrayObject*)PyArray_SimpleNew + (2, extent_dims, PyArray_DOUBLE); + if (extents == NULL) + throw Py::MemoryError("Could not allocate result array"); + minpos = (PyArrayObject*)PyArray_SimpleNew + (1, minpos_dims, PyArray_DOUBLE); + if (minpos == NULL) + throw Py::MemoryError("Could not allocate result array"); + + extents_data = (double*)PyArray_DATA(extents); + minpos_data = (double*)PyArray_DATA(minpos); + if (ignore) { extents_data[0] = std::numeric_limits<double>::infinity(); @@ -396,21 +408,11 @@ minpos_data[0] != xm || minpos_data[1] != ym); - extents = (PyArrayObject*)PyArray_SimpleNewFromData - (2, extent_dims, PyArray_DOUBLE, extents_data); - minpos = (PyArrayObject*)PyArray_SimpleNewFromData - (1, minpos_dims, PyArray_DOUBLE, minpos_data); } catch (...) { - if (extents) - Py_XDECREF(extents); - else - delete[] extents_data; - if (minpos) - Py_XDECREF(minpos); - else - delete[] minpos_data; + Py_XDECREF(extents); + Py_XDECREF(minpos); throw; } @@ -419,6 +421,9 @@ result[1] = Py::Object((PyObject*) minpos); result[2] = Py::Int(changed ? 1 : 0); + Py_XDECREF(extents); + Py_XDECREF(minpos); + return result; } @@ -964,7 +969,7 @@ { args.verify_length(2); - Py::Object bbox = args[0]; + Py::Object bbox = args[0]; Py::SeqBase<Py::Object> bboxes = args[1]; double ax0, ay0, ax1, ay1; @@ -1086,16 +1091,15 @@ if (polygon.size() == 0) return; npy_intp polygon_dims[] = { polygon.size() / 2, 2, 0 }; - double* polygon_data = new double[polygon.size()]; - memcpy(polygon_data, &polygon[0], polygon.size() * sizeof(double)); PyArrayObject* polygon_array = NULL; - polygon_array = (PyArrayObject*)PyArray_SimpleNewFromData - (2, polygon_dims, PyArray_DOUBLE, polygon_data); + polygon_array = (PyArrayObject*)PyArray_SimpleNew + (2, polygon_dims, PyArray_DOUBLE); if (!polygon_array) { - delete[] polygon_data; - throw Py::RuntimeError("Error creating polygon array"); + throw Py::MemoryError("Error creating polygon array"); } + double* polygon_data = (double*)PyArray_DATA(polygon_array); + memcpy(polygon_data, &polygon[0], polygon.size() * sizeof(double)); polygons.append(Py::Object((PyObject*)polygon_array)); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2008-01-22 19:43:27
|
Revision: 4885 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4885&view=rev Author: mdboom Date: 2008-01-22 11:43:18 -0800 (Tue, 22 Jan 2008) Log Message: ----------- Speed improvements for path simplification algorithm. Modified Paths: -------------- trunk/matplotlib/src/_backend_agg.cpp trunk/matplotlib/src/agg_py_path_iterator.h Modified: trunk/matplotlib/src/_backend_agg.cpp =================================================================== --- trunk/matplotlib/src/_backend_agg.cpp 2008-01-22 13:08:27 UTC (rev 4884) +++ trunk/matplotlib/src/_backend_agg.cpp 2008-01-22 19:43:18 UTC (rev 4885) @@ -370,7 +370,7 @@ template<class Path> bool should_simplify(Path& path) { - return !path.has_curves() && path.total_vertices() > 5; + return !path.has_curves() && path.total_vertices() >= 128; } Py::Object @@ -803,10 +803,7 @@ if (gc.linewidth != 0.0) { double linewidth = gc.linewidth; if (!gc.isaa) { - if (linewidth < 0.5) - linewidth = 0.5; - else - linewidth = round(linewidth); + linewidth = (linewidth < 0.5) ? 0.5 : round(linewidth); } if (gc.dashes.size() == 0) { stroke_t stroke(path); Modified: trunk/matplotlib/src/agg_py_path_iterator.h =================================================================== --- trunk/matplotlib/src/agg_py_path_iterator.h 2008-01-22 13:08:27 UTC (rev 4884) +++ trunk/matplotlib/src/agg_py_path_iterator.h 2008-01-22 19:43:18 UTC (rev 4885) @@ -24,7 +24,9 @@ m_vertices = (PyArrayObject*)PyArray_FromObject (vertices_obj.ptr(), PyArray_DOUBLE, 2, 2); - if (!m_vertices || PyArray_NDIM(m_vertices) != 2 || PyArray_DIM(m_vertices, 1) != 2) + if (!m_vertices || + PyArray_NDIM(m_vertices) != 2 || + PyArray_DIM(m_vertices, 1) != 2) throw Py::ValueError("Invalid vertices array."); if (codes_obj.ptr() != Py_None) @@ -116,7 +118,7 @@ SimplifyPath(VertexSource& source, bool quantize, bool simplify, double width = 0.0, double height = 0.0) : m_source(&source), m_quantize(quantize), m_simplify(simplify), - m_width(width), m_height(height), + m_width(width), m_height(height), m_queue_read(0), m_queue_write(0), m_moveto(true), m_lastx(0.0), m_lasty(0.0), m_clipped(false), m_do_clipping(width > 0.0 && height > 0.0), m_origdx(0.0), m_origdy(0.0), @@ -177,19 +179,21 @@ // will be popped from the queue in subsequent calls. The following // block will empty the queue before proceeding to the main loop below. // -- Michael Droettboom - if (m_queue.size()) + if (m_queue_read < m_queue_write) { - const item& front = m_queue.front(); + const item& front = m_queue[m_queue_read++]; unsigned cmd = front.cmd; *x = front.x; *y = front.y; - m_queue.pop(); #if DEBUG_SIMPLIFY printf((cmd == agg::path_cmd_move_to) ? "|" : "-"); #endif return cmd; } + m_queue_read = 0; + m_queue_write = 0; + // If the queue is now empty, and the path was fully consumed // in the last call to the main loop, return agg::path_cmd_stop to // signal that there are no more points to emit. @@ -200,8 +204,8 @@ return agg::path_cmd_stop; } - // The main simplification loop. The point is consume only as many - // points as necessary until some have been added to the outbound + // The main simplification loop. The point is to consume only as many + // points as necessary until something has been added to the outbound // queue, not to run through the entire path in one go. This // eliminates the need to allocate and fill an entire additional path // array on each draw. @@ -241,10 +245,10 @@ //skip any lines that are outside the drawing area. Note: More lines //could be clipped, but a more involved calculation would be needed if (m_do_clipping && - ((*x < -1 && m_lastx < -1) || - (*x > m_width + 1 && m_lastx > m_width + 1) || - (*y < -1 && m_lasty < -1) || - (*y > m_height + 1 && m_lasty > m_height + 1))) + ((*x < -1.0 && m_lastx < -1.0) || + (*x > m_width + 1.0 && m_lastx > m_width + 1.0) || + (*y < -1.0 && m_lasty < -1.0) || + (*y > m_height + 1.0 && m_lasty > m_height + 1.0))) { m_lastx = *x; m_lasty = *y; @@ -264,31 +268,24 @@ { if (m_clipped) { - m_queue.push(item(agg::path_cmd_move_to, m_lastx, m_lasty)); + m_queue[m_queue_write++].set(agg::path_cmd_move_to, m_lastx, m_lasty); m_clipped = false; } m_origdx = *x - m_lastx; m_origdy = *y - m_lasty; - m_origdNorm2 = m_origdx*m_origdx + m_origdy+m_origdy; + m_origdNorm2 = m_origdx*m_origdx + m_origdy*m_origdy; //set all the variables to reflect this new orig vecor m_dnorm2Max = m_origdNorm2; - m_dnorm2Min = 0; + m_dnorm2Min = 0.0; m_haveMin = false; m_lastMax = true; - m_maxX = *x; - m_maxY = *y; - m_minX = m_lastx; - m_minY = m_lasty; - - m_lastWrittenX = m_lastx; - m_lastWrittenY = m_lasty; - - // set the last point seen - m_lastx = *x; - m_lasty = *y; + m_lastx = m_maxX = *x; + m_lasty = m_maxY = *y; + m_lastWrittenX = m_minX = m_lastx; + m_lastWrittenY = m_minY = m_lasty; #if DEBUG_SIMPLIFY m_skipped++; #endif @@ -313,7 +310,6 @@ // get the para vector ( = (o.v)o/(o.o)) double paradx = totdot*m_origdx/m_origdNorm2; double parady = totdot*m_origdy/m_origdNorm2; - double paradNorm2 = paradx*paradx + parady*parady; // get the perp vector ( = v - para) double perpdx = totdx - paradx; @@ -330,6 +326,8 @@ //direction. If anti-p, test if it is the longest in the //opposite direction (the min of our final line) + double paradNorm2 = paradx*paradx + parady*parady; + m_lastMax = false; if (totdot >= 0) { @@ -368,25 +366,21 @@ //direction we are drawing in, move back to we start drawing from //back there. if (m_haveMin) - m_queue.push(item(agg::path_cmd_line_to, m_minX, m_minY)); - m_queue.push(item(agg::path_cmd_line_to, m_maxX, m_maxY)); + m_queue[m_queue_write++].set(agg::path_cmd_move_to, m_minX, m_minY); + m_queue[m_queue_write++].set(agg::path_cmd_line_to, m_maxX, m_maxY); //if we clipped some segments between this line and the next line //we are starting, we also need to move to the last point. if (m_clipped) - { - m_queue.push(item(agg::path_cmd_move_to, m_lastx, m_lasty)); - } + m_queue[m_queue_write++].set(agg::path_cmd_move_to, m_lastx, m_lasty); else if (!m_lastMax) - { //if the last line was not the longest line, then move back to //the end point of the last line in the sequence. Only do this //if not clipped, since in that case lastx,lasty is not part of //the line just drawn. //Would be move_to if not for the artifacts - m_queue.push(item(agg::path_cmd_line_to, m_lastx, m_lasty)); - } + m_queue[m_queue_write++].set(agg::path_cmd_line_to, m_lastx, m_lasty); //now reset all the variables to get ready for the next line m_origdx = *x - m_lastx; @@ -394,23 +388,17 @@ m_origdNorm2 = m_origdx*m_origdx + m_origdy*m_origdy; m_dnorm2Max = m_origdNorm2; - m_dnorm2Min = 0; + m_dnorm2Min = 0.0; m_haveMin = false; m_lastMax = true; - m_maxX = *x; - m_maxY = *y; - m_minX = m_lastx; - m_minY = m_lasty; + m_lastx = m_maxX = *x; + m_lasty = m_maxY = *y; + m_lastWrittenX = m_minX = m_lastx; + m_lastWrittenY = m_minY = m_lasty; - m_lastWrittenX = m_lastx; - m_lastWrittenY = m_lasty; - m_clipped = false; - - m_lastx = *x; - m_lasty = *y; #if DEBUG_SIMPLIFY - m_pushed += m_queue.size(); + m_pushed += m_queue_write - m_queue_read; #endif break; } @@ -423,21 +411,20 @@ if (m_origdNorm2 != 0) { if (m_haveMin) - m_queue.push(item(agg::path_cmd_line_to, m_minX, m_minY)); - m_queue.push(item(agg::path_cmd_line_to, m_maxX, m_maxY)); + m_queue[m_queue_write++].set(agg::path_cmd_line_to, m_minX, m_minY); + m_queue[m_queue_write++].set(agg::path_cmd_line_to, m_maxX, m_maxY); } m_done = true; } // Return the first item in the queue, if any, otherwise // indicate that we're done. - if (m_queue.size()) + if (m_queue_read < m_queue_write) { - const item& front = m_queue.front(); + const item& front = m_queue[m_queue_read++]; unsigned cmd = front.cmd; *x = front.x; *y = front.y; - m_queue.pop(); #if DEBUG_SIMPLIFY printf((cmd == agg::path_cmd_move_to) ? "|" : "-"); #endif @@ -460,14 +447,20 @@ struct item { - item(unsigned cmd_, const double& x_, double& y_) : - cmd(cmd_), x(x_), y(y_) {} + item() {} + inline void set(const unsigned cmd_, const double& x_, const double& y_) { + cmd = cmd_; + x = x_; + y = y_; + } unsigned cmd; double x; double y; }; - typedef std::queue<item> ItemQueue; - ItemQueue m_queue; + int m_queue_read; + int m_queue_write; + item m_queue[6]; + bool m_moveto; double m_lastx, m_lasty; bool m_clipped; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2008-01-23 14:36:21
|
Revision: 4888 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4888&view=rev Author: mdboom Date: 2008-01-23 06:35:21 -0800 (Wed, 23 Jan 2008) Log Message: ----------- Minor speed improvements in Agg backend. Modified Paths: -------------- trunk/matplotlib/src/_backend_agg.cpp trunk/matplotlib/src/agg_py_path_iterator.h Modified: trunk/matplotlib/src/_backend_agg.cpp =================================================================== --- trunk/matplotlib/src/_backend_agg.cpp 2008-01-23 13:33:01 UTC (rev 4887) +++ trunk/matplotlib/src/_backend_agg.cpp 2008-01-23 14:35:21 UTC (rev 4888) @@ -343,6 +343,10 @@ return false; code = path.vertex(&x0, &y0); + if (code == agg::path_cmd_stop) { + path.rewind(0); + return false; + } trans.transform(&x0, &y0); while ((code = path.vertex(&x1, &y1)) != agg::path_cmd_stop) { @@ -1602,7 +1606,6 @@ double g = Py::Float(rgb[1]); double b = Py::Float(rgb[2]); return agg::rgba(r, g, b, alpha); - } @@ -1615,8 +1618,6 @@ double p = Py::Float( points ) ; //return (int)(p*PIXELS_PER_INCH/72.0*dpi/72.0)+0.5; return (int)(p*dpi/72.0)+0.5; - - } double Modified: trunk/matplotlib/src/agg_py_path_iterator.h =================================================================== --- trunk/matplotlib/src/agg_py_path_iterator.h 2008-01-23 13:33:01 UTC (rev 4887) +++ trunk/matplotlib/src/agg_py_path_iterator.h 2008-01-23 14:35:21 UTC (rev 4888) @@ -118,7 +118,7 @@ SimplifyPath(VertexSource& source, bool quantize, bool simplify, double width = 0.0, double height = 0.0) : m_source(&source), m_quantize(quantize), m_simplify(simplify), - m_width(width), m_height(height), m_queue_read(0), m_queue_write(0), + m_width(width + 1.0), m_height(height + 1.0), m_queue_read(0), m_queue_write(0), m_moveto(true), m_lastx(0.0), m_lasty(0.0), m_clipped(false), m_do_clipping(width > 0.0 && height > 0.0), m_origdx(0.0), m_origdy(0.0), @@ -246,9 +246,9 @@ //could be clipped, but a more involved calculation would be needed if (m_do_clipping && ((*x < -1.0 && m_lastx < -1.0) || - (*x > m_width + 1.0 && m_lastx > m_width + 1.0) || + (*x > m_width && m_lastx > m_width) || (*y < -1.0 && m_lasty < -1.0) || - (*y > m_height + 1.0 && m_lasty > m_height + 1.0))) + (*y > m_height && m_lasty > m_height))) { m_lastx = *x; m_lasty = *y; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2008-01-23 19:13:17
|
Revision: 4891 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4891&view=rev Author: mdboom Date: 2008-01-23 11:12:41 -0800 (Wed, 23 Jan 2008) Log Message: ----------- Fix warnings on gcc 4.2.1 Modified Paths: -------------- trunk/matplotlib/src/_backend_agg.cpp trunk/matplotlib/src/_image.cpp Modified: trunk/matplotlib/src/_backend_agg.cpp =================================================================== --- trunk/matplotlib/src/_backend_agg.cpp 2008-01-23 18:27:05 UTC (rev 4890) +++ trunk/matplotlib/src/_backend_agg.cpp 2008-01-23 19:12:41 UTC (rev 4891) @@ -1300,7 +1300,7 @@ PyObject* write_method = PyObject_GetAttrString(py_file_obj, "write"); PyObject* result = NULL; if (write_method) - result = PyObject_CallFunction(write_method, "s#", data, length); + result = PyObject_CallFunction(write_method, (char *)"s#", data, length); Py_XDECREF(write_method); Py_XDECREF(result); } @@ -1310,7 +1310,7 @@ PyObject* flush_method = PyObject_GetAttrString(py_file_obj, "flush"); PyObject* result = NULL; if (flush_method) - result = PyObject_CallFunction(flush_method, ""); + result = PyObject_CallFunction(flush_method, (char *)""); Py_XDECREF(flush_method); Py_XDECREF(result); } Modified: trunk/matplotlib/src/_image.cpp =================================================================== --- trunk/matplotlib/src/_image.cpp 2008-01-23 18:27:05 UTC (rev 4890) +++ trunk/matplotlib/src/_image.cpp 2008-01-23 19:12:41 UTC (rev 4891) @@ -580,7 +580,7 @@ PyObject* write_method = PyObject_GetAttrString(py_file_obj, "write"); PyObject* result = NULL; if (write_method) - result = PyObject_CallFunction(write_method, "s#", data, length); + result = PyObject_CallFunction(write_method, (char *)"s#", data, length); Py_XDECREF(write_method); Py_XDECREF(result); } @@ -590,7 +590,7 @@ PyObject* flush_method = PyObject_GetAttrString(py_file_obj, "flush"); PyObject* result = NULL; if (flush_method) - result = PyObject_CallFunction(flush_method, ""); + result = PyObject_CallFunction(flush_method, (char *)""); Py_XDECREF(flush_method); Py_XDECREF(result); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2008-05-05 15:12:32
|
Revision: 5111 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5111&view=rev Author: mdboom Date: 2008-05-05 08:12:29 -0700 (Mon, 05 May 2008) Log Message: ----------- Fix a number of minor issues discovered with "-pedantic" Modified Paths: -------------- trunk/matplotlib/src/MPL_isnan.h trunk/matplotlib/src/_backend_agg.cpp trunk/matplotlib/src/_image.cpp trunk/matplotlib/src/_image.h trunk/matplotlib/src/_path.cpp trunk/matplotlib/src/_tkagg.cpp trunk/matplotlib/src/_ttconv.cpp trunk/matplotlib/src/cntr.c trunk/matplotlib/src/ft2font.cpp Modified: trunk/matplotlib/src/MPL_isnan.h =================================================================== --- trunk/matplotlib/src/MPL_isnan.h 2008-05-02 21:52:05 UTC (rev 5110) +++ trunk/matplotlib/src/MPL_isnan.h 2008-05-05 15:12:29 UTC (rev 5111) @@ -8,6 +8,10 @@ */ +#ifdef _ISOC99_SOURCE +#include <stdint.h> +#endif + #if defined(SIZEOF_VOID_P) #if SIZEOF_VOID_P == 8 #define MPL_LP64 1 @@ -24,9 +28,13 @@ #if defined(_MSC_VER) typedef __int64 MPL_Int64; #else +#if defined(_ISOC99_SOURCE) +typedef int64_t MPL_Int64; +#else typedef long long MPL_Int64; #endif #endif +#endif #if !defined(MPL_U64) #define MPL_U64(u) (* (MPL_Int64 *) &(u) ) Modified: trunk/matplotlib/src/_backend_agg.cpp =================================================================== --- trunk/matplotlib/src/_backend_agg.cpp 2008-05-02 21:52:05 UTC (rev 5110) +++ trunk/matplotlib/src/_backend_agg.cpp 2008-05-05 15:12:29 UTC (rev 5111) @@ -249,7 +249,7 @@ //theRasterizer->filling_rule(agg::fill_even_odd); //theRasterizer->filling_rule(agg::fill_non_zero); -}; +} void RendererAgg::create_alpha_buffers() { if (!alphaBuffer) { @@ -1762,4 +1762,4 @@ static _backend_agg_module* _backend_agg = NULL; _backend_agg = new _backend_agg_module; -}; +} Modified: trunk/matplotlib/src/_image.cpp =================================================================== --- trunk/matplotlib/src/_image.cpp 2008-05-02 21:52:05 UTC (rev 5110) +++ trunk/matplotlib/src/_image.cpp 2008-05-05 15:12:29 UTC (rev 5111) @@ -826,7 +826,7 @@ for (size_t i=0; i<thisim->colsOut; i++) { thisx = i+ox; thisy = j+oy; - if (thisx<0 || thisx>=numcols || thisy<0 || thisy>=numrows) { + if (thisx>=numcols || thisy>=numrows) { ind +=4; continue; } Modified: trunk/matplotlib/src/_image.h =================================================================== --- trunk/matplotlib/src/_image.h 2008-05-02 21:52:05 UTC (rev 5110) +++ trunk/matplotlib/src/_image.h 2008-05-05 15:12:29 UTC (rev 5111) @@ -61,7 +61,7 @@ MITCHELL, SINC, LANCZOS, - BLACKMAN,}; + BLACKMAN}; //enum { BICUBIC=0, BILINEAR, BLACKMAN100, BLACKMAN256, BLACKMAN64, // NEAREST, SINC144, SINC256, SINC64, SPLINE16, SPLINE36}; Modified: trunk/matplotlib/src/_path.cpp =================================================================== --- trunk/matplotlib/src/_path.cpp 2008-05-02 21:52:05 UTC (rev 5110) +++ trunk/matplotlib/src/_path.cpp 2008-05-05 15:12:29 UTC (rev 5111) @@ -1161,4 +1161,4 @@ static _path_module* _path = NULL; _path = new _path_module; -}; +} Modified: trunk/matplotlib/src/_tkagg.cpp =================================================================== --- trunk/matplotlib/src/_tkagg.cpp 2008-05-02 21:52:05 UTC (rev 5110) +++ trunk/matplotlib/src/_tkagg.cpp 2008-05-05 15:12:29 UTC (rev 5111) @@ -27,7 +27,7 @@ #else # include <tk.h> #endif -}; +} Modified: trunk/matplotlib/src/_ttconv.cpp =================================================================== --- trunk/matplotlib/src/_ttconv.cpp 2008-05-02 21:52:05 UTC (rev 5110) +++ trunk/matplotlib/src/_ttconv.cpp 2008-05-05 15:12:29 UTC (rev 5111) @@ -204,7 +204,7 @@ "the values are the stream content needed to render that glyph. This\n" "is useful to generate the CharProcs dictionary in a PDF Type 3 font.\n" }, - {NULL} /* Sentinel */ + {0, 0, 0, 0} /* Sentinel */ }; #ifndef PyMODINIT_FUNC /* declarations for DLL import/export */ Modified: trunk/matplotlib/src/cntr.c =================================================================== --- trunk/matplotlib/src/cntr.c 2008-05-02 21:52:05 UTC (rev 5110) +++ trunk/matplotlib/src/cntr.c 2008-05-05 15:12:29 UTC (rev 5111) @@ -1688,7 +1688,7 @@ " Optional argument: nchunk; approximate number of grid points\n" " per chunk. 0 (default) for no chunking.\n" }, - {NULL} /* Sentinel */ + {0, 0, 0, 0} /* Sentinel */ }; static PyTypeObject CntrType = { Modified: trunk/matplotlib/src/ft2font.cpp =================================================================== --- trunk/matplotlib/src/ft2font.cpp 2008-05-02 21:52:05 UTC (rev 5110) +++ trunk/matplotlib/src/ft2font.cpp 2008-05-05 15:12:29 UTC (rev 5111) @@ -153,8 +153,7 @@ void FT2Image::draw_rect(unsigned long x0, unsigned long y0, unsigned long x1, unsigned long y1) { - if ( x0<0 || y0<0 || x1<0 || y1<0 || - x0>_width || x1>_width || + if ( x0>_width || x1>_width || y0>_height || y1>_height ) throw Py::ValueError("Rect coords outside image bounds"); @@ -197,10 +196,10 @@ void FT2Image::draw_rect_filled(unsigned long x0, unsigned long y0, unsigned long x1, unsigned long y1) { - x0 = CLAMP(x0, 0, _width); - y0 = CLAMP(y0, 0, _height); - x1 = CLAMP(x1, 0, _width); - y1 = CLAMP(y1, 0, _height); + x0 = std::min(x0, _width); + y0 = std::min(y0, _height); + x1 = std::min(x1, _width); + y1 = std::min(y1, _height); for (size_t j=y0; j<y1+1; j++) { for (size_t i=x0; i<x1+1; i++) { @@ -1207,7 +1206,7 @@ "draw_glyphs_to_bitmap. This function is intended for people who\n" "want to render individual glyphs at precise locations, eg, a\n" "a glyph returned by load_char\n"; -; + Py::Object FT2Font::draw_glyph_to_bitmap(const Py::Tuple & args) { _VERBOSE("FT2Font::draw_glyph_to_bitmap"); @@ -1768,7 +1767,7 @@ behaviors().supportGetattr(); behaviors().supportSetattr(); -}; +} //todo add module docs strings This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2008-07-10 18:14:15
|
Revision: 5733 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5733&view=rev Author: mdboom Date: 2008-07-10 11:12:50 -0700 (Thu, 10 Jul 2008) Log Message: ----------- Add some range checking based on testing in Fusil. Modified Paths: -------------- trunk/matplotlib/src/_backend_agg.cpp trunk/matplotlib/src/_image.cpp Modified: trunk/matplotlib/src/_backend_agg.cpp =================================================================== --- trunk/matplotlib/src/_backend_agg.cpp 2008-07-10 15:45:15 UTC (rev 5732) +++ trunk/matplotlib/src/_backend_agg.cpp 2008-07-10 18:12:50 UTC (rev 5733) @@ -1611,10 +1611,26 @@ if ( kws.hasKey("debug") ) debug = Py::Int( kws["debug"] ); else debug=0; - int width = Py::Int(args[0]); - int height = Py::Int(args[1]); + unsigned int width = (unsigned int)Py::Int(args[0]); + unsigned int height = (unsigned int)Py::Int(args[1]); double dpi = Py::Float(args[2]); - return Py::asObject(new RendererAgg(width, height, dpi, debug)); + + if (width > 1 << 15 || height > 1 << 15) { + throw Py::ValueError("width and height must each be below 32768"); + } + + if (dpi <= 0.0) { + throw Py::ValueError("dpi must be positive"); + } + + RendererAgg* renderer = NULL; + try { + renderer = new RendererAgg(width, height, dpi, debug); + } catch (std::bad_alloc) { + throw Py::RuntimeError("Could not allocate memory for image"); + } + + return Py::asObject(renderer); } Modified: trunk/matplotlib/src/_image.cpp =================================================================== --- trunk/matplotlib/src/_image.cpp 2008-07-10 15:45:15 UTC (rev 5732) +++ trunk/matplotlib/src/_image.cpp 2008-07-10 18:12:50 UTC (rev 5733) @@ -708,9 +708,13 @@ args.verify_length(3); - size_t numrows = Py::Int(args[0]); - size_t numcols = Py::Int(args[1]); + size_t numrows = (size_t)Py::Int(args[0]); + size_t numcols = (size_t)Py::Int(args[1]); + if (numrows > 1 << 15 || numcols > 1 << 15) { + throw Py::RuntimeError("numrows and numcols must both be less than 32768"); + } + Py::SeqBase<Py::Object> tups = args[2]; size_t N = tups.length(); @@ -1084,8 +1088,13 @@ args.verify_length(4); PyObject *bufin = new_reference_to(args[0]); - int x = Py::Int(args[1]); - int y = Py::Int(args[2]); + size_t x = Py::Int(args[1]); + size_t y = Py::Int(args[2]); + + if (x > 1 << 15 || y > 1 << 15) { + throw Py::ValueError("x and y must both be less than 32768"); + } + int isoutput = Py::Int(args[3]); if (PyObject_CheckReadBuffer(bufin) != 1) @@ -1155,6 +1164,10 @@ unsigned int cols = Py::Int(args[4]); Py::Tuple bounds = args[5]; + if (rows > 1 << 15 || cols > 1 << 15) { + throw Py::ValueError("rows and cols must both be less than 32768"); + } + if (bounds.length() !=4) throw Py::TypeError("Incorrect number of bounds (4 expected)"); float x_min = Py::Float(bounds[0]); @@ -1391,6 +1404,10 @@ Py::Tuple bounds = args[5]; Py::Object bgp = args[6]; + if (rows > 1 << 15 || cols > 1 << 15) { + throw Py::ValueError("rows and cols must both be less than 32768"); + } + if (bounds.length() !=4) throw Py::TypeError("Incorrect number of bounds (4 expected)"); double x_left = Py::Float(bounds[0]); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |