Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3ed08be

Browse files
committed
Merge pull request #2479 from tacaswell/rastized_background
Set default agg canvas background color to ```(1, 1, 1, 0)```, rather than ```(0, 0, 0, 0)```.
2 parents 95cfcae + 6e54d8d commit 3ed08be

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

lib/matplotlib/tests/test_image.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ def test_imsave_color_alpha():
147147
# Wherever alpha values were rounded down to 0, the rgb values all get set
148148
# to 0 during imsave (this is reasonable behaviour).
149149
# Recreate that here:
150-
data[data[:, :, 3] == 0] = 0
150+
for j in range(3):
151+
data[data[:, :, 3] == 0, j] = 1
151152

152153
assert_array_equal(data, arr_buf)
153154

src/_backend_agg.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,8 @@ RendererAgg::RendererAgg(unsigned int width, unsigned int height, double dpi,
421421
rendererAA(),
422422
rendererBin(),
423423
theRasterizer(),
424-
debug(debug)
424+
debug(debug),
425+
_fill_color(agg::rgba(1, 1, 1, 0))
425426
{
426427
_VERBOSE("RendererAgg::RendererAgg");
427428
unsigned stride(width*4);
@@ -430,7 +431,7 @@ RendererAgg::RendererAgg(unsigned int width, unsigned int height, double dpi,
430431
renderingBuffer.attach(pixBuffer, width, height, stride);
431432
pixFmt.attach(renderingBuffer);
432433
rendererBase.attach(pixFmt);
433-
rendererBase.clear(agg::rgba(0, 0, 0, 0));
434+
rendererBase.clear(_fill_color);
434435
rendererAA.attach(rendererBase);
435436
rendererBin.attach(rendererBase);
436437
hatchRenderingBuffer.attach(hatchBuffer, HATCH_SIZE, HATCH_SIZE,
@@ -1287,7 +1288,7 @@ void RendererAgg::_draw_path(path_t& path, bool has_clippath,
12871288
pixfmt hatch_img_pixf(hatchRenderingBuffer);
12881289
renderer_base rb(hatch_img_pixf);
12891290
renderer_aa rs(rb);
1290-
rb.clear(agg::rgba(0.0, 0.0, 0.0, 0.0));
1291+
rb.clear(_fill_color);
12911292
rs.color(gc.color);
12921293

12931294
try {
@@ -2425,7 +2426,7 @@ RendererAgg::clear(const Py::Tuple& args)
24252426
_VERBOSE("RendererAgg::clear");
24262427

24272428
args.verify_length(0);
2428-
rendererBase.clear(agg::rgba(0, 0, 0, 0));
2429+
rendererBase.clear(_fill_color);
24292430

24302431
return Py::Object();
24312432
}

src/_backend_agg.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@ class RendererAgg: public Py::PythonExtension<RendererAgg>
241241

242242
const int debug;
243243

244+
agg::rgba _fill_color;
245+
246+
244247
protected:
245248
double points_to_pixels(const Py::Object& points);
246249
agg::rgba rgb_to_color(const Py::SeqBase<Py::Object>& rgb, double alpha);

0 commit comments

Comments
 (0)