Skip to content
Permalink
Browse files

Merge c413af9 into 956432e

  • Loading branch information...
radarhere committed Jun 13, 2018
2 parents 956432e + c413af9 commit 5331c8ccd28d79cefe8b41bf6a886452b9327041
Showing with 468 additions and 242 deletions.
  1. +4 −2 Tests/helper.py
  2. +2 −1 Tests/test_color_lut.py
  3. +2 −1 Tests/test_file_gif.py
  4. +0 −1 Tests/test_file_jpeg.py
  5. +8 −5 Tests/test_file_libtiff.py
  6. +3 −1 Tests/test_file_pdf.py
  7. +4 −2 Tests/test_file_png.py
  8. +2 −1 Tests/test_file_tiff.py
  9. +2 −1 Tests/test_font_leaks.py
  10. +2 −1 Tests/test_image_access.py
  11. +4 −2 Tests/test_image_array.py
  12. +2 −1 Tests/test_image_convert.py
  13. +8 −4 Tests/test_image_resample.py
  14. +3 −2 Tests/test_image_rotate.py
  15. +10 −5 Tests/test_imagecms.py
  16. +3 −2 Tests/test_imageenhance.py
  17. +6 −2 Tests/test_imagefile.py
  18. +6 −3 Tests/test_imagefont.py
  19. +4 −2 Tests/test_imagefontctl.py
  20. +2 −1 Tests/test_lib_pack.py
  21. +1 −1 Tests/test_locale.py
  22. +2 −1 Tests/test_map.py
  23. +41 −20 Tests/test_pdfparser.py
  24. +4 −2 setup.py
  25. +14 −6 src/PIL/BmpImagePlugin.py
  26. +2 −1 src/PIL/DdsImagePlugin.py
  27. +14 −8 src/PIL/FtexImagePlugin.py
  28. +4 −2 src/PIL/GbrImagePlugin.py
  29. +0 −1 src/PIL/GifImagePlugin.py
  30. +28 −28 src/PIL/ImageCms.py
  31. +3 −2 src/PIL/ImageDraw.py
  32. +12 −9 src/PIL/ImageFile.py
  33. +11 −8 src/PIL/ImageFont.py
  34. +2 −1 src/PIL/ImageQt.py
  35. +2 −1 src/PIL/Jpeg2KImagePlugin.py
  36. +5 −3 src/PIL/MspImagePlugin.py
  37. +41 −22 src/PIL/PdfImagePlugin.py
  38. +186 −74 src/PIL/PdfParser.py
  39. +2 −2 src/PIL/PngImagePlugin.py
  40. +2 −1 src/PIL/PpmImagePlugin.py
  41. +2 −1 src/PIL/SgiImagePlugin.py
  42. +3 −2 src/PIL/SunImagePlugin.py
  43. +2 −1 src/PIL/TiffImagePlugin.py
  44. +4 −3 src/PIL/TiffTags.py
  45. +2 −1 src/PIL/WmfImagePlugin.py
  46. +2 −1 src/PIL/_util.py
@@ -153,7 +153,8 @@ def assert_image_similar(self, a, b, epsilon, msg=None):
pass
raise e

def assert_image_similar_tofile(self, a, filename, epsilon, msg=None, mode=None):
def assert_image_similar_tofile(self, a, filename, epsilon, msg=None,
mode=None):
with Image.open(filename) as img:
if mode:
img = img.convert(mode)
@@ -246,7 +247,8 @@ def _get_mem_usage(self):
mem = getrusage(RUSAGE_SELF).ru_maxrss
if sys.platform == 'darwin':
# man 2 getrusage:
# ru_maxrss the maximum resident set size utilized (in bytes).
# ru_maxrss
# This is the maximum resident set size utilized (in bytes).
return mem / 1024 # Kb
else:
# linux
@@ -319,7 +319,8 @@ def test_4_channels(self):
self.assertEqual(lut.name, "Color 3D LUT")
self.assertEqual(lut.table[:24], [
0.0, 0.0, 0.0, 0.0, 0.0, 0.25, 0.0, 0.125, 0.0, 0.5, 0.0, 0.25,
0.0, 0.75, 0.0, 0.375, 0.0, 1.0, 0.0, 0.5, 0.0, 0.0, 0.25, 0.125])
0.0, 0.75, 0.0, 0.375, 0.0, 1.0, 0.0, 0.5, 0.0, 0.0, 0.25, 0.125
])

def test_apply(self):
lut = ImageFilter.Color3DLUT.generate(5, lambda r, g, b: (r, g, b))
@@ -402,7 +402,8 @@ def test_background(self):

def test_comment(self):
im = Image.open(TEST_GIF)
self.assertEqual(im.info['comment'], b"File written by Adobe Photoshop\xa8 4.0")
self.assertEqual(im.info['comment'],
b"File written by Adobe Photoshop\xa8 4.0")

out = self.tempfile('temp.gif')
im = Image.new('L', (100, 100), '#000')
@@ -363,7 +363,6 @@ def test_truncated_jpeg_throws_IOError(self):
with self.assertRaises(IOError):
im.load()


def _n_qtables_helper(self, n, test_file):
im = Image.open(test_file)
f = self.tempfile('temp.jpg')
@@ -31,7 +31,7 @@ def _assert_noerr(self, im):

try:
self.assertEqual(im._compression, 'group4')
except:
except AttributeError:
print("No _compression")
print(dir(im))

@@ -126,7 +126,8 @@ def test_adobe_deflate_tiff(self):
im.tile[0][:3], ('tiff_adobe_deflate', (0, 0, 278, 374), 0))
im.load()

self.assert_image_equal_tofile(im, 'Tests/images/tiff_adobe_deflate.png')
self.assert_image_equal_tofile(im,
'Tests/images/tiff_adobe_deflate.png')

def test_write_metadata(self):
""" Test metadata writing through libtiff """
@@ -194,7 +195,7 @@ def test_additional_metadata(self):
for tag in im.tag_v2:
try:
del(core_items[tag])
except:
except KeyError:
pass

# Type codes:
@@ -217,7 +218,8 @@ def test_additional_metadata(self):
if info.length == 0:
new_ifd[tag] = tuple(values[info.type] for _ in range(3))
else:
new_ifd[tag] = tuple(values[info.type] for _ in range(info.length))
new_ifd[tag] = tuple(values[info.type]
for _ in range(info.length))

# Extra samples really doesn't make sense in this application.
del(new_ifd[338])
@@ -607,7 +609,8 @@ def test_sampleformat(self):
im = Image.open("Tests/images/copyleft.tiff")
self.assertEqual(im.mode, 'RGB')

self.assert_image_equal_tofile(im, "Tests/images/copyleft.png", mode='RGB')
self.assert_image_equal_tofile(im, "Tests/images/copyleft.png",
mode='RGB')

def test_lzw(self):
im = Image.open("Tests/images/hopper_lzw.tif")
@@ -209,7 +209,9 @@ def test_pdf_append(self):

def test_pdf_info(self):
# make a PDF file
pdf_filename = self.helper_save_as_pdf("RGB", title="title", author="author", subject="subject", keywords="keywords", creator="creator", producer="producer")
pdf_filename = self.helper_save_as_pdf("RGB", title="title",
author="author", subject="subject", keywords="keywords",
creator="creator", producer="producer")

# open it, check pages and info
with PdfParser.PdfParser(pdf_filename) as pdf:
@@ -341,7 +341,8 @@ def test_verify_ignores_crc_error(self):
broken_crc_chunk_data = chunk_data[:-1] + b'q' # break CRC

image_data = HEAD + broken_crc_chunk_data + TAIL
self.assertRaises(SyntaxError, PngImagePlugin.PngImageFile, BytesIO(image_data))
self.assertRaises(SyntaxError, PngImagePlugin.PngImageFile,
BytesIO(image_data))

ImageFile.LOAD_TRUNCATED_IMAGES = True
try:
@@ -357,7 +358,8 @@ def test_verify_not_ignores_crc_error_in_required_chunk(self):

ImageFile.LOAD_TRUNCATED_IMAGES = True
try:
self.assertRaises(SyntaxError, PngImagePlugin.PngImageFile, BytesIO(image_data))
self.assertRaises(SyntaxError, PngImagePlugin.PngImageFile,
BytesIO(image_data))
finally:
ImageFile.LOAD_TRUNCATED_IMAGES = False

@@ -444,7 +444,8 @@ def imGenerator(ims):
for im in ims:
yield im
mp = io.BytesIO()
im.save(mp, format="TIFF", save_all=True, append_images=imGenerator(ims))
im.save(mp, format="TIFF", save_all=True,
append_images=imGenerator(ims))

mp.seek(0, os.SEEK_SET)
reread = Image.open(mp)
@@ -16,7 +16,8 @@ def _test_font(self, font):
self._test_leak(lambda: draw.text((0, 0), "some text "*1024, # ~10k
font=font, fill="black"))

@unittest.skipIf(not features.check('freetype2'), "Test requires freetype2")
@unittest.skipIf(not features.check('freetype2'),
"Test requires freetype2")
def test_leak(self):
ttype = ImageFont.truetype('Tests/fonts/FreeMono.ttf', 20)
self._test_font(ttype)
@@ -294,7 +294,8 @@ def test_embeddable(self):
compiler = ccompiler.new_compiler()
compiler.add_include_dir(sysconfig.get_python_inc())

libdir = sysconfig.get_config_var('LIBDIR') or sysconfig.get_python_inc().replace('include', 'libs')
libdir = sysconfig.get_config_var('LIBDIR') or \
sysconfig.get_python_inc().replace('include', 'libs')
print(libdir)
compiler.add_library_dir(libdir)
objects = compiler.compile(['embed_pil.c'])
@@ -15,9 +15,11 @@ def test(mode):
self.assertEqual(test("L"), (3, (100, 128), '|u1', 12800))

# FIXME: wrong?
self.assertEqual(test("I"), (3, (100, 128), Image._ENDIAN + 'i4', 51200))
self.assertEqual(test("I"), (3, (100, 128),
Image._ENDIAN + 'i4', 51200))
# FIXME: wrong?
self.assertEqual(test("F"), (3, (100, 128), Image._ENDIAN + 'f4', 51200))
self.assertEqual(test("F"), (3, (100, 128),
Image._ENDIAN + 'f4', 51200))

self.assertEqual(test("LA"), (3, (100, 128, 2), '|u1', 25600))
self.assertEqual(test("RGB"), (3, (100, 128, 3), '|u1', 38400))
@@ -191,7 +191,8 @@ def matrix_convert(mode):
if converted_im.mode == 'RGB':
self.assert_image_similar(converted_im, target, 3)
else:
self.assert_image_similar(converted_im, target.getchannel(0), 1)
self.assert_image_similar(converted_im,
target.getchannel(0), 1)

matrix_convert('RGB')
matrix_convert('L')
@@ -288,10 +288,14 @@ def run_dirty_case(self, i, clean_pixel):
def test_dirty_pixels_rgba(self):
case = self.make_dirty_case('RGBA', (255, 255, 0, 128), (0, 0, 255, 0))
self.run_dirty_case(case.resize((20, 20), Image.BOX), (255, 255, 0))
self.run_dirty_case(case.resize((20, 20), Image.BILINEAR), (255, 255, 0))
self.run_dirty_case(case.resize((20, 20), Image.HAMMING), (255, 255, 0))
self.run_dirty_case(case.resize((20, 20), Image.BICUBIC), (255, 255, 0))
self.run_dirty_case(case.resize((20, 20), Image.LANCZOS), (255, 255, 0))
self.run_dirty_case(case.resize((20, 20), Image.BILINEAR),
(255, 255, 0))
self.run_dirty_case(case.resize((20, 20), Image.HAMMING),
(255, 255, 0))
self.run_dirty_case(case.resize((20, 20), Image.BICUBIC),
(255, 255, 0))
self.run_dirty_case(case.resize((20, 20), Image.LANCZOS),
(255, 255, 0))

def test_dirty_pixels_la(self):
case = self.make_dirty_case('LA', (255, 128), (0, 0))
@@ -95,8 +95,9 @@ def test_center(self):
im = hopper()
self.rotate(im, im.mode, 45, center=(0, 0))
self.rotate(im, im.mode, 45, translate=(im.size[0]/2, 0))
self.rotate(im, im.mode, 45, center=(0, 0), translate=(im.size[0]/2, 0))

self.rotate(im, im.mode, 45, center=(0, 0),
translate=(im.size[0]/2, 0))

def test_rotate_no_fill(self):
im = Image.new('RGB', (100, 100), 'green')
target = Image.open('Tests/images/rotate_45_no_fill.png')
@@ -392,16 +392,20 @@ def create_test_image():
self.assert_image_equal(source_image_aux, result_image_aux)

def test_preserve_auxiliary_channels_rgba(self):
self.assert_aux_channel_preserved(mode='RGBA', transform_in_place=False, preserved_channel='A')
self.assert_aux_channel_preserved(mode='RGBA',
transform_in_place=False, preserved_channel='A')

def test_preserve_auxiliary_channels_rgba_in_place(self):
self.assert_aux_channel_preserved(mode='RGBA', transform_in_place=True, preserved_channel='A')
self.assert_aux_channel_preserved(mode='RGBA',
transform_in_place=True, preserved_channel='A')

def test_preserve_auxiliary_channels_rgbx(self):
self.assert_aux_channel_preserved(mode='RGBX', transform_in_place=False, preserved_channel='X')
self.assert_aux_channel_preserved(mode='RGBX',
transform_in_place=False, preserved_channel='X')

def test_preserve_auxiliary_channels_rgbx_in_place(self):
self.assert_aux_channel_preserved(mode='RGBX', transform_in_place=True, preserved_channel='X')
self.assert_aux_channel_preserved(mode='RGBX',
transform_in_place=True, preserved_channel='X')

def test_auxiliary_channels_isolated(self):
# test data in aux channels does not affect non-aux channels
@@ -422,7 +426,8 @@ def test_auxiliary_channels_isolated(self):
source_profile = ImageCms.createProfile(src_format[1])
destination_profile = ImageCms.createProfile(dst_format[1])
source_image = src_format[3]
test_transform = ImageCms.buildTransform(source_profile, destination_profile, inMode=src_format[0], outMode=dst_format[0])
test_transform = ImageCms.buildTransform(source_profile,
destination_profile, inMode=src_format[0], outMode=dst_format[0])

# test conversion from aux-ful source
if transform_in_place:
@@ -45,8 +45,9 @@ def test_alpha(self):

for op in ['Color', 'Brightness', 'Contrast', 'Sharpness']:
for amount in [0, 0.5, 1.0]:
self._check_alpha(getattr(ImageEnhance, op)(original).enhance(amount),
original, op, amount)
self._check_alpha(
getattr(ImageEnhance, op)(original).enhance(amount),
original, op, amount)


if __name__ == '__main__':
@@ -215,12 +215,16 @@ def test_oversize(self):
buf = BytesIO(b'\x00'*255)

im = MockImageFile(buf)
im.tile = [("MOCK", (xoff, yoff, xoff+xsize + 100, yoff+ysize), 32, None)]
im.tile = [
("MOCK", (xoff, yoff, xoff+xsize + 100, yoff+ysize), 32, None)
]
d = self.get_decoder()

self.assertRaises(ValueError, im.load)

im.tile = [("MOCK", (xoff, yoff, xoff+xsize, yoff+ysize + 100), 32, None)]
im.tile = [
("MOCK", (xoff, yoff, xoff+xsize, yoff+ysize + 100), 32, None)
]
self.assertRaises(ValueError, im.load)


@@ -68,7 +68,8 @@ class TestImageFont(PillowTestCase):

def setUp(self):
freetype_version = tuple(ImageFont.core.freetype2_version.split('.'))[:2]
self.metrics = self.METRICS.get(freetype_version, self.METRICS['Default'])
self.metrics = self.METRICS.get(freetype_version,
self.METRICS['Default'])

def get_font(self):
return ImageFont.truetype(FONT_PATH, FONT_SIZE,
@@ -202,7 +203,8 @@ def test_render_multiline_text(self):
target_img = Image.open(target)

# Epsilon ~.5 fails with FreeType 2.7
self.assert_image_similar(im, target_img, self.metrics['multiline'])
self.assert_image_similar(im, target_img,
self.metrics['multiline'])

def test_unknown_align(self):
im = Image.new(mode='RGB', size=(300, 100))
@@ -423,7 +425,8 @@ def _test_fake_loading_font(self, path_to_fake, fontname):
# Make a copy of FreeTypeFont so we can patch the original
free_type_font = copy.deepcopy(ImageFont.FreeTypeFont)
with SimplePatcher(ImageFont, '_FreeTypeFont', free_type_font):
def loadable_font(filepath, size, index, encoding, *args, **kwargs):
def loadable_font(filepath, size, index, encoding,
*args, **kwargs):
if filepath == path_to_fake:
return ImageFont._FreeTypeFont(FONT_PATH, size, index,
encoding, *args, **kwargs)
@@ -30,7 +30,8 @@ def test_complex_text(self):
self.assert_image_similar(im, target_img, .5)

def test_y_offset(self):
ttf = ImageFont.truetype("Tests/fonts/NotoNastaliqUrdu-Regular.ttf", FONT_SIZE)
ttf = ImageFont.truetype("Tests/fonts/NotoNastaliqUrdu-Regular.ttf",
FONT_SIZE)

im = Image.new(mode='RGB', size=(300, 100))
draw = ImageDraw.Draw(im)
@@ -120,7 +121,8 @@ def test_arabictext_features(self):

im = Image.new(mode='RGB', size=(300, 100))
draw = ImageDraw.Draw(im)
draw.text((0, 0), 'اللغة العربية', font=ttf, fill=500, features=['-fina', '-init', '-medi'])
draw.text((0, 0), 'اللغة العربية', font=ttf, fill=500,
features=['-fina', '-init', '-medi'])

target = 'Tests/images/test_arabictext_features.png'
target_img = Image.open(target)
@@ -460,7 +460,8 @@ def test_F_int(self):
16777348, -2097152000)
else:
self.assert_unpack("F", "F;16N", 2, 0x0102, 0x0304)
self.assert_unpack("F", "F;16NS", b'\x83\x01\x01\x83', -31999, 0x0183)
self.assert_unpack("F", "F;16NS",
b'\x83\x01\x01\x83', -31999, 0x0183)
self.assert_unpack("F", "F;32N", 4, 0x01020304, 0x05060708)
self.assert_unpack("F", "F;32NS",
b'\x83\x00\x00\x01\x01\x00\x00\x83',
@@ -29,7 +29,7 @@ def test_sanity(self):
Image.open(path)
try:
locale.setlocale(locale.LC_ALL, "polish")
except:
except locale.Error:
unittest.skip('Polish locale not available')
Image.open(path)

@@ -4,7 +4,8 @@
from PIL import Image


@unittest.skipIf(sys.platform.startswith('win32'), "Win32 does not call map_buffer")
@unittest.skipIf(sys.platform.startswith('win32'),
"Win32 does not call map_buffer")
class TestMap(PillowTestCase):
def test_overflow(self):
# There is the potential to overflow comparisons in map.c

0 comments on commit 5331c8c

Please sign in to comment.
You can’t perform that action at this time.