mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-08 06:14:45 +03:00
refactoring: extract common from lena and hopper
This commit is contained in:
parent
1ecc3195d9
commit
4ea0ff7118
|
@ -180,8 +180,9 @@ def tostring(im, format, **options):
|
||||||
return out.getvalue()
|
return out.getvalue()
|
||||||
|
|
||||||
|
|
||||||
def hopper(mode="RGB", cache={}):
|
def test_image(filename, mode="RGB", cache={}):
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
from os import path
|
||||||
im = None
|
im = None
|
||||||
# FIXME: Implement caching to reduce reading from disk but so an original
|
# 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
|
# copy is returned each time and the cached image isn't modified by tests
|
||||||
|
@ -189,35 +190,23 @@ def hopper(mode="RGB", cache={}):
|
||||||
# im = cache.get(mode)
|
# im = cache.get(mode)
|
||||||
if im is None:
|
if im is None:
|
||||||
if mode == "RGB":
|
if mode == "RGB":
|
||||||
im = Image.open("Tests/images/hopper.ppm")
|
im = Image.open(path.join("Tests/images", filename))
|
||||||
elif mode == "F":
|
elif mode == "F":
|
||||||
im = lena("L").convert(mode)
|
im = test_image(filename, "L").convert(mode)
|
||||||
elif mode[:4] == "I;16":
|
elif mode[:4] == "I;16":
|
||||||
im = lena("I").convert(mode)
|
im = test_image(filename, "I").convert(mode)
|
||||||
else:
|
else:
|
||||||
im = lena("RGB").convert(mode)
|
im = test_image(filename, "RGB").convert(mode)
|
||||||
# cache[mode] = im
|
# cache[mode] = im
|
||||||
return im
|
return im
|
||||||
|
|
||||||
|
|
||||||
|
def hopper(mode="RGB", cache={}):
|
||||||
|
return test_image("hopper.ppm", mode, cache)
|
||||||
|
|
||||||
|
|
||||||
def lena(mode="RGB", cache={}):
|
def lena(mode="RGB", cache={}):
|
||||||
from PIL import Image
|
return test_image("lena.ppm", mode, cache)
|
||||||
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/lena.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 command_succeeds(cmd):
|
def command_succeeds(cmd):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user