From 04673ac98b62f979a8dfc41cc0678ee6ac19e882 Mon Sep 17 00:00:00 2001 From: KIU Shueng Chuan Date: Sat, 31 Jul 2021 21:10:34 +0800 Subject: [PATCH] rename: qimage_to_ndarray -> ndarray_from_qimage --- pyqtgraph/exporters/ImageExporter.py | 2 +- pyqtgraph/functions.py | 6 +++--- pyqtgraph/graphicsItems/ROI.py | 2 +- tests/exporters/test_image.py | 2 +- tests/image_testing.py | 4 ++-- tests/test_functions.py | 6 +++--- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/pyqtgraph/exporters/ImageExporter.py b/pyqtgraph/exporters/ImageExporter.py index a6aec63f..4991bb79 100644 --- a/pyqtgraph/exporters/ImageExporter.py +++ b/pyqtgraph/exporters/ImageExporter.py @@ -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: diff --git a/pyqtgraph/functions.py b/pyqtgraph/functions.py index 25d1f773..9b123b08 100644 --- a/pyqtgraph/functions.py +++ b/pyqtgraph/functions.py @@ -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: diff --git a/pyqtgraph/graphicsItems/ROI.py b/pyqtgraph/graphicsItems/ROI.py index a4526804..86528d5f 100644 --- a/pyqtgraph/graphicsItems/ROI.py +++ b/pyqtgraph/graphicsItems/ROI.py @@ -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): diff --git a/tests/exporters/test_image.py b/tests/exporters/test_image.py index a3015e67..374fa4e5 100644 --- a/tests/exporters/test_image.py +++ b/tests/exporters/test_image.py @@ -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." diff --git a/tests/image_testing.py b/tests/image_testing.py index f5f688eb..0887e271 100644 --- a/tests/image_testing.py +++ b/tests/image_testing.py @@ -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. diff --git a/tests/test_functions.py b/tests/test_functions.py index 169453f8..40a58fb3 100644 --- a/tests/test_functions.py +++ b/tests/test_functions.py @@ -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)