Skip to content

Commit

Permalink
Merge pull request #2479 from tacaswell/rastized_background
Browse files Browse the repository at this point in the history
Set default agg canvas background color to ```(1, 1, 1, 0)```, rather than ```(0, 0, 0, 0)```.
  • Loading branch information
pelson committed Oct 18, 2013
2 parents 95cfcae + 6e54d8d commit 3ed08be
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion lib/matplotlib/tests/test_image.py
Expand Up @@ -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)

Expand Down
9 changes: 5 additions & 4 deletions src/_backend_agg.cpp
Expand Up @@ -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);
Expand All @@ -430,7 +431,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(_fill_color);
rendererAA.attach(rendererBase);
rendererBin.attach(rendererBase);
hatchRenderingBuffer.attach(hatchBuffer, HATCH_SIZE, HATCH_SIZE,
Expand Down Expand Up @@ -1287,7 +1288,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 {
Expand Down Expand Up @@ -2425,7 +2426,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();
}
Expand Down
3 changes: 3 additions & 0 deletions src/_backend_agg.h
Expand Up @@ -241,6 +241,9 @@ class RendererAgg: public Py::PythonExtension<RendererAgg>

const int debug;

agg::rgba _fill_color;


protected:
double points_to_pixels(const Py::Object& points);
agg::rgba rgb_to_color(const Py::SeqBase<Py::Object>& rgb, double alpha);
Expand Down

0 comments on commit 3ed08be

Please sign in to comment.