check ImageItem uint8 and uint16 QImage formats
This commit is contained in:
parent
a6bbb1c48c
commit
81cc4eb797
78
pyqtgraph/graphicsItems/tests/test_ImageItemFormat.py
Normal file
78
pyqtgraph/graphicsItems/tests/test_ImageItemFormat.py
Normal file
@ -0,0 +1,78 @@
|
||||
import numpy as np
|
||||
import pyqtgraph as pg
|
||||
from pyqtgraph.Qt import QtGui
|
||||
|
||||
|
||||
def check_format(shape, dtype, levels, lut, expected_format):
|
||||
data = np.zeros(shape, dtype=dtype)
|
||||
item = pg.ImageItem(data, autoLevels=False)
|
||||
item.setLevels(levels)
|
||||
item.setLookupTable(lut)
|
||||
item.render()
|
||||
assert item.qimage.format() == expected_format
|
||||
|
||||
|
||||
|
||||
def test_uint8():
|
||||
Format = QtGui.QImage.Format
|
||||
dtype = np.uint8
|
||||
w, h = 192, 108
|
||||
lo, hi = 50, 200
|
||||
lut_none = None
|
||||
lut_mono1 = np.random.randint(256, size=256, dtype=np.uint8)
|
||||
lut_mono2 = np.random.randint(256, size=(256, 1), dtype=np.uint8)
|
||||
lut_rgb = np.random.randint(256, size=(256, 3), dtype=np.uint8)
|
||||
lut_rgba = np.random.randint(256, size=(256, 4), dtype=np.uint8)
|
||||
|
||||
levels = None
|
||||
check_format((w, h), dtype, levels, lut_none, Format.Format_Grayscale8)
|
||||
check_format((w, h, 3), dtype, levels, lut_none, Format.Format_RGB888)
|
||||
check_format((w, h, 4), dtype, levels, lut_none, Format.Format_RGBA8888)
|
||||
|
||||
levels = [lo, hi]
|
||||
check_format((w, h), dtype, levels, lut_none, Format.Format_Indexed8)
|
||||
levels = None
|
||||
check_format((w, h), dtype, levels, lut_mono1, Format.Format_Indexed8)
|
||||
check_format((w, h), dtype, levels, lut_mono2, Format.Format_Indexed8)
|
||||
check_format((w, h), dtype, levels, lut_rgb, Format.Format_Indexed8)
|
||||
check_format((w, h), dtype, levels, lut_rgba, Format.Format_Indexed8)
|
||||
levels = [lo, hi]
|
||||
check_format((w, h), dtype, levels, lut_mono1, Format.Format_Indexed8)
|
||||
check_format((w, h), dtype, levels, lut_mono2, Format.Format_Indexed8)
|
||||
check_format((w, h), dtype, levels, lut_rgb, Format.Format_Indexed8)
|
||||
check_format((w, h), dtype, levels, lut_rgba, Format.Format_Indexed8)
|
||||
|
||||
levels = [lo, hi]
|
||||
check_format((w, h, 3), dtype, levels, lut_none, Format.Format_RGB888)
|
||||
|
||||
|
||||
def test_uint16():
|
||||
Format = QtGui.QImage.Format
|
||||
dtype = np.uint16
|
||||
w, h = 192, 108
|
||||
lo, hi = 100, 10000
|
||||
lut_none = None
|
||||
lut_mono1 = np.random.randint(256, size=256, dtype=np.uint8)
|
||||
lut_mono2 = np.random.randint(256, size=(256, 1), dtype=np.uint8)
|
||||
lut_rgb = np.random.randint(256, size=(256, 3), dtype=np.uint8)
|
||||
lut_rgba = np.random.randint(256, size=(256, 4), dtype=np.uint8)
|
||||
|
||||
levels = None
|
||||
try:
|
||||
fmt_gray16 = Format.Format_Grayscale16
|
||||
except AttributeError:
|
||||
fmt_gray16 = Format.Format_ARGB32
|
||||
check_format((w, h), dtype, levels, lut_none, fmt_gray16)
|
||||
check_format((w, h, 3), dtype, levels, lut_none, Format.Format_RGB888)
|
||||
check_format((w, h, 4), dtype, levels, lut_none, Format.Format_RGBA64)
|
||||
|
||||
levels = [lo, hi]
|
||||
check_format((w, h), dtype, levels, lut_none, Format.Format_Grayscale8)
|
||||
levels = None
|
||||
check_format((w, h), dtype, levels, lut_mono1, Format.Format_Grayscale8)
|
||||
check_format((w, h), dtype, levels, lut_mono2, Format.Format_Grayscale8)
|
||||
check_format((w, h), dtype, levels, lut_rgb, Format.Format_RGBA8888)
|
||||
check_format((w, h), dtype, levels, lut_rgba, Format.Format_RGBA8888)
|
||||
|
||||
levels = [lo, hi]
|
||||
check_format((w, h, 3), dtype, levels, lut_none, Format.Format_RGB888)
|
Loading…
Reference in New Issue
Block a user