@@ -324,9 +324,8 @@ def read_region(self, location, layer, size):
324
324
size: (width, height) tuple giving the region size."""
325
325
if layer != 0 :
326
326
raise OpenSlideError ("Invalid layer" )
327
- for s in size :
328
- if s <= 0 :
329
- raise OpenSlideError ("Size must be positive" )
327
+ if ['fail' for s in size if s < 0 ]:
328
+ raise OpenSlideError ("Size %s must be non-negative" % (size ,))
330
329
# Any corner of the requested region may be outside the bounds of
331
330
# the image. Create a transparent tile of the correct size and
332
331
# paste the valid part of the region into the correct location.
@@ -335,8 +334,8 @@ def read_region(self, location, layer, size):
335
334
image_bottomright = [max (0 , min (l + s - 1 , limit - 1 ))
336
335
for l , s , limit in zip (location , size , self ._image .size )]
337
336
tile = Image .new ("RGBA" , size , (0 ,) * 4 )
338
- if 0 not in [ br - tl for tl , br in
339
- zip ( image_topleft , image_bottomright )]:
337
+ if not [ 'fail' for tl , br in zip ( image_topleft , image_bottomright )
338
+ if br - tl < 0 ]: # "< 0" not a typo
340
339
# Crop size is greater than zero in both dimensions.
341
340
# PIL thinks the bottom right is the first *excluded* pixel
342
341
crop = self ._image .crop (image_topleft +
0 commit comments