FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Backport PR #24692 on branch v3.6.x (Avoid rgba8888->argb32 conversion if qt can do it for us.) by meeseeksmachine · Pull Request #24694 · matplotlib/matplotlib · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
23 changes: 12 additions & 11 deletions lib/matplotlib/backends/backend_qtagg.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,31 @@ def paintEvent(self, event):
right = left + width
# create a buffer using the image bounding box
bbox = Bbox([[left, bottom], [right, top]])
reg = self.copy_from_bbox(bbox)
buf = cbook._unmultiplied_rgba8888_to_premultiplied_argb32(
memoryview(reg))
buf = memoryview(self.copy_from_bbox(bbox))

# clear the widget canvas
painter.eraseRect(rect)
fmts = _enum("QtGui.QImage.Format")
if hasattr(fmts, "Format_RGBA8888"):
fmt = fmts.Format_RGBA8888
else: # Qt<=5.1 support.
fmt = fmts.Format_ARGB32_Premultiplied
buf = cbook._unmultiplied_rgba8888_to_premultiplied_argb32(buf)

if QT_API == "PyQt6":
from PyQt6 import sip
ptr = int(sip.voidptr(buf))
else:
ptr = buf
qimage = QtGui.QImage(
ptr, buf.shape[1], buf.shape[0],
_enum("QtGui.QImage.Format").Format_ARGB32_Premultiplied)

painter.eraseRect(rect) # clear the widget canvas
qimage = QtGui.QImage(ptr, buf.shape[1], buf.shape[0], fmt)
_setDevicePixelRatio(qimage, self.device_pixel_ratio)
# set origin using original QT coordinates
origin = QtCore.QPoint(rect.left(), rect.top())
painter.drawImage(origin, qimage)
# Adjust the buf reference count to work around a memory
# leak bug in QImage under PySide.
if QT_API in ('PySide', 'PySide2'):
if QtCore.__version_info__ < (5, 12):
ctypes.c_long.from_address(id(buf)).value = 1
if QT_API == "PySide2" and QtCore.__version_info__ < (5, 12):
ctypes.c_long.from_address(id(buf)).value = 1

self._draw_rect_callback(painter)
finally:
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/cbook/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2090,7 +2090,7 @@ def discard(self, key):
self._od.pop(key, None)


# Agg's buffers are unmultiplied RGBA8888, which neither PyQt5 nor cairo
# Agg's buffers are unmultiplied RGBA8888, which neither PyQt<=5.1 nor cairo
# support; however, both do support premultiplied ARGB32.


Expand Down

Back | FazBrowse Home | New Git URL