From: <md...@us...> - 2008-06-02 14:53:33
|
Revision: 5358 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5358&view=rev Author: mdboom Date: 2008-06-02 07:53:20 -0700 (Mon, 02 Jun 2008) Log Message: ----------- Fix crash in Agg drawing collections with no fill and/or edge color. Modified Paths: -------------- branches/v0_91_maint/CHANGELOG branches/v0_91_maint/src/_backend_agg.cpp Modified: branches/v0_91_maint/CHANGELOG =================================================================== --- branches/v0_91_maint/CHANGELOG 2008-06-02 14:17:14 UTC (rev 5357) +++ branches/v0_91_maint/CHANGELOG 2008-06-02 14:53:20 UTC (rev 5358) @@ -1,4 +1,6 @@ -=============================================================== +2008-06-02 Fix crash in Agg when drawing collections with no fill and/or + edge color - MGD + 2008-05-29 Released 0.91.3 at revision 5313 2008-05-29 matplotlib.image.imread now no longer always returns RGBA Modified: branches/v0_91_maint/src/_backend_agg.cpp =================================================================== --- branches/v0_91_maint/src/_backend_agg.cpp 2008-06-02 14:17:14 UTC (rev 5357) +++ branches/v0_91_maint/src/_backend_agg.cpp 2008-06-02 14:53:20 UTC (rev 5358) @@ -690,6 +690,9 @@ size_t N = Nsegments; size_t Ndash = 0; + if (Nsegments == 0) + throw Py::ValueError("segments must have non-zero length"); + Py::SeqBase<Py::Object> dashtup(linestyle); bool useDashes = dashtup[0].ptr() != Py_None; @@ -791,50 +794,54 @@ else path.line_to(thisx, height-thisy); } + if (Nc != 0 && Nlw != 0) { + double lw = points_to_pixels ( Py::Float( linewidths[i%Nlw] ) ); + if (! useDashes ) { - double lw = points_to_pixels ( Py::Float( linewidths[i%Nlw] ) ); + agg::conv_stroke<agg::path_storage> stroke(path); + //stroke.line_cap(cap); + //stroke.line_join(join); + stroke.width(lw); + theRasterizer->add_path(stroke); + } + else { - if (! useDashes ) { + dash_t dash(path); + //dash.dash_start(offset); + for (size_t idash=0; idash<Ndash/2; idash++) + dash.add_dash(dasha[2*idash], dasha[2*idash+1]); - agg::conv_stroke<agg::path_storage> stroke(path); - //stroke.line_cap(cap); - //stroke.line_join(join); - stroke.width(lw); - theRasterizer->add_path(stroke); - } - else { + agg::conv_stroke<dash_t> stroke(dash); + //stroke.line_cap(cap); + //stroke.line_join(join); + stroke.width(lw); + theRasterizer->add_path(stroke); + } - dash_t dash(path); - //dash.dash_start(offset); - for (size_t idash=0; idash<Ndash/2; idash++) - dash.add_dash(dasha[2*idash], dasha[2*idash+1]); + // get the color and render + Py::SeqBase<Py::Object> rgba(colors[ i%Nc]); + double r = Py::Float(rgba[0]); + double g = Py::Float(rgba[1]); + double b = Py::Float(rgba[2]); + double a = Py::Float(rgba[3]); + agg::rgba color(r, g, b, a); - agg::conv_stroke<dash_t> stroke(dash); - //stroke.line_cap(cap); - //stroke.line_join(join); - stroke.width(lw); - theRasterizer->add_path(stroke); + // render antialiased or not + int isaa; + if (Naa != 0) + isaa = Py::Int(antialiaseds[i%Naa]); + else + isaa = true; + if ( isaa ) { + rendererAA->color(color); + agg::render_scanlines(*theRasterizer, *slineP8, *rendererAA); + } + else { + rendererBin->color(color); + agg::render_scanlines(*theRasterizer, *slineBin, *rendererBin); + } } - - // get the color and render - Py::SeqBase<Py::Object> rgba(colors[ i%Nc]); - double r = Py::Float(rgba[0]); - double g = Py::Float(rgba[1]); - double b = Py::Float(rgba[2]); - double a = Py::Float(rgba[3]); - agg::rgba color(r, g, b, a); - - // render antialiased or not - int isaa = Py::Int(antialiaseds[i%Naa]); - if ( isaa ) { - rendererAA->color(color); - agg::render_scanlines(*theRasterizer, *slineP8, *rendererAA); - } - else { - rendererBin->color(color); - agg::render_scanlines(*theRasterizer, *slineBin, *rendererBin); - } } //for every segment if (useDashes) delete [] dasha; return Py::Object(); @@ -1219,6 +1226,9 @@ size_t N = (Noffsets>Nverts) ? Noffsets : Nverts; + if (Nverts == 0) + throw Py::ValueError("Must have at least one set of vertices"); + std::pair<double, double> xyo, xy; Py::SeqBase<Py::Object> thisverts; size_t i, j; @@ -1302,55 +1312,64 @@ } path.close_polygon(); - int isaa = Py::Int(antialiaseds[i%Naa]); + int isaa; + if (Naa != 0) + isaa = Py::Int(antialiaseds[i%Naa]); + else + isaa = true; + // get the facecolor and render - Py::SeqBase<Py::Object> rgba = Py::SeqBase<Py::Object>(facecolors[ i%Nface]); - double r = Py::Float(rgba[0]); - double g = Py::Float(rgba[1]); - double b = Py::Float(rgba[2]); - double a = Py::Float(rgba[3]); - if (a>0) { //only render if alpha>0 - agg::rgba facecolor(r, g, b, a); + if (Nface != 0) { + Py::SeqBase<Py::Object> rgba = Py::SeqBase<Py::Object>(facecolors[ i%Nface]); + double r = Py::Float(rgba[0]); + double g = Py::Float(rgba[1]); + double b = Py::Float(rgba[2]); + double a = Py::Float(rgba[3]); + if (a>0) { //only render if alpha>0 + agg::rgba facecolor(r, g, b, a); - theRasterizer->add_path(path); + theRasterizer->add_path(path); - if (isaa) { - rendererAA->color(facecolor); - agg::render_scanlines(*theRasterizer, *slineP8, *rendererAA); - } - else { - rendererBin->color(facecolor); - agg::render_scanlines(*theRasterizer, *slineBin, *rendererBin); - } - } //renderer face + if (isaa) { + rendererAA->color(facecolor); + agg::render_scanlines(*theRasterizer, *slineP8, *rendererAA); + } + else { + rendererBin->color(facecolor); + agg::render_scanlines(*theRasterizer, *slineBin, *rendererBin); + } + } //renderer face + } + if (Nedge != 0 && Nlw != 0) { // get the edgecolor and render - rgba = Py::SeqBase<Py::Object>(edgecolors[ i%Nedge]); - r = Py::Float(rgba[0]); - g = Py::Float(rgba[1]); - b = Py::Float(rgba[2]); - a = Py::Float(rgba[3]); + Py::SeqBase<Py::Object> rgba = Py::SeqBase<Py::Object>(edgecolors[ i%Nedge]); + double r = Py::Float(rgba[0]); + double g = Py::Float(rgba[1]); + double b = Py::Float(rgba[2]); + double a = Py::Float(rgba[3]); - double lw = points_to_pixels ( Py::Float( linewidths[i%Nlw] ) ); - if ((a>0) && lw) { //only render if alpha>0 and linewidth !=0 - agg::rgba edgecolor(r, g, b, a); + double lw = points_to_pixels ( Py::Float( linewidths[i%Nlw] ) ); + if ((a>0) && lw) { //only render if alpha>0 and linewidth !=0 + agg::rgba edgecolor(r, g, b, a); - agg::conv_stroke<agg::path_storage> stroke(path); - //stroke.line_cap(cap); - //stroke.line_join(join); - stroke.width(lw); - theRasterizer->add_path(stroke); + agg::conv_stroke<agg::path_storage> stroke(path); + //stroke.line_cap(cap); + //stroke.line_join(join); + stroke.width(lw); + theRasterizer->add_path(stroke); - // render antialiased or not - if ( isaa ) { - rendererAA->color(edgecolor); - agg::render_scanlines(*theRasterizer, *slineP8, *rendererAA); - } - else { - rendererBin->color(edgecolor); - agg::render_scanlines(*theRasterizer, *slineBin, *rendererBin); - } - } //rendered edge + // render antialiased or not + if ( isaa ) { + rendererAA->color(edgecolor); + agg::render_scanlines(*theRasterizer, *slineP8, *rendererAA); + } + else { + rendererBin->color(edgecolor); + agg::render_scanlines(*theRasterizer, *slineBin, *rendererBin); + } + } //rendered edge + } delete [] xs; delete [] ys; @@ -1429,10 +1448,14 @@ } + double scale; + if (Nsizes != 0) { + scale = Py::Float(sizes[i%Nsizes]); + } else { + scale = 1.0; + } - double scale = Py::Float(sizes[i%Nsizes]); - agg::path_storage path; for (j=0; j<Nverts; j++) { @@ -1445,54 +1468,63 @@ } path.close_polygon(); - int isaa = Py::Int(antialiaseds[i%Naa]); - // get the facecolor and render - Py::SeqBase<Py::Object> rgba = Py::SeqBase<Py::Object>(facecolors[ i%Nface]); - double r = Py::Float(rgba[0]); - double g = Py::Float(rgba[1]); - double b = Py::Float(rgba[2]); - double a = Py::Float(rgba[3]); - if (a>0) { //only render if alpha>0 - agg::rgba facecolor(r, g, b, a); + int isaa; + if (Naa != 0) + isaa = Py::Int(antialiaseds[i%Naa]); + else + isaa = true; - theRasterizer->add_path(path); + if (Nface != 0) { + // get the facecolor and render + Py::SeqBase<Py::Object> rgba = Py::SeqBase<Py::Object>(facecolors[ i%Nface]); + double r = Py::Float(rgba[0]); + double g = Py::Float(rgba[1]); + double b = Py::Float(rgba[2]); + double a = Py::Float(rgba[3]); + if (a>0) { //only render if alpha>0 + agg::rgba facecolor(r, g, b, a); - if (isaa) { - rendererAA->color(facecolor); - agg::render_scanlines(*theRasterizer, *slineP8, *rendererAA); - } - else { - rendererBin->color(facecolor); - agg::render_scanlines(*theRasterizer, *slineBin, *rendererBin); - } - } //renderer face + theRasterizer->add_path(path); + if (isaa) { + rendererAA->color(facecolor); + agg::render_scanlines(*theRasterizer, *slineP8, *rendererAA); + } + else { + rendererBin->color(facecolor); + agg::render_scanlines(*theRasterizer, *slineBin, *rendererBin); + } + } //renderer face + } + + if (Nedge != 0 && Nlw != 0) { // get the edgecolor and render - rgba = Py::SeqBase<Py::Object>(edgecolors[ i%Nedge]); - r = Py::Float(rgba[0]); - g = Py::Float(rgba[1]); - b = Py::Float(rgba[2]); - a = Py::Float(rgba[3]); - double lw = points_to_pixels ( Py::Float( linewidths[i%Nlw] ) ); - if ((a>0) && lw) { //only render if alpha>0 - agg::rgba edgecolor(r, g, b, a); + Py::SeqBase<Py::Object> rgba = Py::SeqBase<Py::Object>(edgecolors[ i%Nedge]); + double r = Py::Float(rgba[0]); + double g = Py::Float(rgba[1]); + double b = Py::Float(rgba[2]); + double a = Py::Float(rgba[3]); + double lw = points_to_pixels ( Py::Float( linewidths[i%Nlw] ) ); + if ((a>0) && lw) { //only render if alpha>0 + agg::rgba edgecolor(r, g, b, a); - agg::conv_stroke<agg::path_storage> stroke(path); - //stroke.line_cap(cap); - //stroke.line_join(join); - stroke.width(lw); - theRasterizer->add_path(stroke); + agg::conv_stroke<agg::path_storage> stroke(path); + //stroke.line_cap(cap); + //stroke.line_join(join); + stroke.width(lw); + theRasterizer->add_path(stroke); - // render antialiased or not - if ( isaa ) { - rendererAA->color(edgecolor); - agg::render_scanlines(*theRasterizer, *slineP8, *rendererAA); - } - else { - rendererBin->color(edgecolor); - agg::render_scanlines(*theRasterizer, *slineBin, *rendererBin); - } - } //rendered edge + // render antialiased or not + if ( isaa ) { + rendererAA->color(edgecolor); + agg::render_scanlines(*theRasterizer, *slineP8, *rendererAA); + } + else { + rendererBin->color(edgecolor); + agg::render_scanlines(*theRasterizer, *slineBin, *rendererBin); + } + } //rendered edge + } } // for every poly delete [] xverts; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |