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

Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 4 additions & 6 deletions lib/matplotlib/backends/backend_tkcairo.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import sys

import numpy as np

from .. import cbook
from . import _backend_tk
from .backend_cairo import cairo, FigureCanvasCairo
from ._backend_tk import _BackendTk, FigureCanvasTk
Expand All @@ -14,10 +13,9 @@ def draw(self):
self._renderer.set_context(cairo.Context(surface))
self._renderer.dpi = self.figure.dpi
self.figure.draw(self._renderer)
buf = np.reshape(surface.get_data(), (height, width, 4))
_backend_tk.blit(
self._tkphoto, buf,
(2, 1, 0, 3) if sys.byteorder == "little" else (1, 2, 3, 0))
premult_argb = np.reshape(surface.get_data(), (height, width, 4))
unmult_rgba = cbook._premultiplied_argb32_to_unmultiplied_rgba8888(premult_argb)
_backend_tk.blit(self._tkphoto, unmult_rgba, (0, 1, 2, 3))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The removal of byteorder confused me until I realized that _premultiplied_argb32_to_unmultiplied_rgba8888 was handling it.

I don't think we need a comment in the code about this, as it only applies to the diff.



@_BackendTk.export
Expand Down
2 changes: 2 additions & 0 deletions lib/matplotlib/cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -2210,6 +2210,8 @@ def _premultiplied_argb32_to_unmultiplied_rgba8888(buf):
[2, 1, 0, 3] if sys.byteorder == "little" else [1, 2, 3, 0], axis=2)
rgb = rgba[..., :-1]
alpha = rgba[..., -1]
if alpha.min() == 0xff:
return rgba
# Un-premultiply alpha. The formula is the same as in cairo-png.c.
mask = alpha != 0
for channel in np.rollaxis(rgb, -1):
Expand Down
Loading