Skip to content

Commit 8aba35e

Browse files
committed
test image formats outside of ImageItem
1 parent 8e61bf3 commit 8aba35e

File tree

1 file changed

+44
-50
lines changed

1 file changed

+44
-50
lines changed

tests/graphicsItems/test_ImageItemFormat.py renamed to tests/test_ImageFormat.py

Lines changed: 44 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@
44
from pyqtgraph.Qt import QtGui
55

66

7-
def check_image_format(data, levels, lut, expected_format):
8-
item = pg.ImageItem(axisOrder='row-major')
9-
item.setImage(data, autoLevels=False, lut=lut, levels=levels)
10-
item.render()
11-
assert item.qimage.format() == expected_format
7+
rng = np.random.default_rng()
128

139

14-
def check_format(shape, dtype, levels, lut, expected_format):
10+
def check_format(shape, dtype, levels, lut, expected_format, *, transparentLocations=None):
1511
data = np.zeros(shape, dtype=dtype)
16-
check_image_format(data, levels, lut, expected_format)
12+
qimage = pg.functions_qimage.try_make_qimage(data, levels=levels, lut=lut, transparentLocations=transparentLocations)
13+
assert qimage is not None and qimage.format() == expected_format
1714

1815

1916
def test_uint8():
@@ -22,22 +19,22 @@ def test_uint8():
2219
w, h = 192, 108
2320
lo, hi = 50, 200
2421
lut_none = None
25-
lut_mono1 = np.random.randint(256, size=256, dtype=np.uint8)
26-
lut_mono2 = np.random.randint(256, size=(256, 1), dtype=np.uint8)
27-
lut_rgb = np.random.randint(256, size=(256, 3), dtype=np.uint8)
28-
lut_rgba = np.random.randint(256, size=(256, 4), dtype=np.uint8)
22+
lut_mono1 = rng.integers(256, size=256, dtype=np.uint8)
23+
lut_mono2 = rng.integers(256, size=(256, 1), dtype=np.uint8)
24+
lut_rgb = rng.integers(256, size=(256, 3), dtype=np.uint8)
25+
lut_rgba = rng.integers(256, size=(256, 4), dtype=np.uint8)
2926

3027
# lut with less than 256 entries
31-
lut_mono1_s = np.random.randint(256, size=255, dtype=np.uint8)
32-
lut_mono2_s = np.random.randint(256, size=(255, 1), dtype=np.uint8)
33-
lut_rgb_s = np.random.randint(256, size=(255, 3), dtype=np.uint8)
34-
lut_rgba_s = np.random.randint(256, size=(255, 4), dtype=np.uint8)
28+
lut_mono1_s = rng.integers(256, size=255, dtype=np.uint8)
29+
lut_mono2_s = rng.integers(256, size=(255, 1), dtype=np.uint8)
30+
lut_rgb_s = rng.integers(256, size=(255, 3), dtype=np.uint8)
31+
lut_rgba_s = rng.integers(256, size=(255, 4), dtype=np.uint8)
3532

3633
# lut with more than 256 entries
37-
lut_mono1_l = np.random.randint(256, size=257, dtype=np.uint8)
38-
lut_mono2_l = np.random.randint(256, size=(257, 1), dtype=np.uint8)
39-
lut_rgb_l = np.random.randint(256, size=(257, 3), dtype=np.uint8)
40-
lut_rgba_l = np.random.randint(256, size=(257, 4), dtype=np.uint8)
34+
lut_mono1_l = rng.integers(256, size=257, dtype=np.uint8)
35+
lut_mono2_l = rng.integers(256, size=(257, 1), dtype=np.uint8)
36+
lut_rgb_l = rng.integers(256, size=(257, 3), dtype=np.uint8)
37+
lut_rgba_l = rng.integers(256, size=(257, 4), dtype=np.uint8)
4138

4239
levels = None
4340
check_format((h, w), dtype, levels, lut_none, Format.Format_Grayscale8)
@@ -78,22 +75,22 @@ def test_uint16():
7875
lo, hi = 100, 10000
7976
lut_none = None
8077

81-
lut_mono1 = np.random.randint(256, size=256, dtype=np.uint8)
82-
lut_mono2 = np.random.randint(256, size=(256, 1), dtype=np.uint8)
83-
lut_rgb = np.random.randint(256, size=(256, 3), dtype=np.uint8)
84-
lut_rgba = np.random.randint(256, size=(256, 4), dtype=np.uint8)
78+
lut_mono1 = rng.integers(256, size=256, dtype=np.uint8)
79+
lut_mono2 = rng.integers(256, size=(256, 1), dtype=np.uint8)
80+
lut_rgb = rng.integers(256, size=(256, 3), dtype=np.uint8)
81+
lut_rgba = rng.integers(256, size=(256, 4), dtype=np.uint8)
8582

8683
# lut with less than 256 entries
87-
lut_mono1_s = np.random.randint(256, size=255, dtype=np.uint8)
88-
lut_mono2_s = np.random.randint(256, size=(255, 1), dtype=np.uint8)
89-
lut_rgb_s = np.random.randint(256, size=(255, 3), dtype=np.uint8)
90-
lut_rgba_s = np.random.randint(256, size=(255, 4), dtype=np.uint8)
84+
lut_mono1_s = rng.integers(256, size=255, dtype=np.uint8)
85+
lut_mono2_s = rng.integers(256, size=(255, 1), dtype=np.uint8)
86+
lut_rgb_s = rng.integers(256, size=(255, 3), dtype=np.uint8)
87+
lut_rgba_s = rng.integers(256, size=(255, 4), dtype=np.uint8)
9188

9289
# lut with more than 256 entries
93-
lut_mono1_l = np.random.randint(256, size=257, dtype=np.uint8)
94-
lut_mono2_l = np.random.randint(256, size=(257, 1), dtype=np.uint8)
95-
lut_rgb_l = np.random.randint(256, size=(257, 3), dtype=np.uint8)
96-
lut_rgba_l = np.random.randint(256, size=(257, 4), dtype=np.uint8)
90+
lut_mono1_l = rng.integers(256, size=257, dtype=np.uint8)
91+
lut_mono2_l = rng.integers(256, size=(257, 1), dtype=np.uint8)
92+
lut_rgb_l = rng.integers(256, size=(257, 3), dtype=np.uint8)
93+
lut_rgba_l = rng.integers(256, size=(257, 4), dtype=np.uint8)
9794

9895
levels = None
9996
check_format((h, w), dtype, levels, lut_none, Format.Format_Grayscale16)
@@ -129,22 +126,22 @@ def test_float32():
129126
lo, hi = -1, 1
130127
lut_none = None
131128

132-
lut_mono1 = np.random.randint(256, size=256, dtype=np.uint8)
133-
lut_mono2 = np.random.randint(256, size=(256, 1), dtype=np.uint8)
134-
lut_rgb = np.random.randint(256, size=(256, 3), dtype=np.uint8)
135-
lut_rgba = np.random.randint(256, size=(256, 4), dtype=np.uint8)
129+
lut_mono1 = rng.integers(256, size=256, dtype=np.uint8)
130+
lut_mono2 = rng.integers(256, size=(256, 1), dtype=np.uint8)
131+
lut_rgb = rng.integers(256, size=(256, 3), dtype=np.uint8)
132+
lut_rgba = rng.integers(256, size=(256, 4), dtype=np.uint8)
136133

137134
# lut with less than 256 entries
138-
lut_mono1_s = np.random.randint(256, size=255, dtype=np.uint8)
139-
lut_mono2_s = np.random.randint(256, size=(255, 1), dtype=np.uint8)
140-
lut_rgb_s = np.random.randint(256, size=(255, 3), dtype=np.uint8)
141-
lut_rgba_s = np.random.randint(256, size=(255, 4), dtype=np.uint8)
135+
lut_mono1_s = rng.integers(256, size=255, dtype=np.uint8)
136+
lut_mono2_s = rng.integers(256, size=(255, 1), dtype=np.uint8)
137+
lut_rgb_s = rng.integers(256, size=(255, 3), dtype=np.uint8)
138+
lut_rgba_s = rng.integers(256, size=(255, 4), dtype=np.uint8)
142139

143140
# lut with more than 256 entries
144-
lut_mono1_l = np.random.randint(256, size=257, dtype=np.uint8)
145-
lut_mono2_l = np.random.randint(256, size=(257, 1), dtype=np.uint8)
146-
lut_rgb_l = np.random.randint(256, size=(257, 3), dtype=np.uint8)
147-
lut_rgba_l = np.random.randint(256, size=(257, 4), dtype=np.uint8)
141+
lut_mono1_l = rng.integers(256, size=257, dtype=np.uint8)
142+
lut_mono2_l = rng.integers(256, size=(257, 1), dtype=np.uint8)
143+
lut_rgb_l = rng.integers(256, size=(257, 3), dtype=np.uint8)
144+
lut_rgba_l = rng.integers(256, size=(257, 4), dtype=np.uint8)
148145

149146
levels = [lo, hi]
150147

@@ -173,12 +170,9 @@ def test_float32():
173170
lut_mono1_l, lut_mono2_l, lut_rgb_l, lut_rgba_l,
174171
]
175172

176-
nandata = np.zeros((h, w), dtype=dtype)
177-
nandata[h//2, w//2] = np.nan
178-
for lut in all_lut_types:
179-
check_image_format(nandata, levels, lut, Format.Format_RGBA8888)
173+
center = (np.array([h//2]), np.array([w//2]))
180174

181-
nandata = np.zeros((h, w, 3), dtype=dtype)
182-
nandata[h//2, w//2, 1] = np.nan
183175
for lut in all_lut_types:
184-
check_image_format(nandata, levels, lut, Format.Format_RGBA8888)
176+
check_format((h, w), dtype, levels, lut, Format.Format_RGBA8888, transparentLocations=center)
177+
178+
check_format((h, w, 3), dtype, levels, lut_none, Format.Format_RGBA8888, transparentLocations=center)

0 commit comments

Comments
 (0)