From 659392d4bb3322c0215942b99a4117fb409d9233 Mon Sep 17 00:00:00 2001 From: KIU Shueng Chuan Date: Thu, 11 Feb 2021 09:35:48 +0800 Subject: [PATCH] don't rely on QImage being non-const the previous formulation creates an ndarray and then creates an QImage over it w/o copying. this relies on the QImage thus created being non-const. if the QImage was (unintentionally) created as const, the subsequent QPainter render on the const QImage would trigger a COW. i.e. the original underlying ndarray wouldn't be updated. this is only an issue for PyQt bindings where const QImages can be created. --- pyqtgraph/tests/image_testing.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pyqtgraph/tests/image_testing.py b/pyqtgraph/tests/image_testing.py index 1fcfeb53..bfb8dc0f 100644 --- a/pyqtgraph/tests/image_testing.py +++ b/pyqtgraph/tests/image_testing.py @@ -137,12 +137,14 @@ def assertImageApproved(image, standardFile, message=None, **kwargs): QtGui.QApplication.processEvents() graphstate = scenegraphState(w, standardFile) - image = np.zeros((w.height(), w.width(), 4), dtype=np.ubyte) - qimg = fn.makeQImage(image, alpha=True, copy=False, transpose=False) + qimg = QtGui.QImage(w.size(), QtGui.QImage.Format.Format_ARGB32) + qimg.fill(QtCore.Qt.GlobalColor.transparent) painter = QtGui.QPainter(qimg) w.render(painter) painter.end() + image = fn.imageToArray(qimg, copy=False, transpose=False) + # transpose BGRA to RGBA image = image[..., [2, 1, 0, 3]]