Merge pull request #887 from hugovk/hopper2a

Replace Lena with Hopper (Part I)
This commit is contained in:
wiredfool 2014-09-04 10:05:25 -07:00
commit fc447afb05
34 changed files with 92 additions and 71 deletions

View File

@ -180,6 +180,26 @@ def tostring(im, format, **options):
return out.getvalue() return out.getvalue()
def hopper(mode="RGB", cache={}):
from PIL import Image
im = None
# FIXME: Implement caching to reduce reading from disk but so an original
# copy is returned each time and the cached image isn't modified by tests
# (for fast, isolated, repeatable tests).
# im = cache.get(mode)
if im is None:
if mode == "RGB":
im = Image.open("Tests/images/hopper.ppm")
elif mode == "F":
im = lena("L").convert(mode)
elif mode[:4] == "I;16":
im = lena("I").convert(mode)
else:
im = lena("RGB").convert(mode)
# cache[mode] = im
return im
def lena(mode="RGB", cache={}): def lena(mode="RGB", cache={}):
from PIL import Image from PIL import Image
im = None im = None

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

After

Width:  |  Height:  |  Size: 40 KiB

BIN
Tests/images/hopper.bw Normal file

Binary file not shown.

BIN
Tests/images/hopper.dcx Normal file

Binary file not shown.

BIN
Tests/images/hopper.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

BIN
Tests/images/hopper.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
Tests/images/hopper.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

BIN
Tests/images/hopper.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

BIN
Tests/images/hopper.ppm Normal file

Binary file not shown.

BIN
Tests/images/hopper.ras Normal file

Binary file not shown.

BIN
Tests/images/hopper.rgb Normal file

Binary file not shown.

BIN
Tests/images/hopper.spider Normal file

Binary file not shown.

BIN
Tests/images/hopper.tar Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,9 +1,9 @@
from helper import unittest, PillowTestCase, lena from helper import unittest, PillowTestCase, hopper
from PIL import Image, DcxImagePlugin from PIL import Image, DcxImagePlugin
# Created with ImageMagick: convert lena.ppm lena.dcx # Created with ImageMagick: convert hopper.ppm hopper.dcx
TEST_FILE = "Tests/images/lena.dcx" TEST_FILE = "Tests/images/hopper.dcx"
class TestFileDcx(PillowTestCase): class TestFileDcx(PillowTestCase):
@ -17,7 +17,7 @@ class TestFileDcx(PillowTestCase):
# Assert # Assert
self.assertEqual(im.size, (128, 128)) self.assertEqual(im.size, (128, 128))
self.assertIsInstance(im, DcxImagePlugin.DcxImageFile) self.assertIsInstance(im, DcxImagePlugin.DcxImageFile)
orig = lena() orig = hopper()
self.assert_image_equal(im, orig) self.assert_image_equal(im, orig)
def test_tell(self): def test_tell(self):

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena, netpbm_available from helper import unittest, PillowTestCase, hopper, netpbm_available
from PIL import Image from PIL import Image
from PIL import GifImagePlugin from PIL import GifImagePlugin
@ -6,8 +6,9 @@ from PIL import GifImagePlugin
codecs = dir(Image.core) codecs = dir(Image.core)
# sample gif stream # sample gif stream
file = "Tests/images/lena.gif" TEST_GIF = "Tests/images/hopper.gif"
with open(file, "rb") as f:
with open(TEST_GIF, "rb") as f:
data = f.read() data = f.read()
@ -18,7 +19,7 @@ class TestFileGif(PillowTestCase):
self.skipTest("gif support not available") # can this happen? self.skipTest("gif support not available") # can this happen?
def test_sanity(self): def test_sanity(self):
im = Image.open(file) im = Image.open(TEST_GIF)
im.load() im.load()
self.assertEqual(im.mode, "P") self.assertEqual(im.mode, "P")
self.assertEqual(im.size, (128, 128)) self.assertEqual(im.size, (128, 128))
@ -45,7 +46,7 @@ class TestFileGif(PillowTestCase):
def test_roundtrip(self): def test_roundtrip(self):
out = self.tempfile('temp.gif') out = self.tempfile('temp.gif')
im = lena() im = hopper()
im.save(out) im.save(out)
reread = Image.open(out) reread = Image.open(out)
@ -54,17 +55,17 @@ class TestFileGif(PillowTestCase):
def test_roundtrip2(self): def test_roundtrip2(self):
# see https://github.com/python-pillow/Pillow/issues/403 # see https://github.com/python-pillow/Pillow/issues/403
out = self.tempfile('temp.gif') out = self.tempfile('temp.gif')
im = Image.open('Tests/images/lena.gif') im = Image.open(TEST_GIF)
im2 = im.copy() im2 = im.copy()
im2.save(out) im2.save(out)
reread = Image.open(out) reread = Image.open(out)
self.assert_image_similar(reread.convert('RGB'), lena(), 50) self.assert_image_similar(reread.convert('RGB'), hopper(), 50)
def test_palette_handling(self): def test_palette_handling(self):
# see https://github.com/python-pillow/Pillow/issues/513 # see https://github.com/python-pillow/Pillow/issues/513
im = Image.open('Tests/images/lena.gif') im = Image.open(TEST_GIF)
im = im.convert('RGB') im = im.convert('RGB')
im = im.resize((100, 100), Image.ANTIALIAS) im = im.resize((100, 100), Image.ANTIALIAS)
@ -100,7 +101,7 @@ class TestFileGif(PillowTestCase):
@unittest.skipUnless(netpbm_available(), "netpbm not available") @unittest.skipUnless(netpbm_available(), "netpbm not available")
def test_save_netpbm_bmp_mode(self): def test_save_netpbm_bmp_mode(self):
img = Image.open(file).convert("RGB") img = Image.open(TEST_GIF).convert("RGB")
tempfile = self.tempfile("temp.gif") tempfile = self.tempfile("temp.gif")
GifImagePlugin._save_netpbm(img, 0, tempfile) GifImagePlugin._save_netpbm(img, 0, tempfile)
@ -108,7 +109,7 @@ class TestFileGif(PillowTestCase):
@unittest.skipUnless(netpbm_available(), "netpbm not available") @unittest.skipUnless(netpbm_available(), "netpbm not available")
def test_save_netpbm_l_mode(self): def test_save_netpbm_l_mode(self):
img = Image.open(file).convert("L") img = Image.open(TEST_GIF).convert("L")
tempfile = self.tempfile("temp.gif") tempfile = self.tempfile("temp.gif")
GifImagePlugin._save_netpbm(img, 0, tempfile) GifImagePlugin._save_netpbm(img, 0, tempfile)

View File

@ -3,14 +3,14 @@ from helper import unittest, PillowTestCase
from PIL import Image from PIL import Image
# sample ppm stream # sample ppm stream
file = "Tests/images/lena.ico" TEST_ICO_FILE = "Tests/images/hopper.ico"
data = open(file, "rb").read() TEST_DATA = open(TEST_ICO_FILE, "rb").read()
class TestFileIco(PillowTestCase): class TestFileIco(PillowTestCase):
def test_sanity(self): def test_sanity(self):
im = Image.open(file) im = Image.open(TEST_ICO_FILE)
im.load() im.load()
self.assertEqual(im.mode, "RGBA") self.assertEqual(im.mode, "RGBA")
self.assertEqual(im.size, (16, 16)) self.assertEqual(im.size, (16, 16))

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena from helper import unittest, PillowTestCase, hopper
from io import BytesIO from io import BytesIO
@ -10,8 +10,8 @@ codecs = dir(Image.core)
# sample png stream # sample png stream
file = "Tests/images/lena.png" TEST_PNG_FILE = "Tests/images/hopper.png"
data = open(file, "rb").read() TEST_DATA = open(TEST_PNG_FILE, "rb").read()
# stuff to create inline PNG images # stuff to create inline PNG images
@ -58,7 +58,7 @@ class TestFilePng(PillowTestCase):
file = self.tempfile("temp.png") file = self.tempfile("temp.png")
lena("RGB").save(file) hopper("RGB").save(file)
im = Image.open(file) im = Image.open(file)
im.load() im.load()
@ -66,19 +66,19 @@ class TestFilePng(PillowTestCase):
self.assertEqual(im.size, (128, 128)) self.assertEqual(im.size, (128, 128))
self.assertEqual(im.format, "PNG") self.assertEqual(im.format, "PNG")
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_broken(self): def test_broken(self):
@ -237,17 +237,17 @@ class TestFilePng(PillowTestCase):
def test_load_verify(self): def test_load_verify(self):
# Check open/load/verify exception (@PIL150) # Check open/load/verify exception (@PIL150)
im = Image.open("Tests/images/lena.png") im = Image.open(TEST_PNG_FILE)
im.verify() im.verify()
im = Image.open("Tests/images/lena.png") im = Image.open(TEST_PNG_FILE)
im.load() im.load()
self.assertRaises(RuntimeError, lambda: im.verify()) self.assertRaises(RuntimeError, lambda: im.verify())
def test_roundtrip_dpi(self): def test_roundtrip_dpi(self):
# Check dpi roundtripping # Check dpi roundtripping
im = Image.open(file) im = Image.open(TEST_PNG_FILE)
im = roundtrip(im, dpi=(100, 100)) im = roundtrip(im, dpi=(100, 100))
self.assertEqual(im.info["dpi"], (100, 100)) self.assertEqual(im.info["dpi"], (100, 100))
@ -255,7 +255,7 @@ class TestFilePng(PillowTestCase):
def test_roundtrip_text(self): def test_roundtrip_text(self):
# Check text roundtripping # Check text roundtripping
im = Image.open(file) im = Image.open(TEST_PNG_FILE)
info = PngImagePlugin.PngInfo() info = PngImagePlugin.PngInfo()
info.add_text("TXT", "VALUE") info.add_text("TXT", "VALUE")
@ -338,7 +338,7 @@ class TestFilePng(PillowTestCase):
def test_trns_p(self): def test_trns_p(self):
# Check writing a transparency of 0, issue #528 # Check writing a transparency of 0, issue #528
im = lena('P') im = hopper('P')
im.info['transparency'] = 0 im.info['transparency'] = 0
f = self.tempfile("temp.png") f = self.tempfile("temp.png")
@ -360,7 +360,7 @@ class TestFilePng(PillowTestCase):
def test_roundtrip_icc_profile(self): def test_roundtrip_icc_profile(self):
# check that we can roundtrip the icc profile # check that we can roundtrip the icc profile
im = lena('RGB') im = hopper('RGB')
jpeg_image = Image.open('Tests/images/flower2.jpg') jpeg_image = Image.open('Tests/images/flower2.jpg')
expected_icc = jpeg_image.info['icc_profile'] expected_icc = jpeg_image.info['icc_profile']

View File

@ -8,8 +8,8 @@ class TestFileSgi(PillowTestCase):
def test_rgb(self): def test_rgb(self):
# Arrange # Arrange
# Created with ImageMagick then renamed: # Created with ImageMagick then renamed:
# convert lena.ppm lena.sgi # convert hopper.ppm hopper.sgi
test_file = "Tests/images/lena.rgb" test_file = "Tests/images/hopper.rgb"
# Act / Assert # Act / Assert
self.assertRaises(ValueError, lambda: Image.open(test_file)) self.assertRaises(ValueError, lambda: Image.open(test_file))
@ -17,8 +17,8 @@ class TestFileSgi(PillowTestCase):
def test_l(self): def test_l(self):
# Arrange # Arrange
# Created with ImageMagick then renamed: # Created with ImageMagick then renamed:
# convert lena.ppm -monochrome lena.sgi # convert hopper.ppm -monochrome hopper.sgi
test_file = "Tests/images/lena.bw" test_file = "Tests/images/hopper.bw"
# Act / Assert # Act / Assert
self.assertRaises(ValueError, lambda: Image.open(test_file)) self.assertRaises(ValueError, lambda: Image.open(test_file))

View File

@ -1,9 +1,9 @@
from helper import unittest, PillowTestCase, lena from helper import unittest, PillowTestCase, hopper
from PIL import Image from PIL import Image
from PIL import SpiderImagePlugin from PIL import SpiderImagePlugin
TEST_FILE = "Tests/images/lena.spider" TEST_FILE = "Tests/images/hopper.spider"
class TestImageSpider(PillowTestCase): class TestImageSpider(PillowTestCase):
@ -18,7 +18,7 @@ class TestImageSpider(PillowTestCase):
def test_save(self): def test_save(self):
# Arrange # Arrange
temp = self.tempfile('temp.spider') temp = self.tempfile('temp.spider')
im = lena() im = hopper()
# Act # Act
im.save(temp, "SPIDER") im.save(temp, "SPIDER")
@ -44,7 +44,7 @@ class TestImageSpider(PillowTestCase):
def test_loadImageSeries(self): def test_loadImageSeries(self):
# Arrange # Arrange
not_spider_file = "Tests/images/lena.ppm" not_spider_file = "Tests/images/hopper.ppm"
file_list = [TEST_FILE, not_spider_file, "path/not_found.ext"] file_list = [TEST_FILE, not_spider_file, "path/not_found.ext"]
# Act # Act

View File

@ -7,8 +7,8 @@ class TestFileSun(PillowTestCase):
def test_sanity(self): def test_sanity(self):
# Arrange # Arrange
# Created with ImageMagick: convert lena.ppm lena.ras # Created with ImageMagick: convert hopper.jpg hopper.ras
test_file = "Tests/images/lena.ras" test_file = "Tests/images/hopper.ras"
# Act # Act
im = Image.open(test_file) im = Image.open(test_file)

View File

@ -4,8 +4,8 @@ from PIL import Image, TarIO
codecs = dir(Image.core) codecs = dir(Image.core)
# sample ppm stream # Sample tar archive
tarfile = "Tests/images/lena.tar" TEST_TAR_FILE = "Tests/images/hopper.tar"
class TestFileTar(PillowTestCase): class TestFileTar(PillowTestCase):
@ -16,7 +16,7 @@ class TestFileTar(PillowTestCase):
def test_sanity(self): def test_sanity(self):
if "zip_decoder" in codecs: if "zip_decoder" in codecs:
tar = TarIO.TarIO(tarfile, 'lena.png') tar = TarIO.TarIO(TEST_TAR_FILE, 'hopper.png')
im = Image.open(tar) im = Image.open(tar)
im.load() im.load()
self.assertEqual(im.mode, "RGB") self.assertEqual(im.mode, "RGB")
@ -24,7 +24,7 @@ class TestFileTar(PillowTestCase):
self.assertEqual(im.format, "PNG") self.assertEqual(im.format, "PNG")
if "jpeg_decoder" in codecs: if "jpeg_decoder" in codecs:
tar = TarIO.TarIO(tarfile, 'lena.jpg') tar = TarIO.TarIO(TEST_TAR_FILE, 'hopper.jpg')
im = Image.open(tar) im = Image.open(tar)
im.load() im.load()
self.assertEqual(im.mode, "RGB") self.assertEqual(im.mode, "RGB")

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 sys import sys
@ -58,7 +58,7 @@ class TestImage(PillowTestCase):
def test_expand_x(self): def test_expand_x(self):
# Arrange # Arrange
im = lena() im = hopper()
orig_size = im.size orig_size = im.size
xmargin = 5 xmargin = 5
@ -71,7 +71,7 @@ class TestImage(PillowTestCase):
def test_expand_xy(self): def test_expand_xy(self):
# Arrange # Arrange
im = lena() im = hopper()
orig_size = im.size orig_size = im.size
xmargin = 5 xmargin = 5
ymargin = 3 ymargin = 3
@ -85,7 +85,7 @@ class TestImage(PillowTestCase):
def test_getbands(self): def test_getbands(self):
# Arrange # Arrange
im = lena() im = hopper()
# Act # Act
bands = im.getbands() bands = im.getbands()
@ -95,7 +95,7 @@ class TestImage(PillowTestCase):
def test_getbbox(self): def test_getbbox(self):
# Arrange # Arrange
im = lena() im = hopper()
# Act # Act
bbox = im.getbbox() bbox = im.getbbox()
@ -185,7 +185,7 @@ class TestImage(PillowTestCase):
def test_effect_spread(self): def test_effect_spread(self):
# Arrange # Arrange
im = lena() im = hopper()
distance = 10 distance = 10
# Act # Act
@ -194,7 +194,7 @@ class TestImage(PillowTestCase):
# Assert # Assert
self.assertEqual(im.size, (128, 128)) self.assertEqual(im.size, (128, 128))
im3 = Image.open('Tests/images/effect_spread.png') im3 = Image.open('Tests/images/effect_spread.png')
self.assert_image_similar(im2, im3, 80) self.assert_image_similar(im2, im3, 110)
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
@ -9,21 +9,21 @@ class TestImageLoad(PillowTestCase):
def test_sanity(self): def test_sanity(self):
im = lena() im = hopper()
pix = im.load() pix = im.load()
self.assertEqual(pix[0, 0], (223, 162, 133)) self.assertEqual(pix[0, 0], (20, 20, 70))
def test_close(self): def test_close(self):
im = Image.open("Tests/images/lena.gif") im = Image.open("Tests/images/hopper.gif")
im.close() im.close()
self.assertRaises(ValueError, lambda: im.load()) self.assertRaises(ValueError, lambda: im.load())
self.assertRaises(ValueError, lambda: im.getpixel((0, 0))) self.assertRaises(ValueError, lambda: im.getpixel((0, 0)))
def test_contextmanager(self): def test_contextmanager(self):
fn = None fn = None
with Image.open("Tests/images/lena.gif") as im: with Image.open("Tests/images/hopper.gif") as im:
fn = im.fp.fileno() fn = im.fp.fileno()
os.fstat(fn) os.fstat(fn)

View File

@ -6,8 +6,8 @@ import shutil
from PIL import Image, JpegImagePlugin, GifImagePlugin from PIL import Image, JpegImagePlugin, GifImagePlugin
test_jpg = "Tests/images/lena.jpg" TEST_JPG = "Tests/images/hopper.jpg"
test_gif = "Tests/images/lena.gif" TEST_GIF = "Tests/images/hopper.gif"
test_filenames = ( test_filenames = (
"temp_';", "temp_';",
@ -31,24 +31,24 @@ class TestShellInjection(PillowTestCase):
def test_load_djpeg_filename(self): def test_load_djpeg_filename(self):
for filename in test_filenames: for filename in test_filenames:
src_file = self.tempfile(filename) src_file = self.tempfile(filename)
shutil.copy(test_jpg, src_file) shutil.copy(TEST_JPG, src_file)
im = Image.open(src_file) im = Image.open(src_file)
im.load_djpeg() im.load_djpeg()
@unittest.skipUnless(cjpeg_available(), "cjpeg not available") @unittest.skipUnless(cjpeg_available(), "cjpeg not available")
def test_save_cjpeg_filename(self): def test_save_cjpeg_filename(self):
im = Image.open(test_jpg) im = Image.open(TEST_JPG)
self.assert_save_filename_check(im, JpegImagePlugin._save_cjpeg) self.assert_save_filename_check(im, JpegImagePlugin._save_cjpeg)
@unittest.skipUnless(netpbm_available(), "netpbm not available") @unittest.skipUnless(netpbm_available(), "netpbm not available")
def test_save_netpbm_filename_bmp_mode(self): def test_save_netpbm_filename_bmp_mode(self):
im = Image.open(test_gif).convert("RGB") im = Image.open(TEST_GIF).convert("RGB")
self.assert_save_filename_check(im, GifImagePlugin._save_netpbm) self.assert_save_filename_check(im, GifImagePlugin._save_netpbm)
@unittest.skipUnless(netpbm_available(), "netpbm not available") @unittest.skipUnless(netpbm_available(), "netpbm not available")
def test_save_netpbm_filename_l_mode(self): def test_save_netpbm_filename_l_mode(self):
im = Image.open(test_gif).convert("L") im = Image.open(TEST_GIF).convert("L")
self.assert_save_filename_check(im, GifImagePlugin._save_netpbm) self.assert_save_filename_check(im, GifImagePlugin._save_netpbm)

View File

@ -49,13 +49,13 @@ def testimage():
Or open existing files: Or open existing files:
>>> im = Image.open(os.path.join(ROOT, "Tests/images/lena.gif")) >>> im = Image.open(os.path.join(ROOT, "Tests/images/hopper.gif"))
>>> _info(im) >>> _info(im)
('GIF', 'P', (128, 128)) ('GIF', 'P', (128, 128))
>>> _info(Image.open(os.path.join(ROOT, "Tests/images/lena.ppm"))) >>> _info(Image.open(os.path.join(ROOT, "Tests/images/hopper.ppm")))
('PPM', 'RGB', (128, 128)) ('PPM', 'RGB', (128, 128))
>>> try: >>> try:
... _info(Image.open(os.path.join(ROOT, "Tests/images/lena.jpg"))) ... _info(Image.open(os.path.join(ROOT, "Tests/images/hopper.jpg")))
... except IOError as v: ... except IOError as v:
... print(v) ... print(v)
('JPEG', 'RGB', (128, 128)) ('JPEG', 'RGB', (128, 128))
@ -63,7 +63,7 @@ def testimage():
PIL doesn't actually load the image data until it's needed, PIL doesn't actually load the image data until it's needed,
or you call the "load" method: or you call the "load" method:
>>> im = Image.open(os.path.join(ROOT, "Tests/images/lena.ppm")) >>> im = Image.open(os.path.join(ROOT, "Tests/images/hopper.ppm"))
>>> print(im.im) # internal image attribute >>> print(im.im) # internal image attribute
None None
>>> a = im.load() >>> a = im.load()
@ -73,7 +73,7 @@ def testimage():
You can apply many different operations on images. Most You can apply many different operations on images. Most
operations return a new image: operations return a new image:
>>> im = Image.open(os.path.join(ROOT, "Tests/images/lena.ppm")) >>> im = Image.open(os.path.join(ROOT, "Tests/images/hopper.ppm"))
>>> _info(im.convert("L")) >>> _info(im.convert("L"))
(None, 'L', (128, 128)) (None, 'L', (128, 128))
>>> _info(im.copy()) >>> _info(im.copy())
@ -89,9 +89,9 @@ def testimage():
>>> len(im.getdata()) >>> len(im.getdata())
16384 16384
>>> im.getextrema() >>> im.getextrema()
((61, 255), (26, 234), (44, 223)) ((0, 255), (0, 255), (0, 255))
>>> im.getpixel((0, 0)) >>> im.getpixel((0, 0))
(223, 162, 133) (20, 20, 70)
>>> len(im.getprojection()) >>> len(im.getprojection())
2 2
>>> len(im.histogram()) >>> len(im.histogram())