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

Commit00ec4ec

Browse files
authored
Merge pull request#24692 from anntzer/qtrgba
Avoid rgba8888->argb32 conversion if qt can do it for us.
2 parentse710123 +718fc0e commit00ec4ec

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

‎lib/matplotlib/backends/backend_qtagg.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,30 +48,31 @@ def paintEvent(self, event):
4848
right=left+width
4949
# create a buffer using the image bounding box
5050
bbox=Bbox([[left,bottom], [right,top]])
51-
reg=self.copy_from_bbox(bbox)
52-
buf=cbook._unmultiplied_rgba8888_to_premultiplied_argb32(
53-
memoryview(reg))
51+
buf=memoryview(self.copy_from_bbox(bbox))
5452

55-
# clear the widget canvas
56-
painter.eraseRect(rect)
53+
fmts=_enum("QtGui.QImage.Format")
54+
ifhasattr(fmts,"Format_RGBA8888"):
55+
fmt=fmts.Format_RGBA8888
56+
else:# Qt<=5.1 support.
57+
fmt=fmts.Format_ARGB32_Premultiplied
58+
buf=cbook._unmultiplied_rgba8888_to_premultiplied_argb32(buf)
5759

5860
ifQT_API=="PyQt6":
5961
fromPyQt6importsip
6062
ptr=int(sip.voidptr(buf))
6163
else:
6264
ptr=buf
63-
qimage=QtGui.QImage(
64-
ptr,buf.shape[1],buf.shape[0],
65-
_enum("QtGui.QImage.Format").Format_ARGB32_Premultiplied)
65+
66+
painter.eraseRect(rect)# clear the widget canvas
67+
qimage=QtGui.QImage(ptr,buf.shape[1],buf.shape[0],fmt)
6668
_setDevicePixelRatio(qimage,self.device_pixel_ratio)
6769
# set origin using original QT coordinates
6870
origin=QtCore.QPoint(rect.left(),rect.top())
6971
painter.drawImage(origin,qimage)
7072
# Adjust the buf reference count to work around a memory
7173
# leak bug in QImage under PySide.
72-
ifQT_APIin ('PySide','PySide2'):
73-
ifQtCore.__version_info__< (5,12):
74-
ctypes.c_long.from_address(id(buf)).value=1
74+
ifQT_API=="PySide2"andQtCore.__version_info__< (5,12):
75+
ctypes.c_long.from_address(id(buf)).value=1
7576

7677
self._draw_rect_callback(painter)
7778
finally:

‎lib/matplotlib/cbook/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2056,7 +2056,7 @@ def discard(self, key):
20562056
self._od.pop(key,None)
20572057

20582058

2059-
# Agg's buffers are unmultiplied RGBA8888, which neitherPyQt5 nor cairo
2059+
# Agg's buffers are unmultiplied RGBA8888, which neitherPyQt<=5.1 nor cairo
20602060
# support; however, both do support premultiplied ARGB32.
20612061

20622062

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp