4
from PIL import ImageFile
6
# save original block sizes
7
MAXBLOCK = ImageFile.MAXBLOCK
8
SAFEBLOCK = ImageFile.SAFEBLOCK
12
def roundtrip(format):
14
im = lena("L").resize((1000, 1000))
15
if format in ("MSP", "XBM"):
22
data = file.getvalue()
24
parser = ImageFile.Parser()
26
imOut = parser.close()
30
assert_image_equal(*roundtrip("BMP"))
31
assert_image_equal(*roundtrip("GIF"))
32
assert_image_equal(*roundtrip("IM"))
33
assert_image_equal(*roundtrip("MSP"))
35
# force multiple blocks in PNG driver
36
ImageFile.MAXBLOCK = 8192
37
assert_image_equal(*roundtrip("PNG"))
39
ImageFile.MAXBLOCK = MAXBLOCK
40
assert_image_equal(*roundtrip("PPM"))
41
assert_image_equal(*roundtrip("TIFF"))
42
assert_image_equal(*roundtrip("XBM"))
43
#assert_image_equal(*roundtrip("EPS")) #no eps_decoder
44
assert_image_equal(*roundtrip("TGA"))
45
assert_image_equal(*roundtrip("PCX"))
47
im1, im2 = roundtrip("JPEG") # lossy compression
48
assert_image(im1, im2.mode, im2.size)
50
assert_exception(IOError, lambda: roundtrip("PDF"))
58
ImageFile.SAFEBLOCK = 1
59
im2 = fromstring(tostring(im1, "PNG"))
61
ImageFile.SAFEBLOCK = SAFEBLOCK
63
assert_image_equal(im1, im2)