This commit is contained in:
hugovk 2014-08-28 14:44:19 +03:00
parent 8de95676e0
commit 1335006cd7
41 changed files with 214 additions and 183 deletions

View File

@ -25,12 +25,14 @@ i16 = _binary.i16le
i32 = _binary.i32le
o8 = _binary.o8
#
# decoder
def _accept(prefix):
return i16(prefix[4:6]) in [0xAF11, 0xAF12]
##
# Image plugin for the FLI/FLC animation format. Use the <b>seek</b>
# method to load individual frames.
@ -47,7 +49,7 @@ class FliImageFile(ImageFile.ImageFile):
magic = i16(s[4:6])
if not (magic in [0xAF11, 0xAF12] and
i16(s[14:16]) in [0, 3] and # flags
s[20:22] == b"\x00\x00"): # reserved
s[20:22] == b"\x00\x00"): # reserved
raise SyntaxError("not an FLI/FLC file")
# image characteristics
@ -61,7 +63,7 @@ class FliImageFile(ImageFile.ImageFile):
self.info["duration"] = duration
# look for palette
palette = [(a,a,a) for a in range(256)]
palette = [(a, a, a) for a in range(256)]
s = self.fp.read(16)
@ -80,7 +82,7 @@ class FliImageFile(ImageFile.ImageFile):
elif i16(s[4:6]) == 4:
self._palette(palette, 0)
palette = [o8(r)+o8(g)+o8(b) for (r,g,b) in palette]
palette = [o8(r)+o8(g)+o8(b) for (r, g, b) in palette]
self.palette = ImagePalette.raw("RGB", b"".join(palette))
# set things up to decode first frame
@ -124,7 +126,7 @@ class FliImageFile(ImageFile.ImageFile):
framesize = i32(s)
self.decodermaxblock = framesize
self.tile = [("fli", (0,0)+self.size, self.__offset, None)]
self.tile = [("fli", (0, 0)+self.size, self.__offset, None)]
self.__offset = self.__offset + framesize

View File

@ -159,8 +159,8 @@ class ImImageFile(ImageFile.ImageFile):
k, v = m.group(1, 2)
# Don't know if this is the correct encoding, but a decent guess
# (I guess)
# Don't know if this is the correct encoding,
# but a decent guess (I guess)
k = k.decode('latin-1', 'replace')
v = v.decode('latin-1', 'replace')

View File

@ -34,6 +34,7 @@ import warnings
class DecompressionBombWarning(RuntimeWarning):
pass
class _imaging_not_installed:
# module placeholder
def __getattr__(self, id):
@ -847,8 +848,9 @@ class Image:
t = self.info['transparency']
if isinstance(t, bytes):
# Dragons. This can't be represented by a single color
warnings.warn('Palette images with Transparency expressed ' +
' in bytes should be converted to RGBA images')
warnings.warn('Palette images with Transparency ' +
' expressed in bytes should be converted ' +
'to RGBA images')
delete_trns = True
else:
# get the new transparency color.
@ -864,7 +866,7 @@ class Image:
# can't just retrieve the palette number, got to do it
# after quantization.
trns_im = trns_im.convert('RGB')
trns = trns_im.getpixel((0,0))
trns = trns_im.getpixel((0, 0))
elif self.mode == 'P' and mode == 'RGBA':
delete_trns = True

View File

@ -1,19 +1,19 @@
## The Python Imaging Library.
## $Id$
# The Python Imaging Library.
# $Id$
## Optional color managment support, based on Kevin Cazabon's PyCMS
## library.
# Optional color managment support, based on Kevin Cazabon's PyCMS
# 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) 2009 by Fredrik Lundh
## Copyright (c) 2013 by Eric Soroos
# Copyright (C) 2002-2003 Kevin Cazabon
# Copyright (c) 2009 by Fredrik Lundh
# Copyright (c) 2013 by Eric Soroos
## See the README file for information on usage and redistribution. See
## below for the original description.
# See the README file for information on usage and redistribution. See
# below for the original description.
from __future__ import print_function
@ -184,6 +184,7 @@ class ImageCmsProfile:
return core.profile_tobytes(self.profile)
class ImageCmsTransform(Image.ImagePointHandler):
# 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'].
def __init__(self, input, output, input_mode, output_mode,
intent=INTENT_PERCEPTUAL, proof=None,
proof_intent=INTENT_ABSOLUTE_COLORIMETRIC, flags=0):

View File

@ -40,6 +40,7 @@ try:
except ImportError:
warnings = None
##
# A simple 2D drawing interface for PIL images.
# <p>

View File

@ -162,7 +162,8 @@ class UnsharpMask(Filter):
See Wikipedia's entry on `digital unsharp masking`_ for an explanation of
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"

View File

@ -24,6 +24,7 @@ try:
except:
from PyQt4.QtGui import QImage, qRgba
##
# (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.
return (qRgba(r, g, b, a) & 0xffffffff)
##
# An PIL image wrapper for Qt. This is a subclass of PyQt4's QImage
# class.

View File

@ -26,6 +26,7 @@ from PIL import Image, ImageFile
field = re.compile(br"([a-z]*) ([^ \r\n]*)")
##
# 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
# 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")
self.fp.seek(0)
@ -54,7 +55,7 @@ class ImtImageFile(ImageFile.ImageFile):
if s == b'\x0C':
# image data begins
self.tile = [("raw", (0,0)+self.size,
self.tile = [("raw", (0, 0)+self.size,
self.fp.tell(),
(self.mode, 0, 1))]
@ -68,12 +69,12 @@ class ImtImageFile(ImageFile.ImageFile):
if len(s) == 1 or len(s) > 100:
break
if s[0] == b"*":
continue # comment
continue # comment
m = field.match(s)
if not m:
break
k, v = m.group(1,2)
k, v = m.group(1, 2)
if k == "width":
xsize = int(v)
self.size = xsize, ysize

View File

@ -115,7 +115,8 @@ def APP(self, marker):
elif marker == 0xFFE2 and s[:4] == b"MPF\0":
# extract MPO information
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
@ -321,7 +322,8 @@ class JpegImageFile(ImageFile.ImageFile):
rawmode = self.mode
if self.mode == "CMYK":
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()
break
s = self.fp.read(1)
@ -472,14 +474,18 @@ def _getmp(self):
for entrynum in range(0, quant):
rawmpentry = mp[0xB002][entrynum * 16:(entrynum + 1) * 16]
unpackedentry = unpack('{0}LLLHH'.format(endianness), rawmpentry)
labels = ('Attribute', 'Size', 'DataOffset', 'EntryNo1', 'EntryNo2')
labels = ('Attribute', 'Size', 'DataOffset', 'EntryNo1',
'EntryNo2')
mpentry = dict(zip(labels, unpackedentry))
mpentryattr = {
'DependentParentImageFlag': bool(mpentry['Attribute'] & (1<<31)),
'DependentChildImageFlag': bool(mpentry['Attribute'] & (1<<30)),
'RepresentativeImageFlag': bool(mpentry['Attribute'] & (1<<29)),
'Reserved': (mpentry['Attribute'] & (3<<27)) >> 27,
'ImageDataFormat': (mpentry['Attribute'] & (7<<24)) >> 24,
'DependentParentImageFlag': bool(mpentry['Attribute'] &
(1 << 31)),
'DependentChildImageFlag': bool(mpentry['Attribute'] &
(1 << 30)),
'RepresentativeImageFlag': bool(mpentry['Attribute'] &
(1 << 29)),
'Reserved': (mpentry['Attribute'] & (3 << 27)) >> 27,
'ImageDataFormat': (mpentry['Attribute'] & (7 << 24)) >> 24,
'MPType': mpentry['Attribute'] & 0x00FFFFFF
}
if mpentryattr['ImageDataFormat'] == 0:
@ -496,7 +502,7 @@ def _getmp(self):
0x030000: 'Baseline MP Primary Image'
}
mpentryattr['MPType'] = mptypemap.get(mpentryattr['MPType'],
'Unknown')
'Unknown')
mpentry['Attribute'] = mpentryattr
mpentries.append(mpentry)
mp[0xB002] = mpentries
@ -530,11 +536,10 @@ zigzag_index = ( 0, 1, 5, 6, 14, 15, 27, 28,
21, 34, 37, 47, 50, 56, 59, 61,
35, 36, 48, 49, 57, 58, 62, 63)
samplings = {
(1, 1, 1, 1, 1, 1): 0,
samplings = {(1, 1, 1, 1, 1, 1): 0,
(2, 1, 1, 1, 1, 1): 1,
(2, 2, 1, 1, 1, 1): 2,
}
}
def convert_dict_qtables(qtables):
@ -589,7 +594,8 @@ def _save(im, fp, filename):
subsampling = 2
elif subsampling == "keep":
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)
def validate_qtables(qtables):
@ -623,7 +629,8 @@ def _save(im, fp, filename):
if qtables == "keep":
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 = validate_qtables(qtables)
@ -641,7 +648,8 @@ def _save(im, fp, filename):
i = 1
for marker in markers:
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
# get keyword arguments

View File

@ -48,8 +48,8 @@ You can get the quantization tables of a JPEG with::
im.quantization
This will return a dict with a number of arrays. You can pass this dict directly
as the qtables argument when saving a JPEG.
This will return a dict with a number of arrays. You can pass this dict
directly as the qtables argument when saving a JPEG.
The tables format between im.quantization and quantization in presets differ in
3 ways:

View File

@ -46,7 +46,7 @@ class MpoImageFile(JpegImagePlugin.JpegImageFile):
self.mpinfo = self._getmp()
self.__framecount = self.mpinfo[0xB001]
self.__mpoffsets = [mpent['DataOffset'] + self.info['mpoffset']
for mpent in self.mpinfo[0xB002]]
for mpent in self.mpinfo[0xB002]]
self.__mpoffsets[0] = 0
# Note that the following assertion will only be invalid if something
# gets broken within JpegImagePlugin.

View File

@ -30,6 +30,7 @@ for r in range(8):
for b in range(4):
PALETTE = PALETTE + (o8((r*255)//7)+o8((g*255)//7)+o8((b*255)//3))
##
# Image plugin for XV thumbnail images.

View File

@ -6,5 +6,3 @@ import sys
if sys.maxsize < 2**32:
im = Image.new('L', (999999, 999999), 0)

View File

@ -1,4 +1,4 @@
from helper import *
from helper import unittest, PillowTestCase, lena
# Not running this test by default. No DOS against Travis CI.

View File

@ -7,4 +7,5 @@ from io import BytesIO
if bytes is str:
Image.open(BytesIO(bytes('icns\x00\x00\x00\x10hang\x00\x00\x00\x00')))
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')))

View File

@ -5,7 +5,9 @@ from PIL import Image
from io import BytesIO
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:
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')))

View File

@ -9,6 +9,6 @@ i = Image.new("RGB", (500, h), "white")
d = ImageDraw.Draw(i)
# this line causes a MemoryError
d.text((0,0), s, font=f, fill=0)
d.text((0, 0), s, font=f, fill=0)
i.show()

View File

@ -100,7 +100,8 @@ class PillowTestCase(unittest.TestCase):
ave_diff = float(diff)/(a.size[0]*a.size[1])
self.assertGreaterEqual(
epsilon, ave_diff,
(msg or '') + " average pixel value difference %.4f > epsilon %.4f" % (
(msg or '') +
" average pixel value difference %.4f > epsilon %.4f" % (
ave_diff, epsilon))
def assert_warning(self, warn_class, func):
@ -138,7 +139,8 @@ class PillowTestCase(unittest.TestCase):
if travis is not None:
skip = skip and (travis == bool(os.environ.get('TRAVIS', False)))
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:
self.skipTest(msg or "Known Bad Test")

View File

@ -1,6 +1,6 @@
import sys
from helper import *
from helper import unittest, PillowTestCase
# This test is not run automatically.
#

View File

@ -1,6 +1,6 @@
import sys
from helper import *
from helper import unittest, PillowTestCase
# This test is not run automatically.
#

View File

@ -38,7 +38,7 @@ class TestFileMpo(PillowTestCase):
self.assertEqual(im.applist[0][0], 'APP1')
self.assertEqual(im.applist[1][0], 'APP2')
self.assertEqual(im.applist[1][1][:16],
b'MPF\x00MM\x00*\x00\x00\x00\x08\x00\x03\xb0\x00')
b'MPF\x00MM\x00*\x00\x00\x00\x08\x00\x03\xb0\x00')
self.assertEqual(len(im.applist), 2)
def test_exif(self):
@ -71,7 +71,7 @@ class TestFileMpo(PillowTestCase):
self.assertFalse(mpattr['DependentChildImageFlag'])
self.assertEqual(mpattr['ImageDataFormat'], 'JPEG')
self.assertEqual(mpattr['MPType'],
'Multi-Frame Image: (Disparity)')
'Multi-Frame Image: (Disparity)')
self.assertEqual(mpattr['Reserved'], 0)
frameNumber += 1
@ -82,7 +82,8 @@ class TestFileMpo(PillowTestCase):
# prior to first image raises an error, both blatant and borderline
self.assertRaises(EOFError, im.seek, -1)
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, 523)
# bad calls shouldn't change the frame

View File

@ -29,7 +29,6 @@ class TestFilePalm(PillowTestCase):
converted = self.open_withImagemagick(outfile)
self.assert_image_equal(converted, im)
def test_monochrome(self):
# Arrange
mode = "1"

View File

@ -151,13 +151,16 @@ class TestFilePng(PillowTestCase):
self.assertEqual(im.info["spam"].lang, "en")
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, {})
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, {})
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"].lang, "en")
self.assertEqual(im.info["spam"].tkey, "Spam")
@ -271,7 +274,8 @@ class TestFilePng(PillowTestCase):
im = Image.new("RGB", (32, 32))
info = PngImagePlugin.PngInfo()
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)
self.assertEqual(im.info, {"spam": "Eggs", "eggs": "Spam"})
@ -303,11 +307,11 @@ class TestFilePng(PillowTestCase):
self.assertEqual(im.info, {"Text": value})
if str is not bytes:
rt_text(" Aa" + chr(0xa0) + chr(0xc4) + chr(0xff)) # Latin1
rt_text(chr(0x400) + chr(0x472) + chr(0x4ff)) # Cyrillic
rt_text(chr(0x4e00) + chr(0x66f0) + # CJK
rt_text(" Aa" + chr(0xa0) + chr(0xc4) + chr(0xff)) # Latin1
rt_text(chr(0x400) + chr(0x472) + chr(0x4ff)) # Cyrillic
rt_text(chr(0x4e00) + chr(0x66f0) + # CJK
chr(0x9fba) + chr(0x3042) + chr(0xac00))
rt_text("A" + chr(0xc4) + chr(0x472) + chr(0x3042)) # Combined
rt_text("A" + chr(0xc4) + chr(0x472) + chr(0x3042)) # Combined
def test_scary(self):
# Check reading of evil PNG file. For information, see:

View File

@ -50,7 +50,8 @@ class TestFileTiffMetadata(PillowTestCase):
'StripByteCounts': (1796,),
'SamplesPerPixel': (1,),
'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,
# but less helpful in telling what's wrong.

View File

@ -18,7 +18,8 @@ class TestFileWebpAlpha(PillowTestCase):
self.skipTest('WebP support not installed')
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):
# Generated with `cwebp transparent.png -o transparent.webp`

View File

@ -2,54 +2,60 @@ from helper import unittest, PillowTestCase, lena
from PIL import Image
import colorsys, itertools
import colorsys
import itertools
class TestFormatHSV(PillowTestCase):
def int_to_float(self, i):
return float(i)/255.0
def str_to_float(self, i):
return float(ord(i))/255.0
def to_int(self, f):
return int(f*255.0)
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))
def test_sanity(self):
im = Image.new('HSV', (100,100))
Image.new('HSV', (100, 100))
def wedge(self):
w =Image._wedge()
w = Image._wedge()
w90 = w.rotate(90)
(px, h) = w.size
r = Image.new('L', (px*3,h))
r = Image.new('L', (px*3, h))
g = r.copy()
b = r.copy()
r.paste(w, (0,0))
r.paste(w90, (px,0))
r.paste(w, (0, 0))
r.paste(w90, (px, 0))
g.paste(w90, (0,0))
g.paste(w, (2*px,0))
g.paste(w90, (0, 0))
g.paste(w, (2*px, 0))
b.paste(w, (px,0))
b.paste(w90, (2*px,0))
b.paste(w, (px, 0))
b.paste(w90, (2*px, 0))
img = Image.merge('RGB',(r,g,b))
img = Image.merge('RGB', (r, g, b))
#print (("%d, %d -> "% (int(1.75*px),int(.25*px))) + \
# "(%s, %s, %s)"%img.getpixel((1.75*px, .25*px)))
#print (("%d, %d -> "% (int(.75*px),int(.25*px))) + \
# "(%s, %s, %s)"%img.getpixel((.75*px, .25*px)))
# print (("%d, %d -> "% (int(1.75*px),int(.25*px))) + \
# "(%s, %s, %s)"%img.getpixel((1.75*px, .25*px)))
# print (("%d, %d -> "% (int(.75*px),int(.25*px))) + \
# "(%s, %s, %s)"%img.getpixel((.75*px, .25*px)))
return img
def to_xxx_colorsys(self, im, func, mode):
# convert the hard way using the library colorsys routines.
(r,g,b) = im.split()
(r, g, b) = im.split()
if bytes is str:
conv_func = self.str_to_float
@ -61,16 +67,19 @@ class TestFormatHSV(PillowTestCase):
else:
iter_helper = itertools.zip_longest
converted = [self.tuple_to_ints(func(conv_func(_r), conv_func(_g), conv_func(_b)))
for (_r, _g, _b) in iter_helper(r.tobytes(), g.tobytes(), b.tobytes())]
converted = [self.tuple_to_ints(func(conv_func(_r), conv_func(_g),
conv_func(_b)))
for (_r, _g, _b) in iter_helper(r.tobytes(), g.tobytes(),
b.tobytes())]
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:
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)
return hsv
@ -81,18 +90,18 @@ class TestFormatHSV(PillowTestCase):
return self.to_xxx_colorsys(im, colorsys.hsv_to_rgb, 'RGB')
def test_wedge(self):
src = self.wedge().resize((3*32,32),Image.BILINEAR)
src = self.wedge().resize((3*32, 32), Image.BILINEAR)
im = src.convert('HSV')
comparable = self.to_hsv_colorsys(src)
#print (im.getpixel((448, 64)))
#print (comparable.getpixel((448, 64)))
# print (im.getpixel((448, 64)))
# print (comparable.getpixel((448, 64)))
#print(im.split()[0].histogram())
#print(comparable.split()[0].histogram())
# print(im.split()[0].histogram())
# print(comparable.split()[0].histogram())
#im.split()[0].show()
#comparable.split()[0].show()
# im.split()[0].show()
# comparable.split()[0].show()
self.assert_image_similar(im.split()[0], comparable.split()[0],
1, "Hue conversion is wrong")
@ -101,15 +110,15 @@ class TestFormatHSV(PillowTestCase):
self.assert_image_similar(im.split()[2], comparable.split()[2],
1, "Value conversion is wrong")
#print (im.getpixel((192, 64)))
# print (im.getpixel((192, 64)))
comparable = src
im = im.convert('RGB')
#im.split()[0].show()
#comparable.split()[0].show()
#print (im.getpixel((192, 64)))
#print (comparable.getpixel((192, 64)))
# im.split()[0].show()
# comparable.split()[0].show()
# print (im.getpixel((192, 64)))
# print (comparable.getpixel((192, 64)))
self.assert_image_similar(im.split()[0], comparable.split()[0],
3, "R conversion is wrong")
@ -118,7 +127,6 @@ class TestFormatHSV(PillowTestCase):
self.assert_image_similar(im.split()[2], comparable.split()[2],
3, "B conversion is wrong")
def test_convert(self):
im = lena('RGB').convert('HSV')
comparable = self.to_hsv_colorsys(lena('RGB'))
@ -136,18 +144,16 @@ class TestFormatHSV(PillowTestCase):
self.assert_image_similar(im.split()[2], comparable.split()[2],
1, "Value conversion is wrong")
def test_hsv_to_rgb(self):
comparable = self.to_hsv_colorsys(lena('RGB'))
converted = comparable.convert('RGB')
comparable = self.to_rgb_colorsys(comparable)
# print(converted.split()[1].histogram())
# print(target.split()[1].histogram())
# print ([ord(x) for x in target.split()[1].tobytes()[:80]])
# print ([ord(x) for x in converted.split()[1].tobytes()[:80]])
# print(converted.split()[1].histogram())
# print(target.split()[1].histogram())
# print ([ord(x) for x in target.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],
3, "R conversion is wrong")
@ -157,12 +163,6 @@ class TestFormatHSV(PillowTestCase):
3, "B conversion is wrong")
if __name__ == '__main__':
unittest.main()

View File

@ -1,7 +1,5 @@
from helper import unittest, PillowTestCase, lena
from PIL import Image
class TestImageCopy(PillowTestCase):

View File

@ -1,7 +1,5 @@
from helper import unittest, PillowTestCase, lena
import sys
class TestImagePoint(PillowTestCase):
@ -26,7 +24,7 @@ class TestImagePoint(PillowTestCase):
"""
# This takes _forever_ on PyPy. Open Bug,
# see https://github.com/python-pillow/Pillow/issues/484
#self.skipKnownBadTest(msg="Too Slow on pypy", interpreter='pypy')
# self.skipKnownBadTest(msg="Too Slow on pypy", interpreter='pypy')
im = lena("I")
im.point(list(range(256))*256, 'L')

View File

@ -41,9 +41,8 @@ class TestImagePutData(PillowTestCase):
else:
self.assertEqual(put(sys.maxsize), (255, 255, 255, 127))
def test_pypy_performance(self):
im = Image.new('L', (256,256))
im = Image.new('L', (256, 256))
im.putdata(list(range(256))*256)
def test_mode_i(self):
@ -52,7 +51,7 @@ class TestImagePutData(PillowTestCase):
im = Image.new('I', src.size, 0)
im.putdata(data, 2, 256)
target = [2* elt + 256 for elt in data]
target = [2 * elt + 256 for elt in data]
self.assertEqual(list(im.getdata()), target)
def test_mode_F(self):
@ -61,11 +60,10 @@ class TestImagePutData(PillowTestCase):
im = Image.new('F', src.size, 0)
im.putdata(data, 2.0, 256.0)
target = [2.0* float(elt) + 256.0 for elt in data]
target = [2.0 * float(elt) + 256.0 for elt in data]
self.assertEqual(list(im.getdata()), target)
if __name__ == '__main__':
unittest.main()

View File

@ -202,8 +202,7 @@ class TestImageCms(PillowTestCase):
self.assertTrue(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):
# check to see if we're at least internally consistent.
@ -221,7 +220,6 @@ class TestImageCms(PillowTestCase):
self.assert_image_similar(lena(), out, 2)
def test_profile_tobytes(self):
from io import BytesIO
i = Image.open("Tests/images/rgb.jpg")
@ -231,14 +229,13 @@ class TestImageCms(PillowTestCase):
# not the same bytes as the original icc_profile,
# but it does roundtrip
self.assertEqual(p.tobytes(),p2.tobytes())
self.assertEqual(p.tobytes(), p2.tobytes())
self.assertEqual(ImageCms.getProfileName(p),
ImageCms.getProfileName(p2))
self.assertEqual(ImageCms.getProfileDescription(p),
ImageCms.getProfileDescription(p2))
if __name__ == '__main__':
unittest.main()

View File

@ -350,12 +350,15 @@ class TestImageDraw(PillowTestCase):
expected.load()
img, draw = self.create_base_image_draw((110, 200))
draw.line((55, 5, 55, 195), BLACK, 101)
self.assert_image_equal(img, expected, 'line straigth vertical 101px wide failed')
expected = Image.open(os.path.join(IMAGES_PATH, 'line_vertical_slope1px_w2px.png'))
self.assert_image_equal(img, expected,
'line straigth vertical 101px wide failed')
expected = Image.open(os.path.join(IMAGES_PATH,
'line_vertical_slope1px_w2px.png'))
expected.load()
img, draw = self.create_base_image_draw((20, 20))
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):
@ -363,22 +366,26 @@ class TestImageDraw(PillowTestCase):
expected.load()
img, draw = self.create_base_image_draw((20, 20))
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))
draw.line((14, 14, 5, 5), BLACK, 3)
self.assert_image_equal(img, expected, 'line oblique 45 inverted 3px wide A failed')
expected = Image.open(os.path.join(IMAGES_PATH, 'line_oblique_45_w3px_b.png'))
self.assert_image_equal(img, expected,
'line oblique 45 inverted 3px wide A failed')
expected = Image.open(os.path.join(IMAGES_PATH,
'line_oblique_45_w3px_b.png'))
expected.load()
img, draw = self.create_base_image_draw((20, 20))
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))
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__':
unittest.main()
# End of file

View File

@ -1,5 +1,5 @@
# Test the ImageMorphology functionality
from helper import *
from helper import unittest, PillowTestCase
from PIL import Image
from PIL import ImageMorph

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase
from PIL import Image
from PIL import ImageWin

View File

@ -5,7 +5,7 @@ from PIL import Image
class TestModeI16(PillowTestCase):
original = lena().resize((32,32)).convert('I')
original = lena().resize((32, 32)).convert('I')
def verify(self, im1):
im2 = self.original.copy()

View File

@ -17,6 +17,7 @@ test_filenames = (
"temp_'\"&&",
)
@unittest.skipIf(sys.platform.startswith('win32'), "requires Unix or MacOS")
class TestShellInjection(PillowTestCase):

View File

@ -1,8 +1,10 @@
from PIL import Image
import sys, time
import io
import threading, queue
import queue
import sys
import threading
import time
try:
format = sys.argv[1]
@ -16,6 +18,7 @@ queue = queue.Queue()
result = []
class Worker(threading.Thread):
def run(self):
while True:

View File

@ -1,5 +1,6 @@
from PIL import Image
def version(module, version):
v = getattr(module.core, version + "_version", None)
if v:

View File

@ -57,6 +57,7 @@ if MAX_PROCS != 1:
pool = Pool(2)
CCompiler.compile = _mp_compile
except Exception as msg:
print("Exception installing mp_compile, proceeding without: %s" %msg)
print("Exception installing mp_compile, proceeding without: %s" % msg)
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)

View File

@ -24,8 +24,8 @@ if 'NOSE_PROCESSES' not in os.environ:
for arg in sys.argv:
if '--processes' in arg:
break
else: # for
sys.argv.insert(1, '--processes=-1') # -1 == number of cores
else: # for
sys.argv.insert(1, '--processes=-1') # -1 == number of cores
sys.argv.insert(1, '--process-timeout=30')
if __name__ == '__main__':