Merge remote-tracking branch 'upstream/master' into flake8

Conflicts:
	Tests/bench_cffi_access.py
	Tests/test_file_palm.py
	Tests/test_format_hsv.py
	Tests/test_image_putdata.py
	Tests/test_locale.py
	Tests/test_mode_i16.py
This commit is contained in:
Hugo 2014-09-23 16:35:20 +03:00
commit 5e676ea0bd
74 changed files with 403 additions and 307 deletions

View File

@ -4,13 +4,25 @@ Changelog (Pillow)
2.6.0 (unreleased)
------------------
- Jpeg2k Decode/Encode Memory Leak Fix #898
- On Windows, do not execute convert.exe without specifying path #912
[cgohlke]
- Fix msvc build error #911
[cgohlke]
- Fix for handling P + transparency -> RGBA conversions #904
[wiredfool]
- Retain alpha in ImageEnhance operations #909
[wiredfool]
- Jpeg2k Decode/encode memory leak fix #898
[joshware, wiredfool]
- EpsFilePlugin Speed improvements #886
[wiredfool, karstenw]
- Don't resize if already the right size.
- Don't resize if already the right size #892
[radarhere]
- Fix for reading multipage TIFFs #885

View File

@ -7,7 +7,7 @@ Send a pull request. We'll generally want documentation and [tests](Tests/README
- Fork the repo
- Make a branch
- Add your changes + Tests
- Run the test suite. Try to run on both Python 2.x and 3.x, or you'll get tripped up. You can enable [Travis CI on your repo](https://travis-ci.org/profile/) to catch test failures prior to the pull request.
- Run the test suite. Try to run on both Python 2.x and 3.x, or you'll get tripped up. You can enable [Travis CI on your repo](https://travis-ci.org/profile/) to catch test failures prior to the pull request, and [Coveralls](https://coveralls.io/repos/new) to see if the changed code is covered by tests.
- Push to your fork, and make a pull request.
A few guidelines:

View File

@ -531,7 +531,7 @@ class Image:
"""
Closes the file pointer, if possible.
This operation will destroy the image core and release it's memory.
This operation will destroy the image core and release its memory.
The image data will be unusable afterward.
This function is only required to close images that have not
@ -869,8 +869,18 @@ class Image:
trns = trns_im.getpixel((0, 0))
elif self.mode == 'P' and mode == 'RGBA':
t = self.info['transparency']
delete_trns = True
if isinstance(t, bytes):
self.im.putpalettealphas(t)
elif isinstance(t, int):
self.im.putpalettealpha(t,0)
else:
raise ValueError("Transparency for P mode should" +
" be bytes or int")
if mode == "P" and palette == ADAPTIVE:
im = self.im.quantize(colors)
new = self._new(im)

View File

@ -47,8 +47,11 @@ class Color(_Enhance):
"""
def __init__(self, image):
self.image = image
self.degenerate = image.convert("L").convert(image.mode)
self.intermediate_mode = 'L'
if 'A' in image.getbands():
self.intermediate_mode = 'LA'
self.degenerate = image.convert(self.intermediate_mode).convert(image.mode)
class Contrast(_Enhance):
"""Adjust image contrast.
@ -62,6 +65,9 @@ class Contrast(_Enhance):
mean = int(ImageStat.Stat(image.convert("L")).mean[0] + 0.5)
self.degenerate = Image.new("L", image.size, mean).convert(image.mode)
if 'A' in image.getbands():
self.degenerate.putalpha(image.split()[-1])
class Brightness(_Enhance):
"""Adjust image brightness.
@ -74,6 +80,9 @@ class Brightness(_Enhance):
self.image = image
self.degenerate = Image.new(image.mode, image.size, 0)
if 'A' in image.getbands():
self.degenerate.putalpha(image.split()[-1])
class Sharpness(_Enhance):
"""Adjust image sharpness.
@ -85,3 +94,6 @@ class Sharpness(_Enhance):
def __init__(self, image):
self.image = image
self.degenerate = image.filter(ImageFilter.SMOOTH)
if 'A' in image.getbands():
self.degenerate.putalpha(image.split()[-1])

View File

@ -17,6 +17,9 @@
from PIL import Image
import sys
if sys.platform != "win32":
raise ImportError("ImageGrab is Windows only")
try:
# built-in driver (1.1.3 and later)

View File

@ -19,7 +19,3 @@ Pillow is the "friendly" PIL fork by `Alex Clark and Contributors <https://githu
.. image:: https://coveralls.io/repos/python-pillow/Pillow/badge.png?branch=master
:target: https://coveralls.io/r/python-pillow/Pillow?branch=master
.. image:: https://landscape.io/github/python-pillow/Pillow/master/landscape.png
:target: https://landscape.io/github/python-pillow/Pillow/master
:alt: Code Health

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
# Not running this test by default. No DOS against Travis CI.
@ -39,7 +39,7 @@ def timer(func, label, *args):
class BenchCffiAccess(PillowTestCase):
def test_direct(self):
im = lena()
im = hopper()
im.load()
# im = Image.new( "RGB", (2000, 2000), (1, 3, 2))
caccess = im.im.pixel_access(False)

View File

@ -6,7 +6,7 @@ import timeit
def bench(mode):
im = helper.lena(mode)
im = helper.hopper(mode)
get = im.im.getpixel
xy = 50, 50 # position shouldn't really matter
t0 = timeit.default_timer()

View File

@ -157,7 +157,7 @@ class PillowTestCase(unittest.TestCase):
raise IOError()
outfile = self.tempfile("temp.png")
if command_succeeds(['convert', f, outfile]):
if command_succeeds([IMCONVERT, f, outfile]):
from PIL import Image
return Image.open(outfile)
raise IOError()
@ -182,6 +182,7 @@ def tostring(im, format, **options):
return out.getvalue()
# Note: hopper() should be used in place of lena(), which will be removed.
def hopper(mode="RGB", cache={}):
from PIL import Image
im = None
@ -193,15 +194,16 @@ def hopper(mode="RGB", cache={}):
if mode == "RGB":
im = Image.open("Tests/images/hopper.ppm")
elif mode == "F":
im = lena("L").convert(mode)
im = hopper("L").convert(mode)
elif mode[:4] == "I;16":
im = lena("I").convert(mode)
im = hopper("I").convert(mode)
else:
im = lena("RGB").convert(mode)
im = hopper("RGB").convert(mode)
# cache[mode] = im
return im
# Note: hopper() should be used instead lena(), which will be removed.
def lena(mode="RGB", cache={}):
from PIL import Image
im = None
@ -251,6 +253,14 @@ def netpbm_available():
def imagemagick_available():
return command_succeeds(['convert', '-version'])
return IMCONVERT and command_succeeds([IMCONVERT, '-version'])
if sys.platform == 'win32':
IMCONVERT = os.environ.get('MAGICK_HOME', '')
if IMCONVERT:
IMCONVERT = os.path.join(IMCONVERT, 'convert.exe')
else:
IMCONVERT = 'convert'
# End of file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
Tests/images/hopper.tif Normal file

Binary file not shown.

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
try:
import cffi
@ -62,16 +62,16 @@ class TestCffi(PillowTestCase):
self.assertEqual(access[(x, y)], caccess[(x, y)])
def test_get_vs_c(self):
rgb = lena('RGB')
rgb = hopper('RGB')
rgb.load()
self._test_get_access(rgb)
self._test_get_access(lena('RGBA'))
self._test_get_access(lena('L'))
self._test_get_access(lena('LA'))
self._test_get_access(lena('1'))
self._test_get_access(lena('P'))
# self._test_get_access(lena('PA')) # PA -- how do I make a PA image?
self._test_get_access(lena('F'))
self._test_get_access(hopper('RGBA'))
self._test_get_access(hopper('L'))
self._test_get_access(hopper('LA'))
self._test_get_access(hopper('1'))
self._test_get_access(hopper('P'))
# self._test_get_access(hopper('PA')) # PA -- how do I make a PA image?
self._test_get_access(hopper('F'))
im = Image.new('I;16', (10, 10), 40000)
self._test_get_access(im)
@ -104,16 +104,16 @@ class TestCffi(PillowTestCase):
self.assertEqual(color, caccess[(x, y)])
def test_set_vs_c(self):
rgb = lena('RGB')
rgb = hopper('RGB')
rgb.load()
self._test_set_access(rgb, (255, 128, 0))
self._test_set_access(lena('RGBA'), (255, 192, 128, 0))
self._test_set_access(lena('L'), 128)
self._test_set_access(lena('LA'), (128, 128))
self._test_set_access(lena('1'), 255)
self._test_set_access(lena('P'), 128)
self._test_set_access(hopper('RGBA'), (255, 192, 128, 0))
self._test_set_access(hopper('L'), 128)
self._test_set_access(hopper('LA'), (128, 128))
self._test_set_access(hopper('1'), 255)
self._test_set_access(hopper('P'), 128)
# self._test_set_access(i, (128, 128)) #PA -- undone how to make
self._test_set_access(lena('F'), 1024.0)
self._test_set_access(hopper('F'), 1024.0)
im = Image.new('I;16', (10, 10), 40000)
self._test_set_access(im, 45000)

View File

@ -2,7 +2,7 @@ from helper import unittest, PillowTestCase
from PIL import Image
test_file = "Tests/images/lena.ppm"
TEST_FILE = "Tests/images/hopper.ppm"
ORIGINAL_LIMIT = Image.MAX_IMAGE_PIXELS
@ -15,7 +15,7 @@ class TestDecompressionBomb(PillowTestCase):
def test_no_warning_small_file(self):
# Implicit assert: no warning.
# A warning would cause a failure.
Image.open(test_file)
Image.open(TEST_FILE)
def test_no_warning_no_limit(self):
# Arrange
@ -26,7 +26,7 @@ class TestDecompressionBomb(PillowTestCase):
# Act / Assert
# Implicit assert: no warning.
# A warning would cause a failure.
Image.open(test_file)
Image.open(TEST_FILE)
def test_warning(self):
# Arrange
@ -37,7 +37,7 @@ class TestDecompressionBomb(PillowTestCase):
# Act / Assert
self.assert_warning(
Image.DecompressionBombWarning,
lambda: Image.open(test_file))
lambda: Image.open(TEST_FILE))
if __name__ == '__main__':
unittest.main()

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
from PIL import Image
import io
@ -18,16 +18,16 @@ class TestFileBmp(PillowTestCase):
self.assertEqual(reloaded.format, "BMP")
def test_sanity(self):
self.roundtrip(lena())
self.roundtrip(hopper())
self.roundtrip(lena("1"))
self.roundtrip(lena("L"))
self.roundtrip(lena("P"))
self.roundtrip(lena("RGB"))
self.roundtrip(hopper("1"))
self.roundtrip(hopper("L"))
self.roundtrip(hopper("P"))
self.roundtrip(hopper("RGB"))
def test_save_to_bytes(self):
output = io.BytesIO()
im = lena()
im = hopper()
im.save(output, "BMP")
output.seek(0)
@ -41,7 +41,7 @@ class TestFileBmp(PillowTestCase):
dpi = (72, 72)
output = io.BytesIO()
im = lena()
im = hopper()
im.save(output, "BMP", dpi=dpi)
output.seek(0)

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
from PIL import Image, IptcImagePlugin
@ -21,7 +21,7 @@ class TestFileIptc(PillowTestCase):
def test_getiptcinfo_jpg_none(self):
# Arrange
im = lena()
im = hopper()
# Act
iptc = IptcImagePlugin.getiptcinfo(im)

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena, py3
from helper import unittest, PillowTestCase, hopper, py3
import os
@ -268,7 +268,7 @@ class TestFileLibTiff(LibTiffTestCase):
self.assert_image_equal(im, im2)
def test_compressions(self):
im = lena('RGB')
im = hopper('RGB')
out = self.tempfile('temp.tif')
for compression in ('packbits', 'tiff_lzw'):
@ -281,7 +281,7 @@ class TestFileLibTiff(LibTiffTestCase):
self.assert_image_similar(im, im2, 30)
def test_cmyk_save(self):
im = lena('CMYK')
im = hopper('CMYK')
out = self.tempfile('temp.tif')
im.save(out, compression='tiff_adobe_deflate')
@ -293,7 +293,7 @@ class TestFileLibTiff(LibTiffTestCase):
to output on stderr from the error thrown by libtiff. We need to
capture that but not now"""
im = lena('RGB')
im = hopper('RGB')
out = self.tempfile('temp.tif')
self.assertRaises(
@ -337,7 +337,7 @@ class TestFileLibTiff(LibTiffTestCase):
def test__next(self):
TiffImagePlugin.READ_LIBTIFF = True
im = Image.open('Tests/images/lena.tif')
im = Image.open('Tests/images/hopper.tif')
self.assertFalse(im.tag.next)
im.load()
self.assertFalse(im.tag.next)

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
from PIL import Image
@ -9,7 +9,7 @@ class TestFileMsp(PillowTestCase):
file = self.tempfile("temp.msp")
lena("1").save(file)
hopper("1").save(file)
im = Image.open(file)
im.load()

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena, imagemagick_available
from helper import unittest, PillowTestCase, hopper, imagemagick_available
import os.path
@ -8,7 +8,7 @@ class TestFilePalm(PillowTestCase):
def helper_save_as_palm(self, mode):
# Arrange
im = lena(mode)
im = hopper(mode)
outfile = self.tempfile("temp_" + mode + ".palm")
# Act
@ -22,7 +22,7 @@ class TestFilePalm(PillowTestCase):
if not self._roundtrip:
return
im = lena(mode)
im = hopper(mode)
outfile = self.tempfile("temp.palm")
im.save(outfile)

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
from PIL import Image
@ -17,7 +17,7 @@ class TestFilePcx(PillowTestCase):
def test_sanity(self):
for mode in ('1', 'L', 'P', 'RGB'):
self._roundtrip(lena(mode))
self._roundtrip(hopper(mode))
def test_odd(self):
# see issue #523, odd sized images should have a stride that's even.
@ -26,7 +26,7 @@ class TestFilePcx(PillowTestCase):
for mode in ('1', 'L', 'P', 'RGB'):
# larger, odd sized images are better here to ensure that
# we handle interrupted scan lines properly.
self._roundtrip(lena(mode).resize((511, 511)))
self._roundtrip(hopper(mode).resize((511, 511)))
def test_pil184(self):
# Check reading of files where xmin/xmax is not zero.

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
import os.path
@ -7,7 +7,7 @@ class TestFilePdf(PillowTestCase):
def helper_save_as_pdf(self, mode):
# Arrange
im = lena(mode)
im = hopper(mode)
outfile = self.tempfile("temp_" + mode + ".pdf")
# Act

View File

@ -351,7 +351,8 @@ class TestFilePng(PillowTestCase):
im2 = Image.open(f)
self.assertIn('transparency', im2.info)
self.assert_image_equal(im2.convert('RGBA'), im.convert('RGBA'))
self.assert_image_equal(im2.convert('RGBA'),
im.convert('RGBA'))
def test_save_icc_profile_none(self):
# check saving files with an ICC profile set to None (omit profile)

View File

@ -3,7 +3,7 @@ from helper import unittest, PillowTestCase
from PIL import Image
# sample ppm stream
file = "Tests/images/lena.ppm"
file = "Tests/images/hopper.ppm"
data = open(file, "rb").read()

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena, py3
from helper import unittest, PillowTestCase, hopper, py3
from PIL import Image, TiffImagePlugin
@ -9,7 +9,7 @@ class TestFileTiff(PillowTestCase):
file = self.tempfile("temp.tif")
lena("RGB").save(file)
hopper("RGB").save(file)
im = Image.open(file)
im.load()
@ -17,19 +17,19 @@ class TestFileTiff(PillowTestCase):
self.assertEqual(im.size, (128, 128))
self.assertEqual(im.format, "TIFF")
lena("1").save(file)
hopper("1").save(file)
im = Image.open(file)
lena("L").save(file)
hopper("L").save(file)
im = Image.open(file)
lena("P").save(file)
hopper("P").save(file)
im = Image.open(file)
lena("RGB").save(file)
hopper("RGB").save(file)
im = Image.open(file)
lena("I").save(file)
hopper("I").save(file)
im = Image.open(file)
def test_mac_tiff(self):

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
from PIL import Image, TiffImagePlugin, TiffTags
@ -13,7 +13,7 @@ class TestFileTiffMetadata(PillowTestCase):
data. https://github.com/python-pillow/Pillow/issues/291
"""
img = lena()
img = hopper()
textdata = "This is some arbitrary metadata for a text field"
info = TiffImagePlugin.ImageFileDirectory()
@ -64,7 +64,7 @@ class TestFileTiffMetadata(PillowTestCase):
def test_write_metadata(self):
""" Test metadata writing through the python code """
img = Image.open('Tests/images/lena.tif')
img = Image.open('Tests/images/hopper.tif')
f = self.tempfile('temp.tiff')
img.save(f, tiffinfo=img.tag)

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
from PIL import Image
@ -41,7 +41,7 @@ class TestFileWebpAlpha(PillowTestCase):
temp_file = self.tempfile("temp.webp")
# temp_file = "temp.webp"
pil_image = lena('RGBA')
pil_image = hopper('RGBA')
mask = Image.new("RGBA", (64, 64), (128, 128, 128, 128))
# Add some partially transparent bits:

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
from PIL import Image
@ -23,7 +23,7 @@ class TestFileWebpLossless(PillowTestCase):
def test_write_lossless_rgb(self):
temp_file = self.tempfile("temp.webp")
lena("RGB").save(temp_file, lossless=True)
hopper("RGB").save(temp_file, lossless=True)
image = Image.open(temp_file)
image.load()
@ -34,7 +34,7 @@ class TestFileWebpLossless(PillowTestCase):
image.load()
image.getdata()
self.assert_image_equal(image, lena("RGB"))
self.assert_image_equal(image, hopper("RGB"))
if __name__ == '__main__':

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
from PIL import Image
@ -128,8 +128,8 @@ class TestFormatHSV(PillowTestCase):
3, "B conversion is wrong")
def test_convert(self):
im = lena('RGB').convert('HSV')
comparable = self.to_hsv_colorsys(lena('RGB'))
im = hopper('RGB').convert('HSV')
comparable = self.to_hsv_colorsys(hopper('RGB'))
# print ([ord(x) for x in im.split()[0].tobytes()[:80]])
# print ([ord(x) for x in comparable.split()[0].tobytes()[:80]])
@ -145,7 +145,7 @@ class TestFormatHSV(PillowTestCase):
1, "Value conversion is wrong")
def test_hsv_to_rgb(self):
comparable = self.to_hsv_colorsys(lena('RGB'))
comparable = self.to_hsv_colorsys(hopper('RGB'))
converted = comparable.convert('RGB')
comparable = self.to_rgb_colorsys(comparable)

View File

@ -1,8 +1,8 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
from PIL import Image
im = lena().resize((128, 100))
im = hopper().resize((128, 100))
class TestImageArray(PillowTestCase):

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
from PIL import Image
@ -15,13 +15,13 @@ class TestImageConvert(PillowTestCase):
modes = "1", "L", "I", "F", "RGB", "RGBA", "RGBX", "CMYK", "YCbCr"
for mode in modes:
im = lena(mode)
im = hopper(mode)
for mode in modes:
convert(im, mode)
def test_default(self):
im = lena("P")
im = hopper("P")
self.assert_image(im, "P", im.size)
im = im.convert()
self.assert_image(im, "RGB", im.size)
@ -36,7 +36,7 @@ class TestImageConvert(PillowTestCase):
self.assertEqual(orig, converted)
def test_8bit(self):
im = Image.open('Tests/images/lena.jpg')
im = Image.open('Tests/images/hopper.jpg')
self._test_float_conversion(im.convert('L'))
def test_16bit(self):
@ -48,8 +48,8 @@ class TestImageConvert(PillowTestCase):
self._test_float_conversion(im.convert('I'))
def test_rgba_p(self):
im = lena('RGBA')
im.putalpha(lena('L'))
im = hopper('RGBA')
im.putalpha(hopper('L'))
converted = im.convert('P')
comparable = converted.convert('RGBA')
@ -57,7 +57,7 @@ class TestImageConvert(PillowTestCase):
self.assert_image_similar(im, comparable, 20)
def test_trns_p(self):
im = lena('P')
im = hopper('P')
im.info['transparency'] = 0
f = self.tempfile('temp.png')
@ -74,7 +74,7 @@ class TestImageConvert(PillowTestCase):
def test_trns_p_rgba(self):
# Arrange
im = lena('P')
im = hopper('P')
im.info['transparency'] = 128
# Act
@ -84,7 +84,7 @@ class TestImageConvert(PillowTestCase):
self.assertNotIn('transparency', rgba.info)
def test_trns_l(self):
im = lena('L')
im = hopper('L')
im.info['transparency'] = 128
f = self.tempfile('temp.png')
@ -104,7 +104,7 @@ class TestImageConvert(PillowTestCase):
p.save(f)
def test_trns_RGB(self):
im = lena('RGB')
im = hopper('RGB')
im.info['transparency'] = im.getpixel((0, 0))
f = self.tempfile('temp.png')

View File

@ -1,11 +1,11 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
class TestImageCopy(PillowTestCase):
def test_copy(self):
def copy(mode):
im = lena(mode)
im = hopper(mode)
out = im.copy()
self.assertEqual(out.mode, mode)
self.assertEqual(out.size, im.size)

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
from PIL import Image
@ -7,7 +7,7 @@ class TestImageCrop(PillowTestCase):
def test_crop(self):
def crop(mode):
out = lena(mode).crop((50, 50, 100, 100))
out = hopper(mode).crop((50, 50, 100, 100))
self.assertEqual(out.mode, mode)
self.assertEqual(out.size, (50, 50))
for mode in "1", "P", "L", "RGB", "I", "F":

View File

@ -2,13 +2,13 @@ from helper import unittest, PillowTestCase, fromstring, tostring
from PIL import Image
codecs = dir(Image.core)
filename = "Tests/images/lena.jpg"
data = tostring(Image.open(filename).resize((512, 512)), "JPEG")
CODECS = dir(Image.core)
FILENAME = "Tests/images/hopper.jpg"
DATA = tostring(Image.open(FILENAME).resize((512, 512)), "JPEG")
def draft(mode, size):
im = fromstring(data)
im = fromstring(DATA)
im.draft(mode, size)
return im
@ -16,7 +16,7 @@ def draft(mode, size):
class TestImageDraft(PillowTestCase):
def setUp(self):
if "jpeg_encoder" not in codecs or "jpeg_decoder" not in codecs:
if "jpeg_encoder" not in CODECS or "jpeg_decoder" not in CODECS:
self.skipTest("jpeg support not available")
def test_size(self):

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
from PIL import Image
from PIL import ImageFilter
@ -9,7 +9,7 @@ class TestImageFilter(PillowTestCase):
def test_sanity(self):
def filter(filter):
im = lena("L")
im = hopper("L")
out = im.filter(filter)
self.assertEqual(out.mode, im.mode)
self.assertEqual(out.size, im.size)

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
from PIL import Image
@ -6,7 +6,7 @@ from PIL import Image
class TestImageFromBytes(PillowTestCase):
def test_sanity(self):
im1 = lena()
im1 = hopper()
im2 = Image.frombytes(im1.mode, im1.size, im1.tobytes())
self.assert_image_equal(im1, im2)

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
from PIL import Image
@ -7,7 +7,7 @@ class TestImageGetBbox(PillowTestCase):
def test_sanity(self):
bbox = lena().getbbox()
bbox = hopper().getbbox()
self.assertIsInstance(bbox, tuple)
def test_bbox(self):

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
class TestImageGetColors(PillowTestCase):
@ -6,7 +6,7 @@ class TestImageGetColors(PillowTestCase):
def test_getcolors(self):
def getcolors(mode, limit=None):
im = lena(mode)
im = hopper(mode)
if limit:
colors = im.getcolors(limit)
else:
@ -16,37 +16,36 @@ class TestImageGetColors(PillowTestCase):
return None
self.assertEqual(getcolors("1"), 2)
self.assertEqual(getcolors("L"), 193)
self.assertEqual(getcolors("I"), 193)
self.assertEqual(getcolors("F"), 193)
self.assertEqual(getcolors("P"), 54) # fixed palette
self.assertEqual(getcolors("L"), 255)
self.assertEqual(getcolors("I"), 255)
self.assertEqual(getcolors("F"), 255)
self.assertEqual(getcolors("P"), 90) # fixed palette
self.assertEqual(getcolors("RGB"), None)
self.assertEqual(getcolors("RGBA"), None)
self.assertEqual(getcolors("CMYK"), None)
self.assertEqual(getcolors("YCbCr"), None)
self.assertEqual(getcolors("L", 128), None)
self.assertEqual(getcolors("L", 1024), 193)
self.assertEqual(getcolors("L", 1024), 255)
self.assertEqual(getcolors("RGB", 8192), None)
self.assertEqual(getcolors("RGB", 16384), 14836)
self.assertEqual(getcolors("RGB", 100000), 14836)
self.assertEqual(getcolors("RGB", 16384), 10100)
self.assertEqual(getcolors("RGB", 100000), 10100)
self.assertEqual(getcolors("RGBA", 16384), 14836)
self.assertEqual(getcolors("CMYK", 16384), 14836)
self.assertEqual(getcolors("YCbCr", 16384), 11995)
self.assertEqual(getcolors("RGBA", 16384), 10100)
self.assertEqual(getcolors("CMYK", 16384), 10100)
self.assertEqual(getcolors("YCbCr", 16384), 9329)
# --------------------------------------------------------------------
def test_pack(self):
# Pack problems for small tables (@PIL209)
im = lena().quantize(3).convert("RGB")
im = hopper().quantize(3).convert("RGB")
expected = [
(3236, (227, 183, 147)),
(6297, (143, 84, 81)),
(6851, (208, 143, 112))]
expected = [(4039, (172, 166, 181)),
(4385, (124, 113, 134)),
(7960, (31, 20, 33))]
A = im.getcolors(maxcolors=2)
self.assertEqual(A, None)

View File

@ -1,32 +1,32 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
class TestImageGetData(PillowTestCase):
def test_sanity(self):
data = lena().getdata()
data = hopper().getdata()
len(data)
list(data)
self.assertEqual(data[0], (223, 162, 133))
self.assertEqual(data[0], (20, 20, 70))
def test_roundtrip(self):
def getdata(mode):
im = lena(mode).resize((32, 30))
im = hopper(mode).resize((32, 30))
data = im.getdata()
return data[0], len(data), len(list(data))
self.assertEqual(getdata("1"), (255, 960, 960))
self.assertEqual(getdata("L"), (176, 960, 960))
self.assertEqual(getdata("I"), (176, 960, 960))
self.assertEqual(getdata("F"), (176.0, 960, 960))
self.assertEqual(getdata("RGB"), ((223, 162, 133), 960, 960))
self.assertEqual(getdata("RGBA"), ((223, 162, 133, 255), 960, 960))
self.assertEqual(getdata("CMYK"), ((32, 93, 122, 0), 960, 960))
self.assertEqual(getdata("YCbCr"), ((176, 103, 160), 960, 960))
self.assertEqual(getdata("1"), (0, 960, 960))
self.assertEqual(getdata("L"), (25, 960, 960))
self.assertEqual(getdata("I"), (25, 960, 960))
self.assertEqual(getdata("F"), (25.0, 960, 960))
self.assertEqual(getdata("RGB"), (((20, 20, 70), 960, 960)))
self.assertEqual(getdata("RGBA"), ((20, 20, 70, 255), 960, 960))
self.assertEqual(getdata("CMYK"), ((235, 235, 185, 0), 960, 960))
self.assertEqual(getdata("YCbCr"), ((25, 153, 123), 960, 960))
if __name__ == '__main__':

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
class TestImageGetExtrema(PillowTestCase):
@ -6,19 +6,19 @@ class TestImageGetExtrema(PillowTestCase):
def test_extrema(self):
def extrema(mode):
return lena(mode).getextrema()
return hopper(mode).getextrema()
self.assertEqual(extrema("1"), (0, 255))
self.assertEqual(extrema("L"), (40, 235))
self.assertEqual(extrema("I"), (40, 235))
self.assertEqual(extrema("F"), (40.0, 235.0))
self.assertEqual(extrema("P"), (11, 218)) # fixed palette
self.assertEqual(extrema("L"), (0, 255))
self.assertEqual(extrema("I"), (0, 255))
self.assertEqual(extrema("F"), (0, 255))
self.assertEqual(extrema("P"), (0, 225)) # fixed palette
self.assertEqual(
extrema("RGB"), ((61, 255), (26, 234), (44, 223)))
extrema("RGB"), ((0, 255), (0, 255), (0, 255)))
self.assertEqual(
extrema("RGBA"), ((61, 255), (26, 234), (44, 223), (255, 255)))
extrema("RGBA"), ((0, 255), (0, 255), (0, 255), (255, 255)))
self.assertEqual(
extrema("CMYK"), ((0, 194), (21, 229), (32, 211), (0, 0)))
extrema("CMYK"), (((0, 255), (0, 255), (0, 255), (0, 0))))
if __name__ == '__main__':

View File

@ -1,10 +1,10 @@
from helper import unittest, PillowTestCase, lena, py3
from helper import unittest, PillowTestCase, hopper, py3
class TestImageGetIm(PillowTestCase):
def test_sanity(self):
im = lena()
im = hopper()
type_repr = repr(type(im.getim()))
if py3:

View File

@ -1,11 +1,11 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
class TestImageGetPalette(PillowTestCase):
def test_palette(self):
def palette(mode):
p = lena(mode).getpalette()
p = hopper(mode).getpalette()
if p:
return p[:10]
return None

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
from PIL import Image
@ -7,7 +7,7 @@ class TestImageGetProjection(PillowTestCase):
def test_sanity(self):
im = lena()
im = hopper()
projection = im.getprojection()

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
class TestImageHistogram(PillowTestCase):
@ -6,18 +6,18 @@ class TestImageHistogram(PillowTestCase):
def test_histogram(self):
def histogram(mode):
h = lena(mode).histogram()
h = hopper(mode).histogram()
return len(h), min(h), max(h)
self.assertEqual(histogram("1"), (256, 0, 8872))
self.assertEqual(histogram("L"), (256, 0, 199))
self.assertEqual(histogram("I"), (256, 0, 199))
self.assertEqual(histogram("F"), (256, 0, 199))
self.assertEqual(histogram("P"), (256, 0, 2912))
self.assertEqual(histogram("RGB"), (768, 0, 285))
self.assertEqual(histogram("1"), (256, 0, 10994))
self.assertEqual(histogram("L"), (256, 0, 638))
self.assertEqual(histogram("I"), (256, 0, 638))
self.assertEqual(histogram("F"), (256, 0, 638))
self.assertEqual(histogram("P"), (256, 0, 1871))
self.assertEqual(histogram("RGB"), (768, 4, 675))
self.assertEqual(histogram("RGBA"), (1024, 0, 16384))
self.assertEqual(histogram("CMYK"), (1024, 0, 16384))
self.assertEqual(histogram("YCbCr"), (768, 0, 741))
self.assertEqual(histogram("YCbCr"), (768, 0, 1908))
if __name__ == '__main__':

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
from PIL import Image
@ -7,7 +7,7 @@ class TestImageMode(PillowTestCase):
def test_sanity(self):
im = lena()
im = hopper()
im.mode
from PIL import ImageMode

View File

@ -1,11 +1,11 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
class TestImageOffset(PillowTestCase):
def test_offset(self):
im1 = lena()
im1 = hopper()
im2 = self.assert_warning(DeprecationWarning, lambda: im1.offset(10))
self.assertEqual(im1.getpixel((0, 0)), im2.getpixel((10, 10)))

View File

@ -1,10 +1,10 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
class TestImagePoint(PillowTestCase):
def test_sanity(self):
im = lena()
im = hopper()
self.assertRaises(ValueError, lambda: im.point(list(range(256))))
im.point(list(range(256))*3)
@ -26,12 +26,12 @@ class TestImagePoint(PillowTestCase):
# see https://github.com/python-pillow/Pillow/issues/484
# self.skipKnownBadTest(msg="Too Slow on pypy", interpreter='pypy')
im = lena("I")
im = hopper("I")
im.point(list(range(256))*256, 'L')
def test_f_lut(self):
""" Tests for floating point lut of 8bit gray image """
im = lena('L')
im = hopper('L')
lut = [0.5 * float(x) for x in range(256)]
out = im.point(lut, 'F')

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
import sys
@ -9,7 +9,7 @@ class TestImagePutData(PillowTestCase):
def test_sanity(self):
im1 = lena()
im1 = hopper()
data = list(im1.getdata())
@ -46,7 +46,7 @@ class TestImagePutData(PillowTestCase):
im.putdata(list(range(256))*256)
def test_mode_i(self):
src = lena('L')
src = hopper('L')
data = list(src.getdata())
im = Image.new('I', src.size, 0)
im.putdata(data, 2, 256)
@ -55,7 +55,7 @@ class TestImagePutData(PillowTestCase):
self.assertEqual(list(im.getdata()), target)
def test_mode_F(self):
src = lena('L')
src = hopper('L')
data = list(src.getdata())
im = Image.new('F', src.size, 0)
im.putdata(data, 2.0, 256.0)

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
from PIL import ImagePalette
@ -7,7 +7,7 @@ class TestImagePutPalette(PillowTestCase):
def test_putpalette(self):
def palette(mode):
im = lena(mode).copy()
im = hopper(mode).copy()
im.putpalette(list(range(256))*3)
p = im.getpalette()
if p:
@ -23,7 +23,7 @@ class TestImagePutPalette(PillowTestCase):
self.assertRaises(ValueError, lambda: palette("YCbCr"))
def test_imagepalette(self):
im = lena("P")
im = hopper("P")
im.putpalette(ImagePalette.negative())
im.putpalette(ImagePalette.random())
im.putpalette(ImagePalette.sepia())

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
from PIL import Image
@ -9,7 +9,7 @@ class TestImagePutPixel(PillowTestCase):
def test_sanity(self):
im1 = lena()
im1 = hopper()
im2 = Image.new(im1.mode, im1.size, 0)
for y in range(im1.size[1]):

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
from PIL import Image
@ -6,17 +6,17 @@ from PIL import Image
class TestImageQuantize(PillowTestCase):
def test_sanity(self):
im = lena()
im = hopper()
im = im.quantize()
self.assert_image(im, "P", im.size)
im = lena()
im = im.quantize(palette=lena("P"))
im = hopper()
im = im.quantize(palette=hopper("P"))
self.assert_image(im, "P", im.size)
def test_octree_quantize(self):
im = lena()
im = hopper()
im = im.quantize(100, Image.FASTOCTREE)
self.assert_image(im, "P", im.size)
@ -24,7 +24,7 @@ class TestImageQuantize(PillowTestCase):
assert len(im.getcolors()) == 100
def test_rgba_quantize(self):
im = lena('RGBA')
im = hopper('RGBA')
im.quantize()
self.assertRaises(Exception, lambda: im.quantize(method=0))

View File

@ -1,11 +1,11 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
class TestImageResize(PillowTestCase):
def test_resize(self):
def resize(mode, size):
out = lena(mode).resize(size)
out = hopper(mode).resize(size)
self.assertEqual(out.mode, mode)
self.assertEqual(out.size, size)
for mode in "1", "P", "L", "RGB", "I", "F":

View File

@ -1,11 +1,11 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
class TestImageRotate(PillowTestCase):
def test_rotate(self):
def rotate(mode):
im = lena(mode)
im = hopper(mode)
out = im.rotate(45)
self.assertEqual(out.mode, mode)
self.assertEqual(out.size, im.size) # default rotate clips output

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
from PIL import Image
@ -7,7 +7,7 @@ class TestImageSplit(PillowTestCase):
def test_split(self):
def split(mode):
layers = lena(mode).split()
layers = hopper(mode).split()
return [(i.mode, i.size[0], i.size[1]) for i in layers]
self.assertEqual(split("1"), [('1', 128, 128)])
self.assertEqual(split("L"), [('L', 128, 128)])
@ -30,16 +30,16 @@ class TestImageSplit(PillowTestCase):
def test_split_merge(self):
def split_merge(mode):
return Image.merge(mode, lena(mode).split())
self.assert_image_equal(lena("1"), split_merge("1"))
self.assert_image_equal(lena("L"), split_merge("L"))
self.assert_image_equal(lena("I"), split_merge("I"))
self.assert_image_equal(lena("F"), split_merge("F"))
self.assert_image_equal(lena("P"), split_merge("P"))
self.assert_image_equal(lena("RGB"), split_merge("RGB"))
self.assert_image_equal(lena("RGBA"), split_merge("RGBA"))
self.assert_image_equal(lena("CMYK"), split_merge("CMYK"))
self.assert_image_equal(lena("YCbCr"), split_merge("YCbCr"))
return Image.merge(mode, hopper(mode).split())
self.assert_image_equal(hopper("1"), split_merge("1"))
self.assert_image_equal(hopper("L"), split_merge("L"))
self.assert_image_equal(hopper("I"), split_merge("I"))
self.assert_image_equal(hopper("F"), split_merge("F"))
self.assert_image_equal(hopper("P"), split_merge("P"))
self.assert_image_equal(hopper("RGB"), split_merge("RGB"))
self.assert_image_equal(hopper("RGBA"), split_merge("RGBA"))
self.assert_image_equal(hopper("CMYK"), split_merge("CMYK"))
self.assert_image_equal(hopper("YCbCr"), split_merge("YCbCr"))
def test_split_open(self):
codecs = dir(Image.core)
@ -50,7 +50,7 @@ class TestImageSplit(PillowTestCase):
file = self.tempfile("temp.pcx")
def split_open(mode):
lena(mode).save(file)
hopper(mode).save(file)
im = Image.open(file)
return len(im.split())
self.assertEqual(split_open("1"), 1)

View File

@ -1,38 +1,38 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
class TestImageThumbnail(PillowTestCase):
def test_sanity(self):
im = lena()
im = hopper()
im.thumbnail((100, 100))
self.assert_image(im, im.mode, (100, 100))
def test_aspect(self):
im = lena()
im = hopper()
im.thumbnail((100, 100))
self.assert_image(im, im.mode, (100, 100))
im = lena().resize((128, 256))
im = hopper().resize((128, 256))
im.thumbnail((100, 100))
self.assert_image(im, im.mode, (50, 100))
im = lena().resize((128, 256))
im = hopper().resize((128, 256))
im.thumbnail((50, 100))
self.assert_image(im, im.mode, (50, 100))
im = lena().resize((256, 128))
im = hopper().resize((256, 128))
im.thumbnail((100, 100))
self.assert_image(im, im.mode, (100, 50))
im = lena().resize((256, 128))
im = hopper().resize((256, 128))
im.thumbnail((100, 50))
self.assert_image(im, im.mode, (100, 50))
im = lena().resize((128, 128))
im = hopper().resize((128, 128))
im.thumbnail((100, 100))
self.assert_image(im, im.mode, (100, 100))

View File

@ -1,14 +1,14 @@
from helper import unittest, PillowTestCase, lena, fromstring
from helper import unittest, PillowTestCase, hopper, fromstring
class TestImageToBitmap(PillowTestCase):
def test_sanity(self):
self.assertRaises(ValueError, lambda: lena().tobitmap())
lena().convert("1").tobitmap()
self.assertRaises(ValueError, lambda: hopper().tobitmap())
hopper().convert("1").tobitmap()
im1 = lena().convert("1")
im1 = hopper().convert("1")
bitmap = im1.tobitmap()

View File

@ -1,10 +1,10 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
class TestImageToBytes(PillowTestCase):
def test_sanity(self):
data = lena().tobytes()
data = hopper().tobytes()
self.assertTrue(isinstance(data, bytes))
if __name__ == '__main__':

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
from PIL import Image
@ -22,7 +22,7 @@ class TestImageTransform(PillowTestCase):
im.transform((100, 100), transform)
def test_extent(self):
im = lena('RGB')
im = hopper('RGB')
(w, h) = im.size
transformed = im.transform(im.size, Image.EXTENT,
(0, 0,
@ -32,11 +32,11 @@ class TestImageTransform(PillowTestCase):
scaled = im.resize((w*2, h*2), Image.BILINEAR).crop((0, 0, w, h))
# undone -- precision?
self.assert_image_similar(transformed, scaled, 10)
self.assert_image_similar(transformed, scaled, 23)
def test_quad(self):
# one simple quad transform, equivalent to scale & crop upper left quad
im = lena('RGB')
im = hopper('RGB')
(w, h) = im.size
transformed = im.transform(im.size, Image.QUAD,
(0, 0, 0, h//2,
@ -49,8 +49,8 @@ class TestImageTransform(PillowTestCase):
self.assert_image_equal(transformed, scaled)
def test_mesh(self):
# this should be a checkerboard of halfsized lenas in ul, lr
im = lena('RGBA')
# this should be a checkerboard of halfsized hoppers in ul, lr
im = hopper('RGBA')
(w, h) = im.size
transformed = im.transform(im.size, Image.MESH,
[((0, 0, w//2, h//2), # box

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
from PIL import Image
@ -13,7 +13,7 @@ class TestImageTranspose(PillowTestCase):
def test_sanity(self):
im = lena()
im = hopper()
im.transpose(FLIP_LEFT_RIGHT)
im.transpose(FLIP_TOP_BOTTOM)
@ -24,7 +24,7 @@ class TestImageTranspose(PillowTestCase):
def test_roundtrip(self):
im = lena()
im = hopper()
def transpose(first, second):
return im.transpose(first).transpose(second)

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
from PIL import Image
from PIL import ImageChops
@ -8,7 +8,7 @@ class TestImageChops(PillowTestCase):
def test_sanity(self):
im = lena("L")
im = hopper("L")
ImageChops.constant(im, 128)
ImageChops.duplicate(im)

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
from PIL import Image
from PIL import ImageColor
@ -34,7 +34,7 @@ POINTS2 = [10, 10, 20, 40, 30, 30]
class TestImageDraw(PillowTestCase):
def test_sanity(self):
im = lena("RGB").copy()
im = hopper("RGB").copy()
draw = ImageDraw.ImageDraw(im)
draw = ImageDraw.Draw(im)
@ -45,7 +45,7 @@ class TestImageDraw(PillowTestCase):
draw.rectangle(list(range(4)))
def test_deprecated(self):
im = lena().copy()
im = hopper().copy()
draw = ImageDraw.Draw(im)

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
from PIL import Image
from PIL import ImageEnhance
@ -10,10 +10,10 @@ class TestImageEnhance(PillowTestCase):
# FIXME: assert_image
# Implicit asserts no exception:
ImageEnhance.Color(lena()).enhance(0.5)
ImageEnhance.Contrast(lena()).enhance(0.5)
ImageEnhance.Brightness(lena()).enhance(0.5)
ImageEnhance.Sharpness(lena()).enhance(0.5)
ImageEnhance.Color(hopper()).enhance(0.5)
ImageEnhance.Contrast(hopper()).enhance(0.5)
ImageEnhance.Brightness(hopper()).enhance(0.5)
ImageEnhance.Sharpness(hopper()).enhance(0.5)
def test_crash(self):
@ -22,6 +22,34 @@ class TestImageEnhance(PillowTestCase):
ImageEnhance.Sharpness(im).enhance(0.5)
def _half_transparent_image(self):
# returns an image, half transparent, half solid
im = hopper('RGB')
transparent = Image.new('L', im.size, 0)
solid = Image.new('L', (im.size[0]//2, im.size[1]), 255)
transparent.paste(solid, (0,0))
im.putalpha(transparent)
return im
def _check_alpha(self,im, original, op, amount):
self.assertEqual(im.getbands(), original.getbands())
self.assert_image_equal(im.split()[-1], original.split()[-1],
"Diff on %s: %s" % (op, amount))
def test_alpha(self):
# Issue https://github.com/python-pillow/Pillow/issues/899
# Is alpha preserved through image enhancement?
original = self._half_transparent_image()
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)
if __name__ == '__main__':
unittest.main()

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena, fromstring, tostring
from helper import unittest, PillowTestCase, hopper, fromstring, tostring
from io import BytesIO
@ -20,7 +20,7 @@ class TestImageFile(PillowTestCase):
def roundtrip(format):
im = lena("L").resize((1000, 1000))
im = hopper("L").resize((1000, 1000))
if format in ("MSP", "XBM"):
im = im.convert("1")
@ -73,7 +73,7 @@ class TestImageFile(PillowTestCase):
def test_safeblock(self):
im1 = lena()
im1 = hopper()
if "zip_encoder" not in codecs:
self.skipTest("PNG (zlib) encoder not available")

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena, tostring
from helper import unittest, PillowTestCase, hopper, tostring
from PIL import Image
from PIL import ImageFileIO
@ -19,7 +19,7 @@ class TestImageFileIo(PillowTestCase):
def close(self):
pass
im1 = lena()
im1 = hopper()
io = ImageFileIO.ImageFileIO(DumbFile(tostring(im1, "PPM")))

View File

@ -1,5 +1,7 @@
from helper import unittest, PillowTestCase
import sys
try:
from PIL import ImageGrab
@ -19,6 +21,27 @@ except ImportError:
self.skipTest("ImportError")
class TestImageGrabImport(PillowTestCase):
def test_import(self):
# Arrange
exception = None
# Act
try:
from PIL import ImageGrab
ImageGrab.__name__ # dummy to prevent Pyflakes warning
except Exception as e:
exception = e
# Assert
if sys.platform == 'win32':
self.assertIsNone(exception, None)
else:
self.assertIsInstance(exception, ImportError)
self.assertEqual(str(exception), "ImageGrab is Windows only")
if __name__ == '__main__':
unittest.main()

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
from PIL import ImageOps
@ -14,65 +14,65 @@ class TestImageOps(PillowTestCase):
def test_sanity(self):
ImageOps.autocontrast(lena("L"))
ImageOps.autocontrast(lena("RGB"))
ImageOps.autocontrast(hopper("L"))
ImageOps.autocontrast(hopper("RGB"))
ImageOps.autocontrast(lena("L"), cutoff=10)
ImageOps.autocontrast(lena("L"), ignore=[0, 255])
ImageOps.autocontrast(hopper("L"), cutoff=10)
ImageOps.autocontrast(hopper("L"), ignore=[0, 255])
ImageOps.colorize(lena("L"), (0, 0, 0), (255, 255, 255))
ImageOps.colorize(lena("L"), "black", "white")
ImageOps.colorize(hopper("L"), (0, 0, 0), (255, 255, 255))
ImageOps.colorize(hopper("L"), "black", "white")
ImageOps.crop(lena("L"), 1)
ImageOps.crop(lena("RGB"), 1)
ImageOps.crop(hopper("L"), 1)
ImageOps.crop(hopper("RGB"), 1)
ImageOps.deform(lena("L"), self.deformer)
ImageOps.deform(lena("RGB"), self.deformer)
ImageOps.deform(hopper("L"), self.deformer)
ImageOps.deform(hopper("RGB"), self.deformer)
ImageOps.equalize(lena("L"))
ImageOps.equalize(lena("RGB"))
ImageOps.equalize(hopper("L"))
ImageOps.equalize(hopper("RGB"))
ImageOps.expand(lena("L"), 1)
ImageOps.expand(lena("RGB"), 1)
ImageOps.expand(lena("L"), 2, "blue")
ImageOps.expand(lena("RGB"), 2, "blue")
ImageOps.expand(hopper("L"), 1)
ImageOps.expand(hopper("RGB"), 1)
ImageOps.expand(hopper("L"), 2, "blue")
ImageOps.expand(hopper("RGB"), 2, "blue")
ImageOps.fit(lena("L"), (128, 128))
ImageOps.fit(lena("RGB"), (128, 128))
ImageOps.fit(hopper("L"), (128, 128))
ImageOps.fit(hopper("RGB"), (128, 128))
ImageOps.flip(lena("L"))
ImageOps.flip(lena("RGB"))
ImageOps.flip(hopper("L"))
ImageOps.flip(hopper("RGB"))
ImageOps.grayscale(lena("L"))
ImageOps.grayscale(lena("RGB"))
ImageOps.grayscale(hopper("L"))
ImageOps.grayscale(hopper("RGB"))
ImageOps.invert(lena("L"))
ImageOps.invert(lena("RGB"))
ImageOps.invert(hopper("L"))
ImageOps.invert(hopper("RGB"))
ImageOps.mirror(lena("L"))
ImageOps.mirror(lena("RGB"))
ImageOps.mirror(hopper("L"))
ImageOps.mirror(hopper("RGB"))
ImageOps.posterize(lena("L"), 4)
ImageOps.posterize(lena("RGB"), 4)
ImageOps.posterize(hopper("L"), 4)
ImageOps.posterize(hopper("RGB"), 4)
ImageOps.solarize(lena("L"))
ImageOps.solarize(lena("RGB"))
ImageOps.solarize(hopper("L"))
ImageOps.solarize(hopper("RGB"))
def test_1pxfit(self):
# Division by zero in equalize if image is 1 pixel high
newimg = ImageOps.fit(lena("RGB").resize((1, 1)), (35, 35))
newimg = ImageOps.fit(hopper("RGB").resize((1, 1)), (35, 35))
self.assertEqual(newimg.size, (35, 35))
newimg = ImageOps.fit(lena("RGB").resize((1, 100)), (35, 35))
newimg = ImageOps.fit(hopper("RGB").resize((1, 100)), (35, 35))
self.assertEqual(newimg.size, (35, 35))
newimg = ImageOps.fit(lena("RGB").resize((100, 1)), (35, 35))
newimg = ImageOps.fit(hopper("RGB").resize((100, 1)), (35, 35))
self.assertEqual(newimg.size, (35, 35))
def test_pil163(self):
# Division by zero in equalize if < 255 pixels in image (@PIL163)
i = lena("RGB").resize((15, 16))
i = hopper("RGB").resize((15, 16))
ImageOps.equalize(i.convert("L"))
ImageOps.equalize(i.convert("P"))

View File

@ -4,7 +4,7 @@ from PIL import Image
from PIL import ImageOps
from PIL import ImageFilter
im = Image.open("Tests/images/lena.ppm")
im = Image.open("Tests/images/hopper.ppm")
class TestImageOpsUsm(PillowTestCase):

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
try:
from PIL import ImageQt
@ -44,7 +44,7 @@ class TestImageQt(PillowTestCase):
def test_image(self):
for mode in ('1', 'RGB', 'RGBA', 'L', 'P'):
ImageQt.ImageQt(lena(mode))
ImageQt.ImageQt(hopper(mode))
if __name__ == '__main__':

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
from PIL import Image, ImageSequence, TiffImagePlugin
@ -9,7 +9,7 @@ class TestImageSequence(PillowTestCase):
file = self.tempfile("temp.im")
im = lena("RGB")
im = hopper("RGB")
im.save(file)
seq = ImageSequence.Iterator(im)

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
from PIL import Image
from PIL import ImageStat
@ -8,7 +8,7 @@ class TestImageStat(PillowTestCase):
def test_sanity(self):
im = lena()
im = hopper()
st = ImageStat.Stat(im)
st = ImageStat.Stat(im.histogram())
@ -28,18 +28,18 @@ class TestImageStat(PillowTestCase):
self.assertRaises(TypeError, lambda: ImageStat.Stat(1))
def test_lena(self):
def test_hopper(self):
im = lena()
im = hopper()
st = ImageStat.Stat(im)
# verify a few values
self.assertEqual(st.extrema[0], (61, 255))
self.assertEqual(st.median[0], 197)
self.assertEqual(st.sum[0], 2954416)
self.assertEqual(st.sum[1], 2027250)
self.assertEqual(st.sum[2], 1727331)
self.assertEqual(st.extrema[0], (0, 255))
self.assertEqual(st.median[0], 72)
self.assertEqual(st.sum[0], 1470218)
self.assertEqual(st.sum[1], 1311896)
self.assertEqual(st.sum[2], 1563008)
def test_constant(self):

View File

@ -19,7 +19,7 @@ import locale
# one of string.whitespace is not freely convertable into ascii.
path = "Tests/images/lena.jpg"
path = "Tests/images/hopper.jpg"
class TestLocale(PillowTestCase):

View File

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

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena
from helper import unittest, PillowTestCase, hopper
from PIL import Image
@ -90,7 +90,7 @@ class TestNumpy(PillowTestCase):
def test_to_array(self):
def _to_array(mode, dtype):
img = lena(mode)
img = hopper(mode)
np_img = numpy.array(img)
self._test_img_equals_nparray(img, np_img)
self.assertEqual(np_img.dtype, numpy.dtype(dtype))
@ -117,7 +117,7 @@ class TestNumpy(PillowTestCase):
data = list(range(256))*3
lut = numpy.array(data, dtype='uint8')
im = lena()
im = hopper()
im.point(lut)

View File

@ -6,7 +6,8 @@ from PIL import Image
class TestPickle(PillowTestCase):
def helper_pickle_file(self, pickle, protocol=0):
im = Image.open('Tests/images/lena.jpg')
# Arrange
im = Image.open('Tests/images/hopper.jpg')
filename = self.tempfile('temp.pkl')
# Act
@ -19,7 +20,7 @@ class TestPickle(PillowTestCase):
self.assertEqual(im, loaded_im)
def helper_pickle_string(
self, pickle, protocol=0, file='Tests/images/lena.jpg'):
self, pickle, protocol=0, file='Tests/images/hopper.jpg'):
im = Image.open(file)
# Act

View File

@ -11,7 +11,7 @@ try:
except:
format = "PNG"
im = Image.open("Tests/images/lena.ppm")
im = Image.open("Tests/images/hopper.ppm")
im.load()
queue = queue.Queue()

View File

@ -221,9 +221,10 @@ int ImagingLibTiffDecode(Imaging im, ImagingCodecState state, UINT8* buffer, int
}
if (clientstate->ifd){
int rv;
unsigned int ifdoffset = clientstate->ifd;
TRACE(("reading tiff ifd %d\n", ifdoffset));
int rv = TIFFSetSubDirectory(tiff, ifdoffset);
rv = TIFFSetSubDirectory(tiff, ifdoffset);
if (!rv){
TRACE(("error in TIFFSetSubDirectory"));
return -1;