mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-14 05:36:48 +03:00
bb1b3a532c
find * -type f "-(" -name "*.bdf" -o -name "*.c" -o -name "*.h" -o -name "*.py" -o -name "*.rst" -o -name "*.txt" "-)" -exec sed -e "s/[[:space:]]*$//" -i {} \;
72 lines
1.8 KiB
Python
72 lines
1.8 KiB
Python
from tester import *
|
|
|
|
from PIL import Image
|
|
from PIL import ImageFile
|
|
|
|
codecs = dir(Image.core)
|
|
|
|
# save original block sizes
|
|
MAXBLOCK = ImageFile.MAXBLOCK
|
|
SAFEBLOCK = ImageFile.SAFEBLOCK
|
|
|
|
def test_parser():
|
|
|
|
def roundtrip(format):
|
|
|
|
im = lena("L").resize((1000, 1000))
|
|
if format in ("MSP", "XBM"):
|
|
im = im.convert("1")
|
|
|
|
file = BytesIO()
|
|
|
|
im.save(file, format)
|
|
|
|
data = file.getvalue()
|
|
|
|
parser = ImageFile.Parser()
|
|
parser.feed(data)
|
|
imOut = parser.close()
|
|
|
|
return im, imOut
|
|
|
|
assert_image_equal(*roundtrip("BMP"))
|
|
assert_image_equal(*roundtrip("GIF"))
|
|
assert_image_equal(*roundtrip("IM"))
|
|
assert_image_equal(*roundtrip("MSP"))
|
|
if "zip_encoder" in codecs:
|
|
try:
|
|
# force multiple blocks in PNG driver
|
|
ImageFile.MAXBLOCK = 8192
|
|
assert_image_equal(*roundtrip("PNG"))
|
|
finally:
|
|
ImageFile.MAXBLOCK = MAXBLOCK
|
|
assert_image_equal(*roundtrip("PPM"))
|
|
assert_image_equal(*roundtrip("TIFF"))
|
|
assert_image_equal(*roundtrip("XBM"))
|
|
#assert_image_equal(*roundtrip("EPS")) #no eps_decoder
|
|
assert_image_equal(*roundtrip("TGA"))
|
|
assert_image_equal(*roundtrip("PCX"))
|
|
|
|
if "jpeg_encoder" in codecs:
|
|
im1, im2 = roundtrip("JPEG") # lossy compression
|
|
assert_image(im1, im2.mode, im2.size)
|
|
|
|
# XXX Why assert exception and why does it fail?
|
|
# https://github.com/python-imaging/Pillow/issues/78
|
|
#assert_exception(IOError, lambda: roundtrip("PDF"))
|
|
|
|
def test_safeblock():
|
|
|
|
im1 = lena()
|
|
|
|
if "zip_encoder" not in codecs:
|
|
skip("PNG (zlib) encoder not available")
|
|
|
|
try:
|
|
ImageFile.SAFEBLOCK = 1
|
|
im2 = fromstring(tostring(im1, "PNG"))
|
|
finally:
|
|
ImageFile.SAFEBLOCK = SAFEBLOCK
|
|
|
|
assert_image_equal(im1, im2)
|