Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Broken alpha handling in images#545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mdboom merged 2 commits intomatplotlib:v1.1.xfrommdboom:alpha_image_resize_bug
Oct 28, 2011
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletionslib/matplotlib/backends/backend_svg.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -757,6 +757,10 @@ def draw_image(self, gc, x, y, im, dx=None, dy=None, transform=None):
im.flipud_out()
attrib['xlink:href'] = filename

alpha = gc.get_alpha()
if alpha != 1.0:
attrib['opacity'] = str(alpha)

if transform is None:
self.writer.element(
'image',
Expand Down
14 changes: 9 additions & 5 deletionslib/matplotlib/image.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -199,7 +199,7 @@ def _get_unsampled_image(self, A, image_extents, viewlim):
im.is_grayscale = False
else:
if self._rgbacache is None:
x = self.to_rgba(self._A,self._alpha,bytes=True)
x = self.to_rgba(self._A, bytes=True)
self._rgbacache = x
else:
x = self._rgbacache
Expand DownExpand Up@@ -345,6 +345,7 @@ def draw(self, renderer, *args, **kwargs):
gc = renderer.new_gc()
gc.set_clip_rectangle(self.axes.bbox.frozen())
gc.set_clip_path(self.get_clip_path())
gc.set_alpha(self.get_alpha())

if self._check_unsampled_image(renderer):
self._draw_unsampled_image(renderer, gc)
Expand DownExpand Up@@ -722,7 +723,7 @@ def set_data(self, x, y, A):
A.shape = A.shape[0:2]
if len(A.shape) == 2:
if A.dtype != np.uint8:
A = self.to_rgba(A,alpha=self._alpha,bytes=True)
A = self.to_rgba(A, bytes=True)
self.is_grayscale = self.cmap.is_gray()
else:
A = np.repeat(A[:,:,np.newaxis], 4, 2)
Expand DownExpand Up@@ -824,7 +825,7 @@ def make_image(self, magnification=1.0):
width = width * magnification
height = height * magnification
if self._rgbacache is None:
A = self.to_rgba(self._A,alpha=self._alpha,bytes=True)
A = self.to_rgba(self._A, bytes=True)
self._rgbacache = A
if self._A.ndim == 2:
self.is_grayscale = self.cmap.is_gray()
Expand All@@ -851,6 +852,7 @@ def draw(self, renderer, *args, **kwargs):
gc = renderer.new_gc()
gc.set_clip_rectangle(self.axes.bbox.frozen())
gc.set_clip_path(self.get_clip_path())
gc.set_alpha(self.get_alpha())
renderer.draw_image(gc,
round(self.axes.bbox.xmin),
round(self.axes.bbox.ymin),
Expand DownExpand Up@@ -974,7 +976,7 @@ def make_image(self, magnification=1.0):
if self._A is None:
raise RuntimeError('You must first set the image array')

x = self.to_rgba(self._A,self._alpha,bytes=True)
x = self.to_rgba(self._A, bytes=True)
self.magnification = magnification
# if magnification is not one, we need to resize
ismag = magnification!=1
Expand DownExpand Up@@ -1008,6 +1010,7 @@ def draw(self, renderer, *args, **kwargs):
gc = renderer.new_gc()
gc.set_clip_rectangle(self.figure.bbox)
gc.set_clip_path(self.get_clip_path())
gc.set_alpha(self.get_alpha())
renderer.draw_image(gc, round(self.ox), round(self.oy), im)
gc.restore()

Expand DownExpand Up@@ -1096,7 +1099,7 @@ def make_image(self, renderer, magnification=1.0):
im.is_grayscale = False
else:
if self._rgbacache is None:
x = self.to_rgba(self._A,self._alpha,bytes=True)
x = self.to_rgba(self._A, bytes=True)
self._rgbacache = x
else:
x = self._rgbacache
Expand DownExpand Up@@ -1148,6 +1151,7 @@ def draw(self, renderer, *args, **kwargs):
l, b, r, t = self.get_window_extent(renderer).extents
gc = renderer.new_gc()
self._set_gc_clip(gc)
gc.set_alpha(self.get_alpha())
#gc.set_clip_path(self.get_clip_path())
renderer.draw_image(gc, round(l), round(b), im)
gc.restore()
Expand Down
6 changes: 5 additions & 1 deletionsrc/_backend_agg.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -988,6 +988,7 @@ RendererAgg::draw_image(const Py::Tuple& args)
agg::trans_affine affine_trans;
bool has_affine = false;
double x, y, w, h;
double alpha;

if (args.size() == 7)
{
Expand All@@ -1006,6 +1007,8 @@ RendererAgg::draw_image(const Py::Tuple& args)
warnings from the compiler */
}

alpha = gc.alpha;

theRasterizer.reset_clipping();
rendererBase.reset_clipping(true);
set_clipbox(gc.cliprect, theRasterizer);
Expand DownExpand Up@@ -1097,7 +1100,8 @@ RendererAgg::draw_image(const Py::Tuple& args)
else
{
set_clipbox(gc.cliprect, rendererBase);
rendererBase.blend_from(pixf, 0, (int)x, (int)(height - (y + image->rowsOut)));
rendererBase.blend_from(
pixf, 0, (int)x, (int)(height - (y + image->rowsOut)), alpha * 255);
}

rendererBase.reset_clipping(true);
Expand Down
2 changes: 1 addition & 1 deletionsrc/_image.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,7 +33,7 @@
#include "mplutils.h"


typedef agg::pixfmt_rgba32 pixfmt;
typedef agg::pixfmt_rgba32_pre pixfmt;
typedef agg::renderer_base<pixfmt> renderer_base;
typedef agg::span_interpolator_linear<> interpolator_type;
typedef agg::rasterizer_scanline_aa<agg::rasterizer_sl_clip_dbl> rasterizer;
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp