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.
This commit is contained in:
KIU Shueng Chuan 2021-02-11 09:35:48 +08:00
parent 6c8e07c377
commit 659392d4bb

View File

@ -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]]