rename: qimage_to_ndarray -> ndarray_from_qimage

This commit is contained in:
KIU Shueng Chuan 2021-07-31 21:10:34 +08:00
parent f64290be9e
commit 04673ac98b
6 changed files with 11 additions and 11 deletions

View File

@ -98,7 +98,7 @@ class ImageExporter(Exporter):
painter.end() painter.end()
if self.params['invertValue']: if self.params['invertValue']:
bg = fn.qimage_to_ndarray(self.png) bg = fn.ndarray_from_qimage(self.png)
if sys.byteorder == 'little': if sys.byteorder == 'little':
cv = slice(0, 3) cv = slice(0, 3)
else: else:

View File

@ -42,7 +42,7 @@ __all__ = [
'makeRGBA', 'makeARGB', 'makeRGBA', 'makeARGB',
# 'try_fastpath_argb', 'ndarray_to_qimage', # 'try_fastpath_argb', 'ndarray_to_qimage',
'makeQImage', 'makeQImage',
# 'qimage_to_ndarray', # 'ndarray_from_qimage',
'imageToArray', 'colorToAlpha', 'imageToArray', 'colorToAlpha',
'gaussianFilter', 'downsample', 'arrayToQPath', 'gaussianFilter', 'downsample', 'arrayToQPath',
# 'ndarray_from_qpolygonf', 'create_qpolygonf', 'arrayToQPolygonF', # 'ndarray_from_qpolygonf', 'create_qpolygonf', 'arrayToQPolygonF',
@ -1682,7 +1682,7 @@ def makeQImage(imgData, alpha=None, copy=True, transpose=True):
return ndarray_to_qimage(imgData, imgFormat) return ndarray_to_qimage(imgData, imgFormat)
def qimage_to_ndarray(qimg): def ndarray_from_qimage(qimg):
img_ptr = qimg.bits() img_ptr = qimg.bits()
if img_ptr is None: if img_ptr is None:
@ -1727,7 +1727,7 @@ def imageToArray(img, copy=False, transpose=True):
the QImage is collected before the array, there may be trouble). the QImage is collected before the array, there may be trouble).
The array will have shape (width, height, (b,g,r,a)). The array will have shape (width, height, (b,g,r,a)).
""" """
arr = qimage_to_ndarray(img) arr = ndarray_from_qimage(img)
fmt = img.format() fmt = img.format()
if fmt == img.Format.Format_RGB32: if fmt == img.Format.Format_RGB32:

View File

@ -1299,7 +1299,7 @@ class ROI(GraphicsObject):
p.drawPath(shape) p.drawPath(shape)
p.end() p.end()
cidx = 0 if sys.byteorder == 'little' else 3 cidx = 0 if sys.byteorder == 'little' else 3
mask = fn.qimage_to_ndarray(im)[...,cidx].T mask = fn.ndarray_from_qimage(im)[...,cidx].T
return mask.astype(float) / 255 return mask.astype(float) / 255
def getGlobalTransform(self, relativeTo=None): def getGlobalTransform(self, relativeTo=None):

View File

@ -23,6 +23,6 @@ def test_ImageExporter_toBytes():
exp = ImageExporter(p.getPlotItem()) exp = ImageExporter(p.getPlotItem())
qimg = exp.export(toBytes=True) qimg = exp.export(toBytes=True)
qimg = qimg.convertToFormat(QtGui.QImage.Format.Format_RGBA8888) qimg = qimg.convertToFormat(QtGui.QImage.Format.Format_RGBA8888)
data = fn.qimage_to_ndarray(qimg) data = fn.ndarray_from_qimage(qimg)
black = (0, 0, 0, 255) black = (0, 0, 0, 255)
assert np.all(data == black), "Exported image should be entirely black." assert np.all(data == black), "Exported image should be entirely black."

View File

@ -77,7 +77,7 @@ def getImageFromWidget(widget):
painter.end() painter.end()
qimg = qimg.convertToFormat(QtGui.QImage.Format.Format_RGBA8888) qimg = qimg.convertToFormat(QtGui.QImage.Format.Format_RGBA8888)
return fn.qimage_to_ndarray(qimg).copy() return fn.ndarray_from_qimage(qimg).copy()
def assertImageApproved(image, standardFile, message=None, **kwargs): def assertImageApproved(image, standardFile, message=None, **kwargs):
@ -126,7 +126,7 @@ def assertImageApproved(image, standardFile, message=None, **kwargs):
else: else:
qimg = QtGui.QImage(stdFileName) qimg = QtGui.QImage(stdFileName)
qimg = qimg.convertToFormat(QtGui.QImage.Format.Format_RGBA8888) qimg = qimg.convertToFormat(QtGui.QImage.Format.Format_RGBA8888)
stdImage = fn.qimage_to_ndarray(qimg).copy() stdImage = fn.ndarray_from_qimage(qimg).copy()
del qimg del qimg
# If the test image does not match, then we go to audit if requested. # If the test image does not match, then we go to audit if requested.

View File

@ -343,7 +343,7 @@ def test_ndarray_from_qpolygonf():
assert isinstance(arr, np.ndarray) assert isinstance(arr, np.ndarray)
def test_qimage_to_ndarray(): def test_ndarray_from_qimage():
# for QImages created w/o specifying bytesPerLine, Qt will pad # for QImages created w/o specifying bytesPerLine, Qt will pad
# each line to a multiple of 4-bytes. # each line to a multiple of 4-bytes.
# test that we can handle such QImages. # test that we can handle such QImages.
@ -353,12 +353,12 @@ def test_qimage_to_ndarray():
for w in [5, 6, 7, 8]: for w in [5, 6, 7, 8]:
qimg = QtGui.QImage(w, h, fmt) qimg = QtGui.QImage(w, h, fmt)
qimg.fill(0) qimg.fill(0)
arr = pg.functions.qimage_to_ndarray(qimg) arr = pg.functions.ndarray_from_qimage(qimg)
assert arr.shape == (h, w, 3) assert arr.shape == (h, w, 3)
fmt = QtGui.QImage.Format.Format_Grayscale8 fmt = QtGui.QImage.Format.Format_Grayscale8
for w in [5, 6, 7, 8]: for w in [5, 6, 7, 8]:
qimg = QtGui.QImage(w, h, fmt) qimg = QtGui.QImage(w, h, fmt)
qimg.fill(0) qimg.fill(0)
arr = pg.functions.qimage_to_ndarray(qimg) arr = pg.functions.ndarray_from_qimage(qimg)
assert arr.shape == (h, w) assert arr.shape == (h, w)