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()
if self.params['invertValue']:
bg = fn.qimage_to_ndarray(self.png)
bg = fn.ndarray_from_qimage(self.png)
if sys.byteorder == 'little':
cv = slice(0, 3)
else:

View File

@ -42,7 +42,7 @@ __all__ = [
'makeRGBA', 'makeARGB',
# 'try_fastpath_argb', 'ndarray_to_qimage',
'makeQImage',
# 'qimage_to_ndarray',
# 'ndarray_from_qimage',
'imageToArray', 'colorToAlpha',
'gaussianFilter', 'downsample', 'arrayToQPath',
# '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)
def qimage_to_ndarray(qimg):
def ndarray_from_qimage(qimg):
img_ptr = qimg.bits()
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 array will have shape (width, height, (b,g,r,a)).
"""
arr = qimage_to_ndarray(img)
arr = ndarray_from_qimage(img)
fmt = img.format()
if fmt == img.Format.Format_RGB32:

View File

@ -1299,7 +1299,7 @@ class ROI(GraphicsObject):
p.drawPath(shape)
p.end()
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
def getGlobalTransform(self, relativeTo=None):

View File

@ -23,6 +23,6 @@ def test_ImageExporter_toBytes():
exp = ImageExporter(p.getPlotItem())
qimg = exp.export(toBytes=True)
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)
assert np.all(data == black), "Exported image should be entirely black."

View File

@ -77,7 +77,7 @@ def getImageFromWidget(widget):
painter.end()
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):
@ -126,7 +126,7 @@ def assertImageApproved(image, standardFile, message=None, **kwargs):
else:
qimg = QtGui.QImage(stdFileName)
qimg = qimg.convertToFormat(QtGui.QImage.Format.Format_RGBA8888)
stdImage = fn.qimage_to_ndarray(qimg).copy()
stdImage = fn.ndarray_from_qimage(qimg).copy()
del qimg
# 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)
def test_qimage_to_ndarray():
def test_ndarray_from_qimage():
# for QImages created w/o specifying bytesPerLine, Qt will pad
# each line to a multiple of 4-bytes.
# test that we can handle such QImages.
@ -353,12 +353,12 @@ def test_qimage_to_ndarray():
for w in [5, 6, 7, 8]:
qimg = QtGui.QImage(w, h, fmt)
qimg.fill(0)
arr = pg.functions.qimage_to_ndarray(qimg)
arr = pg.functions.ndarray_from_qimage(qimg)
assert arr.shape == (h, w, 3)
fmt = QtGui.QImage.Format.Format_Grayscale8
for w in [5, 6, 7, 8]:
qimg = QtGui.QImage(w, h, fmt)
qimg.fill(0)
arr = pg.functions.qimage_to_ndarray(qimg)
arr = pg.functions.ndarray_from_qimage(qimg)
assert arr.shape == (h, w)