@@ -130,33 +130,27 @@ def test_comment_write(self) -> None:
130
130
def test_cmyk (self ) -> None :
131
131
# Test CMYK handling. Thanks to Tim and Charlie for test data,
132
132
# Michael for getting me to look one more time.
133
- f = "Tests/images/pil_sample_cmyk.jpg"
134
- with Image .open (f ) as im :
135
- # the source image has red pixels in the upper left corner.
136
- c , m , y , k = (x / 255.0 for x in im .getpixel ((0 , 0 )))
137
- assert c == 0.0
138
- assert m > 0.8
139
- assert y > 0.8
140
- assert k == 0.0
141
- # the opposite corner is black
142
- c , m , y , k = (
143
- x / 255.0 for x in im .getpixel ((im .size [0 ] - 1 , im .size [1 ] - 1 ))
144
- )
145
- assert k > 0.9
146
- # roundtrip, and check again
147
- im = self .roundtrip (im )
133
+ def check (im : ImageFile .ImageFile ) -> None :
148
134
cmyk = im .getpixel ((0 , 0 ))
149
135
assert isinstance (cmyk , tuple )
150
136
c , m , y , k = (x / 255.0 for x in cmyk )
151
137
assert c == 0.0
152
138
assert m > 0.8
153
139
assert y > 0.8
154
140
assert k == 0.0
141
+ # the opposite corner is black
155
142
cmyk = im .getpixel ((im .size [0 ] - 1 , im .size [1 ] - 1 ))
156
143
assert isinstance (cmyk , tuple )
157
144
k = cmyk [3 ] / 255.0
158
145
assert k > 0.9
159
146
147
+ with Image .open ("Tests/images/pil_sample_cmyk.jpg" ) as im :
148
+ # the source image has red pixels in the upper left corner.
149
+ check (im )
150
+
151
+ # roundtrip, and check again
152
+ check (self .roundtrip (im ))
153
+
160
154
def test_rgb (self ) -> None :
161
155
def getchannels (im : JpegImagePlugin .JpegImageFile ) -> tuple [int , ...]:
162
156
return tuple (v [0 ] for v in im .layer )
0 commit comments