mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-07 21:33:28 +03:00
flake8
This commit is contained in:
parent
8de95676e0
commit
1335006cd7
|
@ -25,12 +25,14 @@ i16 = _binary.i16le
|
||||||
i32 = _binary.i32le
|
i32 = _binary.i32le
|
||||||
o8 = _binary.o8
|
o8 = _binary.o8
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# decoder
|
# decoder
|
||||||
|
|
||||||
def _accept(prefix):
|
def _accept(prefix):
|
||||||
return i16(prefix[4:6]) in [0xAF11, 0xAF12]
|
return i16(prefix[4:6]) in [0xAF11, 0xAF12]
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# Image plugin for the FLI/FLC animation format. Use the <b>seek</b>
|
# Image plugin for the FLI/FLC animation format. Use the <b>seek</b>
|
||||||
# method to load individual frames.
|
# method to load individual frames.
|
||||||
|
|
|
@ -159,8 +159,8 @@ class ImImageFile(ImageFile.ImageFile):
|
||||||
|
|
||||||
k, v = m.group(1, 2)
|
k, v = m.group(1, 2)
|
||||||
|
|
||||||
# Don't know if this is the correct encoding, but a decent guess
|
# Don't know if this is the correct encoding,
|
||||||
# (I guess)
|
# but a decent guess (I guess)
|
||||||
k = k.decode('latin-1', 'replace')
|
k = k.decode('latin-1', 'replace')
|
||||||
v = v.decode('latin-1', 'replace')
|
v = v.decode('latin-1', 'replace')
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@ import warnings
|
||||||
class DecompressionBombWarning(RuntimeWarning):
|
class DecompressionBombWarning(RuntimeWarning):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class _imaging_not_installed:
|
class _imaging_not_installed:
|
||||||
# module placeholder
|
# module placeholder
|
||||||
def __getattr__(self, id):
|
def __getattr__(self, id):
|
||||||
|
@ -847,8 +848,9 @@ class Image:
|
||||||
t = self.info['transparency']
|
t = self.info['transparency']
|
||||||
if isinstance(t, bytes):
|
if isinstance(t, bytes):
|
||||||
# Dragons. This can't be represented by a single color
|
# Dragons. This can't be represented by a single color
|
||||||
warnings.warn('Palette images with Transparency expressed ' +
|
warnings.warn('Palette images with Transparency ' +
|
||||||
' in bytes should be converted to RGBA images')
|
' expressed in bytes should be converted ' +
|
||||||
|
'to RGBA images')
|
||||||
delete_trns = True
|
delete_trns = True
|
||||||
else:
|
else:
|
||||||
# get the new transparency color.
|
# get the new transparency color.
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
## The Python Imaging Library.
|
# The Python Imaging Library.
|
||||||
## $Id$
|
# $Id$
|
||||||
|
|
||||||
## Optional color managment support, based on Kevin Cazabon's PyCMS
|
# Optional color managment support, based on Kevin Cazabon's PyCMS
|
||||||
## library.
|
# library.
|
||||||
|
|
||||||
## History:
|
# History:
|
||||||
|
|
||||||
## 2009-03-08 fl Added to PIL.
|
# 2009-03-08 fl Added to PIL.
|
||||||
|
|
||||||
## Copyright (C) 2002-2003 Kevin Cazabon
|
# Copyright (C) 2002-2003 Kevin Cazabon
|
||||||
## Copyright (c) 2009 by Fredrik Lundh
|
# Copyright (c) 2009 by Fredrik Lundh
|
||||||
## Copyright (c) 2013 by Eric Soroos
|
# Copyright (c) 2013 by Eric Soroos
|
||||||
|
|
||||||
## See the README file for information on usage and redistribution. See
|
# See the README file for information on usage and redistribution. See
|
||||||
## below for the original description.
|
# below for the original description.
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
|
@ -184,6 +184,7 @@ class ImageCmsProfile:
|
||||||
|
|
||||||
return core.profile_tobytes(self.profile)
|
return core.profile_tobytes(self.profile)
|
||||||
|
|
||||||
|
|
||||||
class ImageCmsTransform(Image.ImagePointHandler):
|
class ImageCmsTransform(Image.ImagePointHandler):
|
||||||
|
|
||||||
# Transform. This can be used with the procedural API, or with the
|
# Transform. This can be used with the procedural API, or with the
|
||||||
|
@ -191,7 +192,6 @@ class ImageCmsTransform(Image.ImagePointHandler):
|
||||||
#
|
#
|
||||||
# Will return the output profile in the output.info['icc_profile'].
|
# Will return the output profile in the output.info['icc_profile'].
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, input, output, input_mode, output_mode,
|
def __init__(self, input, output, input_mode, output_mode,
|
||||||
intent=INTENT_PERCEPTUAL, proof=None,
|
intent=INTENT_PERCEPTUAL, proof=None,
|
||||||
proof_intent=INTENT_ABSOLUTE_COLORIMETRIC, flags=0):
|
proof_intent=INTENT_ABSOLUTE_COLORIMETRIC, flags=0):
|
||||||
|
|
|
@ -40,6 +40,7 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
warnings = None
|
warnings = None
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# A simple 2D drawing interface for PIL images.
|
# A simple 2D drawing interface for PIL images.
|
||||||
# <p>
|
# <p>
|
||||||
|
|
|
@ -162,7 +162,8 @@ class UnsharpMask(Filter):
|
||||||
See Wikipedia's entry on `digital unsharp masking`_ for an explanation of
|
See Wikipedia's entry on `digital unsharp masking`_ for an explanation of
|
||||||
the parameters.
|
the parameters.
|
||||||
|
|
||||||
.. _digital unsharp masking: https://en.wikipedia.org/wiki/Unsharp_masking#Digital_unsharp_masking
|
.. _digital unsharp masking:
|
||||||
|
https://en.wikipedia.org/wiki/Unsharp_masking#Digital_unsharp_masking
|
||||||
"""
|
"""
|
||||||
name = "UnsharpMask"
|
name = "UnsharpMask"
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ try:
|
||||||
except:
|
except:
|
||||||
from PyQt4.QtGui import QImage, qRgba
|
from PyQt4.QtGui import QImage, qRgba
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# (Internal) Turns an RGB color into a Qt compatible color integer.
|
# (Internal) Turns an RGB color into a Qt compatible color integer.
|
||||||
|
|
||||||
|
@ -32,6 +33,7 @@ def rgb(r, g, b, a=255):
|
||||||
# into a negative integer with the same bitpattern.
|
# into a negative integer with the same bitpattern.
|
||||||
return (qRgba(r, g, b, a) & 0xffffffff)
|
return (qRgba(r, g, b, a) & 0xffffffff)
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# An PIL image wrapper for Qt. This is a subclass of PyQt4's QImage
|
# An PIL image wrapper for Qt. This is a subclass of PyQt4's QImage
|
||||||
# class.
|
# class.
|
||||||
|
|
|
@ -26,6 +26,7 @@ from PIL import Image, ImageFile
|
||||||
|
|
||||||
field = re.compile(br"([a-z]*) ([^ \r\n]*)")
|
field = re.compile(br"([a-z]*) ([^ \r\n]*)")
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# Image plugin for IM Tools images.
|
# Image plugin for IM Tools images.
|
||||||
|
|
||||||
|
@ -39,7 +40,7 @@ class ImtImageFile(ImageFile.ImageFile):
|
||||||
# Quick rejection: if there's not a LF among the first
|
# Quick rejection: if there's not a LF among the first
|
||||||
# 100 bytes, this is (probably) not a text header.
|
# 100 bytes, this is (probably) not a text header.
|
||||||
|
|
||||||
if not b"\n" in self.fp.read(100):
|
if b"\n" not in self.fp.read(100):
|
||||||
raise SyntaxError("not an IM file")
|
raise SyntaxError("not an IM file")
|
||||||
self.fp.seek(0)
|
self.fp.seek(0)
|
||||||
|
|
||||||
|
|
|
@ -115,7 +115,8 @@ def APP(self, marker):
|
||||||
elif marker == 0xFFE2 and s[:4] == b"MPF\0":
|
elif marker == 0xFFE2 and s[:4] == b"MPF\0":
|
||||||
# extract MPO information
|
# extract MPO information
|
||||||
self.info["mp"] = s[4:]
|
self.info["mp"] = s[4:]
|
||||||
# offset is current location minus buffer size plus constant header size
|
# offset is current location minus buffer size
|
||||||
|
# plus constant header size
|
||||||
self.info["mpoffset"] = self.fp.tell() - n + 4
|
self.info["mpoffset"] = self.fp.tell() - n + 4
|
||||||
|
|
||||||
|
|
||||||
|
@ -321,7 +322,8 @@ class JpegImageFile(ImageFile.ImageFile):
|
||||||
rawmode = self.mode
|
rawmode = self.mode
|
||||||
if self.mode == "CMYK":
|
if self.mode == "CMYK":
|
||||||
rawmode = "CMYK;I" # assume adobe conventions
|
rawmode = "CMYK;I" # assume adobe conventions
|
||||||
self.tile = [("jpeg", (0, 0) + self.size, 0, (rawmode, ""))]
|
self.tile = [("jpeg", (0, 0) + self.size, 0,
|
||||||
|
(rawmode, ""))]
|
||||||
# self.__offset = self.fp.tell()
|
# self.__offset = self.fp.tell()
|
||||||
break
|
break
|
||||||
s = self.fp.read(1)
|
s = self.fp.read(1)
|
||||||
|
@ -472,12 +474,16 @@ def _getmp(self):
|
||||||
for entrynum in range(0, quant):
|
for entrynum in range(0, quant):
|
||||||
rawmpentry = mp[0xB002][entrynum * 16:(entrynum + 1) * 16]
|
rawmpentry = mp[0xB002][entrynum * 16:(entrynum + 1) * 16]
|
||||||
unpackedentry = unpack('{0}LLLHH'.format(endianness), rawmpentry)
|
unpackedentry = unpack('{0}LLLHH'.format(endianness), rawmpentry)
|
||||||
labels = ('Attribute', 'Size', 'DataOffset', 'EntryNo1', 'EntryNo2')
|
labels = ('Attribute', 'Size', 'DataOffset', 'EntryNo1',
|
||||||
|
'EntryNo2')
|
||||||
mpentry = dict(zip(labels, unpackedentry))
|
mpentry = dict(zip(labels, unpackedentry))
|
||||||
mpentryattr = {
|
mpentryattr = {
|
||||||
'DependentParentImageFlag': bool(mpentry['Attribute'] & (1<<31)),
|
'DependentParentImageFlag': bool(mpentry['Attribute'] &
|
||||||
'DependentChildImageFlag': bool(mpentry['Attribute'] & (1<<30)),
|
(1 << 31)),
|
||||||
'RepresentativeImageFlag': bool(mpentry['Attribute'] & (1<<29)),
|
'DependentChildImageFlag': bool(mpentry['Attribute'] &
|
||||||
|
(1 << 30)),
|
||||||
|
'RepresentativeImageFlag': bool(mpentry['Attribute'] &
|
||||||
|
(1 << 29)),
|
||||||
'Reserved': (mpentry['Attribute'] & (3 << 27)) >> 27,
|
'Reserved': (mpentry['Attribute'] & (3 << 27)) >> 27,
|
||||||
'ImageDataFormat': (mpentry['Attribute'] & (7 << 24)) >> 24,
|
'ImageDataFormat': (mpentry['Attribute'] & (7 << 24)) >> 24,
|
||||||
'MPType': mpentry['Attribute'] & 0x00FFFFFF
|
'MPType': mpentry['Attribute'] & 0x00FFFFFF
|
||||||
|
@ -530,8 +536,7 @@ zigzag_index = ( 0, 1, 5, 6, 14, 15, 27, 28,
|
||||||
21, 34, 37, 47, 50, 56, 59, 61,
|
21, 34, 37, 47, 50, 56, 59, 61,
|
||||||
35, 36, 48, 49, 57, 58, 62, 63)
|
35, 36, 48, 49, 57, 58, 62, 63)
|
||||||
|
|
||||||
samplings = {
|
samplings = {(1, 1, 1, 1, 1, 1): 0,
|
||||||
(1, 1, 1, 1, 1, 1): 0,
|
|
||||||
(2, 1, 1, 1, 1, 1): 1,
|
(2, 1, 1, 1, 1, 1): 1,
|
||||||
(2, 2, 1, 1, 1, 1): 2,
|
(2, 2, 1, 1, 1, 1): 2,
|
||||||
}
|
}
|
||||||
|
@ -589,7 +594,8 @@ def _save(im, fp, filename):
|
||||||
subsampling = 2
|
subsampling = 2
|
||||||
elif subsampling == "keep":
|
elif subsampling == "keep":
|
||||||
if im.format != "JPEG":
|
if im.format != "JPEG":
|
||||||
raise ValueError("Cannot use 'keep' when original image is not a JPEG")
|
raise ValueError(
|
||||||
|
"Cannot use 'keep' when original image is not a JPEG")
|
||||||
subsampling = get_sampling(im)
|
subsampling = get_sampling(im)
|
||||||
|
|
||||||
def validate_qtables(qtables):
|
def validate_qtables(qtables):
|
||||||
|
@ -623,7 +629,8 @@ def _save(im, fp, filename):
|
||||||
|
|
||||||
if qtables == "keep":
|
if qtables == "keep":
|
||||||
if im.format != "JPEG":
|
if im.format != "JPEG":
|
||||||
raise ValueError("Cannot use 'keep' when original image is not a JPEG")
|
raise ValueError(
|
||||||
|
"Cannot use 'keep' when original image is not a JPEG")
|
||||||
qtables = getattr(im, "quantization", None)
|
qtables = getattr(im, "quantization", None)
|
||||||
qtables = validate_qtables(qtables)
|
qtables = validate_qtables(qtables)
|
||||||
|
|
||||||
|
@ -641,7 +648,8 @@ def _save(im, fp, filename):
|
||||||
i = 1
|
i = 1
|
||||||
for marker in markers:
|
for marker in markers:
|
||||||
size = struct.pack(">H", 2 + ICC_OVERHEAD_LEN + len(marker))
|
size = struct.pack(">H", 2 + ICC_OVERHEAD_LEN + len(marker))
|
||||||
extra += b"\xFF\xE2" + size + b"ICC_PROFILE\0" + o8(i) + o8(len(markers)) + marker
|
extra += (b"\xFF\xE2" + size + b"ICC_PROFILE\0" + o8(i) +
|
||||||
|
o8(len(markers)) + marker)
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
# get keyword arguments
|
# get keyword arguments
|
||||||
|
|
|
@ -48,8 +48,8 @@ You can get the quantization tables of a JPEG with::
|
||||||
|
|
||||||
im.quantization
|
im.quantization
|
||||||
|
|
||||||
This will return a dict with a number of arrays. You can pass this dict directly
|
This will return a dict with a number of arrays. You can pass this dict
|
||||||
as the qtables argument when saving a JPEG.
|
directly as the qtables argument when saving a JPEG.
|
||||||
|
|
||||||
The tables format between im.quantization and quantization in presets differ in
|
The tables format between im.quantization and quantization in presets differ in
|
||||||
3 ways:
|
3 ways:
|
||||||
|
|
|
@ -30,6 +30,7 @@ for r in range(8):
|
||||||
for b in range(4):
|
for b in range(4):
|
||||||
PALETTE = PALETTE + (o8((r*255)//7)+o8((g*255)//7)+o8((b*255)//3))
|
PALETTE = PALETTE + (o8((r*255)//7)+o8((g*255)//7)+o8((b*255)//3))
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# Image plugin for XV thumbnail images.
|
# Image plugin for XV thumbnail images.
|
||||||
|
|
||||||
|
|
|
@ -6,5 +6,3 @@ import sys
|
||||||
|
|
||||||
if sys.maxsize < 2**32:
|
if sys.maxsize < 2**32:
|
||||||
im = Image.new('L', (999999, 999999), 0)
|
im = Image.new('L', (999999, 999999), 0)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from helper import *
|
from helper import unittest, PillowTestCase, lena
|
||||||
|
|
||||||
# Not running this test by default. No DOS against Travis CI.
|
# Not running this test by default. No DOS against Travis CI.
|
||||||
|
|
||||||
|
|
|
@ -7,4 +7,5 @@ from io import BytesIO
|
||||||
if bytes is str:
|
if bytes is str:
|
||||||
Image.open(BytesIO(bytes('icns\x00\x00\x00\x10hang\x00\x00\x00\x00')))
|
Image.open(BytesIO(bytes('icns\x00\x00\x00\x10hang\x00\x00\x00\x00')))
|
||||||
else:
|
else:
|
||||||
Image.open(BytesIO(bytes('icns\x00\x00\x00\x10hang\x00\x00\x00\x00', 'latin-1')))
|
Image.open(BytesIO(bytes('icns\x00\x00\x00\x10hang\x00\x00\x00\x00',
|
||||||
|
'latin-1')))
|
||||||
|
|
|
@ -5,7 +5,9 @@ from PIL import Image
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
if bytes is str:
|
if bytes is str:
|
||||||
Image.open(BytesIO(bytes('\x00\x00\x00\x0cjP\x20\x20\x0d\x0a\x87\x0a\x00\x00\x00\x00hang')))
|
Image.open(BytesIO(bytes(
|
||||||
|
'\x00\x00\x00\x0cjP\x20\x20\x0d\x0a\x87\x0a\x00\x00\x00\x00hang')))
|
||||||
else:
|
else:
|
||||||
Image.open(BytesIO(bytes('\x00\x00\x00\x0cjP\x20\x20\x0d\x0a\x87\x0a\x00\x00\x00\x00hang', 'latin-1')))
|
Image.open(BytesIO(bytes(
|
||||||
|
'\x00\x00\x00\x0cjP\x20\x20\x0d\x0a\x87\x0a\x00\x00\x00\x00hang',
|
||||||
|
'latin-1')))
|
||||||
|
|
|
@ -100,7 +100,8 @@ class PillowTestCase(unittest.TestCase):
|
||||||
ave_diff = float(diff)/(a.size[0]*a.size[1])
|
ave_diff = float(diff)/(a.size[0]*a.size[1])
|
||||||
self.assertGreaterEqual(
|
self.assertGreaterEqual(
|
||||||
epsilon, ave_diff,
|
epsilon, ave_diff,
|
||||||
(msg or '') + " average pixel value difference %.4f > epsilon %.4f" % (
|
(msg or '') +
|
||||||
|
" average pixel value difference %.4f > epsilon %.4f" % (
|
||||||
ave_diff, epsilon))
|
ave_diff, epsilon))
|
||||||
|
|
||||||
def assert_warning(self, warn_class, func):
|
def assert_warning(self, warn_class, func):
|
||||||
|
@ -138,7 +139,8 @@ class PillowTestCase(unittest.TestCase):
|
||||||
if travis is not None:
|
if travis is not None:
|
||||||
skip = skip and (travis == bool(os.environ.get('TRAVIS', False)))
|
skip = skip and (travis == bool(os.environ.get('TRAVIS', False)))
|
||||||
if interpreter is not None:
|
if interpreter is not None:
|
||||||
skip = skip and (interpreter == 'pypy' and hasattr(sys, 'pypy_version_info'))
|
skip = skip and (interpreter == 'pypy' and
|
||||||
|
hasattr(sys, 'pypy_version_info'))
|
||||||
if skip:
|
if skip:
|
||||||
self.skipTest(msg or "Known Bad Test")
|
self.skipTest(msg or "Known Bad Test")
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from helper import *
|
from helper import unittest, PillowTestCase
|
||||||
|
|
||||||
# This test is not run automatically.
|
# This test is not run automatically.
|
||||||
#
|
#
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from helper import *
|
from helper import unittest, PillowTestCase
|
||||||
|
|
||||||
# This test is not run automatically.
|
# This test is not run automatically.
|
||||||
#
|
#
|
||||||
|
|
|
@ -82,7 +82,8 @@ class TestFileMpo(PillowTestCase):
|
||||||
# prior to first image raises an error, both blatant and borderline
|
# prior to first image raises an error, both blatant and borderline
|
||||||
self.assertRaises(EOFError, im.seek, -1)
|
self.assertRaises(EOFError, im.seek, -1)
|
||||||
self.assertRaises(EOFError, im.seek, -523)
|
self.assertRaises(EOFError, im.seek, -523)
|
||||||
# after the final image raises an error, both blatant and borderline
|
# after the final image raises an error,
|
||||||
|
# both blatant and borderline
|
||||||
self.assertRaises(EOFError, im.seek, 2)
|
self.assertRaises(EOFError, im.seek, 2)
|
||||||
self.assertRaises(EOFError, im.seek, 523)
|
self.assertRaises(EOFError, im.seek, 523)
|
||||||
# bad calls shouldn't change the frame
|
# bad calls shouldn't change the frame
|
||||||
|
|
|
@ -29,7 +29,6 @@ class TestFilePalm(PillowTestCase):
|
||||||
converted = self.open_withImagemagick(outfile)
|
converted = self.open_withImagemagick(outfile)
|
||||||
self.assert_image_equal(converted, im)
|
self.assert_image_equal(converted, im)
|
||||||
|
|
||||||
|
|
||||||
def test_monochrome(self):
|
def test_monochrome(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
mode = "1"
|
mode = "1"
|
||||||
|
|
|
@ -151,13 +151,16 @@ class TestFilePng(PillowTestCase):
|
||||||
self.assertEqual(im.info["spam"].lang, "en")
|
self.assertEqual(im.info["spam"].lang, "en")
|
||||||
self.assertEqual(im.info["spam"].tkey, "Spam")
|
self.assertEqual(im.info["spam"].tkey, "Spam")
|
||||||
|
|
||||||
im = load(HEAD + chunk(b'iTXt', b'spam\0\1\0en\0Spam\0' + zlib.compress(b"egg")[:1]) + TAIL)
|
im = load(HEAD + chunk(b'iTXt', b'spam\0\1\0en\0Spam\0' +
|
||||||
|
zlib.compress(b"egg")[:1]) + TAIL)
|
||||||
self.assertEqual(im.info, {})
|
self.assertEqual(im.info, {})
|
||||||
|
|
||||||
im = load(HEAD + chunk(b'iTXt', b'spam\0\1\1en\0Spam\0' + zlib.compress(b"egg")) + TAIL)
|
im = load(HEAD + chunk(b'iTXt', b'spam\0\1\1en\0Spam\0' +
|
||||||
|
zlib.compress(b"egg")) + TAIL)
|
||||||
self.assertEqual(im.info, {})
|
self.assertEqual(im.info, {})
|
||||||
|
|
||||||
im = load(HEAD + chunk(b'iTXt', b'spam\0\1\0en\0Spam\0' + zlib.compress(b"egg")) + TAIL)
|
im = load(HEAD + chunk(b'iTXt', b'spam\0\1\0en\0Spam\0' +
|
||||||
|
zlib.compress(b"egg")) + TAIL)
|
||||||
self.assertEqual(im.info, {"spam": "egg"})
|
self.assertEqual(im.info, {"spam": "egg"})
|
||||||
self.assertEqual(im.info["spam"].lang, "en")
|
self.assertEqual(im.info["spam"].lang, "en")
|
||||||
self.assertEqual(im.info["spam"].tkey, "Spam")
|
self.assertEqual(im.info["spam"].tkey, "Spam")
|
||||||
|
@ -271,7 +274,8 @@ class TestFilePng(PillowTestCase):
|
||||||
im = Image.new("RGB", (32, 32))
|
im = Image.new("RGB", (32, 32))
|
||||||
info = PngImagePlugin.PngInfo()
|
info = PngImagePlugin.PngInfo()
|
||||||
info.add_itxt("spam", "Eggs", "en", "Spam")
|
info.add_itxt("spam", "Eggs", "en", "Spam")
|
||||||
info.add_text("eggs", PngImagePlugin.iTXt("Spam", "en", "Eggs"), zip=True)
|
info.add_text("eggs", PngImagePlugin.iTXt("Spam", "en", "Eggs"),
|
||||||
|
zip=True)
|
||||||
|
|
||||||
im = roundtrip(im, pnginfo=info)
|
im = roundtrip(im, pnginfo=info)
|
||||||
self.assertEqual(im.info, {"spam": "Eggs", "eggs": "Spam"})
|
self.assertEqual(im.info, {"spam": "Eggs", "eggs": "Spam"})
|
||||||
|
|
|
@ -50,7 +50,8 @@ class TestFileTiffMetadata(PillowTestCase):
|
||||||
'StripByteCounts': (1796,),
|
'StripByteCounts': (1796,),
|
||||||
'SamplesPerPixel': (1,),
|
'SamplesPerPixel': (1,),
|
||||||
'StripOffsets': (8,),
|
'StripOffsets': (8,),
|
||||||
'Software': 'ImageMagick 6.5.7-8 2012-08-17 Q16 http://www.imagemagick.org'}
|
'Software': 'ImageMagick 6.5.7-8 2012-08-17 Q16' +
|
||||||
|
' http://www.imagemagick.org'}
|
||||||
|
|
||||||
# self.assertEqual is equivalent,
|
# self.assertEqual is equivalent,
|
||||||
# but less helpful in telling what's wrong.
|
# but less helpful in telling what's wrong.
|
||||||
|
|
|
@ -18,7 +18,8 @@ class TestFileWebpAlpha(PillowTestCase):
|
||||||
self.skipTest('WebP support not installed')
|
self.skipTest('WebP support not installed')
|
||||||
|
|
||||||
if _webp.WebPDecoderBuggyAlpha(self):
|
if _webp.WebPDecoderBuggyAlpha(self):
|
||||||
self.skipTest("Buggy early version of WebP installed, not testing transparency")
|
self.skipTest("Buggy early version of WebP installed, "
|
||||||
|
"not testing transparency")
|
||||||
|
|
||||||
def test_read_rgba(self):
|
def test_read_rgba(self):
|
||||||
# Generated with `cwebp transparent.png -o transparent.webp`
|
# Generated with `cwebp transparent.png -o transparent.webp`
|
||||||
|
|
|
@ -2,22 +2,28 @@ from helper import unittest, PillowTestCase, lena
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
import colorsys, itertools
|
import colorsys
|
||||||
|
import itertools
|
||||||
|
|
||||||
|
|
||||||
class TestFormatHSV(PillowTestCase):
|
class TestFormatHSV(PillowTestCase):
|
||||||
|
|
||||||
def int_to_float(self, i):
|
def int_to_float(self, i):
|
||||||
return float(i)/255.0
|
return float(i)/255.0
|
||||||
|
|
||||||
def str_to_float(self, i):
|
def str_to_float(self, i):
|
||||||
|
|
||||||
return float(ord(i))/255.0
|
return float(ord(i))/255.0
|
||||||
|
|
||||||
def to_int(self, f):
|
def to_int(self, f):
|
||||||
return int(f*255.0)
|
return int(f*255.0)
|
||||||
|
|
||||||
def tuple_to_ints(self, tp):
|
def tuple_to_ints(self, tp):
|
||||||
x, y, z = tp
|
x, y, z = tp
|
||||||
return (int(x*255.0), int(y*255.0), int(z*255.0))
|
return (int(x*255.0), int(y*255.0), int(z*255.0))
|
||||||
|
|
||||||
def test_sanity(self):
|
def test_sanity(self):
|
||||||
im = Image.new('HSV', (100,100))
|
Image.new('HSV', (100, 100))
|
||||||
|
|
||||||
def wedge(self):
|
def wedge(self):
|
||||||
w = Image._wedge()
|
w = Image._wedge()
|
||||||
|
@ -61,14 +67,17 @@ class TestFormatHSV(PillowTestCase):
|
||||||
else:
|
else:
|
||||||
iter_helper = itertools.zip_longest
|
iter_helper = itertools.zip_longest
|
||||||
|
|
||||||
|
converted = [self.tuple_to_ints(func(conv_func(_r), conv_func(_g),
|
||||||
converted = [self.tuple_to_ints(func(conv_func(_r), conv_func(_g), conv_func(_b)))
|
conv_func(_b)))
|
||||||
for (_r, _g, _b) in iter_helper(r.tobytes(), g.tobytes(), b.tobytes())]
|
for (_r, _g, _b) in iter_helper(r.tobytes(), g.tobytes(),
|
||||||
|
b.tobytes())]
|
||||||
|
|
||||||
if str is bytes:
|
if str is bytes:
|
||||||
new_bytes = b''.join(chr(h)+chr(s)+chr(v) for (h,s,v) in converted)
|
new_bytes = b''.join(chr(h)+chr(s)+chr(v) for (
|
||||||
|
h, s, v) in converted)
|
||||||
else:
|
else:
|
||||||
new_bytes = b''.join(bytes(chr(h)+chr(s)+chr(v), 'latin-1') for (h,s,v) in converted)
|
new_bytes = b''.join(bytes(chr(h)+chr(s)+chr(v), 'latin-1') for (
|
||||||
|
h, s, v) in converted)
|
||||||
|
|
||||||
hsv = Image.frombytes(mode, r.size, new_bytes)
|
hsv = Image.frombytes(mode, r.size, new_bytes)
|
||||||
|
|
||||||
|
@ -118,7 +127,6 @@ class TestFormatHSV(PillowTestCase):
|
||||||
self.assert_image_similar(im.split()[2], comparable.split()[2],
|
self.assert_image_similar(im.split()[2], comparable.split()[2],
|
||||||
3, "B conversion is wrong")
|
3, "B conversion is wrong")
|
||||||
|
|
||||||
|
|
||||||
def test_convert(self):
|
def test_convert(self):
|
||||||
im = lena('RGB').convert('HSV')
|
im = lena('RGB').convert('HSV')
|
||||||
comparable = self.to_hsv_colorsys(lena('RGB'))
|
comparable = self.to_hsv_colorsys(lena('RGB'))
|
||||||
|
@ -136,7 +144,6 @@ class TestFormatHSV(PillowTestCase):
|
||||||
self.assert_image_similar(im.split()[2], comparable.split()[2],
|
self.assert_image_similar(im.split()[2], comparable.split()[2],
|
||||||
1, "Value conversion is wrong")
|
1, "Value conversion is wrong")
|
||||||
|
|
||||||
|
|
||||||
def test_hsv_to_rgb(self):
|
def test_hsv_to_rgb(self):
|
||||||
comparable = self.to_hsv_colorsys(lena('RGB'))
|
comparable = self.to_hsv_colorsys(lena('RGB'))
|
||||||
converted = comparable.convert('RGB')
|
converted = comparable.convert('RGB')
|
||||||
|
@ -148,7 +155,6 @@ class TestFormatHSV(PillowTestCase):
|
||||||
# print ([ord(x) for x in target.split()[1].tobytes()[:80]])
|
# print ([ord(x) for x in target.split()[1].tobytes()[:80]])
|
||||||
# print ([ord(x) for x in converted.split()[1].tobytes()[:80]])
|
# print ([ord(x) for x in converted.split()[1].tobytes()[:80]])
|
||||||
|
|
||||||
|
|
||||||
self.assert_image_similar(converted.split()[0], comparable.split()[0],
|
self.assert_image_similar(converted.split()[0], comparable.split()[0],
|
||||||
3, "R conversion is wrong")
|
3, "R conversion is wrong")
|
||||||
self.assert_image_similar(converted.split()[1], comparable.split()[1],
|
self.assert_image_similar(converted.split()[1], comparable.split()[1],
|
||||||
|
@ -157,12 +163,6 @@ class TestFormatHSV(PillowTestCase):
|
||||||
3, "B conversion is wrong")
|
3, "B conversion is wrong")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
from helper import unittest, PillowTestCase, lena
|
from helper import unittest, PillowTestCase, lena
|
||||||
|
|
||||||
from PIL import Image
|
|
||||||
|
|
||||||
|
|
||||||
class TestImageCopy(PillowTestCase):
|
class TestImageCopy(PillowTestCase):
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
from helper import unittest, PillowTestCase, lena
|
from helper import unittest, PillowTestCase, lena
|
||||||
|
|
||||||
import sys
|
|
||||||
|
|
||||||
|
|
||||||
class TestImagePoint(PillowTestCase):
|
class TestImagePoint(PillowTestCase):
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,6 @@ class TestImagePutData(PillowTestCase):
|
||||||
else:
|
else:
|
||||||
self.assertEqual(put(sys.maxsize), (255, 255, 255, 127))
|
self.assertEqual(put(sys.maxsize), (255, 255, 255, 127))
|
||||||
|
|
||||||
|
|
||||||
def test_pypy_performance(self):
|
def test_pypy_performance(self):
|
||||||
im = Image.new('L', (256, 256))
|
im = Image.new('L', (256, 256))
|
||||||
im.putdata(list(range(256))*256)
|
im.putdata(list(range(256))*256)
|
||||||
|
@ -65,7 +64,6 @@ class TestImagePutData(PillowTestCase):
|
||||||
self.assertEqual(list(im.getdata()), target)
|
self.assertEqual(list(im.getdata()), target)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
||||||
|
|
|
@ -204,7 +204,6 @@ class TestImageCms(PillowTestCase):
|
||||||
profile = ImageCmsProfile(BytesIO(img_srgb.info['icc_profile']))
|
profile = ImageCmsProfile(BytesIO(img_srgb.info['icc_profile']))
|
||||||
self.assertTrue('sRGB' in ImageCms.getProfileDescription(profile))
|
self.assertTrue('sRGB' in ImageCms.getProfileDescription(profile))
|
||||||
|
|
||||||
|
|
||||||
def test_lab_roundtrip(self):
|
def test_lab_roundtrip(self):
|
||||||
# check to see if we're at least internally consistent.
|
# check to see if we're at least internally consistent.
|
||||||
pLab = ImageCms.createProfile("LAB")
|
pLab = ImageCms.createProfile("LAB")
|
||||||
|
@ -221,7 +220,6 @@ class TestImageCms(PillowTestCase):
|
||||||
|
|
||||||
self.assert_image_similar(lena(), out, 2)
|
self.assert_image_similar(lena(), out, 2)
|
||||||
|
|
||||||
|
|
||||||
def test_profile_tobytes(self):
|
def test_profile_tobytes(self):
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
i = Image.open("Tests/images/rgb.jpg")
|
i = Image.open("Tests/images/rgb.jpg")
|
||||||
|
@ -238,7 +236,6 @@ class TestImageCms(PillowTestCase):
|
||||||
ImageCms.getProfileDescription(p2))
|
ImageCms.getProfileDescription(p2))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
||||||
|
|
|
@ -350,12 +350,15 @@ class TestImageDraw(PillowTestCase):
|
||||||
expected.load()
|
expected.load()
|
||||||
img, draw = self.create_base_image_draw((110, 200))
|
img, draw = self.create_base_image_draw((110, 200))
|
||||||
draw.line((55, 5, 55, 195), BLACK, 101)
|
draw.line((55, 5, 55, 195), BLACK, 101)
|
||||||
self.assert_image_equal(img, expected, 'line straigth vertical 101px wide failed')
|
self.assert_image_equal(img, expected,
|
||||||
expected = Image.open(os.path.join(IMAGES_PATH, 'line_vertical_slope1px_w2px.png'))
|
'line straigth vertical 101px wide failed')
|
||||||
|
expected = Image.open(os.path.join(IMAGES_PATH,
|
||||||
|
'line_vertical_slope1px_w2px.png'))
|
||||||
expected.load()
|
expected.load()
|
||||||
img, draw = self.create_base_image_draw((20, 20))
|
img, draw = self.create_base_image_draw((20, 20))
|
||||||
draw.line((5, 5, 6, 14), BLACK, 2)
|
draw.line((5, 5, 6, 14), BLACK, 2)
|
||||||
self.assert_image_equal(img, expected, 'line vertical 1px slope 2px wide failed')
|
self.assert_image_equal(img, expected,
|
||||||
|
'line vertical 1px slope 2px wide failed')
|
||||||
|
|
||||||
|
|
||||||
def test_line_oblique_45(self):
|
def test_line_oblique_45(self):
|
||||||
|
@ -363,22 +366,26 @@ class TestImageDraw(PillowTestCase):
|
||||||
expected.load()
|
expected.load()
|
||||||
img, draw = self.create_base_image_draw((20, 20))
|
img, draw = self.create_base_image_draw((20, 20))
|
||||||
draw.line((5, 5, 14, 14), BLACK, 3)
|
draw.line((5, 5, 14, 14), BLACK, 3)
|
||||||
self.assert_image_equal(img, expected, 'line oblique 45 normal 3px wide A failed')
|
self.assert_image_equal(img, expected,
|
||||||
|
'line oblique 45 normal 3px wide A failed')
|
||||||
img, draw = self.create_base_image_draw((20, 20))
|
img, draw = self.create_base_image_draw((20, 20))
|
||||||
draw.line((14, 14, 5, 5), BLACK, 3)
|
draw.line((14, 14, 5, 5), BLACK, 3)
|
||||||
self.assert_image_equal(img, expected, 'line oblique 45 inverted 3px wide A failed')
|
self.assert_image_equal(img, expected,
|
||||||
expected = Image.open(os.path.join(IMAGES_PATH, 'line_oblique_45_w3px_b.png'))
|
'line oblique 45 inverted 3px wide A failed')
|
||||||
|
expected = Image.open(os.path.join(IMAGES_PATH,
|
||||||
|
'line_oblique_45_w3px_b.png'))
|
||||||
expected.load()
|
expected.load()
|
||||||
img, draw = self.create_base_image_draw((20, 20))
|
img, draw = self.create_base_image_draw((20, 20))
|
||||||
draw.line((14, 5, 5, 14), BLACK, 3)
|
draw.line((14, 5, 5, 14), BLACK, 3)
|
||||||
self.assert_image_equal(img, expected, 'line oblique 45 normal 3px wide B failed')
|
self.assert_image_equal(img, expected,
|
||||||
|
'line oblique 45 normal 3px wide B failed')
|
||||||
img, draw = self.create_base_image_draw((20, 20))
|
img, draw = self.create_base_image_draw((20, 20))
|
||||||
draw.line((5, 14, 14, 5), BLACK, 3)
|
draw.line((5, 14, 14, 5), BLACK, 3)
|
||||||
self.assert_image_equal(img, expected, 'line oblique 45 inverted 3px wide B failed')
|
self.assert_image_equal(img, expected,
|
||||||
|
'line oblique 45 inverted 3px wide B failed')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
||||||
# End of file
|
# End of file
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# Test the ImageMorphology functionality
|
# Test the ImageMorphology functionality
|
||||||
from helper import *
|
from helper import unittest, PillowTestCase
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from PIL import ImageMorph
|
from PIL import ImageMorph
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from helper import unittest, PillowTestCase, lena
|
from helper import unittest, PillowTestCase
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from PIL import ImageWin
|
from PIL import ImageWin
|
||||||
|
|
|
@ -17,6 +17,7 @@ test_filenames = (
|
||||||
"temp_'\"&&",
|
"temp_'\"&&",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipIf(sys.platform.startswith('win32'), "requires Unix or MacOS")
|
@unittest.skipIf(sys.platform.startswith('win32'), "requires Unix or MacOS")
|
||||||
class TestShellInjection(PillowTestCase):
|
class TestShellInjection(PillowTestCase):
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
import sys, time
|
|
||||||
import io
|
import io
|
||||||
import threading, queue
|
import queue
|
||||||
|
import sys
|
||||||
|
import threading
|
||||||
|
import time
|
||||||
|
|
||||||
try:
|
try:
|
||||||
format = sys.argv[1]
|
format = sys.argv[1]
|
||||||
|
@ -16,6 +18,7 @@ queue = queue.Queue()
|
||||||
|
|
||||||
result = []
|
result = []
|
||||||
|
|
||||||
|
|
||||||
class Worker(threading.Thread):
|
class Worker(threading.Thread):
|
||||||
def run(self):
|
def run(self):
|
||||||
while True:
|
while True:
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
|
|
||||||
def version(module, version):
|
def version(module, version):
|
||||||
v = getattr(module.core, version + "_version", None)
|
v = getattr(module.core, version + "_version", None)
|
||||||
if v:
|
if v:
|
||||||
|
|
|
@ -59,4 +59,5 @@ if MAX_PROCS != 1:
|
||||||
except Exception as msg:
|
except Exception as msg:
|
||||||
print("Exception installing mp_compile, proceeding without: %s" % msg)
|
print("Exception installing mp_compile, proceeding without: %s" % msg)
|
||||||
else:
|
else:
|
||||||
print("Single threaded build, not installing mp_compile: %s processes" %MAX_PROCS)
|
print("Single threaded build, not installing mp_compile: %s processes" %
|
||||||
|
MAX_PROCS)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user