4
4
from pyqtgraph .Qt import QtGui
5
5
6
6
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 ()
12
8
13
9
14
- def check_format (shape , dtype , levels , lut , expected_format ):
10
+ def check_format (shape , dtype , levels , lut , expected_format , * , transparentLocations = None ):
15
11
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
17
14
18
15
19
16
def test_uint8 ():
@@ -22,22 +19,22 @@ def test_uint8():
22
19
w , h = 192 , 108
23
20
lo , hi = 50 , 200
24
21
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 )
29
26
30
27
# 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 )
35
32
36
33
# 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 )
41
38
42
39
levels = None
43
40
check_format ((h , w ), dtype , levels , lut_none , Format .Format_Grayscale8 )
@@ -78,22 +75,22 @@ def test_uint16():
78
75
lo , hi = 100 , 10000
79
76
lut_none = None
80
77
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 )
85
82
86
83
# 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 )
91
88
92
89
# 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 )
97
94
98
95
levels = None
99
96
check_format ((h , w ), dtype , levels , lut_none , Format .Format_Grayscale16 )
@@ -129,22 +126,22 @@ def test_float32():
129
126
lo , hi = - 1 , 1
130
127
lut_none = None
131
128
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 )
136
133
137
134
# 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 )
142
139
143
140
# 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 )
148
145
149
146
levels = [lo , hi ]
150
147
@@ -173,12 +170,9 @@ def test_float32():
173
170
lut_mono1_l , lut_mono2_l , lut_rgb_l , lut_rgba_l ,
174
171
]
175
172
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 ]))
180
174
181
- nandata = np .zeros ((h , w , 3 ), dtype = dtype )
182
- nandata [h // 2 , w // 2 , 1 ] = np .nan
183
175
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