From b3fc5ff5384c9b7e0d2f8e92b01c5aa24c20794d Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Mon, 30 Sep 2013 12:14:25 -0500 Subject: [PATCH 1/3] patch to fix issue #2473. The change to the agg propagate to how `imsave` works so one test had to be changed to account for the fact that pixels with alpha=0 are now set to (1, 1, 1, 0) instead of (0, 0, 0, 0). --- lib/matplotlib/tests/test_image.py | 3 ++- src/_backend_agg.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/tests/test_image.py b/lib/matplotlib/tests/test_image.py index 6f2ec0c83188..6838c982b9f5 100644 --- a/lib/matplotlib/tests/test_image.py +++ b/lib/matplotlib/tests/test_image.py @@ -147,7 +147,8 @@ def test_imsave_color_alpha(): # Wherever alpha values were rounded down to 0, the rgb values all get set # to 0 during imsave (this is reasonable behaviour). # Recreate that here: - data[data[:, :, 3] == 0] = 0 + for j in range(3): + data[data[:, :, 3] == 0, j] = 1 assert_array_equal(data, arr_buf) diff --git a/src/_backend_agg.cpp b/src/_backend_agg.cpp index 8914f3ffd199..e271b5e426d2 100644 --- a/src/_backend_agg.cpp +++ b/src/_backend_agg.cpp @@ -430,7 +430,7 @@ RendererAgg::RendererAgg(unsigned int width, unsigned int height, double dpi, renderingBuffer.attach(pixBuffer, width, height, stride); pixFmt.attach(renderingBuffer); rendererBase.attach(pixFmt); - rendererBase.clear(agg::rgba(0, 0, 0, 0)); + rendererBase.clear(agg::rgba(1, 1, 1, 0)); rendererAA.attach(rendererBase); rendererBin.attach(rendererBase); hatchRenderingBuffer.attach(hatchBuffer, HATCH_SIZE, HATCH_SIZE, From 3020d1344290139818c329f579695b9fc831caa8 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Mon, 30 Sep 2013 13:10:51 -0500 Subject: [PATCH 2/3] added class variable `_fill_color` to RendererAgg to hold the color to use in `clear` calls to the render_base. Changed all uses of `clear((...))` -> `clear(_fil_color)`. --- src/_backend_agg.cpp | 6 +++--- src/_backend_agg.h | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/_backend_agg.cpp b/src/_backend_agg.cpp index e271b5e426d2..fb8ba815674e 100644 --- a/src/_backend_agg.cpp +++ b/src/_backend_agg.cpp @@ -430,7 +430,7 @@ RendererAgg::RendererAgg(unsigned int width, unsigned int height, double dpi, renderingBuffer.attach(pixBuffer, width, height, stride); pixFmt.attach(renderingBuffer); rendererBase.attach(pixFmt); - rendererBase.clear(agg::rgba(1, 1, 1, 0)); + rendererBase.clear(_fill_color); rendererAA.attach(rendererBase); rendererBin.attach(rendererBase); hatchRenderingBuffer.attach(hatchBuffer, HATCH_SIZE, HATCH_SIZE, @@ -1287,7 +1287,7 @@ void RendererAgg::_draw_path(path_t& path, bool has_clippath, pixfmt hatch_img_pixf(hatchRenderingBuffer); renderer_base rb(hatch_img_pixf); renderer_aa rs(rb); - rb.clear(agg::rgba(0.0, 0.0, 0.0, 0.0)); + rb.clear(_fill_color); rs.color(gc.color); try { @@ -2425,7 +2425,7 @@ RendererAgg::clear(const Py::Tuple& args) _VERBOSE("RendererAgg::clear"); args.verify_length(0); - rendererBase.clear(agg::rgba(0, 0, 0, 0)); + rendererBase.clear(_fill_color); return Py::Object(); } diff --git a/src/_backend_agg.h b/src/_backend_agg.h index 7612942b9c06..631616d09414 100644 --- a/src/_backend_agg.h +++ b/src/_backend_agg.h @@ -241,6 +241,9 @@ class RendererAgg: public Py::PythonExtension const int debug; + agg::rgba _fill_color = agg::rgba(1, 1, 1, 0); + + protected: double points_to_pixels(const Py::Object& points); agg::rgba rgb_to_color(const Py::SeqBase& rgb, double alpha); From 6e54d8dc3f6af4a12e27280af2623a246579c3ca Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Mon, 30 Sep 2013 13:33:15 -0500 Subject: [PATCH 3/3] changes to c++ because gcc 4.8 seems to allow things the compiler on travis will not. --- src/_backend_agg.cpp | 3 ++- src/_backend_agg.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/_backend_agg.cpp b/src/_backend_agg.cpp index fb8ba815674e..c65af527e30a 100644 --- a/src/_backend_agg.cpp +++ b/src/_backend_agg.cpp @@ -421,7 +421,8 @@ RendererAgg::RendererAgg(unsigned int width, unsigned int height, double dpi, rendererAA(), rendererBin(), theRasterizer(), - debug(debug) + debug(debug), + _fill_color(agg::rgba(1, 1, 1, 0)) { _VERBOSE("RendererAgg::RendererAgg"); unsigned stride(width*4); diff --git a/src/_backend_agg.h b/src/_backend_agg.h index 631616d09414..65cc60aec92c 100644 --- a/src/_backend_agg.h +++ b/src/_backend_agg.h @@ -241,7 +241,7 @@ class RendererAgg: public Py::PythonExtension const int debug; - agg::rgba _fill_color = agg::rgba(1, 1, 1, 0); + agg::rgba _fill_color; protected: