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) 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] [joshware, wiredfool]
- EpsFilePlugin Speed improvements #886 - EpsFilePlugin Speed improvements #886
[wiredfool, karstenw] [wiredfool, karstenw]
- Don't resize if already the right size. - Don't resize if already the right size #892
[radarhere] [radarhere]
- Fix for reading multipage TIFFs #885 - 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 - Fork the repo
- Make a branch - Make a branch
- Add your changes + Tests - 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. - Push to your fork, and make a pull request.
A few guidelines: A few guidelines:

View File

@ -531,7 +531,7 @@ class Image:
""" """
Closes the file pointer, if possible. 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. The image data will be unusable afterward.
This function is only required to close images that have not This function is only required to close images that have not
@ -869,7 +869,17 @@ class Image:
trns = trns_im.getpixel((0, 0)) trns = trns_im.getpixel((0, 0))
elif self.mode == 'P' and mode == 'RGBA': elif self.mode == 'P' and mode == 'RGBA':
t = self.info['transparency']
delete_trns = True 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: if mode == "P" and palette == ADAPTIVE:
im = self.im.quantize(colors) im = self.im.quantize(colors)

View File

@ -47,8 +47,11 @@ class Color(_Enhance):
""" """
def __init__(self, image): def __init__(self, image):
self.image = 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): class Contrast(_Enhance):
"""Adjust image contrast. """Adjust image contrast.
@ -62,6 +65,9 @@ class Contrast(_Enhance):
mean = int(ImageStat.Stat(image.convert("L")).mean[0] + 0.5) mean = int(ImageStat.Stat(image.convert("L")).mean[0] + 0.5)
self.degenerate = Image.new("L", image.size, mean).convert(image.mode) 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): class Brightness(_Enhance):
"""Adjust image brightness. """Adjust image brightness.
@ -74,6 +80,9 @@ class Brightness(_Enhance):
self.image = image self.image = image
self.degenerate = Image.new(image.mode, image.size, 0) self.degenerate = Image.new(image.mode, image.size, 0)
if 'A' in image.getbands():
self.degenerate.putalpha(image.split()[-1])
class Sharpness(_Enhance): class Sharpness(_Enhance):
"""Adjust image sharpness. """Adjust image sharpness.
@ -85,3 +94,6 @@ class Sharpness(_Enhance):
def __init__(self, image): def __init__(self, image):
self.image = image self.image = image
self.degenerate = image.filter(ImageFilter.SMOOTH) 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 from PIL import Image
import sys
if sys.platform != "win32":
raise ImportError("ImageGrab is Windows only")
try: try:
# built-in driver (1.1.3 and later) # 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 .. image:: https://coveralls.io/repos/python-pillow/Pillow/badge.png?branch=master
:target: https://coveralls.io/r/python-pillow/Pillow?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. # Not running this test by default. No DOS against Travis CI.
@ -39,7 +39,7 @@ def timer(func, label, *args):
class BenchCffiAccess(PillowTestCase): class BenchCffiAccess(PillowTestCase):
def test_direct(self): def test_direct(self):
im = lena() im = hopper()
im.load() im.load()
# im = Image.new( "RGB", (2000, 2000), (1, 3, 2)) # im = Image.new( "RGB", (2000, 2000), (1, 3, 2))
caccess = im.im.pixel_access(False) caccess = im.im.pixel_access(False)

View File

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

View File

@ -157,7 +157,7 @@ class PillowTestCase(unittest.TestCase):
raise IOError() raise IOError()
outfile = self.tempfile("temp.png") outfile = self.tempfile("temp.png")
if command_succeeds(['convert', f, outfile]): if command_succeeds([IMCONVERT, f, outfile]):
from PIL import Image from PIL import Image
return Image.open(outfile) return Image.open(outfile)
raise IOError() raise IOError()
@ -182,6 +182,7 @@ def tostring(im, format, **options):
return out.getvalue() return out.getvalue()
# Note: hopper() should be used in place of lena(), which will be removed.
def hopper(mode="RGB", cache={}): def hopper(mode="RGB", cache={}):
from PIL import Image from PIL import Image
im = None im = None
@ -193,15 +194,16 @@ def hopper(mode="RGB", cache={}):
if mode == "RGB": if mode == "RGB":
im = Image.open("Tests/images/hopper.ppm") im = Image.open("Tests/images/hopper.ppm")
elif mode == "F": elif mode == "F":
im = lena("L").convert(mode) im = hopper("L").convert(mode)
elif mode[:4] == "I;16": elif mode[:4] == "I;16":
im = lena("I").convert(mode) im = hopper("I").convert(mode)
else: else:
im = lena("RGB").convert(mode) im = hopper("RGB").convert(mode)
# cache[mode] = im # cache[mode] = im
return im return im
# Note: hopper() should be used instead lena(), which will be removed.
def lena(mode="RGB", cache={}): def lena(mode="RGB", cache={}):
from PIL import Image from PIL import Image
im = None im = None
@ -251,6 +253,14 @@ def netpbm_available():
def imagemagick_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 # 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: try:
import cffi import cffi
@ -62,16 +62,16 @@ class TestCffi(PillowTestCase):
self.assertEqual(access[(x, y)], caccess[(x, y)]) self.assertEqual(access[(x, y)], caccess[(x, y)])
def test_get_vs_c(self): def test_get_vs_c(self):
rgb = lena('RGB') rgb = hopper('RGB')
rgb.load() rgb.load()
self._test_get_access(rgb) self._test_get_access(rgb)
self._test_get_access(lena('RGBA')) self._test_get_access(hopper('RGBA'))
self._test_get_access(lena('L')) self._test_get_access(hopper('L'))
self._test_get_access(lena('LA')) self._test_get_access(hopper('LA'))
self._test_get_access(lena('1')) self._test_get_access(hopper('1'))
self._test_get_access(lena('P')) self._test_get_access(hopper('P'))
# self._test_get_access(lena('PA')) # PA -- how do I make a PA image? # self._test_get_access(hopper('PA')) # PA -- how do I make a PA image?
self._test_get_access(lena('F')) self._test_get_access(hopper('F'))
im = Image.new('I;16', (10, 10), 40000) im = Image.new('I;16', (10, 10), 40000)
self._test_get_access(im) self._test_get_access(im)
@ -104,16 +104,16 @@ class TestCffi(PillowTestCase):
self.assertEqual(color, caccess[(x, y)]) self.assertEqual(color, caccess[(x, y)])
def test_set_vs_c(self): def test_set_vs_c(self):
rgb = lena('RGB') rgb = hopper('RGB')
rgb.load() rgb.load()
self._test_set_access(rgb, (255, 128, 0)) self._test_set_access(rgb, (255, 128, 0))
self._test_set_access(lena('RGBA'), (255, 192, 128, 0)) self._test_set_access(hopper('RGBA'), (255, 192, 128, 0))
self._test_set_access(lena('L'), 128) self._test_set_access(hopper('L'), 128)
self._test_set_access(lena('LA'), (128, 128)) self._test_set_access(hopper('LA'), (128, 128))
self._test_set_access(lena('1'), 255) self._test_set_access(hopper('1'), 255)
self._test_set_access(lena('P'), 128) self._test_set_access(hopper('P'), 128)
# self._test_set_access(i, (128, 128)) #PA -- undone how to make # 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) im = Image.new('I;16', (10, 10), 40000)
self._test_set_access(im, 45000) self._test_set_access(im, 45000)

View File

@ -2,7 +2,7 @@ from helper import unittest, PillowTestCase
from PIL import Image from PIL import Image
test_file = "Tests/images/lena.ppm" TEST_FILE = "Tests/images/hopper.ppm"
ORIGINAL_LIMIT = Image.MAX_IMAGE_PIXELS ORIGINAL_LIMIT = Image.MAX_IMAGE_PIXELS
@ -15,7 +15,7 @@ class TestDecompressionBomb(PillowTestCase):
def test_no_warning_small_file(self): def test_no_warning_small_file(self):
# Implicit assert: no warning. # Implicit assert: no warning.
# A warning would cause a failure. # A warning would cause a failure.
Image.open(test_file) Image.open(TEST_FILE)
def test_no_warning_no_limit(self): def test_no_warning_no_limit(self):
# Arrange # Arrange
@ -26,7 +26,7 @@ class TestDecompressionBomb(PillowTestCase):
# Act / Assert # Act / Assert
# Implicit assert: no warning. # Implicit assert: no warning.
# A warning would cause a failure. # A warning would cause a failure.
Image.open(test_file) Image.open(TEST_FILE)
def test_warning(self): def test_warning(self):
# Arrange # Arrange
@ -37,7 +37,7 @@ class TestDecompressionBomb(PillowTestCase):
# Act / Assert # Act / Assert
self.assert_warning( self.assert_warning(
Image.DecompressionBombWarning, Image.DecompressionBombWarning,
lambda: Image.open(test_file)) lambda: Image.open(TEST_FILE))
if __name__ == '__main__': if __name__ == '__main__':
unittest.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 from PIL import Image
import io import io
@ -18,16 +18,16 @@ class TestFileBmp(PillowTestCase):
self.assertEqual(reloaded.format, "BMP") self.assertEqual(reloaded.format, "BMP")
def test_sanity(self): def test_sanity(self):
self.roundtrip(lena()) self.roundtrip(hopper())
self.roundtrip(lena("1")) self.roundtrip(hopper("1"))
self.roundtrip(lena("L")) self.roundtrip(hopper("L"))
self.roundtrip(lena("P")) self.roundtrip(hopper("P"))
self.roundtrip(lena("RGB")) self.roundtrip(hopper("RGB"))
def test_save_to_bytes(self): def test_save_to_bytes(self):
output = io.BytesIO() output = io.BytesIO()
im = lena() im = hopper()
im.save(output, "BMP") im.save(output, "BMP")
output.seek(0) output.seek(0)
@ -41,7 +41,7 @@ class TestFileBmp(PillowTestCase):
dpi = (72, 72) dpi = (72, 72)
output = io.BytesIO() output = io.BytesIO()
im = lena() im = hopper()
im.save(output, "BMP", dpi=dpi) im.save(output, "BMP", dpi=dpi)
output.seek(0) 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 from PIL import Image, IptcImagePlugin
@ -21,7 +21,7 @@ class TestFileIptc(PillowTestCase):
def test_getiptcinfo_jpg_none(self): def test_getiptcinfo_jpg_none(self):
# Arrange # Arrange
im = lena() im = hopper()
# Act # Act
iptc = IptcImagePlugin.getiptcinfo(im) 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 import os
@ -268,7 +268,7 @@ class TestFileLibTiff(LibTiffTestCase):
self.assert_image_equal(im, im2) self.assert_image_equal(im, im2)
def test_compressions(self): def test_compressions(self):
im = lena('RGB') im = hopper('RGB')
out = self.tempfile('temp.tif') out = self.tempfile('temp.tif')
for compression in ('packbits', 'tiff_lzw'): for compression in ('packbits', 'tiff_lzw'):
@ -281,7 +281,7 @@ class TestFileLibTiff(LibTiffTestCase):
self.assert_image_similar(im, im2, 30) self.assert_image_similar(im, im2, 30)
def test_cmyk_save(self): def test_cmyk_save(self):
im = lena('CMYK') im = hopper('CMYK')
out = self.tempfile('temp.tif') out = self.tempfile('temp.tif')
im.save(out, compression='tiff_adobe_deflate') 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 to output on stderr from the error thrown by libtiff. We need to
capture that but not now""" capture that but not now"""
im = lena('RGB') im = hopper('RGB')
out = self.tempfile('temp.tif') out = self.tempfile('temp.tif')
self.assertRaises( self.assertRaises(
@ -332,12 +332,12 @@ class TestFileLibTiff(LibTiffTestCase):
self.assertFalse(im.tag.next) self.assertFalse(im.tag.next)
self.assertEqual(im.size, (20,20)) self.assertEqual(im.size, (20,20))
self.assertEqual(im.convert('RGB').getpixel((0,0)), (0,0,255)) self.assertEqual(im.convert('RGB').getpixel((0,0)), (0,0,255))
TiffImagePlugin.READ_LIBTIFF = False TiffImagePlugin.READ_LIBTIFF = False
def test__next(self): def test__next(self):
TiffImagePlugin.READ_LIBTIFF = True TiffImagePlugin.READ_LIBTIFF = True
im = Image.open('Tests/images/lena.tif') im = Image.open('Tests/images/hopper.tif')
self.assertFalse(im.tag.next) self.assertFalse(im.tag.next)
im.load() im.load()
self.assertFalse(im.tag.next) 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 from PIL import Image
@ -9,7 +9,7 @@ class TestFileMsp(PillowTestCase):
file = self.tempfile("temp.msp") file = self.tempfile("temp.msp")
lena("1").save(file) hopper("1").save(file)
im = Image.open(file) im = Image.open(file)
im.load() 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 import os.path
@ -8,7 +8,7 @@ class TestFilePalm(PillowTestCase):
def helper_save_as_palm(self, mode): def helper_save_as_palm(self, mode):
# Arrange # Arrange
im = lena(mode) im = hopper(mode)
outfile = self.tempfile("temp_" + mode + ".palm") outfile = self.tempfile("temp_" + mode + ".palm")
# Act # Act
@ -22,7 +22,7 @@ class TestFilePalm(PillowTestCase):
if not self._roundtrip: if not self._roundtrip:
return return
im = lena(mode) im = hopper(mode)
outfile = self.tempfile("temp.palm") outfile = self.tempfile("temp.palm")
im.save(outfile) 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 from PIL import Image
@ -17,7 +17,7 @@ class TestFilePcx(PillowTestCase):
def test_sanity(self): def test_sanity(self):
for mode in ('1', 'L', 'P', 'RGB'): for mode in ('1', 'L', 'P', 'RGB'):
self._roundtrip(lena(mode)) self._roundtrip(hopper(mode))
def test_odd(self): def test_odd(self):
# see issue #523, odd sized images should have a stride that's even. # 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'): for mode in ('1', 'L', 'P', 'RGB'):
# larger, odd sized images are better here to ensure that # larger, odd sized images are better here to ensure that
# we handle interrupted scan lines properly. # we handle interrupted scan lines properly.
self._roundtrip(lena(mode).resize((511, 511))) self._roundtrip(hopper(mode).resize((511, 511)))
def test_pil184(self): def test_pil184(self):
# Check reading of files where xmin/xmax is not zero. # 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 import os.path
@ -7,7 +7,7 @@ class TestFilePdf(PillowTestCase):
def helper_save_as_pdf(self, mode): def helper_save_as_pdf(self, mode):
# Arrange # Arrange
im = lena(mode) im = hopper(mode)
outfile = self.tempfile("temp_" + mode + ".pdf") outfile = self.tempfile("temp_" + mode + ".pdf")
# Act # Act

View File

@ -351,7 +351,8 @@ class TestFilePng(PillowTestCase):
im2 = Image.open(f) im2 = Image.open(f)
self.assertIn('transparency', im2.info) 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): def test_save_icc_profile_none(self):
# check saving files with an ICC profile set to None (omit profile) # 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 from PIL import Image
# sample ppm stream # sample ppm stream
file = "Tests/images/lena.ppm" file = "Tests/images/hopper.ppm"
data = open(file, "rb").read() 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 from PIL import Image, TiffImagePlugin
@ -9,7 +9,7 @@ class TestFileTiff(PillowTestCase):
file = self.tempfile("temp.tif") file = self.tempfile("temp.tif")
lena("RGB").save(file) hopper("RGB").save(file)
im = Image.open(file) im = Image.open(file)
im.load() im.load()
@ -17,19 +17,19 @@ class TestFileTiff(PillowTestCase):
self.assertEqual(im.size, (128, 128)) self.assertEqual(im.size, (128, 128))
self.assertEqual(im.format, "TIFF") self.assertEqual(im.format, "TIFF")
lena("1").save(file) hopper("1").save(file)
im = Image.open(file) im = Image.open(file)
lena("L").save(file) hopper("L").save(file)
im = Image.open(file) im = Image.open(file)
lena("P").save(file) hopper("P").save(file)
im = Image.open(file) im = Image.open(file)
lena("RGB").save(file) hopper("RGB").save(file)
im = Image.open(file) im = Image.open(file)
lena("I").save(file) hopper("I").save(file)
im = Image.open(file) im = Image.open(file)
def test_mac_tiff(self): def test_mac_tiff(self):
@ -158,14 +158,14 @@ class TestFileTiff(PillowTestCase):
im.seek(2) im.seek(2)
im.load() im.load()
self.assertEqual(im.size, (20,20)) self.assertEqual(im.size, (20,20))
self.assertEqual(im.convert('RGB').getpixel((0,0)), (0,0,255)) self.assertEqual(im.convert('RGB').getpixel((0,0)), (0,0,255))
def test_multipage_last_frame(self): def test_multipage_last_frame(self):
im = Image.open('Tests/images/multipage-lastframe.tif') im = Image.open('Tests/images/multipage-lastframe.tif')
im.load() im.load()
self.assertEqual(im.size, (20,20)) self.assertEqual(im.size, (20,20))
self.assertEqual(im.convert('RGB').getpixel((0,0)), (0,0,255)) self.assertEqual(im.convert('RGB').getpixel((0,0)), (0,0,255))
def test___str__(self): def test___str__(self):
# Arrange # Arrange

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena from helper import unittest, PillowTestCase, hopper
from PIL import Image, TiffImagePlugin, TiffTags from PIL import Image, TiffImagePlugin, TiffTags
@ -13,7 +13,7 @@ class TestFileTiffMetadata(PillowTestCase):
data. https://github.com/python-pillow/Pillow/issues/291 data. https://github.com/python-pillow/Pillow/issues/291
""" """
img = lena() img = hopper()
textdata = "This is some arbitrary metadata for a text field" textdata = "This is some arbitrary metadata for a text field"
info = TiffImagePlugin.ImageFileDirectory() info = TiffImagePlugin.ImageFileDirectory()
@ -64,7 +64,7 @@ class TestFileTiffMetadata(PillowTestCase):
def test_write_metadata(self): def test_write_metadata(self):
""" Test metadata writing through the python code """ """ 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') f = self.tempfile('temp.tiff')
img.save(f, tiffinfo=img.tag) 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 from PIL import Image
@ -41,7 +41,7 @@ class TestFileWebpAlpha(PillowTestCase):
temp_file = self.tempfile("temp.webp") temp_file = self.tempfile("temp.webp")
# temp_file = "temp.webp" # temp_file = "temp.webp"
pil_image = lena('RGBA') pil_image = hopper('RGBA')
mask = Image.new("RGBA", (64, 64), (128, 128, 128, 128)) mask = Image.new("RGBA", (64, 64), (128, 128, 128, 128))
# Add some partially transparent bits: # 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 from PIL import Image
@ -23,7 +23,7 @@ class TestFileWebpLossless(PillowTestCase):
def test_write_lossless_rgb(self): def test_write_lossless_rgb(self):
temp_file = self.tempfile("temp.webp") 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 = Image.open(temp_file)
image.load() image.load()
@ -34,7 +34,7 @@ class TestFileWebpLossless(PillowTestCase):
image.load() image.load()
image.getdata() image.getdata()
self.assert_image_equal(image, lena("RGB")) self.assert_image_equal(image, hopper("RGB"))
if __name__ == '__main__': 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 from PIL import Image
@ -128,8 +128,8 @@ class TestFormatHSV(PillowTestCase):
3, "B conversion is wrong") 3, "B conversion is wrong")
def test_convert(self): def test_convert(self):
im = lena('RGB').convert('HSV') im = hopper('RGB').convert('HSV')
comparable = self.to_hsv_colorsys(lena('RGB')) comparable = self.to_hsv_colorsys(hopper('RGB'))
# print ([ord(x) for x in im.split()[0].tobytes()[:80]]) # print ([ord(x) for x in im.split()[0].tobytes()[:80]])
# print ([ord(x) for x in comparable.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") 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(hopper('RGB'))
converted = comparable.convert('RGB') converted = comparable.convert('RGB')
comparable = self.to_rgb_colorsys(comparable) 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 from PIL import Image
im = lena().resize((128, 100)) im = hopper().resize((128, 100))
class TestImageArray(PillowTestCase): 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 from PIL import Image
@ -15,13 +15,13 @@ class TestImageConvert(PillowTestCase):
modes = "1", "L", "I", "F", "RGB", "RGBA", "RGBX", "CMYK", "YCbCr" modes = "1", "L", "I", "F", "RGB", "RGBA", "RGBX", "CMYK", "YCbCr"
for mode in modes: for mode in modes:
im = lena(mode) im = hopper(mode)
for mode in modes: for mode in modes:
convert(im, mode) convert(im, mode)
def test_default(self): def test_default(self):
im = lena("P") im = hopper("P")
self.assert_image(im, "P", im.size) self.assert_image(im, "P", im.size)
im = im.convert() im = im.convert()
self.assert_image(im, "RGB", im.size) self.assert_image(im, "RGB", im.size)
@ -36,7 +36,7 @@ class TestImageConvert(PillowTestCase):
self.assertEqual(orig, converted) self.assertEqual(orig, converted)
def test_8bit(self): 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')) self._test_float_conversion(im.convert('L'))
def test_16bit(self): def test_16bit(self):
@ -48,8 +48,8 @@ class TestImageConvert(PillowTestCase):
self._test_float_conversion(im.convert('I')) self._test_float_conversion(im.convert('I'))
def test_rgba_p(self): def test_rgba_p(self):
im = lena('RGBA') im = hopper('RGBA')
im.putalpha(lena('L')) im.putalpha(hopper('L'))
converted = im.convert('P') converted = im.convert('P')
comparable = converted.convert('RGBA') comparable = converted.convert('RGBA')
@ -57,7 +57,7 @@ class TestImageConvert(PillowTestCase):
self.assert_image_similar(im, comparable, 20) self.assert_image_similar(im, comparable, 20)
def test_trns_p(self): def test_trns_p(self):
im = lena('P') im = hopper('P')
im.info['transparency'] = 0 im.info['transparency'] = 0
f = self.tempfile('temp.png') f = self.tempfile('temp.png')
@ -74,7 +74,7 @@ class TestImageConvert(PillowTestCase):
def test_trns_p_rgba(self): def test_trns_p_rgba(self):
# Arrange # Arrange
im = lena('P') im = hopper('P')
im.info['transparency'] = 128 im.info['transparency'] = 128
# Act # Act
@ -84,7 +84,7 @@ class TestImageConvert(PillowTestCase):
self.assertNotIn('transparency', rgba.info) self.assertNotIn('transparency', rgba.info)
def test_trns_l(self): def test_trns_l(self):
im = lena('L') im = hopper('L')
im.info['transparency'] = 128 im.info['transparency'] = 128
f = self.tempfile('temp.png') f = self.tempfile('temp.png')
@ -104,7 +104,7 @@ class TestImageConvert(PillowTestCase):
p.save(f) p.save(f)
def test_trns_RGB(self): def test_trns_RGB(self):
im = lena('RGB') im = hopper('RGB')
im.info['transparency'] = im.getpixel((0, 0)) im.info['transparency'] = im.getpixel((0, 0))
f = self.tempfile('temp.png') 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): class TestImageCopy(PillowTestCase):
def test_copy(self): def test_copy(self):
def copy(mode): def copy(mode):
im = lena(mode) im = hopper(mode)
out = im.copy() out = im.copy()
self.assertEqual(out.mode, mode) self.assertEqual(out.mode, mode)
self.assertEqual(out.size, im.size) 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 from PIL import Image
@ -7,7 +7,7 @@ class TestImageCrop(PillowTestCase):
def test_crop(self): def test_crop(self):
def crop(mode): 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.mode, mode)
self.assertEqual(out.size, (50, 50)) self.assertEqual(out.size, (50, 50))
for mode in "1", "P", "L", "RGB", "I", "F": 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 from PIL import Image
codecs = dir(Image.core) CODECS = dir(Image.core)
filename = "Tests/images/lena.jpg" FILENAME = "Tests/images/hopper.jpg"
data = tostring(Image.open(filename).resize((512, 512)), "JPEG") DATA = tostring(Image.open(FILENAME).resize((512, 512)), "JPEG")
def draft(mode, size): def draft(mode, size):
im = fromstring(data) im = fromstring(DATA)
im.draft(mode, size) im.draft(mode, size)
return im return im
@ -16,7 +16,7 @@ def draft(mode, size):
class TestImageDraft(PillowTestCase): class TestImageDraft(PillowTestCase):
def setUp(self): 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") self.skipTest("jpeg support not available")
def test_size(self): 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 Image
from PIL import ImageFilter from PIL import ImageFilter
@ -9,7 +9,7 @@ class TestImageFilter(PillowTestCase):
def test_sanity(self): def test_sanity(self):
def filter(filter): def filter(filter):
im = lena("L") im = hopper("L")
out = im.filter(filter) out = im.filter(filter)
self.assertEqual(out.mode, im.mode) self.assertEqual(out.mode, im.mode)
self.assertEqual(out.size, im.size) 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 from PIL import Image
@ -6,7 +6,7 @@ from PIL import Image
class TestImageFromBytes(PillowTestCase): class TestImageFromBytes(PillowTestCase):
def test_sanity(self): def test_sanity(self):
im1 = lena() im1 = hopper()
im2 = Image.frombytes(im1.mode, im1.size, im1.tobytes()) im2 = Image.frombytes(im1.mode, im1.size, im1.tobytes())
self.assert_image_equal(im1, im2) 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 from PIL import Image
@ -7,7 +7,7 @@ class TestImageGetBbox(PillowTestCase):
def test_sanity(self): def test_sanity(self):
bbox = lena().getbbox() bbox = hopper().getbbox()
self.assertIsInstance(bbox, tuple) self.assertIsInstance(bbox, tuple)
def test_bbox(self): 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): class TestImageGetColors(PillowTestCase):
@ -6,7 +6,7 @@ class TestImageGetColors(PillowTestCase):
def test_getcolors(self): def test_getcolors(self):
def getcolors(mode, limit=None): def getcolors(mode, limit=None):
im = lena(mode) im = hopper(mode)
if limit: if limit:
colors = im.getcolors(limit) colors = im.getcolors(limit)
else: else:
@ -16,37 +16,36 @@ class TestImageGetColors(PillowTestCase):
return None return None
self.assertEqual(getcolors("1"), 2) self.assertEqual(getcolors("1"), 2)
self.assertEqual(getcolors("L"), 193) self.assertEqual(getcolors("L"), 255)
self.assertEqual(getcolors("I"), 193) self.assertEqual(getcolors("I"), 255)
self.assertEqual(getcolors("F"), 193) self.assertEqual(getcolors("F"), 255)
self.assertEqual(getcolors("P"), 54) # fixed palette self.assertEqual(getcolors("P"), 90) # fixed palette
self.assertEqual(getcolors("RGB"), None) self.assertEqual(getcolors("RGB"), None)
self.assertEqual(getcolors("RGBA"), None) self.assertEqual(getcolors("RGBA"), None)
self.assertEqual(getcolors("CMYK"), None) self.assertEqual(getcolors("CMYK"), None)
self.assertEqual(getcolors("YCbCr"), None) self.assertEqual(getcolors("YCbCr"), None)
self.assertEqual(getcolors("L", 128), 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", 8192), None)
self.assertEqual(getcolors("RGB", 16384), 14836) self.assertEqual(getcolors("RGB", 16384), 10100)
self.assertEqual(getcolors("RGB", 100000), 14836) self.assertEqual(getcolors("RGB", 100000), 10100)
self.assertEqual(getcolors("RGBA", 16384), 14836) self.assertEqual(getcolors("RGBA", 16384), 10100)
self.assertEqual(getcolors("CMYK", 16384), 14836) self.assertEqual(getcolors("CMYK", 16384), 10100)
self.assertEqual(getcolors("YCbCr", 16384), 11995) self.assertEqual(getcolors("YCbCr", 16384), 9329)
# -------------------------------------------------------------------- # --------------------------------------------------------------------
def test_pack(self): def test_pack(self):
# Pack problems for small tables (@PIL209) # Pack problems for small tables (@PIL209)
im = lena().quantize(3).convert("RGB") im = hopper().quantize(3).convert("RGB")
expected = [ expected = [(4039, (172, 166, 181)),
(3236, (227, 183, 147)), (4385, (124, 113, 134)),
(6297, (143, 84, 81)), (7960, (31, 20, 33))]
(6851, (208, 143, 112))]
A = im.getcolors(maxcolors=2) A = im.getcolors(maxcolors=2)
self.assertEqual(A, None) 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): class TestImageGetData(PillowTestCase):
def test_sanity(self): def test_sanity(self):
data = lena().getdata() data = hopper().getdata()
len(data) len(data)
list(data) list(data)
self.assertEqual(data[0], (223, 162, 133)) self.assertEqual(data[0], (20, 20, 70))
def test_roundtrip(self): def test_roundtrip(self):
def getdata(mode): def getdata(mode):
im = lena(mode).resize((32, 30)) im = hopper(mode).resize((32, 30))
data = im.getdata() data = im.getdata()
return data[0], len(data), len(list(data)) return data[0], len(data), len(list(data))
self.assertEqual(getdata("1"), (255, 960, 960)) self.assertEqual(getdata("1"), (0, 960, 960))
self.assertEqual(getdata("L"), (176, 960, 960)) self.assertEqual(getdata("L"), (25, 960, 960))
self.assertEqual(getdata("I"), (176, 960, 960)) self.assertEqual(getdata("I"), (25, 960, 960))
self.assertEqual(getdata("F"), (176.0, 960, 960)) self.assertEqual(getdata("F"), (25.0, 960, 960))
self.assertEqual(getdata("RGB"), ((223, 162, 133), 960, 960)) self.assertEqual(getdata("RGB"), (((20, 20, 70), 960, 960)))
self.assertEqual(getdata("RGBA"), ((223, 162, 133, 255), 960, 960)) self.assertEqual(getdata("RGBA"), ((20, 20, 70, 255), 960, 960))
self.assertEqual(getdata("CMYK"), ((32, 93, 122, 0), 960, 960)) self.assertEqual(getdata("CMYK"), ((235, 235, 185, 0), 960, 960))
self.assertEqual(getdata("YCbCr"), ((176, 103, 160), 960, 960)) self.assertEqual(getdata("YCbCr"), ((25, 153, 123), 960, 960))
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena from helper import unittest, PillowTestCase, hopper
class TestImageGetExtrema(PillowTestCase): class TestImageGetExtrema(PillowTestCase):
@ -6,19 +6,19 @@ class TestImageGetExtrema(PillowTestCase):
def test_extrema(self): def test_extrema(self):
def extrema(mode): def extrema(mode):
return lena(mode).getextrema() return hopper(mode).getextrema()
self.assertEqual(extrema("1"), (0, 255)) self.assertEqual(extrema("1"), (0, 255))
self.assertEqual(extrema("L"), (40, 235)) self.assertEqual(extrema("L"), (0, 255))
self.assertEqual(extrema("I"), (40, 235)) self.assertEqual(extrema("I"), (0, 255))
self.assertEqual(extrema("F"), (40.0, 235.0)) self.assertEqual(extrema("F"), (0, 255))
self.assertEqual(extrema("P"), (11, 218)) # fixed palette self.assertEqual(extrema("P"), (0, 225)) # fixed palette
self.assertEqual( self.assertEqual(
extrema("RGB"), ((61, 255), (26, 234), (44, 223))) extrema("RGB"), ((0, 255), (0, 255), (0, 255)))
self.assertEqual( self.assertEqual(
extrema("RGBA"), ((61, 255), (26, 234), (44, 223), (255, 255))) extrema("RGBA"), ((0, 255), (0, 255), (0, 255), (255, 255)))
self.assertEqual( 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__': 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): class TestImageGetIm(PillowTestCase):
def test_sanity(self): def test_sanity(self):
im = lena() im = hopper()
type_repr = repr(type(im.getim())) type_repr = repr(type(im.getim()))
if py3: if py3:

View File

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

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 Image
@ -7,7 +7,7 @@ class TestImageGetProjection(PillowTestCase):
def test_sanity(self): def test_sanity(self):
im = lena() im = hopper()
projection = im.getprojection() projection = im.getprojection()

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena from helper import unittest, PillowTestCase, hopper
class TestImageHistogram(PillowTestCase): class TestImageHistogram(PillowTestCase):
@ -6,18 +6,18 @@ class TestImageHistogram(PillowTestCase):
def test_histogram(self): def test_histogram(self):
def histogram(mode): def histogram(mode):
h = lena(mode).histogram() h = hopper(mode).histogram()
return len(h), min(h), max(h) return len(h), min(h), max(h)
self.assertEqual(histogram("1"), (256, 0, 8872)) self.assertEqual(histogram("1"), (256, 0, 10994))
self.assertEqual(histogram("L"), (256, 0, 199)) self.assertEqual(histogram("L"), (256, 0, 638))
self.assertEqual(histogram("I"), (256, 0, 199)) self.assertEqual(histogram("I"), (256, 0, 638))
self.assertEqual(histogram("F"), (256, 0, 199)) self.assertEqual(histogram("F"), (256, 0, 638))
self.assertEqual(histogram("P"), (256, 0, 2912)) self.assertEqual(histogram("P"), (256, 0, 1871))
self.assertEqual(histogram("RGB"), (768, 0, 285)) self.assertEqual(histogram("RGB"), (768, 4, 675))
self.assertEqual(histogram("RGBA"), (1024, 0, 16384)) self.assertEqual(histogram("RGBA"), (1024, 0, 16384))
self.assertEqual(histogram("CMYK"), (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__': 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 from PIL import Image
@ -7,7 +7,7 @@ class TestImageMode(PillowTestCase):
def test_sanity(self): def test_sanity(self):
im = lena() im = hopper()
im.mode im.mode
from PIL import ImageMode 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): class TestImageOffset(PillowTestCase):
def test_offset(self): def test_offset(self):
im1 = lena() im1 = hopper()
im2 = self.assert_warning(DeprecationWarning, lambda: im1.offset(10)) im2 = self.assert_warning(DeprecationWarning, lambda: im1.offset(10))
self.assertEqual(im1.getpixel((0, 0)), im2.getpixel((10, 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): class TestImagePoint(PillowTestCase):
def test_sanity(self): def test_sanity(self):
im = lena() im = hopper()
self.assertRaises(ValueError, lambda: im.point(list(range(256)))) self.assertRaises(ValueError, lambda: im.point(list(range(256))))
im.point(list(range(256))*3) im.point(list(range(256))*3)
@ -26,12 +26,12 @@ class TestImagePoint(PillowTestCase):
# see https://github.com/python-pillow/Pillow/issues/484 # 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 = hopper("I")
im.point(list(range(256))*256, 'L') im.point(list(range(256))*256, 'L')
def test_f_lut(self): def test_f_lut(self):
""" Tests for floating point lut of 8bit gray image """ """ 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)] lut = [0.5 * float(x) for x in range(256)]
out = im.point(lut, 'F') 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 import sys
@ -9,7 +9,7 @@ class TestImagePutData(PillowTestCase):
def test_sanity(self): def test_sanity(self):
im1 = lena() im1 = hopper()
data = list(im1.getdata()) data = list(im1.getdata())
@ -46,7 +46,7 @@ class TestImagePutData(PillowTestCase):
im.putdata(list(range(256))*256) im.putdata(list(range(256))*256)
def test_mode_i(self): def test_mode_i(self):
src = lena('L') src = hopper('L')
data = list(src.getdata()) data = list(src.getdata())
im = Image.new('I', src.size, 0) im = Image.new('I', src.size, 0)
im.putdata(data, 2, 256) im.putdata(data, 2, 256)
@ -55,7 +55,7 @@ class TestImagePutData(PillowTestCase):
self.assertEqual(list(im.getdata()), target) self.assertEqual(list(im.getdata()), target)
def test_mode_F(self): def test_mode_F(self):
src = lena('L') src = hopper('L')
data = list(src.getdata()) data = list(src.getdata())
im = Image.new('F', src.size, 0) im = Image.new('F', src.size, 0)
im.putdata(data, 2.0, 256.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 from PIL import ImagePalette
@ -7,7 +7,7 @@ class TestImagePutPalette(PillowTestCase):
def test_putpalette(self): def test_putpalette(self):
def palette(mode): def palette(mode):
im = lena(mode).copy() im = hopper(mode).copy()
im.putpalette(list(range(256))*3) im.putpalette(list(range(256))*3)
p = im.getpalette() p = im.getpalette()
if p: if p:
@ -23,7 +23,7 @@ class TestImagePutPalette(PillowTestCase):
self.assertRaises(ValueError, lambda: palette("YCbCr")) self.assertRaises(ValueError, lambda: palette("YCbCr"))
def test_imagepalette(self): def test_imagepalette(self):
im = lena("P") im = hopper("P")
im.putpalette(ImagePalette.negative()) im.putpalette(ImagePalette.negative())
im.putpalette(ImagePalette.random()) im.putpalette(ImagePalette.random())
im.putpalette(ImagePalette.sepia()) 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 from PIL import Image
@ -9,7 +9,7 @@ class TestImagePutPixel(PillowTestCase):
def test_sanity(self): def test_sanity(self):
im1 = lena() im1 = hopper()
im2 = Image.new(im1.mode, im1.size, 0) im2 = Image.new(im1.mode, im1.size, 0)
for y in range(im1.size[1]): 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 from PIL import Image
@ -6,17 +6,17 @@ from PIL import Image
class TestImageQuantize(PillowTestCase): class TestImageQuantize(PillowTestCase):
def test_sanity(self): def test_sanity(self):
im = lena() im = hopper()
im = im.quantize() im = im.quantize()
self.assert_image(im, "P", im.size) self.assert_image(im, "P", im.size)
im = lena() im = hopper()
im = im.quantize(palette=lena("P")) im = im.quantize(palette=hopper("P"))
self.assert_image(im, "P", im.size) self.assert_image(im, "P", im.size)
def test_octree_quantize(self): def test_octree_quantize(self):
im = lena() im = hopper()
im = im.quantize(100, Image.FASTOCTREE) im = im.quantize(100, Image.FASTOCTREE)
self.assert_image(im, "P", im.size) self.assert_image(im, "P", im.size)
@ -24,7 +24,7 @@ class TestImageQuantize(PillowTestCase):
assert len(im.getcolors()) == 100 assert len(im.getcolors()) == 100
def test_rgba_quantize(self): def test_rgba_quantize(self):
im = lena('RGBA') im = hopper('RGBA')
im.quantize() im.quantize()
self.assertRaises(Exception, lambda: im.quantize(method=0)) 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): class TestImageResize(PillowTestCase):
def test_resize(self): def test_resize(self):
def resize(mode, size): def resize(mode, size):
out = lena(mode).resize(size) out = hopper(mode).resize(size)
self.assertEqual(out.mode, mode) self.assertEqual(out.mode, mode)
self.assertEqual(out.size, size) self.assertEqual(out.size, size)
for mode in "1", "P", "L", "RGB", "I", "F": 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): class TestImageRotate(PillowTestCase):
def test_rotate(self): def test_rotate(self):
def rotate(mode): def rotate(mode):
im = lena(mode) im = hopper(mode)
out = im.rotate(45) out = im.rotate(45)
self.assertEqual(out.mode, mode) self.assertEqual(out.mode, mode)
self.assertEqual(out.size, im.size) # default rotate clips output 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 from PIL import Image
@ -7,7 +7,7 @@ class TestImageSplit(PillowTestCase):
def test_split(self): def test_split(self):
def split(mode): def split(mode):
layers = lena(mode).split() layers = hopper(mode).split()
return [(i.mode, i.size[0], i.size[1]) for i in layers] return [(i.mode, i.size[0], i.size[1]) for i in layers]
self.assertEqual(split("1"), [('1', 128, 128)]) self.assertEqual(split("1"), [('1', 128, 128)])
self.assertEqual(split("L"), [('L', 128, 128)]) self.assertEqual(split("L"), [('L', 128, 128)])
@ -30,16 +30,16 @@ class TestImageSplit(PillowTestCase):
def test_split_merge(self): def test_split_merge(self):
def split_merge(mode): def split_merge(mode):
return Image.merge(mode, lena(mode).split()) return Image.merge(mode, hopper(mode).split())
self.assert_image_equal(lena("1"), split_merge("1")) self.assert_image_equal(hopper("1"), split_merge("1"))
self.assert_image_equal(lena("L"), split_merge("L")) self.assert_image_equal(hopper("L"), split_merge("L"))
self.assert_image_equal(lena("I"), split_merge("I")) self.assert_image_equal(hopper("I"), split_merge("I"))
self.assert_image_equal(lena("F"), split_merge("F")) self.assert_image_equal(hopper("F"), split_merge("F"))
self.assert_image_equal(lena("P"), split_merge("P")) self.assert_image_equal(hopper("P"), split_merge("P"))
self.assert_image_equal(lena("RGB"), split_merge("RGB")) self.assert_image_equal(hopper("RGB"), split_merge("RGB"))
self.assert_image_equal(lena("RGBA"), split_merge("RGBA")) self.assert_image_equal(hopper("RGBA"), split_merge("RGBA"))
self.assert_image_equal(lena("CMYK"), split_merge("CMYK")) self.assert_image_equal(hopper("CMYK"), split_merge("CMYK"))
self.assert_image_equal(lena("YCbCr"), split_merge("YCbCr")) self.assert_image_equal(hopper("YCbCr"), split_merge("YCbCr"))
def test_split_open(self): def test_split_open(self):
codecs = dir(Image.core) codecs = dir(Image.core)
@ -50,7 +50,7 @@ class TestImageSplit(PillowTestCase):
file = self.tempfile("temp.pcx") file = self.tempfile("temp.pcx")
def split_open(mode): def split_open(mode):
lena(mode).save(file) hopper(mode).save(file)
im = Image.open(file) im = Image.open(file)
return len(im.split()) return len(im.split())
self.assertEqual(split_open("1"), 1) 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): class TestImageThumbnail(PillowTestCase):
def test_sanity(self): def test_sanity(self):
im = lena() im = hopper()
im.thumbnail((100, 100)) im.thumbnail((100, 100))
self.assert_image(im, im.mode, (100, 100)) self.assert_image(im, im.mode, (100, 100))
def test_aspect(self): def test_aspect(self):
im = lena() im = hopper()
im.thumbnail((100, 100)) im.thumbnail((100, 100))
self.assert_image(im, im.mode, (100, 100)) self.assert_image(im, im.mode, (100, 100))
im = lena().resize((128, 256)) im = hopper().resize((128, 256))
im.thumbnail((100, 100)) im.thumbnail((100, 100))
self.assert_image(im, im.mode, (50, 100)) self.assert_image(im, im.mode, (50, 100))
im = lena().resize((128, 256)) im = hopper().resize((128, 256))
im.thumbnail((50, 100)) im.thumbnail((50, 100))
self.assert_image(im, im.mode, (50, 100)) self.assert_image(im, im.mode, (50, 100))
im = lena().resize((256, 128)) im = hopper().resize((256, 128))
im.thumbnail((100, 100)) im.thumbnail((100, 100))
self.assert_image(im, im.mode, (100, 50)) self.assert_image(im, im.mode, (100, 50))
im = lena().resize((256, 128)) im = hopper().resize((256, 128))
im.thumbnail((100, 50)) im.thumbnail((100, 50))
self.assert_image(im, im.mode, (100, 50)) self.assert_image(im, im.mode, (100, 50))
im = lena().resize((128, 128)) im = hopper().resize((128, 128))
im.thumbnail((100, 100)) im.thumbnail((100, 100))
self.assert_image(im, im.mode, (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): class TestImageToBitmap(PillowTestCase):
def test_sanity(self): def test_sanity(self):
self.assertRaises(ValueError, lambda: lena().tobitmap()) self.assertRaises(ValueError, lambda: hopper().tobitmap())
lena().convert("1").tobitmap() hopper().convert("1").tobitmap()
im1 = lena().convert("1") im1 = hopper().convert("1")
bitmap = im1.tobitmap() bitmap = im1.tobitmap()

View File

@ -1,10 +1,10 @@
from helper import unittest, PillowTestCase, lena from helper import unittest, PillowTestCase, hopper
class TestImageToBytes(PillowTestCase): class TestImageToBytes(PillowTestCase):
def test_sanity(self): def test_sanity(self):
data = lena().tobytes() data = hopper().tobytes()
self.assertTrue(isinstance(data, bytes)) self.assertTrue(isinstance(data, bytes))
if __name__ == '__main__': 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 from PIL import Image
@ -22,7 +22,7 @@ class TestImageTransform(PillowTestCase):
im.transform((100, 100), transform) im.transform((100, 100), transform)
def test_extent(self): def test_extent(self):
im = lena('RGB') im = hopper('RGB')
(w, h) = im.size (w, h) = im.size
transformed = im.transform(im.size, Image.EXTENT, transformed = im.transform(im.size, Image.EXTENT,
(0, 0, (0, 0,
@ -32,11 +32,11 @@ class TestImageTransform(PillowTestCase):
scaled = im.resize((w*2, h*2), Image.BILINEAR).crop((0, 0, w, h)) scaled = im.resize((w*2, h*2), Image.BILINEAR).crop((0, 0, w, h))
# undone -- precision? # undone -- precision?
self.assert_image_similar(transformed, scaled, 10) self.assert_image_similar(transformed, scaled, 23)
def test_quad(self): def test_quad(self):
# one simple quad transform, equivalent to scale & crop upper left quad # one simple quad transform, equivalent to scale & crop upper left quad
im = lena('RGB') im = hopper('RGB')
(w, h) = im.size (w, h) = im.size
transformed = im.transform(im.size, Image.QUAD, transformed = im.transform(im.size, Image.QUAD,
(0, 0, 0, h//2, (0, 0, 0, h//2,
@ -49,8 +49,8 @@ class TestImageTransform(PillowTestCase):
self.assert_image_equal(transformed, scaled) self.assert_image_equal(transformed, scaled)
def test_mesh(self): def test_mesh(self):
# this should be a checkerboard of halfsized lenas in ul, lr # this should be a checkerboard of halfsized hoppers in ul, lr
im = lena('RGBA') im = hopper('RGBA')
(w, h) = im.size (w, h) = im.size
transformed = im.transform(im.size, Image.MESH, transformed = im.transform(im.size, Image.MESH,
[((0, 0, w//2, h//2), # box [((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 from PIL import Image
@ -13,7 +13,7 @@ class TestImageTranspose(PillowTestCase):
def test_sanity(self): def test_sanity(self):
im = lena() im = hopper()
im.transpose(FLIP_LEFT_RIGHT) im.transpose(FLIP_LEFT_RIGHT)
im.transpose(FLIP_TOP_BOTTOM) im.transpose(FLIP_TOP_BOTTOM)
@ -24,7 +24,7 @@ class TestImageTranspose(PillowTestCase):
def test_roundtrip(self): def test_roundtrip(self):
im = lena() im = hopper()
def transpose(first, second): def transpose(first, second):
return im.transpose(first).transpose(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 Image
from PIL import ImageChops from PIL import ImageChops
@ -8,7 +8,7 @@ class TestImageChops(PillowTestCase):
def test_sanity(self): def test_sanity(self):
im = lena("L") im = hopper("L")
ImageChops.constant(im, 128) ImageChops.constant(im, 128)
ImageChops.duplicate(im) 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 Image
from PIL import ImageColor from PIL import ImageColor
@ -34,7 +34,7 @@ POINTS2 = [10, 10, 20, 40, 30, 30]
class TestImageDraw(PillowTestCase): class TestImageDraw(PillowTestCase):
def test_sanity(self): def test_sanity(self):
im = lena("RGB").copy() im = hopper("RGB").copy()
draw = ImageDraw.ImageDraw(im) draw = ImageDraw.ImageDraw(im)
draw = ImageDraw.Draw(im) draw = ImageDraw.Draw(im)
@ -45,7 +45,7 @@ class TestImageDraw(PillowTestCase):
draw.rectangle(list(range(4))) draw.rectangle(list(range(4)))
def test_deprecated(self): def test_deprecated(self):
im = lena().copy() im = hopper().copy()
draw = ImageDraw.Draw(im) 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 Image
from PIL import ImageEnhance from PIL import ImageEnhance
@ -10,10 +10,10 @@ class TestImageEnhance(PillowTestCase):
# FIXME: assert_image # FIXME: assert_image
# Implicit asserts no exception: # Implicit asserts no exception:
ImageEnhance.Color(lena()).enhance(0.5) ImageEnhance.Color(hopper()).enhance(0.5)
ImageEnhance.Contrast(lena()).enhance(0.5) ImageEnhance.Contrast(hopper()).enhance(0.5)
ImageEnhance.Brightness(lena()).enhance(0.5) ImageEnhance.Brightness(hopper()).enhance(0.5)
ImageEnhance.Sharpness(lena()).enhance(0.5) ImageEnhance.Sharpness(hopper()).enhance(0.5)
def test_crash(self): def test_crash(self):
@ -22,6 +22,34 @@ class TestImageEnhance(PillowTestCase):
ImageEnhance.Sharpness(im).enhance(0.5) 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__': if __name__ == '__main__':
unittest.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 from io import BytesIO
@ -20,7 +20,7 @@ class TestImageFile(PillowTestCase):
def roundtrip(format): def roundtrip(format):
im = lena("L").resize((1000, 1000)) im = hopper("L").resize((1000, 1000))
if format in ("MSP", "XBM"): if format in ("MSP", "XBM"):
im = im.convert("1") im = im.convert("1")
@ -73,7 +73,7 @@ class TestImageFile(PillowTestCase):
def test_safeblock(self): def test_safeblock(self):
im1 = lena() im1 = hopper()
if "zip_encoder" not in codecs: if "zip_encoder" not in codecs:
self.skipTest("PNG (zlib) encoder not available") 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 Image
from PIL import ImageFileIO from PIL import ImageFileIO
@ -19,7 +19,7 @@ class TestImageFileIo(PillowTestCase):
def close(self): def close(self):
pass pass
im1 = lena() im1 = hopper()
io = ImageFileIO.ImageFileIO(DumbFile(tostring(im1, "PPM"))) io = ImageFileIO.ImageFileIO(DumbFile(tostring(im1, "PPM")))

View File

@ -1,5 +1,7 @@
from helper import unittest, PillowTestCase from helper import unittest, PillowTestCase
import sys
try: try:
from PIL import ImageGrab from PIL import ImageGrab
@ -19,6 +21,27 @@ except ImportError:
self.skipTest("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__': if __name__ == '__main__':
unittest.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 from PIL import ImageOps
@ -14,65 +14,65 @@ class TestImageOps(PillowTestCase):
def test_sanity(self): def test_sanity(self):
ImageOps.autocontrast(lena("L")) ImageOps.autocontrast(hopper("L"))
ImageOps.autocontrast(lena("RGB")) ImageOps.autocontrast(hopper("RGB"))
ImageOps.autocontrast(lena("L"), cutoff=10) ImageOps.autocontrast(hopper("L"), cutoff=10)
ImageOps.autocontrast(lena("L"), ignore=[0, 255]) ImageOps.autocontrast(hopper("L"), ignore=[0, 255])
ImageOps.colorize(lena("L"), (0, 0, 0), (255, 255, 255)) ImageOps.colorize(hopper("L"), (0, 0, 0), (255, 255, 255))
ImageOps.colorize(lena("L"), "black", "white") ImageOps.colorize(hopper("L"), "black", "white")
ImageOps.crop(lena("L"), 1) ImageOps.crop(hopper("L"), 1)
ImageOps.crop(lena("RGB"), 1) ImageOps.crop(hopper("RGB"), 1)
ImageOps.deform(lena("L"), self.deformer) ImageOps.deform(hopper("L"), self.deformer)
ImageOps.deform(lena("RGB"), self.deformer) ImageOps.deform(hopper("RGB"), self.deformer)
ImageOps.equalize(lena("L")) ImageOps.equalize(hopper("L"))
ImageOps.equalize(lena("RGB")) ImageOps.equalize(hopper("RGB"))
ImageOps.expand(lena("L"), 1) ImageOps.expand(hopper("L"), 1)
ImageOps.expand(lena("RGB"), 1) ImageOps.expand(hopper("RGB"), 1)
ImageOps.expand(lena("L"), 2, "blue") ImageOps.expand(hopper("L"), 2, "blue")
ImageOps.expand(lena("RGB"), 2, "blue") ImageOps.expand(hopper("RGB"), 2, "blue")
ImageOps.fit(lena("L"), (128, 128)) ImageOps.fit(hopper("L"), (128, 128))
ImageOps.fit(lena("RGB"), (128, 128)) ImageOps.fit(hopper("RGB"), (128, 128))
ImageOps.flip(lena("L")) ImageOps.flip(hopper("L"))
ImageOps.flip(lena("RGB")) ImageOps.flip(hopper("RGB"))
ImageOps.grayscale(lena("L")) ImageOps.grayscale(hopper("L"))
ImageOps.grayscale(lena("RGB")) ImageOps.grayscale(hopper("RGB"))
ImageOps.invert(lena("L")) ImageOps.invert(hopper("L"))
ImageOps.invert(lena("RGB")) ImageOps.invert(hopper("RGB"))
ImageOps.mirror(lena("L")) ImageOps.mirror(hopper("L"))
ImageOps.mirror(lena("RGB")) ImageOps.mirror(hopper("RGB"))
ImageOps.posterize(lena("L"), 4) ImageOps.posterize(hopper("L"), 4)
ImageOps.posterize(lena("RGB"), 4) ImageOps.posterize(hopper("RGB"), 4)
ImageOps.solarize(lena("L")) ImageOps.solarize(hopper("L"))
ImageOps.solarize(lena("RGB")) ImageOps.solarize(hopper("RGB"))
def test_1pxfit(self): def test_1pxfit(self):
# Division by zero in equalize if image is 1 pixel high # 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)) 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)) 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)) self.assertEqual(newimg.size, (35, 35))
def test_pil163(self): def test_pil163(self):
# Division by zero in equalize if < 255 pixels in image (@PIL163) # 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("L"))
ImageOps.equalize(i.convert("P")) ImageOps.equalize(i.convert("P"))

View File

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

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena from helper import unittest, PillowTestCase, hopper
try: try:
from PIL import ImageQt from PIL import ImageQt
@ -44,7 +44,7 @@ class TestImageQt(PillowTestCase):
def test_image(self): def test_image(self):
for mode in ('1', 'RGB', 'RGBA', 'L', 'P'): for mode in ('1', 'RGB', 'RGBA', 'L', 'P'):
ImageQt.ImageQt(lena(mode)) ImageQt.ImageQt(hopper(mode))
if __name__ == '__main__': 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 from PIL import Image, ImageSequence, TiffImagePlugin
@ -9,7 +9,7 @@ class TestImageSequence(PillowTestCase):
file = self.tempfile("temp.im") file = self.tempfile("temp.im")
im = lena("RGB") im = hopper("RGB")
im.save(file) im.save(file)
seq = ImageSequence.Iterator(im) seq = ImageSequence.Iterator(im)
@ -31,14 +31,14 @@ class TestImageSequence(PillowTestCase):
self.assertEqual(index, im.tell()) self.assertEqual(index, im.tell())
frame.convert('RGB') frame.convert('RGB')
Image.DEBUG=False Image.DEBUG=False
def test_tiff(self): def test_tiff(self):
#self._test_multipage_tiff(True) #self._test_multipage_tiff(True)
self._test_multipage_tiff(False) self._test_multipage_tiff(False)
def test_libtiff(self): def test_libtiff(self):
codecs = dir(Image.core) codecs = dir(Image.core)
if "libtiff_encoder" not in codecs or "libtiff_decoder" not in codecs: if "libtiff_encoder" not in codecs or "libtiff_decoder" not in codecs:
self.skipTest("tiff support not available") self.skipTest("tiff support not available")
@ -46,7 +46,7 @@ class TestImageSequence(PillowTestCase):
#self._test_multipage_tiff(True) #self._test_multipage_tiff(True)
self._test_multipage_tiff(False) self._test_multipage_tiff(False)
TiffImagePlugin.READ_LIBTIFF = False TiffImagePlugin.READ_LIBTIFF = False
if __name__ == '__main__': if __name__ == '__main__':
unittest.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 from PIL import Image
from PIL import ImageStat from PIL import ImageStat
@ -8,7 +8,7 @@ class TestImageStat(PillowTestCase):
def test_sanity(self): def test_sanity(self):
im = lena() im = hopper()
st = ImageStat.Stat(im) st = ImageStat.Stat(im)
st = ImageStat.Stat(im.histogram()) st = ImageStat.Stat(im.histogram())
@ -28,18 +28,18 @@ class TestImageStat(PillowTestCase):
self.assertRaises(TypeError, lambda: ImageStat.Stat(1)) self.assertRaises(TypeError, lambda: ImageStat.Stat(1))
def test_lena(self): def test_hopper(self):
im = lena() im = hopper()
st = ImageStat.Stat(im) st = ImageStat.Stat(im)
# verify a few values # verify a few values
self.assertEqual(st.extrema[0], (61, 255)) self.assertEqual(st.extrema[0], (0, 255))
self.assertEqual(st.median[0], 197) self.assertEqual(st.median[0], 72)
self.assertEqual(st.sum[0], 2954416) self.assertEqual(st.sum[0], 1470218)
self.assertEqual(st.sum[1], 2027250) self.assertEqual(st.sum[1], 1311896)
self.assertEqual(st.sum[2], 1727331) self.assertEqual(st.sum[2], 1563008)
def test_constant(self): def test_constant(self):

View File

@ -19,7 +19,7 @@ import locale
# one of string.whitespace is not freely convertable into ascii. # one of string.whitespace is not freely convertable into ascii.
path = "Tests/images/lena.jpg" path = "Tests/images/hopper.jpg"
class TestLocale(PillowTestCase): 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 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 from PIL import Image
@ -90,7 +90,7 @@ class TestNumpy(PillowTestCase):
def test_to_array(self): def test_to_array(self):
def _to_array(mode, dtype): def _to_array(mode, dtype):
img = lena(mode) img = hopper(mode)
np_img = numpy.array(img) np_img = numpy.array(img)
self._test_img_equals_nparray(img, np_img) self._test_img_equals_nparray(img, np_img)
self.assertEqual(np_img.dtype, numpy.dtype(dtype)) self.assertEqual(np_img.dtype, numpy.dtype(dtype))
@ -117,7 +117,7 @@ class TestNumpy(PillowTestCase):
data = list(range(256))*3 data = list(range(256))*3
lut = numpy.array(data, dtype='uint8') lut = numpy.array(data, dtype='uint8')
im = lena() im = hopper()
im.point(lut) im.point(lut)

View File

@ -6,7 +6,8 @@ from PIL import Image
class TestPickle(PillowTestCase): class TestPickle(PillowTestCase):
def helper_pickle_file(self, pickle, protocol=0): 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') filename = self.tempfile('temp.pkl')
# Act # Act
@ -19,7 +20,7 @@ class TestPickle(PillowTestCase):
self.assertEqual(im, loaded_im) self.assertEqual(im, loaded_im)
def helper_pickle_string( 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) im = Image.open(file)
# Act # Act

View File

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

View File

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