Merge from master, pre-unittest conversion
11
.coveragerc
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
# .coveragerc to control coverage.py
|
||||||
|
|
||||||
|
[report]
|
||||||
|
# Regexes for lines to exclude from consideration
|
||||||
|
exclude_lines =
|
||||||
|
# Have to re-enable the standard pragma:
|
||||||
|
pragma: no cover
|
||||||
|
|
||||||
|
# Don't complain if non-runnable code isn't run:
|
||||||
|
if 0:
|
||||||
|
if __name__ == .__main__.:
|
22
.travis.yml
|
@ -26,18 +26,20 @@ script:
|
||||||
- coverage erase
|
- coverage erase
|
||||||
- python setup.py clean
|
- python setup.py clean
|
||||||
- python setup.py build_ext --inplace
|
- python setup.py build_ext --inplace
|
||||||
- coverage run --append --include=PIL/* selftest.py
|
|
||||||
- python Tests/run.py --coverage
|
# Don't cover PyPy: it fails intermittently and is x5.8 slower (#640)
|
||||||
|
- if [ "$TRAVIS_PYTHON_VERSION" == "pypy" ]; then python selftest.py; fi
|
||||||
|
- if [ "$TRAVIS_PYTHON_VERSION" == "pypy" ]; then python Tests/run.py; fi
|
||||||
|
|
||||||
|
# Cover the others
|
||||||
|
- if [ "$TRAVIS_PYTHON_VERSION" != "pypy" ]; then coverage run --append --include=PIL/* selftest.py; fi
|
||||||
|
- if [ "$TRAVIS_PYTHON_VERSION" != "pypy" ]; then python Tests/run.py --coverage; fi
|
||||||
|
|
||||||
after_success:
|
after_success:
|
||||||
- coverage report
|
- coverage report
|
||||||
- coveralls
|
- coveralls
|
||||||
- pip install pep8 pyflakes
|
- pip install pep8 pyflakes
|
||||||
- pep8 PIL/*.py
|
- pep8 --statistics --count PIL/*.py
|
||||||
- pyflakes PIL/*.py
|
- pep8 --statistics --count Tests/*.py
|
||||||
- pep8 Tests/*.py
|
- pyflakes PIL/*.py | tee >(wc -l)
|
||||||
- pyflakes Tests/*.py
|
- pyflakes Tests/*.py | tee >(wc -l)
|
||||||
|
|
||||||
matrix:
|
|
||||||
allow_failures:
|
|
||||||
- python: "pypy"
|
|
||||||
|
|
40
CHANGES.rst
|
@ -3,6 +3,44 @@ Changelog (Pillow)
|
||||||
|
|
||||||
2.5.0 (unreleased)
|
2.5.0 (unreleased)
|
||||||
------------------
|
------------------
|
||||||
|
- Added more ImageDraw tests
|
||||||
|
[hugovk]
|
||||||
|
|
||||||
|
- Added tests for Spider files
|
||||||
|
[hugovk]
|
||||||
|
|
||||||
|
- Use libtiff to write any compressed tiff files
|
||||||
|
[wiredfool]
|
||||||
|
|
||||||
|
- Support for pickling Image objects
|
||||||
|
[hugovk]
|
||||||
|
|
||||||
|
- Fixed resolution handling for EPS thumbnails
|
||||||
|
[eliempje]
|
||||||
|
|
||||||
|
- Fixed rendering of some binary EPS files (Issue #302)
|
||||||
|
[eliempje]
|
||||||
|
|
||||||
|
- Rename variables not to use built-in function names
|
||||||
|
[hugovk]
|
||||||
|
|
||||||
|
- Ignore junk JPEG markers
|
||||||
|
[hugovk]
|
||||||
|
|
||||||
|
- Change default interpolation for Image.thumbnail to Image.ANTIALIAS
|
||||||
|
[hugovk]
|
||||||
|
|
||||||
|
- Add tests and fixes for saving PDFs
|
||||||
|
[hugovk]
|
||||||
|
|
||||||
|
- Remove transparency resource after P->RGBA conversion
|
||||||
|
[hugovk]
|
||||||
|
|
||||||
|
- Clean up preprocessor cruft for Windows
|
||||||
|
[CounterPillow]
|
||||||
|
|
||||||
|
- Adjust Homebrew freetype detection logic
|
||||||
|
[jacknagel]
|
||||||
|
|
||||||
- Added Image.close, context manager support.
|
- Added Image.close, context manager support.
|
||||||
[wiredfool]
|
[wiredfool]
|
||||||
|
@ -399,7 +437,7 @@ Changelog (Pillow)
|
||||||
- Add Python 3 support. (Pillow >= 2.0.0 supports Python 2.6, 2.7, 3.2, 3.3. Pillow < 2.0.0 supports Python 2.4, 2.5, 2.6, 2.7.)
|
- Add Python 3 support. (Pillow >= 2.0.0 supports Python 2.6, 2.7, 3.2, 3.3. Pillow < 2.0.0 supports Python 2.4, 2.5, 2.6, 2.7.)
|
||||||
[fluggo]
|
[fluggo]
|
||||||
|
|
||||||
- Add PyPy support (experimental, please see: https://github.com/python-imaging/Pillow/issues/67)
|
- Add PyPy support (experimental, please see: https://github.com/python-pillow/Pillow/issues/67)
|
||||||
|
|
||||||
- Add WebP support.
|
- Add WebP support.
|
||||||
[lqs]
|
[lqs]
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
# 1996-08-23 fl Handle files from Macintosh (0.3)
|
# 1996-08-23 fl Handle files from Macintosh (0.3)
|
||||||
# 2001-02-17 fl Use 're' instead of 'regex' (Python 2.1) (0.4)
|
# 2001-02-17 fl Use 're' instead of 'regex' (Python 2.1) (0.4)
|
||||||
# 2003-09-07 fl Check gs.close status (from Federico Di Gregorio) (0.5)
|
# 2003-09-07 fl Check gs.close status (from Federico Di Gregorio) (0.5)
|
||||||
|
# 2014-05-07 e Handling of EPS with binary preview and fixed resolution resizing
|
||||||
#
|
#
|
||||||
# Copyright (c) 1997-2003 by Secret Labs AB.
|
# Copyright (c) 1997-2003 by Secret Labs AB.
|
||||||
# Copyright (c) 1995-2003 by Fredrik Lundh
|
# Copyright (c) 1995-2003 by Fredrik Lundh
|
||||||
|
@ -77,8 +78,9 @@ def Ghostscript(tile, size, fp, scale=1):
|
||||||
orig_size = size
|
orig_size = size
|
||||||
orig_bbox = bbox
|
orig_bbox = bbox
|
||||||
size = (size[0] * scale, size[1] * scale)
|
size = (size[0] * scale, size[1] * scale)
|
||||||
bbox = [bbox[0], bbox[1], bbox[2] * scale, bbox[3] * scale]
|
# resolution is dependend on bbox and size
|
||||||
#print("Ghostscript", scale, size, orig_size, bbox, orig_bbox)
|
res = ( float((72.0 * size[0]) / (bbox[2]-bbox[0])), float((72.0 * size[1]) / (bbox[3]-bbox[1])) )
|
||||||
|
#print("Ghostscript", scale, size, orig_size, bbox, orig_bbox, res)
|
||||||
|
|
||||||
import tempfile, os, subprocess
|
import tempfile, os, subprocess
|
||||||
|
|
||||||
|
@ -87,10 +89,19 @@ def Ghostscript(tile, size, fp, scale=1):
|
||||||
in_fd, infile = tempfile.mkstemp()
|
in_fd, infile = tempfile.mkstemp()
|
||||||
os.close(in_fd)
|
os.close(in_fd)
|
||||||
|
|
||||||
|
# ignore length and offset!
|
||||||
|
# ghostscript can read it
|
||||||
|
# copy whole file to read in ghostscript
|
||||||
with open(infile, 'wb') as f:
|
with open(infile, 'wb') as f:
|
||||||
fp.seek(offset)
|
# fetch length of fp
|
||||||
while length >0:
|
fp.seek(0, 2)
|
||||||
s = fp.read(100*1024)
|
fsize = fp.tell()
|
||||||
|
# ensure start position
|
||||||
|
# go back
|
||||||
|
fp.seek(0)
|
||||||
|
lengthfile = fsize
|
||||||
|
while lengthfile > 0:
|
||||||
|
s = fp.read(min(lengthfile, 100*1024))
|
||||||
if not s:
|
if not s:
|
||||||
break
|
break
|
||||||
length -= len(s)
|
length -= len(s)
|
||||||
|
@ -100,7 +111,7 @@ def Ghostscript(tile, size, fp, scale=1):
|
||||||
command = ["gs",
|
command = ["gs",
|
||||||
"-q", # quiet mode
|
"-q", # quiet mode
|
||||||
"-g%dx%d" % size, # set output geometry (pixels)
|
"-g%dx%d" % size, # set output geometry (pixels)
|
||||||
"-r%d" % (72*scale), # set input DPI (dots per inch)
|
"-r%fx%f" % res, # set input DPI (dots per inch)
|
||||||
"-dNOPAUSE -dSAFER", # don't pause between pages, safe mode
|
"-dNOPAUSE -dSAFER", # don't pause between pages, safe mode
|
||||||
"-sDEVICE=ppmraw", # ppm driver
|
"-sDEVICE=ppmraw", # ppm driver
|
||||||
"-sOutputFile=%s" % outfile, # output file
|
"-sOutputFile=%s" % outfile, # output file
|
||||||
|
@ -145,6 +156,8 @@ class PSFile:
|
||||||
self.fp.seek(offset, whence)
|
self.fp.seek(offset, whence)
|
||||||
def read(self, count):
|
def read(self, count):
|
||||||
return self.fp.read(count).decode('latin-1')
|
return self.fp.read(count).decode('latin-1')
|
||||||
|
def readbinary(self, count):
|
||||||
|
return self.fp.read(count)
|
||||||
def tell(self):
|
def tell(self):
|
||||||
pos = self.fp.tell()
|
pos = self.fp.tell()
|
||||||
if self.char:
|
if self.char:
|
||||||
|
@ -182,24 +195,32 @@ class EpsImageFile(ImageFile.ImageFile):
|
||||||
|
|
||||||
def _open(self):
|
def _open(self):
|
||||||
|
|
||||||
# FIXME: should check the first 512 bytes to see if this
|
|
||||||
# really is necessary (platform-dependent, though...)
|
|
||||||
|
|
||||||
fp = PSFile(self.fp)
|
fp = PSFile(self.fp)
|
||||||
|
|
||||||
# HEAD
|
# FIX for: Some EPS file not handled correctly / issue #302
|
||||||
s = fp.read(512)
|
# EPS can contain binary data
|
||||||
|
# or start directly with latin coding
|
||||||
|
# read header in both ways to handle both
|
||||||
|
# file types
|
||||||
|
# more info see http://partners.adobe.com/public/developer/en/ps/5002.EPSF_Spec.pdf
|
||||||
|
|
||||||
|
# for HEAD without binary preview
|
||||||
|
s = fp.read(4)
|
||||||
|
# for HEAD with binary preview
|
||||||
|
fp.seek(0)
|
||||||
|
sb = fp.readbinary(160)
|
||||||
|
|
||||||
if s[:4] == "%!PS":
|
if s[:4] == "%!PS":
|
||||||
offset = 0
|
|
||||||
fp.seek(0, 2)
|
fp.seek(0, 2)
|
||||||
length = fp.tell()
|
length = fp.tell()
|
||||||
elif i32(s) == 0xC6D3D0C5:
|
offset = 0
|
||||||
offset = i32(s[4:])
|
elif i32(sb[0:4]) == 0xC6D3D0C5:
|
||||||
length = i32(s[8:])
|
offset = i32(sb[4:8])
|
||||||
fp.seek(offset)
|
length = i32(sb[8:12])
|
||||||
else:
|
else:
|
||||||
raise SyntaxError("not an EPS file")
|
raise SyntaxError("not an EPS file")
|
||||||
|
|
||||||
|
# go to offset - start of "%!PS"
|
||||||
fp.seek(offset)
|
fp.seek(offset)
|
||||||
|
|
||||||
box = None
|
box = None
|
||||||
|
|
175
PIL/Image.py
|
@ -30,6 +30,7 @@ from PIL import VERSION, PILLOW_VERSION, _plugins
|
||||||
|
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
|
|
||||||
class _imaging_not_installed:
|
class _imaging_not_installed:
|
||||||
# module placeholder
|
# module placeholder
|
||||||
def __getattr__(self, id):
|
def __getattr__(self, id):
|
||||||
|
@ -91,10 +92,13 @@ except ImportError:
|
||||||
builtins = __builtin__
|
builtins = __builtin__
|
||||||
|
|
||||||
from PIL import ImageMode
|
from PIL import ImageMode
|
||||||
from PIL._binary import i8, o8
|
from PIL._binary import i8
|
||||||
from PIL._util import isPath, isStringType, deferred_error
|
from PIL._util import isPath
|
||||||
|
from PIL._util import isStringType
|
||||||
|
from PIL._util import deferred_error
|
||||||
|
|
||||||
import os, sys
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
# type stuff
|
# type stuff
|
||||||
import collections
|
import collections
|
||||||
|
@ -104,9 +108,10 @@ import numbers
|
||||||
USE_CFFI_ACCESS = hasattr(sys, 'pypy_version_info')
|
USE_CFFI_ACCESS = hasattr(sys, 'pypy_version_info')
|
||||||
try:
|
try:
|
||||||
import cffi
|
import cffi
|
||||||
HAS_CFFI=True
|
HAS_CFFI = True
|
||||||
except:
|
except:
|
||||||
HAS_CFFI=False
|
HAS_CFFI = False
|
||||||
|
|
||||||
|
|
||||||
def isImageType(t):
|
def isImageType(t):
|
||||||
"""
|
"""
|
||||||
|
@ -248,6 +253,7 @@ _MODE_CONV = {
|
||||||
"I;32LS": ('<i4', None),
|
"I;32LS": ('<i4', None),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def _conv_type_shape(im):
|
def _conv_type_shape(im):
|
||||||
shape = im.size[1], im.size[0]
|
shape = im.size[1], im.size[0]
|
||||||
typ, extra = _MODE_CONV[im.mode]
|
typ, extra = _MODE_CONV[im.mode]
|
||||||
|
@ -368,8 +374,8 @@ def init():
|
||||||
for plugin in _plugins:
|
for plugin in _plugins:
|
||||||
try:
|
try:
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
print ("Importing %s"%plugin)
|
print ("Importing %s" % plugin)
|
||||||
__import__("PIL.%s"%plugin, globals(), locals(), [])
|
__import__("PIL.%s" % plugin, globals(), locals(), [])
|
||||||
except ImportError:
|
except ImportError:
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
print("Image: failed to import", end=' ')
|
print("Image: failed to import", end=' ')
|
||||||
|
@ -379,6 +385,7 @@ def init():
|
||||||
_initialized = 2
|
_initialized = 2
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
# Codec factories (used by tobytes/frombytes and ImageFile.load)
|
# Codec factories (used by tobytes/frombytes and ImageFile.load)
|
||||||
|
|
||||||
|
@ -398,6 +405,7 @@ def _getdecoder(mode, decoder_name, args, extra=()):
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
raise IOError("decoder %s not available" % decoder_name)
|
raise IOError("decoder %s not available" % decoder_name)
|
||||||
|
|
||||||
|
|
||||||
def _getencoder(mode, encoder_name, args, extra=()):
|
def _getencoder(mode, encoder_name, args, extra=()):
|
||||||
|
|
||||||
# tweak arguments
|
# tweak arguments
|
||||||
|
@ -421,30 +429,36 @@ def _getencoder(mode, encoder_name, args, extra=()):
|
||||||
def coerce_e(value):
|
def coerce_e(value):
|
||||||
return value if isinstance(value, _E) else _E(value)
|
return value if isinstance(value, _E) else _E(value)
|
||||||
|
|
||||||
|
|
||||||
class _E:
|
class _E:
|
||||||
def __init__(self, data):
|
def __init__(self, data):
|
||||||
self.data = data
|
self.data = data
|
||||||
|
|
||||||
def __add__(self, other):
|
def __add__(self, other):
|
||||||
return _E((self.data, "__add__", coerce_e(other).data))
|
return _E((self.data, "__add__", coerce_e(other).data))
|
||||||
|
|
||||||
def __mul__(self, other):
|
def __mul__(self, other):
|
||||||
return _E((self.data, "__mul__", coerce_e(other).data))
|
return _E((self.data, "__mul__", coerce_e(other).data))
|
||||||
|
|
||||||
|
|
||||||
def _getscaleoffset(expr):
|
def _getscaleoffset(expr):
|
||||||
stub = ["stub"]
|
stub = ["stub"]
|
||||||
data = expr(_E(stub)).data
|
data = expr(_E(stub)).data
|
||||||
try:
|
try:
|
||||||
(a, b, c) = data # simplified syntax
|
(a, b, c) = data # simplified syntax
|
||||||
if a is stub and b == "__mul__" and isinstance(c, numbers.Number):
|
if (a is stub and b == "__mul__" and isinstance(c, numbers.Number)):
|
||||||
return c, 0.0
|
return c, 0.0
|
||||||
if a is stub and b == "__add__" and isinstance(c, numbers.Number):
|
if a is stub and b == "__add__" and isinstance(c, numbers.Number):
|
||||||
return 1.0, c
|
return 1.0, c
|
||||||
except TypeError: pass
|
except TypeError:
|
||||||
|
pass
|
||||||
try:
|
try:
|
||||||
((a, b, c), d, e) = data # full syntax
|
((a, b, c), d, e) = data # full syntax
|
||||||
if (a is stub and b == "__mul__" and isinstance(c, numbers.Number) and
|
if (a is stub and b == "__mul__" and isinstance(c, numbers.Number) and
|
||||||
d == "__add__" and isinstance(e, numbers.Number)):
|
d == "__add__" and isinstance(e, numbers.Number)):
|
||||||
return c, e
|
return c, e
|
||||||
except TypeError: pass
|
except TypeError:
|
||||||
|
pass
|
||||||
raise ValueError("illegal expression")
|
raise ValueError("illegal expression")
|
||||||
|
|
||||||
|
|
||||||
|
@ -500,6 +514,7 @@ class Image:
|
||||||
# Context Manager Support
|
# Context Manager Support
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __exit__(self, *args):
|
def __exit__(self, *args):
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
|
@ -518,14 +533,13 @@ class Image:
|
||||||
self.fp.close()
|
self.fp.close()
|
||||||
except Exception as msg:
|
except Exception as msg:
|
||||||
if Image.DEBUG:
|
if Image.DEBUG:
|
||||||
print ("Error closing: %s" %msg)
|
print ("Error closing: %s" % msg)
|
||||||
|
|
||||||
# Instead of simply setting to None, we're setting up a
|
# Instead of simply setting to None, we're setting up a
|
||||||
# deferred error that will better explain that the core image
|
# deferred error that will better explain that the core image
|
||||||
# object is gone.
|
# object is gone.
|
||||||
self.im = deferred_error(ValueError("Operation on closed image"))
|
self.im = deferred_error(ValueError("Operation on closed image"))
|
||||||
|
|
||||||
|
|
||||||
def _copy(self):
|
def _copy(self):
|
||||||
self.load()
|
self.load()
|
||||||
self.im = self.im.copy()
|
self.im = self.im.copy()
|
||||||
|
@ -533,7 +547,8 @@ class Image:
|
||||||
self.readonly = 0
|
self.readonly = 0
|
||||||
|
|
||||||
def _dump(self, file=None, format=None):
|
def _dump(self, file=None, format=None):
|
||||||
import tempfile, os
|
import os
|
||||||
|
import tempfile
|
||||||
suffix = ''
|
suffix = ''
|
||||||
if format:
|
if format:
|
||||||
suffix = '.'+format
|
suffix = '.'+format
|
||||||
|
@ -550,6 +565,20 @@ class Image:
|
||||||
self.save(file, format)
|
self.save(file, format)
|
||||||
return file
|
return file
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
a = (self.mode == other.mode)
|
||||||
|
b = (self.size == other.size)
|
||||||
|
c = (self.getpalette() == other.getpalette())
|
||||||
|
d = (self.info == other.info)
|
||||||
|
e = (self.category == other.category)
|
||||||
|
f = (self.readonly == other.readonly)
|
||||||
|
g = (self.tobytes() == other.tobytes())
|
||||||
|
return a and b and c and d and e and f and g
|
||||||
|
|
||||||
|
def __ne__(self, other):
|
||||||
|
eq = (self == other)
|
||||||
|
return not eq
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<%s.%s image mode=%s size=%dx%d at 0x%X>" % (
|
return "<%s.%s image mode=%s size=%dx%d at 0x%X>" % (
|
||||||
self.__class__.__module__, self.__class__.__name__,
|
self.__class__.__module__, self.__class__.__name__,
|
||||||
|
@ -568,6 +597,26 @@ class Image:
|
||||||
return new
|
return new
|
||||||
raise AttributeError(name)
|
raise AttributeError(name)
|
||||||
|
|
||||||
|
def __getstate__(self):
|
||||||
|
return [
|
||||||
|
self.info,
|
||||||
|
self.mode,
|
||||||
|
self.size,
|
||||||
|
self.getpalette(),
|
||||||
|
self.tobytes()]
|
||||||
|
|
||||||
|
def __setstate__(self, state):
|
||||||
|
Image.__init__(self)
|
||||||
|
self.tile = []
|
||||||
|
info, mode, size, palette, data = state
|
||||||
|
self.info = info
|
||||||
|
self.mode = mode
|
||||||
|
self.size = size
|
||||||
|
self.im = core.new(mode, size)
|
||||||
|
if mode in ("L", "P"):
|
||||||
|
self.putpalette(palette)
|
||||||
|
self.frombytes(data)
|
||||||
|
|
||||||
def tobytes(self, encoder_name="raw", *args):
|
def tobytes(self, encoder_name="raw", *args):
|
||||||
"""
|
"""
|
||||||
Return image as a bytes object
|
Return image as a bytes object
|
||||||
|
@ -628,9 +677,11 @@ class Image:
|
||||||
if self.mode != "1":
|
if self.mode != "1":
|
||||||
raise ValueError("not a bitmap")
|
raise ValueError("not a bitmap")
|
||||||
data = self.tobytes("xbm")
|
data = self.tobytes("xbm")
|
||||||
return b"".join([("#define %s_width %d\n" % (name, self.size[0])).encode('ascii'),
|
return b"".join([
|
||||||
("#define %s_height %d\n"% (name, self.size[1])).encode('ascii'),
|
("#define %s_width %d\n" % (name, self.size[0])).encode('ascii'),
|
||||||
("static char %s_bits[] = {\n" % name).encode('ascii'), data, b"};"])
|
("#define %s_height %d\n" % (name, self.size[1])).encode('ascii'),
|
||||||
|
("static char %s_bits[] = {\n" % name).encode('ascii'), data, b"};"
|
||||||
|
])
|
||||||
|
|
||||||
def frombytes(self, data, decoder_name="raw", *args):
|
def frombytes(self, data, decoder_name="raw", *args):
|
||||||
"""
|
"""
|
||||||
|
@ -663,7 +714,9 @@ class Image:
|
||||||
|
|
||||||
.. deprecated:: 2.0
|
.. deprecated:: 2.0
|
||||||
"""
|
"""
|
||||||
warnings.warn('fromstring() is deprecated. Please call frombytes() instead.', DeprecationWarning)
|
warnings.warn(
|
||||||
|
'fromstring() is deprecated. Please call frombytes() instead.',
|
||||||
|
DeprecationWarning)
|
||||||
return self.frombytes(*args, **kw)
|
return self.frombytes(*args, **kw)
|
||||||
|
|
||||||
def load(self):
|
def load(self):
|
||||||
|
@ -774,7 +827,8 @@ class Image:
|
||||||
trns = None
|
trns = None
|
||||||
delete_trns = False
|
delete_trns = False
|
||||||
# transparency handling
|
# transparency handling
|
||||||
if "transparency" in self.info and self.info['transparency'] is not None:
|
if "transparency" in self.info and \
|
||||||
|
self.info['transparency'] is not None:
|
||||||
if self.mode in ('L', 'RGB') and mode == 'RGBA':
|
if self.mode in ('L', 'RGB') and mode == 'RGBA':
|
||||||
# Use transparent conversion to promote from transparent
|
# Use transparent conversion to promote from transparent
|
||||||
# color to an alpha channel.
|
# color to an alpha channel.
|
||||||
|
@ -784,18 +838,18 @@ class Image:
|
||||||
t = self.info['transparency']
|
t = self.info['transparency']
|
||||||
if isinstance(t, bytes):
|
if isinstance(t, bytes):
|
||||||
# Dragons. This can't be represented by a single color
|
# Dragons. This can't be represented by a single color
|
||||||
warnings.warn('Palette images with Transparency expressed '+
|
warnings.warn('Palette images with Transparency expressed ' +
|
||||||
' in bytes should be converted to RGBA images')
|
' in bytes should be converted to RGBA images')
|
||||||
delete_trns = True
|
delete_trns = True
|
||||||
else:
|
else:
|
||||||
# get the new transparency color.
|
# get the new transparency color.
|
||||||
# use existing conversions
|
# use existing conversions
|
||||||
trns_im = Image()._new(core.new(self.mode, (1,1)))
|
trns_im = Image()._new(core.new(self.mode, (1, 1)))
|
||||||
if self.mode == 'P':
|
if self.mode == 'P':
|
||||||
trns_im.putpalette(self.palette)
|
trns_im.putpalette(self.palette)
|
||||||
trns_im.putpixel((0,0), t)
|
trns_im.putpixel((0, 0), t)
|
||||||
|
|
||||||
if mode in ('L','RGB'):
|
if mode in ('L', 'RGB'):
|
||||||
trns_im = trns_im.convert(mode)
|
trns_im = trns_im.convert(mode)
|
||||||
else:
|
else:
|
||||||
# can't just retrieve the palette number, got to do it
|
# can't just retrieve the palette number, got to do it
|
||||||
|
@ -803,6 +857,8 @@ class Image:
|
||||||
trns_im = trns_im.convert('RGB')
|
trns_im = trns_im.convert('RGB')
|
||||||
trns = trns_im.getpixel((0,0))
|
trns = trns_im.getpixel((0,0))
|
||||||
|
|
||||||
|
elif self.mode == 'P' and mode == 'RGBA':
|
||||||
|
delete_trns = True
|
||||||
|
|
||||||
if mode == "P" and palette == ADAPTIVE:
|
if mode == "P" and palette == ADAPTIVE:
|
||||||
im = self.im.quantize(colors)
|
im = self.im.quantize(colors)
|
||||||
|
@ -820,7 +876,8 @@ class Image:
|
||||||
# if we can't make a transparent color, don't leave the old
|
# if we can't make a transparent color, don't leave the old
|
||||||
# transparency hanging around to mess us up.
|
# transparency hanging around to mess us up.
|
||||||
del(new.info['transparency'])
|
del(new.info['transparency'])
|
||||||
warnings.warn("Couldn't allocate palette entry for transparency")
|
warnings.warn("Couldn't allocate palette entry " +
|
||||||
|
"for transparency")
|
||||||
return new
|
return new
|
||||||
|
|
||||||
# colorspace conversion
|
# colorspace conversion
|
||||||
|
@ -839,7 +896,7 @@ class Image:
|
||||||
|
|
||||||
new_im = self._new(im)
|
new_im = self._new(im)
|
||||||
if delete_trns:
|
if delete_trns:
|
||||||
#crash fail if we leave a bytes transparency in an rgb/l mode.
|
# crash fail if we leave a bytes transparency in an rgb/l mode.
|
||||||
del(new_im.info['transparency'])
|
del(new_im.info['transparency'])
|
||||||
if trns is not None:
|
if trns is not None:
|
||||||
if new_im.mode == 'P':
|
if new_im.mode == 'P':
|
||||||
|
@ -847,7 +904,8 @@ class Image:
|
||||||
new_im.info['transparency'] = new_im.palette.getcolor(trns)
|
new_im.info['transparency'] = new_im.palette.getcolor(trns)
|
||||||
except:
|
except:
|
||||||
del(new_im.info['transparency'])
|
del(new_im.info['transparency'])
|
||||||
warnings.warn("Couldn't allocate palette entry for transparency")
|
warnings.warn("Couldn't allocate palette entry " +
|
||||||
|
"for transparency")
|
||||||
else:
|
else:
|
||||||
new_im.info['transparency'] = trns
|
new_im.info['transparency'] = trns
|
||||||
return new_im
|
return new_im
|
||||||
|
@ -963,7 +1021,8 @@ class Image:
|
||||||
if isinstance(filter, collections.Callable):
|
if isinstance(filter, collections.Callable):
|
||||||
filter = filter()
|
filter = filter()
|
||||||
if not hasattr(filter, "filter"):
|
if not hasattr(filter, "filter"):
|
||||||
raise TypeError("filter argument should be ImageFilter.Filter instance or class")
|
raise TypeError("filter argument should be ImageFilter.Filter " +
|
||||||
|
"instance or class")
|
||||||
|
|
||||||
if self.im.bands == 1:
|
if self.im.bands == 1:
|
||||||
return self._new(filter.filter(self.im))
|
return self._new(filter.filter(self.im))
|
||||||
|
@ -1019,7 +1078,7 @@ class Image:
|
||||||
return out
|
return out
|
||||||
return self.im.getcolors(maxcolors)
|
return self.im.getcolors(maxcolors)
|
||||||
|
|
||||||
def getdata(self, band = None):
|
def getdata(self, band=None):
|
||||||
"""
|
"""
|
||||||
Returns the contents of this image as a sequence object
|
Returns the contents of this image as a sequence object
|
||||||
containing pixel values. The sequence object is flattened, so
|
containing pixel values. The sequence object is flattened, so
|
||||||
|
@ -1070,7 +1129,6 @@ class Image:
|
||||||
self.load()
|
self.load()
|
||||||
return self.im.ptr
|
return self.im.ptr
|
||||||
|
|
||||||
|
|
||||||
def getpalette(self):
|
def getpalette(self):
|
||||||
"""
|
"""
|
||||||
Returns the image palette as a list.
|
Returns the image palette as a list.
|
||||||
|
@ -1088,7 +1146,6 @@ class Image:
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return None # no palette
|
return None # no palette
|
||||||
|
|
||||||
|
|
||||||
def getpixel(self, xy):
|
def getpixel(self, xy):
|
||||||
"""
|
"""
|
||||||
Returns the pixel value at a given position.
|
Returns the pixel value at a given position.
|
||||||
|
@ -1209,7 +1266,8 @@ class Image:
|
||||||
|
|
||||||
if isImageType(box) and mask is None:
|
if isImageType(box) and mask is None:
|
||||||
# abbreviated paste(im, mask) syntax
|
# abbreviated paste(im, mask) syntax
|
||||||
mask = box; box = None
|
mask = box
|
||||||
|
box = None
|
||||||
|
|
||||||
if box is None:
|
if box is None:
|
||||||
# cover all of self
|
# cover all of self
|
||||||
|
@ -1422,7 +1480,7 @@ class Image:
|
||||||
self.load()
|
self.load()
|
||||||
|
|
||||||
if self.pyaccess:
|
if self.pyaccess:
|
||||||
return self.pyaccess.putpixel(xy,value)
|
return self.pyaccess.putpixel(xy, value)
|
||||||
return self.im.putpixel(xy, value)
|
return self.im.putpixel(xy, value)
|
||||||
|
|
||||||
def resize(self, size, resample=NEAREST):
|
def resize(self, size, resample=NEAREST):
|
||||||
|
@ -1471,7 +1529,7 @@ class Image:
|
||||||
clockwise around its centre.
|
clockwise around its centre.
|
||||||
|
|
||||||
:param angle: In degrees counter clockwise.
|
:param angle: In degrees counter clockwise.
|
||||||
:param filter: An optional resampling filter. This can be
|
:param resample: An optional resampling filter. This can be
|
||||||
one of :py:attr:`PIL.Image.NEAREST` (use nearest neighbour),
|
one of :py:attr:`PIL.Image.NEAREST` (use nearest neighbour),
|
||||||
:py:attr:`PIL.Image.BILINEAR` (linear interpolation in a 2x2
|
:py:attr:`PIL.Image.BILINEAR` (linear interpolation in a 2x2
|
||||||
environment), or :py:attr:`PIL.Image.BICUBIC`
|
environment), or :py:attr:`PIL.Image.BICUBIC`
|
||||||
|
@ -1492,6 +1550,7 @@ class Image:
|
||||||
math.cos(angle), math.sin(angle), 0.0,
|
math.cos(angle), math.sin(angle), 0.0,
|
||||||
-math.sin(angle), math.cos(angle), 0.0
|
-math.sin(angle), math.cos(angle), 0.0
|
||||||
]
|
]
|
||||||
|
|
||||||
def transform(x, y, matrix=matrix):
|
def transform(x, y, matrix=matrix):
|
||||||
(a, b, c, d, e, f) = matrix
|
(a, b, c, d, e, f) = matrix
|
||||||
return a*x + b*y + c, d*x + e*y + f
|
return a*x + b*y + c, d*x + e*y + f
|
||||||
|
@ -1667,7 +1726,7 @@ class Image:
|
||||||
"""
|
"""
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def thumbnail(self, size, resample=NEAREST):
|
def thumbnail(self, size, resample=ANTIALIAS):
|
||||||
"""
|
"""
|
||||||
Make this image into a thumbnail. This method modifies the
|
Make this image into a thumbnail. This method modifies the
|
||||||
image to contain a thumbnail version of itself, no larger than
|
image to contain a thumbnail version of itself, no larger than
|
||||||
|
@ -1682,26 +1741,28 @@ class Image:
|
||||||
important than quality.
|
important than quality.
|
||||||
|
|
||||||
Also note that this function modifies the :py:class:`~PIL.Image.Image`
|
Also note that this function modifies the :py:class:`~PIL.Image.Image`
|
||||||
object in place. If you need to use the full resolution image as well, apply
|
object in place. If you need to use the full resolution image as well,
|
||||||
this method to a :py:meth:`~PIL.Image.Image.copy` of the original image.
|
apply this method to a :py:meth:`~PIL.Image.Image.copy` of the original
|
||||||
|
image.
|
||||||
|
|
||||||
:param size: Requested size.
|
:param size: Requested size.
|
||||||
:param resample: Optional resampling filter. This can be one
|
:param resample: Optional resampling filter. This can be one
|
||||||
of :py:attr:`PIL.Image.NEAREST`, :py:attr:`PIL.Image.BILINEAR`,
|
of :py:attr:`PIL.Image.NEAREST`, :py:attr:`PIL.Image.BILINEAR`,
|
||||||
:py:attr:`PIL.Image.BICUBIC`, or :py:attr:`PIL.Image.ANTIALIAS`
|
:py:attr:`PIL.Image.BICUBIC`, or :py:attr:`PIL.Image.ANTIALIAS`
|
||||||
(best quality). If omitted, it defaults to
|
(best quality). If omitted, it defaults to
|
||||||
:py:attr:`PIL.Image.NEAREST` (this will be changed to ANTIALIAS in a
|
:py:attr:`PIL.Image.ANTIALIAS`. (was :py:attr:`PIL.Image.NEAREST`
|
||||||
future version).
|
prior to version 2.5.0)
|
||||||
:returns: None
|
:returns: None
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# FIXME: the default resampling filter will be changed
|
|
||||||
# to ANTIALIAS in future versions
|
|
||||||
|
|
||||||
# preserve aspect ratio
|
# preserve aspect ratio
|
||||||
x, y = self.size
|
x, y = self.size
|
||||||
if x > size[0]: y = int(max(y * size[0] / x, 1)); x = int(size[0])
|
if x > size[0]:
|
||||||
if y > size[1]: x = int(max(x * size[1] / y, 1)); y = int(size[1])
|
y = int(max(y * size[0] / x, 1))
|
||||||
|
x = int(size[0])
|
||||||
|
if y > size[1]:
|
||||||
|
x = int(max(x * size[1] / y, 1))
|
||||||
|
y = int(size[1])
|
||||||
size = x, y
|
size = x, y
|
||||||
|
|
||||||
if size == self.size:
|
if size == self.size:
|
||||||
|
@ -1752,7 +1813,8 @@ class Image:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if self.mode == 'RGBA':
|
if self.mode == 'RGBA':
|
||||||
return self.convert('RGBa').transform(size, method, data, resample, fill).convert('RGBA')
|
return self.convert('RGBa').transform(
|
||||||
|
size, method, data, resample, fill).convert('RGBA')
|
||||||
|
|
||||||
if isinstance(method, ImageTransformHandler):
|
if isinstance(method, ImageTransformHandler):
|
||||||
return method.transform(size, self, resample=resample, fill=fill)
|
return method.transform(size, self, resample=resample, fill=fill)
|
||||||
|
@ -1799,8 +1861,13 @@ class Image:
|
||||||
elif method == QUAD:
|
elif method == QUAD:
|
||||||
# quadrilateral warp. data specifies the four corners
|
# quadrilateral warp. data specifies the four corners
|
||||||
# given as NW, SW, SE, and NE.
|
# given as NW, SW, SE, and NE.
|
||||||
nw = data[0:2]; sw = data[2:4]; se = data[4:6]; ne = data[6:8]
|
nw = data[0:2]
|
||||||
x0, y0 = nw; As = 1.0 / w; At = 1.0 / h
|
sw = data[2:4]
|
||||||
|
se = data[4:6]
|
||||||
|
ne = data[6:8]
|
||||||
|
x0, y0 = nw
|
||||||
|
As = 1.0 / w
|
||||||
|
At = 1.0 / h
|
||||||
data = (x0, (ne[0]-x0)*As, (sw[0]-x0)*At,
|
data = (x0, (ne[0]-x0)*As, (sw[0]-x0)*At,
|
||||||
(se[0]-sw[0]-ne[0]+x0)*As*At,
|
(se[0]-sw[0]-ne[0]+x0)*As*At,
|
||||||
y0, (ne[1]-y0)*As, (sw[1]-y0)*At,
|
y0, (ne[1]-y0)*As, (sw[1]-y0)*At,
|
||||||
|
@ -1834,6 +1901,7 @@ class Image:
|
||||||
im = self.im.transpose(method)
|
im = self.im.transpose(method)
|
||||||
return self._new(im)
|
return self._new(im)
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
# Lazy operations
|
# Lazy operations
|
||||||
|
|
||||||
|
@ -1869,6 +1937,7 @@ class _ImageCrop(Image):
|
||||||
# FIXME: future versions should optimize crop/paste
|
# FIXME: future versions should optimize crop/paste
|
||||||
# sequences!
|
# sequences!
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
# Abstract handlers.
|
# Abstract handlers.
|
||||||
|
|
||||||
|
@ -1876,10 +1945,12 @@ class ImagePointHandler:
|
||||||
# used as a mixin by point transforms (for use with im.point)
|
# used as a mixin by point transforms (for use with im.point)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ImageTransformHandler:
|
class ImageTransformHandler:
|
||||||
# used as a mixin by geometry transforms (for use with im.transform)
|
# used as a mixin by geometry transforms (for use with im.transform)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
# Factories
|
# Factories
|
||||||
|
|
||||||
|
@ -1955,6 +2026,7 @@ def frombytes(mode, size, data, decoder_name="raw", *args):
|
||||||
im.frombytes(data, decoder_name, args)
|
im.frombytes(data, decoder_name, args)
|
||||||
return im
|
return im
|
||||||
|
|
||||||
|
|
||||||
def fromstring(*args, **kw):
|
def fromstring(*args, **kw):
|
||||||
"""Deprecated alias to frombytes.
|
"""Deprecated alias to frombytes.
|
||||||
|
|
||||||
|
@ -2018,7 +2090,7 @@ def frombuffer(mode, size, data, decoder_name="raw", *args):
|
||||||
)
|
)
|
||||||
args = mode, 0, -1 # may change to (mode, 0, 1) post-1.1.6
|
args = mode, 0, -1 # may change to (mode, 0, 1) post-1.1.6
|
||||||
if args[0] in _MAPMODES:
|
if args[0] in _MAPMODES:
|
||||||
im = new(mode, (1,1))
|
im = new(mode, (1, 1))
|
||||||
im = im._new(
|
im = im._new(
|
||||||
core.map_buffer(data, size, decoder_name, None, 0, args)
|
core.map_buffer(data, size, decoder_name, None, 0, args)
|
||||||
)
|
)
|
||||||
|
@ -2138,8 +2210,8 @@ def open(fp, mode="r"):
|
||||||
fp.seek(0)
|
fp.seek(0)
|
||||||
return factory(fp, filename)
|
return factory(fp, filename)
|
||||||
except (SyntaxError, IndexError, TypeError):
|
except (SyntaxError, IndexError, TypeError):
|
||||||
#import traceback
|
# import traceback
|
||||||
#traceback.print_exc()
|
# traceback.print_exc()
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if init():
|
if init():
|
||||||
|
@ -2151,13 +2223,14 @@ def open(fp, mode="r"):
|
||||||
fp.seek(0)
|
fp.seek(0)
|
||||||
return factory(fp, filename)
|
return factory(fp, filename)
|
||||||
except (SyntaxError, IndexError, TypeError):
|
except (SyntaxError, IndexError, TypeError):
|
||||||
#import traceback
|
# import traceback
|
||||||
#traceback.print_exc()
|
# traceback.print_exc()
|
||||||
pass
|
pass
|
||||||
|
|
||||||
raise IOError("cannot identify image file %r"
|
raise IOError("cannot identify image file %r"
|
||||||
% (filename if filename else fp))
|
% (filename if filename else fp))
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Image processing.
|
# Image processing.
|
||||||
|
|
||||||
|
@ -2256,6 +2329,7 @@ def merge(mode, bands):
|
||||||
im.putband(bands[i].im, i)
|
im.putband(bands[i].im, i)
|
||||||
return bands[0]._new(im)
|
return bands[0]._new(im)
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
# Plugin registry
|
# Plugin registry
|
||||||
|
|
||||||
|
@ -2314,6 +2388,7 @@ def _show(image, **options):
|
||||||
# override me, as necessary
|
# override me, as necessary
|
||||||
_showxv(image, **options)
|
_showxv(image, **options)
|
||||||
|
|
||||||
|
|
||||||
def _showxv(image, title=None, **options):
|
def _showxv(image, title=None, **options):
|
||||||
from PIL import ImageShow
|
from PIL import ImageShow
|
||||||
ImageShow.show(image, title, **options)
|
ImageShow.show(image, title, **options)
|
||||||
|
|
317
PIL/ImageCms.py
|
@ -1,19 +1,19 @@
|
||||||
#
|
"""
|
||||||
# The Python Imaging Library.
|
The Python Imaging Library.
|
||||||
# $Id$
|
$Id$
|
||||||
#
|
|
||||||
# optional color managment support, based on Kevin Cazabon's PyCMS
|
Optional color managment support, based on Kevin Cazabon's PyCMS
|
||||||
# library.
|
library.
|
||||||
#
|
|
||||||
# History:
|
History:
|
||||||
# 2009-03-08 fl Added to PIL.
|
2009-03-08 fl Added to PIL.
|
||||||
#
|
|
||||||
# Copyright (C) 2002-2003 Kevin Cazabon
|
Copyright (C) 2002-2003 Kevin Cazabon
|
||||||
# Copyright (c) 2009 by Fredrik Lundh
|
Copyright (c) 2009 by Fredrik Lundh
|
||||||
#
|
|
||||||
# See the README file for information on usage and redistribution. See
|
See the README file for information on usage and redistribution. See
|
||||||
# below for the original description.
|
below for the original description.
|
||||||
#
|
"""
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
|
@ -66,7 +66,8 @@ pyCMS
|
||||||
|
|
||||||
Added try/except statements arount type() checks of
|
Added try/except statements arount type() checks of
|
||||||
potential CObjects... Python won't let you use type()
|
potential CObjects... Python won't let you use type()
|
||||||
on them, and raises a TypeError (stupid, if you ask me!)
|
on them, and raises a TypeError (stupid, if you ask
|
||||||
|
me!)
|
||||||
|
|
||||||
Added buildProofTransformFromOpenProfiles() function.
|
Added buildProofTransformFromOpenProfiles() function.
|
||||||
Additional fixes in DLL, see DLL code for details.
|
Additional fixes in DLL, see DLL code for details.
|
||||||
|
@ -89,8 +90,8 @@ try:
|
||||||
except ImportError as ex:
|
except ImportError as ex:
|
||||||
# Allow error import for doc purposes, but error out when accessing
|
# Allow error import for doc purposes, but error out when accessing
|
||||||
# anything in core.
|
# anything in core.
|
||||||
from _util import deferred_error
|
from _util import import_err
|
||||||
_imagingcms = deferred_error(ex)
|
_imagingcms = import_err(ex)
|
||||||
from PIL._util import isStringType
|
from PIL._util import isStringType
|
||||||
|
|
||||||
core = _imagingcms
|
core = _imagingcms
|
||||||
|
@ -113,9 +114,11 @@ DIRECTION_PROOF = 2
|
||||||
FLAGS = {
|
FLAGS = {
|
||||||
"MATRIXINPUT": 1,
|
"MATRIXINPUT": 1,
|
||||||
"MATRIXOUTPUT": 2,
|
"MATRIXOUTPUT": 2,
|
||||||
"MATRIXONLY": (1|2),
|
"MATRIXONLY": (1 | 2),
|
||||||
"NOWHITEONWHITEFIXUP": 4, # Don't hot fix scum dot
|
"NOWHITEONWHITEFIXUP": 4, # Don't hot fix scum dot
|
||||||
"NOPRELINEARIZATION": 16, # Don't create prelinearization tables on precalculated transforms (internal use)
|
# Don't create prelinearization tables on precalculated transforms
|
||||||
|
# (internal use):
|
||||||
|
"NOPRELINEARIZATION": 16,
|
||||||
"GUESSDEVICECLASS": 32, # Guess device class (for transform2devicelink)
|
"GUESSDEVICECLASS": 32, # Guess device class (for transform2devicelink)
|
||||||
"NOTCACHE": 64, # Inhibit 1-pixel cache
|
"NOTCACHE": 64, # Inhibit 1-pixel cache
|
||||||
"NOTPRECALC": 256,
|
"NOTPRECALC": 256,
|
||||||
|
@ -136,6 +139,7 @@ for flag in FLAGS.values():
|
||||||
if isinstance(flag, int):
|
if isinstance(flag, int):
|
||||||
_MAX_FLAG = _MAX_FLAG | flag
|
_MAX_FLAG = _MAX_FLAG | flag
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------.
|
# --------------------------------------------------------------------.
|
||||||
# Experimental PIL-level API
|
# Experimental PIL-level API
|
||||||
# --------------------------------------------------------------------.
|
# --------------------------------------------------------------------.
|
||||||
|
@ -159,20 +163,22 @@ class ImageCmsProfile:
|
||||||
self.profile = profile
|
self.profile = profile
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
if profile:
|
if profile:
|
||||||
self.product_name = None #profile.product_name
|
self.product_name = None # profile.product_name
|
||||||
self.product_info = None #profile.product_info
|
self.product_info = None # profile.product_info
|
||||||
else:
|
else:
|
||||||
self.product_name = None
|
self.product_name = None
|
||||||
self.product_info = None
|
self.product_info = None
|
||||||
|
|
||||||
|
|
||||||
class ImageCmsTransform(Image.ImagePointHandler):
|
class ImageCmsTransform(Image.ImagePointHandler):
|
||||||
|
|
||||||
"""Transform. This can be used with the procedural API, or with the
|
"""Transform. This can be used with the procedural API, or with the
|
||||||
standard Image.point() method.
|
standard Image.point() method.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, input, output, input_mode, output_mode,
|
def __init__(self, input, output, input_mode, output_mode,
|
||||||
intent=INTENT_PERCEPTUAL,
|
intent=INTENT_PERCEPTUAL, proof=None,
|
||||||
proof=None, proof_intent=INTENT_ABSOLUTE_COLORIMETRIC, flags=0):
|
proof_intent=INTENT_ABSOLUTE_COLORIMETRIC, flags=0):
|
||||||
if proof is None:
|
if proof is None:
|
||||||
self.transform = core.buildTransform(
|
self.transform = core.buildTransform(
|
||||||
input.profile, output.profile,
|
input.profile, output.profile,
|
||||||
|
@ -198,16 +204,17 @@ class ImageCmsTransform(Image.ImagePointHandler):
|
||||||
im.load()
|
im.load()
|
||||||
if imOut is None:
|
if imOut is None:
|
||||||
imOut = Image.new(self.output_mode, im.size, None)
|
imOut = Image.new(self.output_mode, im.size, None)
|
||||||
result = self.transform.apply(im.im.id, imOut.im.id)
|
self.transform.apply(im.im.id, imOut.im.id)
|
||||||
return imOut
|
return imOut
|
||||||
|
|
||||||
def apply_in_place(self, im):
|
def apply_in_place(self, im):
|
||||||
im.load()
|
im.load()
|
||||||
if im.mode != self.output_mode:
|
if im.mode != self.output_mode:
|
||||||
raise ValueError("mode mismatch") # wrong output mode
|
raise ValueError("mode mismatch") # wrong output mode
|
||||||
result = self.transform.apply(im.im.id, im.im.id)
|
self.transform.apply(im.im.id, im.im.id)
|
||||||
return im
|
return im
|
||||||
|
|
||||||
|
|
||||||
def get_display_profile(handle=None):
|
def get_display_profile(handle=None):
|
||||||
""" (experimental) Fetches the profile for the current display device.
|
""" (experimental) Fetches the profile for the current display device.
|
||||||
:returns: None if the profile is not known.
|
:returns: None if the profile is not known.
|
||||||
|
@ -229,15 +236,21 @@ def get_display_profile(handle=None):
|
||||||
profile = get()
|
profile = get()
|
||||||
return ImageCmsProfile(profile)
|
return ImageCmsProfile(profile)
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------.
|
# --------------------------------------------------------------------.
|
||||||
# pyCMS compatible layer
|
# pyCMS compatible layer
|
||||||
# --------------------------------------------------------------------.
|
# --------------------------------------------------------------------.
|
||||||
|
|
||||||
class PyCMSError(Exception):
|
class PyCMSError(Exception):
|
||||||
""" (pyCMS) Exception class. This is used for all errors in the pyCMS API. """
|
|
||||||
|
""" (pyCMS) Exception class.
|
||||||
|
This is used for all errors in the pyCMS API. """
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def profileToProfile(im, inputProfile, outputProfile, renderingIntent=INTENT_PERCEPTUAL, outputMode=None, inPlace=0, flags=0):
|
|
||||||
|
def profileToProfile(
|
||||||
|
im, inputProfile, outputProfile, renderingIntent=INTENT_PERCEPTUAL,
|
||||||
|
outputMode=None, inPlace=0, flags=0):
|
||||||
"""
|
"""
|
||||||
(pyCMS) Applies an ICC transformation to a given image, mapping from
|
(pyCMS) Applies an ICC transformation to a given image, mapping from
|
||||||
inputProfile to outputProfile.
|
inputProfile to outputProfile.
|
||||||
|
@ -259,40 +272,45 @@ def profileToProfile(im, inputProfile, outputProfile, renderingIntent=INTENT_PER
|
||||||
profiles, the input profile must handle RGB data, and the output
|
profiles, the input profile must handle RGB data, and the output
|
||||||
profile must handle CMYK data.
|
profile must handle CMYK data.
|
||||||
|
|
||||||
:param im: An open PIL image object (i.e. Image.new(...) or Image.open(...), etc.)
|
:param im: An open PIL image object (i.e. Image.new(...) or
|
||||||
:param inputProfile: String, as a valid filename path to the ICC input profile
|
Image.open(...), etc.)
|
||||||
you wish to use for this image, or a profile object
|
:param inputProfile: String, as a valid filename path to the ICC input
|
||||||
|
profile you wish to use for this image, or a profile object
|
||||||
:param outputProfile: String, as a valid filename path to the ICC output
|
:param outputProfile: String, as a valid filename path to the ICC output
|
||||||
profile you wish to use for this image, or a profile object
|
profile you wish to use for this image, or a profile object
|
||||||
:param renderingIntent: Integer (0-3) specifying the rendering intent you wish
|
:param renderingIntent: Integer (0-3) specifying the rendering intent you
|
||||||
to use for the transform
|
wish to use for the transform
|
||||||
|
|
||||||
INTENT_PERCEPTUAL = 0 (DEFAULT) (ImageCms.INTENT_PERCEPTUAL)
|
INTENT_PERCEPTUAL = 0 (DEFAULT) (ImageCms.INTENT_PERCEPTUAL)
|
||||||
INTENT_RELATIVE_COLORIMETRIC = 1 (ImageCms.INTENT_RELATIVE_COLORIMETRIC)
|
INTENT_RELATIVE_COLORIMETRIC = 1 (ImageCms.INTENT_RELATIVE_COLORIMETRIC)
|
||||||
INTENT_SATURATION = 2 (ImageCms.INTENT_SATURATION)
|
INTENT_SATURATION = 2 (ImageCms.INTENT_SATURATION)
|
||||||
INTENT_ABSOLUTE_COLORIMETRIC = 3 (ImageCms.INTENT_ABSOLUTE_COLORIMETRIC)
|
INTENT_ABSOLUTE_COLORIMETRIC = 3 (ImageCms.INTENT_ABSOLUTE_COLORIMETRIC)
|
||||||
|
|
||||||
see the pyCMS documentation for details on rendering intents and what they do.
|
see the pyCMS documentation for details on rendering intents and what
|
||||||
:param outputMode: A valid PIL mode for the output image (i.e. "RGB", "CMYK",
|
they do.
|
||||||
etc.). Note: if rendering the image "inPlace", outputMode MUST be the
|
:param outputMode: A valid PIL mode for the output image (i.e. "RGB",
|
||||||
same mode as the input, or omitted completely. If omitted, the outputMode
|
"CMYK", etc.). Note: if rendering the image "inPlace", outputMode
|
||||||
will be the same as the mode of the input image (im.mode)
|
MUST be the same mode as the input, or omitted completely. If
|
||||||
:param inPlace: Boolean (1 = True, None or 0 = False). If True, the original
|
omitted, the outputMode will be the same as the mode of the input
|
||||||
image is modified in-place, and None is returned. If False (default), a
|
image (im.mode)
|
||||||
new Image object is returned with the transform applied.
|
:param inPlace: Boolean (1 = True, None or 0 = False). If True, the
|
||||||
|
original image is modified in-place, and None is returned. If False
|
||||||
|
(default), a new Image object is returned with the transform applied.
|
||||||
:param flags: Integer (0-...) specifying additional flags
|
:param flags: Integer (0-...) specifying additional flags
|
||||||
:returns: Either None or a new PIL image object, depending on value of inPlace
|
:returns: Either None or a new PIL image object, depending on value of
|
||||||
|
inPlace
|
||||||
:exception PyCMSError:
|
:exception PyCMSError:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if outputMode is None:
|
if outputMode is None:
|
||||||
outputMode = im.mode
|
outputMode = im.mode
|
||||||
|
|
||||||
if not isinstance(renderingIntent, int) or not (0 <= renderingIntent <=3):
|
if not isinstance(renderingIntent, int) or not (0 <= renderingIntent <= 3):
|
||||||
raise PyCMSError("renderingIntent must be an integer between 0 and 3")
|
raise PyCMSError("renderingIntent must be an integer between 0 and 3")
|
||||||
|
|
||||||
if not isinstance(flags, int) or not (0 <= flags <= _MAX_FLAG):
|
if not isinstance(flags, int) or not (0 <= flags <= _MAX_FLAG):
|
||||||
raise PyCMSError("flags must be an integer between 0 and %s" + _MAX_FLAG)
|
raise PyCMSError(
|
||||||
|
"flags must be an integer between 0 and %s" + _MAX_FLAG)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not isinstance(inputProfile, ImageCmsProfile):
|
if not isinstance(inputProfile, ImageCmsProfile):
|
||||||
|
@ -300,7 +318,8 @@ def profileToProfile(im, inputProfile, outputProfile, renderingIntent=INTENT_PER
|
||||||
if not isinstance(outputProfile, ImageCmsProfile):
|
if not isinstance(outputProfile, ImageCmsProfile):
|
||||||
outputProfile = ImageCmsProfile(outputProfile)
|
outputProfile = ImageCmsProfile(outputProfile)
|
||||||
transform = ImageCmsTransform(
|
transform = ImageCmsTransform(
|
||||||
inputProfile, outputProfile, im.mode, outputMode, renderingIntent, flags=flags
|
inputProfile, outputProfile, im.mode, outputMode,
|
||||||
|
renderingIntent, flags=flags
|
||||||
)
|
)
|
||||||
if inPlace:
|
if inPlace:
|
||||||
transform.apply_in_place(im)
|
transform.apply_in_place(im)
|
||||||
|
@ -323,8 +342,8 @@ def getOpenProfile(profileFilename):
|
||||||
If profileFilename is not a vaild filename for an ICC profile, a PyCMSError
|
If profileFilename is not a vaild filename for an ICC profile, a PyCMSError
|
||||||
will be raised.
|
will be raised.
|
||||||
|
|
||||||
:param profileFilename: String, as a valid filename path to the ICC profile you
|
:param profileFilename: String, as a valid filename path to the ICC profile
|
||||||
wish to open, or a file-like object.
|
you wish to open, or a file-like object.
|
||||||
:returns: A CmsProfile class object.
|
:returns: A CmsProfile class object.
|
||||||
:exception PyCMSError:
|
:exception PyCMSError:
|
||||||
"""
|
"""
|
||||||
|
@ -334,7 +353,10 @@ def getOpenProfile(profileFilename):
|
||||||
except (IOError, TypeError, ValueError) as v:
|
except (IOError, TypeError, ValueError) as v:
|
||||||
raise PyCMSError(v)
|
raise PyCMSError(v)
|
||||||
|
|
||||||
def buildTransform(inputProfile, outputProfile, inMode, outMode, renderingIntent=INTENT_PERCEPTUAL, flags=0):
|
|
||||||
|
def buildTransform(
|
||||||
|
inputProfile, outputProfile, inMode, outMode,
|
||||||
|
renderingIntent=INTENT_PERCEPTUAL, flags=0):
|
||||||
"""
|
"""
|
||||||
(pyCMS) Builds an ICC transform mapping from the inputProfile to the
|
(pyCMS) Builds an ICC transform mapping from the inputProfile to the
|
||||||
outputProfile. Use applyTransform to apply the transform to a given
|
outputProfile. Use applyTransform to apply the transform to a given
|
||||||
|
@ -367,14 +389,14 @@ def buildTransform(inputProfile, outputProfile, inMode, outMode, renderingIntent
|
||||||
manually overridden if you really want to, but I don't know of any
|
manually overridden if you really want to, but I don't know of any
|
||||||
time that would be of use, or would even work).
|
time that would be of use, or would even work).
|
||||||
|
|
||||||
:param inputProfile: String, as a valid filename path to the ICC input profile
|
:param inputProfile: String, as a valid filename path to the ICC input
|
||||||
you wish to use for this transform, or a profile object
|
profile you wish to use for this transform, or a profile object
|
||||||
:param outputProfile: String, as a valid filename path to the ICC output
|
:param outputProfile: String, as a valid filename path to the ICC output
|
||||||
profile you wish to use for this transform, or a profile object
|
profile you wish to use for this transform, or a profile object
|
||||||
:param inMode: String, as a valid PIL mode that the appropriate profile also
|
:param inMode: String, as a valid PIL mode that the appropriate profile
|
||||||
supports (i.e. "RGB", "RGBA", "CMYK", etc.)
|
also supports (i.e. "RGB", "RGBA", "CMYK", etc.)
|
||||||
:param outMode: String, as a valid PIL mode that the appropriate profile also
|
:param outMode: String, as a valid PIL mode that the appropriate profile
|
||||||
supports (i.e. "RGB", "RGBA", "CMYK", etc.)
|
also supports (i.e. "RGB", "RGBA", "CMYK", etc.)
|
||||||
:param renderingIntent: Integer (0-3) specifying the rendering intent you
|
:param renderingIntent: Integer (0-3) specifying the rendering intent you
|
||||||
wish to use for the transform
|
wish to use for the transform
|
||||||
|
|
||||||
|
@ -383,28 +405,37 @@ def buildTransform(inputProfile, outputProfile, inMode, outMode, renderingIntent
|
||||||
INTENT_SATURATION = 2 (ImageCms.INTENT_SATURATION)
|
INTENT_SATURATION = 2 (ImageCms.INTENT_SATURATION)
|
||||||
INTENT_ABSOLUTE_COLORIMETRIC = 3 (ImageCms.INTENT_ABSOLUTE_COLORIMETRIC)
|
INTENT_ABSOLUTE_COLORIMETRIC = 3 (ImageCms.INTENT_ABSOLUTE_COLORIMETRIC)
|
||||||
|
|
||||||
see the pyCMS documentation for details on rendering intents and what they do.
|
see the pyCMS documentation for details on rendering intents and what
|
||||||
|
they do.
|
||||||
:param flags: Integer (0-...) specifying additional flags
|
:param flags: Integer (0-...) specifying additional flags
|
||||||
:returns: A CmsTransform class object.
|
:returns: A CmsTransform class object.
|
||||||
:exception PyCMSError:
|
:exception PyCMSError:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not isinstance(renderingIntent, int) or not (0 <= renderingIntent <=3):
|
if not isinstance(renderingIntent, int) or not (0 <= renderingIntent <= 3):
|
||||||
raise PyCMSError("renderingIntent must be an integer between 0 and 3")
|
raise PyCMSError("renderingIntent must be an integer between 0 and 3")
|
||||||
|
|
||||||
if not isinstance(flags, int) or not (0 <= flags <= _MAX_FLAG):
|
if not isinstance(flags, int) or not (0 <= flags <= _MAX_FLAG):
|
||||||
raise PyCMSError("flags must be an integer between 0 and %s" + _MAX_FLAG)
|
raise PyCMSError(
|
||||||
|
"flags must be an integer between 0 and %s" + _MAX_FLAG)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not isinstance(inputProfile, ImageCmsProfile):
|
if not isinstance(inputProfile, ImageCmsProfile):
|
||||||
inputProfile = ImageCmsProfile(inputProfile)
|
inputProfile = ImageCmsProfile(inputProfile)
|
||||||
if not isinstance(outputProfile, ImageCmsProfile):
|
if not isinstance(outputProfile, ImageCmsProfile):
|
||||||
outputProfile = ImageCmsProfile(outputProfile)
|
outputProfile = ImageCmsProfile(outputProfile)
|
||||||
return ImageCmsTransform(inputProfile, outputProfile, inMode, outMode, renderingIntent, flags=flags)
|
return ImageCmsTransform(
|
||||||
|
inputProfile, outputProfile, inMode, outMode,
|
||||||
|
renderingIntent, flags=flags)
|
||||||
except (IOError, TypeError, ValueError) as v:
|
except (IOError, TypeError, ValueError) as v:
|
||||||
raise PyCMSError(v)
|
raise PyCMSError(v)
|
||||||
|
|
||||||
def buildProofTransform(inputProfile, outputProfile, proofProfile, inMode, outMode, renderingIntent=INTENT_PERCEPTUAL, proofRenderingIntent=INTENT_ABSOLUTE_COLORIMETRIC, flags=FLAGS["SOFTPROOFING"]):
|
|
||||||
|
def buildProofTransform(
|
||||||
|
inputProfile, outputProfile, proofProfile, inMode, outMode,
|
||||||
|
renderingIntent=INTENT_PERCEPTUAL,
|
||||||
|
proofRenderingIntent=INTENT_ABSOLUTE_COLORIMETRIC,
|
||||||
|
flags=FLAGS["SOFTPROOFING"]):
|
||||||
"""
|
"""
|
||||||
(pyCMS) Builds an ICC transform mapping from the inputProfile to the
|
(pyCMS) Builds an ICC transform mapping from the inputProfile to the
|
||||||
outputProfile, but tries to simulate the result that would be
|
outputProfile, but tries to simulate the result that would be
|
||||||
|
@ -443,17 +474,17 @@ def buildProofTransform(inputProfile, outputProfile, proofProfile, inMode, outMo
|
||||||
when the simulated device has a much wider gamut than the output
|
when the simulated device has a much wider gamut than the output
|
||||||
device, you may obtain marginal results.
|
device, you may obtain marginal results.
|
||||||
|
|
||||||
:param inputProfile: String, as a valid filename path to the ICC input profile
|
:param inputProfile: String, as a valid filename path to the ICC input
|
||||||
you wish to use for this transform, or a profile object
|
profile you wish to use for this transform, or a profile object
|
||||||
:param outputProfile: String, as a valid filename path to the ICC output
|
:param outputProfile: String, as a valid filename path to the ICC output
|
||||||
(monitor, usually) profile you wish to use for this transform, or a
|
(monitor, usually) profile you wish to use for this transform, or a
|
||||||
profile object
|
profile object
|
||||||
:param proofProfile: String, as a valid filename path to the ICC proof profile
|
:param proofProfile: String, as a valid filename path to the ICC proof
|
||||||
you wish to use for this transform, or a profile object
|
profile you wish to use for this transform, or a profile object
|
||||||
:param inMode: String, as a valid PIL mode that the appropriate profile also
|
:param inMode: String, as a valid PIL mode that the appropriate profile
|
||||||
supports (i.e. "RGB", "RGBA", "CMYK", etc.)
|
also supports (i.e. "RGB", "RGBA", "CMYK", etc.)
|
||||||
:param outMode: String, as a valid PIL mode that the appropriate profile also
|
:param outMode: String, as a valid PIL mode that the appropriate profile
|
||||||
supports (i.e. "RGB", "RGBA", "CMYK", etc.)
|
also supports (i.e. "RGB", "RGBA", "CMYK", etc.)
|
||||||
:param renderingIntent: Integer (0-3) specifying the rendering intent you
|
:param renderingIntent: Integer (0-3) specifying the rendering intent you
|
||||||
wish to use for the input->proof (simulated) transform
|
wish to use for the input->proof (simulated) transform
|
||||||
|
|
||||||
|
@ -462,7 +493,8 @@ def buildProofTransform(inputProfile, outputProfile, proofProfile, inMode, outMo
|
||||||
INTENT_SATURATION = 2 (ImageCms.INTENT_SATURATION)
|
INTENT_SATURATION = 2 (ImageCms.INTENT_SATURATION)
|
||||||
INTENT_ABSOLUTE_COLORIMETRIC = 3 (ImageCms.INTENT_ABSOLUTE_COLORIMETRIC)
|
INTENT_ABSOLUTE_COLORIMETRIC = 3 (ImageCms.INTENT_ABSOLUTE_COLORIMETRIC)
|
||||||
|
|
||||||
see the pyCMS documentation for details on rendering intents and what they do.
|
see the pyCMS documentation for details on rendering intents and what
|
||||||
|
they do.
|
||||||
:param proofRenderingIntent: Integer (0-3) specifying the rendering intent you
|
:param proofRenderingIntent: Integer (0-3) specifying the rendering intent you
|
||||||
wish to use for proof->output transform
|
wish to use for proof->output transform
|
||||||
|
|
||||||
|
@ -471,17 +503,19 @@ def buildProofTransform(inputProfile, outputProfile, proofProfile, inMode, outMo
|
||||||
INTENT_SATURATION = 2 (ImageCms.INTENT_SATURATION)
|
INTENT_SATURATION = 2 (ImageCms.INTENT_SATURATION)
|
||||||
INTENT_ABSOLUTE_COLORIMETRIC = 3 (ImageCms.INTENT_ABSOLUTE_COLORIMETRIC)
|
INTENT_ABSOLUTE_COLORIMETRIC = 3 (ImageCms.INTENT_ABSOLUTE_COLORIMETRIC)
|
||||||
|
|
||||||
see the pyCMS documentation for details on rendering intents and what they do.
|
see the pyCMS documentation for details on rendering intents and what
|
||||||
|
they do.
|
||||||
:param flags: Integer (0-...) specifying additional flags
|
:param flags: Integer (0-...) specifying additional flags
|
||||||
:returns: A CmsTransform class object.
|
:returns: A CmsTransform class object.
|
||||||
:exception PyCMSError:
|
:exception PyCMSError:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not isinstance(renderingIntent, int) or not (0 <= renderingIntent <=3):
|
if not isinstance(renderingIntent, int) or not (0 <= renderingIntent <= 3):
|
||||||
raise PyCMSError("renderingIntent must be an integer between 0 and 3")
|
raise PyCMSError("renderingIntent must be an integer between 0 and 3")
|
||||||
|
|
||||||
if not isinstance(flags, int) or not (0 <= flags <= _MAX_FLAG):
|
if not isinstance(flags, int) or not (0 <= flags <= _MAX_FLAG):
|
||||||
raise PyCMSError("flags must be an integer between 0 and %s" + _MAX_FLAG)
|
raise PyCMSError(
|
||||||
|
"flags must be an integer between 0 and %s" + _MAX_FLAG)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not isinstance(inputProfile, ImageCmsProfile):
|
if not isinstance(inputProfile, ImageCmsProfile):
|
||||||
|
@ -490,13 +524,16 @@ def buildProofTransform(inputProfile, outputProfile, proofProfile, inMode, outMo
|
||||||
outputProfile = ImageCmsProfile(outputProfile)
|
outputProfile = ImageCmsProfile(outputProfile)
|
||||||
if not isinstance(proofProfile, ImageCmsProfile):
|
if not isinstance(proofProfile, ImageCmsProfile):
|
||||||
proofProfile = ImageCmsProfile(proofProfile)
|
proofProfile = ImageCmsProfile(proofProfile)
|
||||||
return ImageCmsTransform(inputProfile, outputProfile, inMode, outMode, renderingIntent, proofProfile, proofRenderingIntent, flags)
|
return ImageCmsTransform(
|
||||||
|
inputProfile, outputProfile, inMode, outMode, renderingIntent,
|
||||||
|
proofProfile, proofRenderingIntent, flags)
|
||||||
except (IOError, TypeError, ValueError) as v:
|
except (IOError, TypeError, ValueError) as v:
|
||||||
raise PyCMSError(v)
|
raise PyCMSError(v)
|
||||||
|
|
||||||
buildTransformFromOpenProfiles = buildTransform
|
buildTransformFromOpenProfiles = buildTransform
|
||||||
buildProofTransformFromOpenProfiles = buildProofTransform
|
buildProofTransformFromOpenProfiles = buildProofTransform
|
||||||
|
|
||||||
|
|
||||||
def applyTransform(im, transform, inPlace=0):
|
def applyTransform(im, transform, inPlace=0):
|
||||||
"""
|
"""
|
||||||
(pyCMS) Applies a transform to a given image.
|
(pyCMS) Applies a transform to a given image.
|
||||||
|
@ -514,8 +551,8 @@ def applyTransform(im, transform, inPlace=0):
|
||||||
is raised.
|
is raised.
|
||||||
|
|
||||||
This function applies a pre-calculated transform (from
|
This function applies a pre-calculated transform (from
|
||||||
ImageCms.buildTransform() or ImageCms.buildTransformFromOpenProfiles()) to an
|
ImageCms.buildTransform() or ImageCms.buildTransformFromOpenProfiles())
|
||||||
image. The transform can be used for multiple images, saving
|
to an image. The transform can be used for multiple images, saving
|
||||||
considerable calcuation time if doing the same conversion multiple times.
|
considerable calcuation time if doing the same conversion multiple times.
|
||||||
|
|
||||||
If you want to modify im in-place instead of receiving a new image as
|
If you want to modify im in-place instead of receiving a new image as
|
||||||
|
@ -528,10 +565,12 @@ def applyTransform(im, transform, inPlace=0):
|
||||||
:param im: A PIL Image object, and im.mode must be the same as the inMode
|
:param im: A PIL Image object, and im.mode must be the same as the inMode
|
||||||
supported by the transform.
|
supported by the transform.
|
||||||
:param transform: A valid CmsTransform class object
|
:param transform: A valid CmsTransform class object
|
||||||
:param inPlace: Bool (1 == True, 0 or None == False). If True, im is modified
|
:param inPlace: Bool (1 == True, 0 or None == False). If True, im is
|
||||||
in place and None is returned, if False, a new Image object with the
|
modified in place and None is returned, if False, a new Image object
|
||||||
transform applied is returned (and im is not changed). The default is False.
|
with the transform applied is returned (and im is not changed). The
|
||||||
:returns: Either None, or a new PIL Image object, depending on the value of inPlace
|
default is False.
|
||||||
|
:returns: Either None, or a new PIL Image object, depending on the value of
|
||||||
|
inPlace
|
||||||
:exception PyCMSError:
|
:exception PyCMSError:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -546,6 +585,7 @@ def applyTransform(im, transform, inPlace=0):
|
||||||
|
|
||||||
return imOut
|
return imOut
|
||||||
|
|
||||||
|
|
||||||
def createProfile(colorSpace, colorTemp=-1):
|
def createProfile(colorSpace, colorTemp=-1):
|
||||||
"""
|
"""
|
||||||
(pyCMS) Creates a profile.
|
(pyCMS) Creates a profile.
|
||||||
|
@ -562,30 +602,36 @@ def createProfile(colorSpace, colorTemp=-1):
|
||||||
ImageCms.buildTransformFromOpenProfiles() to create a transform to apply
|
ImageCms.buildTransformFromOpenProfiles() to create a transform to apply
|
||||||
to images.
|
to images.
|
||||||
|
|
||||||
:param colorSpace: String, the color space of the profile you wish to create.
|
:param colorSpace: String, the color space of the profile you wish to
|
||||||
|
create.
|
||||||
Currently only "LAB", "XYZ", and "sRGB" are supported.
|
Currently only "LAB", "XYZ", and "sRGB" are supported.
|
||||||
:param colorTemp: Positive integer for the white point for the profile, in
|
:param colorTemp: Positive integer for the white point for the profile, in
|
||||||
degrees Kelvin (i.e. 5000, 6500, 9600, etc.). The default is for D50
|
degrees Kelvin (i.e. 5000, 6500, 9600, etc.). The default is for D50
|
||||||
illuminant if omitted (5000k). colorTemp is ONLY applied to LAB profiles,
|
illuminant if omitted (5000k). colorTemp is ONLY applied to LAB
|
||||||
and is ignored for XYZ and sRGB.
|
profiles, and is ignored for XYZ and sRGB.
|
||||||
:returns: A CmsProfile class object
|
:returns: A CmsProfile class object
|
||||||
:exception PyCMSError:
|
:exception PyCMSError:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if colorSpace not in ["LAB", "XYZ", "sRGB"]:
|
if colorSpace not in ["LAB", "XYZ", "sRGB"]:
|
||||||
raise PyCMSError("Color space not supported for on-the-fly profile creation (%s)" % colorSpace)
|
raise PyCMSError(
|
||||||
|
"Color space not supported for on-the-fly profile creation (%s)"
|
||||||
|
% colorSpace)
|
||||||
|
|
||||||
if colorSpace == "LAB":
|
if colorSpace == "LAB":
|
||||||
try:
|
try:
|
||||||
colorTemp = float(colorTemp)
|
colorTemp = float(colorTemp)
|
||||||
except:
|
except:
|
||||||
raise PyCMSError("Color temperature must be numeric, \"%s\" not valid" % colorTemp)
|
raise PyCMSError(
|
||||||
|
"Color temperature must be numeric, \"%s\" not valid"
|
||||||
|
% colorTemp)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return core.createProfile(colorSpace, colorTemp)
|
return core.createProfile(colorSpace, colorTemp)
|
||||||
except (TypeError, ValueError) as v:
|
except (TypeError, ValueError) as v:
|
||||||
raise PyCMSError(v)
|
raise PyCMSError(v)
|
||||||
|
|
||||||
|
|
||||||
def getProfileName(profile):
|
def getProfileName(profile):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -600,10 +646,10 @@ def getProfileName(profile):
|
||||||
profile was originally created. Sometimes this tag also contains
|
profile was originally created. Sometimes this tag also contains
|
||||||
additional information supplied by the creator.
|
additional information supplied by the creator.
|
||||||
|
|
||||||
:param profile: EITHER a valid CmsProfile object, OR a string of the filename
|
:param profile: EITHER a valid CmsProfile object, OR a string of the
|
||||||
of an ICC profile.
|
filename of an ICC profile.
|
||||||
:returns: A string containing the internal name of the profile as stored in an
|
:returns: A string containing the internal name of the profile as stored
|
||||||
ICC tag.
|
in an ICC tag.
|
||||||
:exception PyCMSError:
|
:exception PyCMSError:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -619,7 +665,7 @@ def getProfileName(profile):
|
||||||
manufacturer = profile.profile.product_manufacturer
|
manufacturer = profile.profile.product_manufacturer
|
||||||
|
|
||||||
if not (model or manufacturer):
|
if not (model or manufacturer):
|
||||||
return profile.profile.product_description+"\n"
|
return profile.profile.product_description + "\n"
|
||||||
if not manufacturer or len(model) > 30:
|
if not manufacturer or len(model) > 30:
|
||||||
return model + "\n"
|
return model + "\n"
|
||||||
return "%s - %s\n" % (model, manufacturer)
|
return "%s - %s\n" % (model, manufacturer)
|
||||||
|
@ -627,6 +673,7 @@ def getProfileName(profile):
|
||||||
except (AttributeError, IOError, TypeError, ValueError) as v:
|
except (AttributeError, IOError, TypeError, ValueError) as v:
|
||||||
raise PyCMSError(v)
|
raise PyCMSError(v)
|
||||||
|
|
||||||
|
|
||||||
def getProfileInfo(profile):
|
def getProfileInfo(profile):
|
||||||
"""
|
"""
|
||||||
(pyCMS) Gets the internal product information for the given profile.
|
(pyCMS) Gets the internal product information for the given profile.
|
||||||
|
@ -641,10 +688,10 @@ def getProfileInfo(profile):
|
||||||
info tag. This often contains details about the profile, and how it
|
info tag. This often contains details about the profile, and how it
|
||||||
was created, as supplied by the creator.
|
was created, as supplied by the creator.
|
||||||
|
|
||||||
:param profile: EITHER a valid CmsProfile object, OR a string of the filename
|
:param profile: EITHER a valid CmsProfile object, OR a string of the
|
||||||
of an ICC profile.
|
filename of an ICC profile.
|
||||||
:returns: A string containing the internal profile information stored in an ICC
|
:returns: A string containing the internal profile information stored in
|
||||||
tag.
|
an ICC tag.
|
||||||
:exception PyCMSError:
|
:exception PyCMSError:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -652,7 +699,8 @@ def getProfileInfo(profile):
|
||||||
if not isinstance(profile, ImageCmsProfile):
|
if not isinstance(profile, ImageCmsProfile):
|
||||||
profile = ImageCmsProfile(profile)
|
profile = ImageCmsProfile(profile)
|
||||||
# add an extra newline to preserve pyCMS compatibility
|
# add an extra newline to preserve pyCMS compatibility
|
||||||
# Python, not C. the white point bits weren't working well, so skipping.
|
# Python, not C. the white point bits weren't working well,
|
||||||
|
# so skipping.
|
||||||
# // info was description \r\n\r\n copyright \r\n\r\n K007 tag \r\n\r\n whitepoint
|
# // info was description \r\n\r\n copyright \r\n\r\n K007 tag \r\n\r\n whitepoint
|
||||||
description = profile.profile.product_description
|
description = profile.profile.product_description
|
||||||
cpright = profile.profile.product_copyright
|
cpright = profile.profile.product_copyright
|
||||||
|
@ -660,7 +708,7 @@ def getProfileInfo(profile):
|
||||||
for elt in (description, cpright):
|
for elt in (description, cpright):
|
||||||
if elt:
|
if elt:
|
||||||
arr.append(elt)
|
arr.append(elt)
|
||||||
return "\r\n\r\n".join(arr)+"\r\n\r\n"
|
return "\r\n\r\n".join(arr) + "\r\n\r\n"
|
||||||
|
|
||||||
except (AttributeError, IOError, TypeError, ValueError) as v:
|
except (AttributeError, IOError, TypeError, ValueError) as v:
|
||||||
raise PyCMSError(v)
|
raise PyCMSError(v)
|
||||||
|
@ -679,10 +727,10 @@ def getProfileCopyright(profile):
|
||||||
Use this function to obtain the information stored in the profile's
|
Use this function to obtain the information stored in the profile's
|
||||||
copyright tag.
|
copyright tag.
|
||||||
|
|
||||||
:param profile: EITHER a valid CmsProfile object, OR a string of the filename
|
:param profile: EITHER a valid CmsProfile object, OR a string of the
|
||||||
of an ICC profile.
|
filename of an ICC profile.
|
||||||
:returns: A string containing the internal profile information stored in an ICC
|
:returns: A string containing the internal profile information stored in
|
||||||
tag.
|
an ICC tag.
|
||||||
:exception PyCMSError:
|
:exception PyCMSError:
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
|
@ -693,6 +741,7 @@ def getProfileCopyright(profile):
|
||||||
except (AttributeError, IOError, TypeError, ValueError) as v:
|
except (AttributeError, IOError, TypeError, ValueError) as v:
|
||||||
raise PyCMSError(v)
|
raise PyCMSError(v)
|
||||||
|
|
||||||
|
|
||||||
def getProfileManufacturer(profile):
|
def getProfileManufacturer(profile):
|
||||||
"""
|
"""
|
||||||
(pyCMS) Gets the manufacturer for the given profile.
|
(pyCMS) Gets the manufacturer for the given profile.
|
||||||
|
@ -700,16 +749,16 @@ def getProfileManufacturer(profile):
|
||||||
If profile isn't a valid CmsProfile object or filename to a profile,
|
If profile isn't a valid CmsProfile object or filename to a profile,
|
||||||
a PyCMSError is raised.
|
a PyCMSError is raised.
|
||||||
|
|
||||||
If an error occurs while trying to obtain the manufacturer tag, a PyCMSError
|
If an error occurs while trying to obtain the manufacturer tag, a
|
||||||
is raised
|
PyCMSError is raised
|
||||||
|
|
||||||
Use this function to obtain the information stored in the profile's
|
Use this function to obtain the information stored in the profile's
|
||||||
manufacturer tag.
|
manufacturer tag.
|
||||||
|
|
||||||
:param profile: EITHER a valid CmsProfile object, OR a string of the filename
|
:param profile: EITHER a valid CmsProfile object, OR a string of the
|
||||||
of an ICC profile.
|
filename of an ICC profile.
|
||||||
:returns: A string containing the internal profile information stored in an ICC
|
:returns: A string containing the internal profile information stored in
|
||||||
tag.
|
an ICC tag.
|
||||||
:exception PyCMSError:
|
:exception PyCMSError:
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
|
@ -720,6 +769,7 @@ def getProfileManufacturer(profile):
|
||||||
except (AttributeError, IOError, TypeError, ValueError) as v:
|
except (AttributeError, IOError, TypeError, ValueError) as v:
|
||||||
raise PyCMSError(v)
|
raise PyCMSError(v)
|
||||||
|
|
||||||
|
|
||||||
def getProfileModel(profile):
|
def getProfileModel(profile):
|
||||||
"""
|
"""
|
||||||
(pyCMS) Gets the model for the given profile.
|
(pyCMS) Gets the model for the given profile.
|
||||||
|
@ -733,10 +783,10 @@ def getProfileModel(profile):
|
||||||
Use this function to obtain the information stored in the profile's
|
Use this function to obtain the information stored in the profile's
|
||||||
model tag.
|
model tag.
|
||||||
|
|
||||||
:param profile: EITHER a valid CmsProfile object, OR a string of the filename
|
:param profile: EITHER a valid CmsProfile object, OR a string of the
|
||||||
of an ICC profile.
|
filename of an ICC profile.
|
||||||
:returns: A string containing the internal profile information stored in an ICC
|
:returns: A string containing the internal profile information stored in
|
||||||
tag.
|
an ICC tag.
|
||||||
:exception PyCMSError:
|
:exception PyCMSError:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -748,6 +798,7 @@ def getProfileModel(profile):
|
||||||
except (AttributeError, IOError, TypeError, ValueError) as v:
|
except (AttributeError, IOError, TypeError, ValueError) as v:
|
||||||
raise PyCMSError(v)
|
raise PyCMSError(v)
|
||||||
|
|
||||||
|
|
||||||
def getProfileDescription(profile):
|
def getProfileDescription(profile):
|
||||||
"""
|
"""
|
||||||
(pyCMS) Gets the description for the given profile.
|
(pyCMS) Gets the description for the given profile.
|
||||||
|
@ -761,10 +812,10 @@ def getProfileDescription(profile):
|
||||||
Use this function to obtain the information stored in the profile's
|
Use this function to obtain the information stored in the profile's
|
||||||
description tag.
|
description tag.
|
||||||
|
|
||||||
:param profile: EITHER a valid CmsProfile object, OR a string of the filename
|
:param profile: EITHER a valid CmsProfile object, OR a string of the
|
||||||
of an ICC profile.
|
filename of an ICC profile.
|
||||||
:returns: A string containing the internal profile information stored in an ICC
|
:returns: A string containing the internal profile information stored in an
|
||||||
tag.
|
ICC tag.
|
||||||
:exception PyCMSError:
|
:exception PyCMSError:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -793,16 +844,18 @@ def getDefaultIntent(profile):
|
||||||
If you wish to use a different intent than returned, use
|
If you wish to use a different intent than returned, use
|
||||||
ImageCms.isIntentSupported() to verify it will work first.
|
ImageCms.isIntentSupported() to verify it will work first.
|
||||||
|
|
||||||
:param profile: EITHER a valid CmsProfile object, OR a string of the filename
|
:param profile: EITHER a valid CmsProfile object, OR a string of the
|
||||||
of an ICC profile.
|
filename of an ICC profile.
|
||||||
:returns: Integer 0-3 specifying the default rendering intent for this profile.
|
:returns: Integer 0-3 specifying the default rendering intent for this
|
||||||
|
profile.
|
||||||
|
|
||||||
INTENT_PERCEPTUAL = 0 (DEFAULT) (ImageCms.INTENT_PERCEPTUAL)
|
INTENT_PERCEPTUAL = 0 (DEFAULT) (ImageCms.INTENT_PERCEPTUAL)
|
||||||
INTENT_RELATIVE_COLORIMETRIC = 1 (ImageCms.INTENT_RELATIVE_COLORIMETRIC)
|
INTENT_RELATIVE_COLORIMETRIC = 1 (ImageCms.INTENT_RELATIVE_COLORIMETRIC)
|
||||||
INTENT_SATURATION = 2 (ImageCms.INTENT_SATURATION)
|
INTENT_SATURATION = 2 (ImageCms.INTENT_SATURATION)
|
||||||
INTENT_ABSOLUTE_COLORIMETRIC = 3 (ImageCms.INTENT_ABSOLUTE_COLORIMETRIC)
|
INTENT_ABSOLUTE_COLORIMETRIC = 3 (ImageCms.INTENT_ABSOLUTE_COLORIMETRIC)
|
||||||
|
|
||||||
see the pyCMS documentation for details on rendering intents and what they do.
|
see the pyCMS documentation for details on rendering intents and what
|
||||||
|
they do.
|
||||||
:exception PyCMSError:
|
:exception PyCMSError:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -813,6 +866,7 @@ def getDefaultIntent(profile):
|
||||||
except (AttributeError, IOError, TypeError, ValueError) as v:
|
except (AttributeError, IOError, TypeError, ValueError) as v:
|
||||||
raise PyCMSError(v)
|
raise PyCMSError(v)
|
||||||
|
|
||||||
|
|
||||||
def isIntentSupported(profile, intent, direction):
|
def isIntentSupported(profile, intent, direction):
|
||||||
"""
|
"""
|
||||||
(pyCMS) Checks if a given intent is supported.
|
(pyCMS) Checks if a given intent is supported.
|
||||||
|
@ -828,17 +882,18 @@ def isIntentSupported(profile, intent, direction):
|
||||||
potential PyCMSError that will occur if they don't support the modes
|
potential PyCMSError that will occur if they don't support the modes
|
||||||
you select.
|
you select.
|
||||||
|
|
||||||
:param profile: EITHER a valid CmsProfile object, OR a string of the filename
|
:param profile: EITHER a valid CmsProfile object, OR a string of the
|
||||||
of an ICC profile.
|
filename of an ICC profile.
|
||||||
:param intent: Integer (0-3) specifying the rendering intent you wish to use
|
:param intent: Integer (0-3) specifying the rendering intent you wish to
|
||||||
with this profile
|
use with this profile
|
||||||
|
|
||||||
INTENT_PERCEPTUAL = 0 (DEFAULT) (ImageCms.INTENT_PERCEPTUAL)
|
INTENT_PERCEPTUAL = 0 (DEFAULT) (ImageCms.INTENT_PERCEPTUAL)
|
||||||
INTENT_RELATIVE_COLORIMETRIC = 1 (ImageCms.INTENT_RELATIVE_COLORIMETRIC)
|
INTENT_RELATIVE_COLORIMETRIC = 1 (ImageCms.INTENT_RELATIVE_COLORIMETRIC)
|
||||||
INTENT_SATURATION = 2 (ImageCms.INTENT_SATURATION)
|
INTENT_SATURATION = 2 (ImageCms.INTENT_SATURATION)
|
||||||
INTENT_ABSOLUTE_COLORIMETRIC = 3 (ImageCms.INTENT_ABSOLUTE_COLORIMETRIC)
|
INTENT_ABSOLUTE_COLORIMETRIC = 3 (ImageCms.INTENT_ABSOLUTE_COLORIMETRIC)
|
||||||
|
|
||||||
see the pyCMS documentation for details on rendering intents and what they do.
|
see the pyCMS documentation for details on rendering intents and what
|
||||||
|
they do.
|
||||||
:param direction: Integer specifing if the profile is to be used for input,
|
:param direction: Integer specifing if the profile is to be used for input,
|
||||||
output, or proof
|
output, or proof
|
||||||
|
|
||||||
|
@ -862,6 +917,7 @@ def isIntentSupported(profile, intent, direction):
|
||||||
except (AttributeError, IOError, TypeError, ValueError) as v:
|
except (AttributeError, IOError, TypeError, ValueError) as v:
|
||||||
raise PyCMSError(v)
|
raise PyCMSError(v)
|
||||||
|
|
||||||
|
|
||||||
def versions():
|
def versions():
|
||||||
"""
|
"""
|
||||||
(pyCMS) Fetches versions.
|
(pyCMS) Fetches versions.
|
||||||
|
@ -869,7 +925,8 @@ def versions():
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
return (
|
return (
|
||||||
VERSION, core.littlecms_version, sys.version.split()[0], Image.VERSION
|
VERSION, core.littlecms_version,
|
||||||
|
sys.version.split()[0], Image.VERSION
|
||||||
)
|
)
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
|
@ -880,14 +937,16 @@ if __name__ == "__main__":
|
||||||
from PIL import ImageCms
|
from PIL import ImageCms
|
||||||
print(__doc__)
|
print(__doc__)
|
||||||
|
|
||||||
for f in dir(pyCMS):
|
for f in dir(ImageCms):
|
||||||
print("="*80)
|
doc = None
|
||||||
print("%s" %f)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
exec ("doc = ImageCms.%s.__doc__" %(f))
|
exec("doc = %s.__doc__" % (f))
|
||||||
if "pyCMS" in doc:
|
if "pyCMS" in doc:
|
||||||
# so we don't get the __doc__ string for imported modules
|
# so we don't get the __doc__ string for imported modules
|
||||||
|
print("=" * 80)
|
||||||
|
print("%s" % f)
|
||||||
print(doc)
|
print(doc)
|
||||||
except AttributeError:
|
except (AttributeError, TypeError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# End of file
|
||||||
|
|
|
@ -20,6 +20,7 @@ import struct
|
||||||
import os
|
import os
|
||||||
import io
|
import io
|
||||||
|
|
||||||
|
|
||||||
def _parse_codestream(fp):
|
def _parse_codestream(fp):
|
||||||
"""Parse the JPEG 2000 codestream to extract the size and component
|
"""Parse the JPEG 2000 codestream to extract the size and component
|
||||||
count from the SIZ marker segment, returning a PIL (size, mode) tuple."""
|
count from the SIZ marker segment, returning a PIL (size, mode) tuple."""
|
||||||
|
@ -51,6 +52,7 @@ def _parse_codestream(fp):
|
||||||
|
|
||||||
return (size, mode)
|
return (size, mode)
|
||||||
|
|
||||||
|
|
||||||
def _parse_jp2_header(fp):
|
def _parse_jp2_header(fp):
|
||||||
"""Parse the JP2 header box to extract size, component count and
|
"""Parse the JP2 header box to extract size, component count and
|
||||||
color space information, returning a PIL (size, mode) tuple."""
|
color space information, returning a PIL (size, mode) tuple."""
|
||||||
|
@ -127,6 +129,7 @@ def _parse_jp2_header(fp):
|
||||||
|
|
||||||
return (size, mode)
|
return (size, mode)
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# Image plugin for JPEG2000 images.
|
# Image plugin for JPEG2000 images.
|
||||||
|
|
||||||
|
@ -180,10 +183,12 @@ class Jpeg2KImageFile(ImageFile.ImageFile):
|
||||||
|
|
||||||
ImageFile.ImageFile.load(self)
|
ImageFile.ImageFile.load(self)
|
||||||
|
|
||||||
|
|
||||||
def _accept(prefix):
|
def _accept(prefix):
|
||||||
return (prefix[:4] == b'\xff\x4f\xff\x51'
|
return (prefix[:4] == b'\xff\x4f\xff\x51'
|
||||||
or prefix[:12] == b'\x00\x00\x00\x0cjP \x0d\x0a\x87\x0a')
|
or prefix[:12] == b'\x00\x00\x00\x0cjP \x0d\x0a\x87\x0a')
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------
|
# ------------------------------------------------------------
|
||||||
# Save support
|
# Save support
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,8 @@
|
||||||
|
|
||||||
__version__ = "0.6"
|
__version__ = "0.6"
|
||||||
|
|
||||||
import array, struct
|
import array
|
||||||
|
import struct
|
||||||
from PIL import Image, ImageFile, _binary
|
from PIL import Image, ImageFile, _binary
|
||||||
from PIL.JpegPresets import presets
|
from PIL.JpegPresets import presets
|
||||||
from PIL._util import isStringType
|
from PIL._util import isStringType
|
||||||
|
@ -44,6 +45,7 @@ o8 = _binary.o8
|
||||||
i16 = _binary.i16be
|
i16 = _binary.i16be
|
||||||
i32 = _binary.i32be
|
i32 = _binary.i32be
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Parser
|
# Parser
|
||||||
|
|
||||||
|
@ -51,6 +53,7 @@ def Skip(self, marker):
|
||||||
n = i16(self.fp.read(2))-2
|
n = i16(self.fp.read(2))-2
|
||||||
ImageFile._safe_read(self.fp, n)
|
ImageFile._safe_read(self.fp, n)
|
||||||
|
|
||||||
|
|
||||||
def APP(self, marker):
|
def APP(self, marker):
|
||||||
#
|
#
|
||||||
# Application marker. Store these in the APP dictionary.
|
# Application marker. Store these in the APP dictionary.
|
||||||
|
@ -59,7 +62,7 @@ def APP(self, marker):
|
||||||
n = i16(self.fp.read(2))-2
|
n = i16(self.fp.read(2))-2
|
||||||
s = ImageFile._safe_read(self.fp, n)
|
s = ImageFile._safe_read(self.fp, n)
|
||||||
|
|
||||||
app = "APP%d" % (marker&15)
|
app = "APP%d" % (marker & 15)
|
||||||
|
|
||||||
self.app[app] = s # compatibility
|
self.app[app] = s # compatibility
|
||||||
self.applist.append((app, s))
|
self.applist.append((app, s))
|
||||||
|
@ -108,16 +111,17 @@ def APP(self, marker):
|
||||||
else:
|
else:
|
||||||
self.info["adobe_transform"] = adobe_transform
|
self.info["adobe_transform"] = adobe_transform
|
||||||
|
|
||||||
|
|
||||||
def COM(self, marker):
|
def COM(self, marker):
|
||||||
#
|
#
|
||||||
# Comment marker. Store these in the APP dictionary.
|
# Comment marker. Store these in the APP dictionary.
|
||||||
|
|
||||||
n = i16(self.fp.read(2))-2
|
n = i16(self.fp.read(2))-2
|
||||||
s = ImageFile._safe_read(self.fp, n)
|
s = ImageFile._safe_read(self.fp, n)
|
||||||
|
|
||||||
self.app["COM"] = s # compatibility
|
self.app["COM"] = s # compatibility
|
||||||
self.applist.append(("COM", s))
|
self.applist.append(("COM", s))
|
||||||
|
|
||||||
|
|
||||||
def SOF(self, marker):
|
def SOF(self, marker):
|
||||||
#
|
#
|
||||||
# Start of frame marker. Defines the size and mode of the
|
# Start of frame marker. Defines the size and mode of the
|
||||||
|
@ -163,7 +167,8 @@ def SOF(self, marker):
|
||||||
for i in range(6, len(s), 3):
|
for i in range(6, len(s), 3):
|
||||||
t = s[i:i+3]
|
t = s[i:i+3]
|
||||||
# 4-tuples: id, vsamp, hsamp, qtable
|
# 4-tuples: id, vsamp, hsamp, qtable
|
||||||
self.layer.append((t[0], i8(t[1])//16, i8(t[1])&15, i8(t[2])))
|
self.layer.append((t[0], i8(t[1])//16, i8(t[1]) & 15, i8(t[2])))
|
||||||
|
|
||||||
|
|
||||||
def DQT(self, marker):
|
def DQT(self, marker):
|
||||||
#
|
#
|
||||||
|
@ -181,7 +186,7 @@ def DQT(self, marker):
|
||||||
raise SyntaxError("bad quantization table marker")
|
raise SyntaxError("bad quantization table marker")
|
||||||
v = i8(s[0])
|
v = i8(s[0])
|
||||||
if v//16 == 0:
|
if v//16 == 0:
|
||||||
self.quantization[v&15] = array.array("b", s[1:65])
|
self.quantization[v & 15] = array.array("b", s[1:65])
|
||||||
s = s[65:]
|
s = s[65:]
|
||||||
else:
|
else:
|
||||||
return # FIXME: add code to read 16-bit tables!
|
return # FIXME: add code to read 16-bit tables!
|
||||||
|
@ -261,6 +266,7 @@ MARKER = {
|
||||||
def _accept(prefix):
|
def _accept(prefix):
|
||||||
return prefix[0:1] == b"\377"
|
return prefix[0:1] == b"\377"
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# Image plugin for JPEG and JFIF images.
|
# Image plugin for JPEG and JFIF images.
|
||||||
|
|
||||||
|
@ -290,9 +296,14 @@ class JpegImageFile(ImageFile.ImageFile):
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
|
i = i8(s)
|
||||||
|
if i == 0xFF:
|
||||||
s = s + self.fp.read(1)
|
s = s + self.fp.read(1)
|
||||||
|
|
||||||
i = i16(s)
|
i = i16(s)
|
||||||
|
else:
|
||||||
|
# Skip non-0xFF junk
|
||||||
|
s = b"\xff"
|
||||||
|
continue
|
||||||
|
|
||||||
if i in MARKER:
|
if i in MARKER:
|
||||||
name, description, handler = MARKER[i]
|
name, description, handler = MARKER[i]
|
||||||
|
@ -303,13 +314,13 @@ class JpegImageFile(ImageFile.ImageFile):
|
||||||
rawmode = self.mode
|
rawmode = self.mode
|
||||||
if self.mode == "CMYK":
|
if self.mode == "CMYK":
|
||||||
rawmode = "CMYK;I" # assume adobe conventions
|
rawmode = "CMYK;I" # assume adobe conventions
|
||||||
self.tile = [("jpeg", (0,0) + self.size, 0, (rawmode, ""))]
|
self.tile = [("jpeg", (0, 0) + self.size, 0, (rawmode, ""))]
|
||||||
# self.__offset = self.fp.tell()
|
# self.__offset = self.fp.tell()
|
||||||
break
|
break
|
||||||
s = self.fp.read(1)
|
s = self.fp.read(1)
|
||||||
elif i == 0 or i == 65535:
|
elif i == 0 or i == 0xFFFF:
|
||||||
# padded marker or junk; move on
|
# padded marker or junk; move on
|
||||||
s = "\xff"
|
s = b"\xff"
|
||||||
else:
|
else:
|
||||||
raise SyntaxError("no marker found")
|
raise SyntaxError("no marker found")
|
||||||
|
|
||||||
|
@ -343,7 +354,8 @@ class JpegImageFile(ImageFile.ImageFile):
|
||||||
|
|
||||||
# ALTERNATIVE: handle JPEGs via the IJG command line utilities
|
# ALTERNATIVE: handle JPEGs via the IJG command line utilities
|
||||||
|
|
||||||
import tempfile, os
|
import tempfile
|
||||||
|
import os
|
||||||
f, path = tempfile.mkstemp()
|
f, path = tempfile.mkstemp()
|
||||||
os.close(f)
|
os.close(f)
|
||||||
if os.path.exists(self.filename):
|
if os.path.exists(self.filename):
|
||||||
|
@ -354,8 +366,10 @@ class JpegImageFile(ImageFile.ImageFile):
|
||||||
try:
|
try:
|
||||||
self.im = Image.core.open_ppm(path)
|
self.im = Image.core.open_ppm(path)
|
||||||
finally:
|
finally:
|
||||||
try: os.unlink(path)
|
try:
|
||||||
except: pass
|
os.unlink(path)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
self.mode = self.im.mode
|
self.mode = self.im.mode
|
||||||
self.size = self.im.size
|
self.size = self.im.size
|
||||||
|
@ -372,6 +386,7 @@ def _getexif(self):
|
||||||
# version.
|
# version.
|
||||||
from PIL import TiffImagePlugin
|
from PIL import TiffImagePlugin
|
||||||
import io
|
import io
|
||||||
|
|
||||||
def fixup(value):
|
def fixup(value):
|
||||||
if len(value) == 1:
|
if len(value) == 1:
|
||||||
return value[0]
|
return value[0]
|
||||||
|
@ -441,16 +456,19 @@ samplings = {
|
||||||
(2, 2, 1, 1, 1, 1): 2,
|
(2, 2, 1, 1, 1, 1): 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def convert_dict_qtables(qtables):
|
def convert_dict_qtables(qtables):
|
||||||
qtables = [qtables[key] for key in range(len(qtables)) if key in qtables]
|
qtables = [qtables[key] for key in range(len(qtables)) if key in qtables]
|
||||||
for idx, table in enumerate(qtables):
|
for idx, table in enumerate(qtables):
|
||||||
qtables[idx] = [table[i] for i in zigzag_index]
|
qtables[idx] = [table[i] for i in zigzag_index]
|
||||||
return qtables
|
return qtables
|
||||||
|
|
||||||
|
|
||||||
def get_sampling(im):
|
def get_sampling(im):
|
||||||
sampling = im.layer[0][1:3] + im.layer[1][1:3] + im.layer[2][1:3]
|
sampling = im.layer[0][1:3] + im.layer[1][1:3] + im.layer[2][1:3]
|
||||||
return samplings.get(sampling, -1)
|
return samplings.get(sampling, -1)
|
||||||
|
|
||||||
|
|
||||||
def _save(im, fp, filename):
|
def _save(im, fp, filename):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -563,12 +581,11 @@ def _save(im, fp, filename):
|
||||||
info.get("exif", b"")
|
info.get("exif", b"")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# if we optimize, libjpeg needs a buffer big enough to hold the whole image
|
||||||
# if we optimize, libjpeg needs a buffer big enough to hold the whole image in a shot.
|
# in a shot. Guessing on the size, at im.size bytes. (raw pizel size is
|
||||||
# Guessing on the size, at im.size bytes. (raw pizel size is channels*size, this
|
# channels*size, this is a value that's been used in a django patch.
|
||||||
# is a value that's been used in a django patch.
|
|
||||||
# https://github.com/jdriscoll/django-imagekit/issues/50
|
# https://github.com/jdriscoll/django-imagekit/issues/50
|
||||||
bufsize=0
|
bufsize = 0
|
||||||
if "optimize" in info or "progressive" in info or "progression" in info:
|
if "optimize" in info or "progressive" in info or "progression" in info:
|
||||||
if quality >= 95:
|
if quality >= 95:
|
||||||
bufsize = 2 * im.size[0] * im.size[1]
|
bufsize = 2 * im.size[0] * im.size[1]
|
||||||
|
@ -577,17 +594,20 @@ def _save(im, fp, filename):
|
||||||
|
|
||||||
# The exif info needs to be written as one block, + APP1, + one spare byte.
|
# The exif info needs to be written as one block, + APP1, + one spare byte.
|
||||||
# Ensure that our buffer is big enough
|
# Ensure that our buffer is big enough
|
||||||
bufsize = max(ImageFile.MAXBLOCK, bufsize, len(info.get("exif",b"")) + 5 )
|
bufsize = max(ImageFile.MAXBLOCK, bufsize, len(info.get("exif", b"")) + 5)
|
||||||
|
|
||||||
|
ImageFile._save(im, fp, [("jpeg", (0, 0)+im.size, 0, rawmode)], bufsize)
|
||||||
|
|
||||||
ImageFile._save(im, fp, [("jpeg", (0,0)+im.size, 0, rawmode)], bufsize)
|
|
||||||
|
|
||||||
def _save_cjpeg(im, fp, filename):
|
def _save_cjpeg(im, fp, filename):
|
||||||
# ALTERNATIVE: handle JPEGs via the IJG command line utilities.
|
# ALTERNATIVE: handle JPEGs via the IJG command line utilities.
|
||||||
import os
|
import os
|
||||||
file = im._dump()
|
file = im._dump()
|
||||||
os.system("cjpeg %s >%s" % (file, filename))
|
os.system("cjpeg %s >%s" % (file, filename))
|
||||||
try: os.unlink(file)
|
try:
|
||||||
except: pass
|
os.unlink(file)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
# -------------------------------------------------------------------q-
|
# -------------------------------------------------------------------q-
|
||||||
# Registry stuff
|
# Registry stuff
|
||||||
|
|
|
@ -7,7 +7,7 @@ This is an improved version of the OleFileIO module from [PIL](http://www.python
|
||||||
|
|
||||||
As far as I know, this module is now the most complete and robust Python implementation to read MS OLE2 files, portable on several operating systems. (please tell me if you know other similar Python modules)
|
As far as I know, this module is now the most complete and robust Python implementation to read MS OLE2 files, portable on several operating systems. (please tell me if you know other similar Python modules)
|
||||||
|
|
||||||
OleFileIO_PL can be used as an independent module or with PIL. The goal is to have it integrated into [Pillow](http://python-imaging.github.io/), the friendly fork of PIL.
|
OleFileIO_PL can be used as an independent module or with PIL. The goal is to have it integrated into [Pillow](http://python-pillow.github.io/), the friendly fork of PIL.
|
||||||
|
|
||||||
OleFileIO\_PL is mostly meant for developers. If you are looking for tools to analyze OLE files or to extract data, then please also check [python-oletools](http://www.decalage.info/python/oletools), which are built upon OleFileIO_PL.
|
OleFileIO\_PL is mostly meant for developers. If you are looking for tools to analyze OLE files or to extract data, then please also check [python-oletools](http://www.decalage.info/python/oletools), which are built upon OleFileIO_PL.
|
||||||
|
|
||||||
|
|
|
@ -46,9 +46,11 @@ def _obj(fp, obj, **dict):
|
||||||
fp.write("/%s %s\n" % (k, v))
|
fp.write("/%s %s\n" % (k, v))
|
||||||
fp.write(">>\n")
|
fp.write(">>\n")
|
||||||
|
|
||||||
|
|
||||||
def _endobj(fp):
|
def _endobj(fp):
|
||||||
fp.write("endobj\n")
|
fp.write("endobj\n")
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# (Internal) Image save plugin for the PDF format.
|
# (Internal) Image save plugin for the PDF format.
|
||||||
|
|
||||||
|
@ -64,8 +66,10 @@ def _save(im, fp, filename):
|
||||||
class TextWriter:
|
class TextWriter:
|
||||||
def __init__(self, fp):
|
def __init__(self, fp):
|
||||||
self.fp = fp
|
self.fp = fp
|
||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
return getattr(self.fp, name)
|
return getattr(self.fp, name)
|
||||||
|
|
||||||
def write(self, value):
|
def write(self, value):
|
||||||
self.fp.write(value.encode('latin-1'))
|
self.fp.write(value.encode('latin-1'))
|
||||||
|
|
||||||
|
@ -105,7 +109,7 @@ def _save(im, fp, filename):
|
||||||
g = i8(palette[i*3+1])
|
g = i8(palette[i*3+1])
|
||||||
b = i8(palette[i*3+2])
|
b = i8(palette[i*3+2])
|
||||||
colorspace += "%02x%02x%02x " % (r, g, b)
|
colorspace += "%02x%02x%02x " % (r, g, b)
|
||||||
colorspace += b"> ]"
|
colorspace += "> ]"
|
||||||
procset = "/ImageI" # indexed color
|
procset = "/ImageI" # indexed color
|
||||||
elif im.mode == "RGB":
|
elif im.mode == "RGB":
|
||||||
filter = "/DCTDecode"
|
filter = "/DCTDecode"
|
||||||
|
@ -122,17 +126,21 @@ def _save(im, fp, filename):
|
||||||
# catalogue
|
# catalogue
|
||||||
|
|
||||||
xref[1] = fp.tell()
|
xref[1] = fp.tell()
|
||||||
_obj(fp, 1, Type = "/Catalog",
|
_obj(
|
||||||
Pages = "2 0 R")
|
fp, 1,
|
||||||
|
Type="/Catalog",
|
||||||
|
Pages="2 0 R")
|
||||||
_endobj(fp)
|
_endobj(fp)
|
||||||
|
|
||||||
#
|
#
|
||||||
# pages
|
# pages
|
||||||
|
|
||||||
xref[2] = fp.tell()
|
xref[2] = fp.tell()
|
||||||
_obj(fp, 2, Type = "/Pages",
|
_obj(
|
||||||
Count = 1,
|
fp, 2,
|
||||||
Kids = "[4 0 R]")
|
Type="/Pages",
|
||||||
|
Count=1,
|
||||||
|
Kids="[4 0 R]")
|
||||||
_endobj(fp)
|
_endobj(fp)
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -144,29 +152,31 @@ def _save(im, fp, filename):
|
||||||
if bits == 1:
|
if bits == 1:
|
||||||
# FIXME: the hex encoder doesn't support packed 1-bit
|
# FIXME: the hex encoder doesn't support packed 1-bit
|
||||||
# images; do things the hard way...
|
# images; do things the hard way...
|
||||||
data = im.tostring("raw", "1")
|
data = im.tobytes("raw", "1")
|
||||||
im = Image.new("L", (len(data), 1), None)
|
im = Image.new("L", (len(data), 1), None)
|
||||||
im.putdata(data)
|
im.putdata(data)
|
||||||
ImageFile._save(im, op, [("hex", (0,0)+im.size, 0, im.mode)])
|
ImageFile._save(im, op, [("hex", (0, 0)+im.size, 0, im.mode)])
|
||||||
elif filter == "/DCTDecode":
|
elif filter == "/DCTDecode":
|
||||||
Image.SAVE["JPEG"](im, op, filename)
|
Image.SAVE["JPEG"](im, op, filename)
|
||||||
elif filter == "/FlateDecode":
|
elif filter == "/FlateDecode":
|
||||||
ImageFile._save(im, op, [("zip", (0,0)+im.size, 0, im.mode)])
|
ImageFile._save(im, op, [("zip", (0, 0)+im.size, 0, im.mode)])
|
||||||
elif filter == "/RunLengthDecode":
|
elif filter == "/RunLengthDecode":
|
||||||
ImageFile._save(im, op, [("packbits", (0,0)+im.size, 0, im.mode)])
|
ImageFile._save(im, op, [("packbits", (0, 0)+im.size, 0, im.mode)])
|
||||||
else:
|
else:
|
||||||
raise ValueError("unsupported PDF filter (%s)" % filter)
|
raise ValueError("unsupported PDF filter (%s)" % filter)
|
||||||
|
|
||||||
xref[3] = fp.tell()
|
xref[3] = fp.tell()
|
||||||
_obj(fp, 3, Type = "/XObject",
|
_obj(
|
||||||
Subtype = "/Image",
|
fp, 3,
|
||||||
Width = width, # * 72.0 / resolution,
|
Type="/XObject",
|
||||||
Height = height, # * 72.0 / resolution,
|
Subtype="/Image",
|
||||||
Length = len(op.getvalue()),
|
Width=width, # * 72.0 / resolution,
|
||||||
Filter = filter,
|
Height=height, # * 72.0 / resolution,
|
||||||
BitsPerComponent = bits,
|
Length=len(op.getvalue()),
|
||||||
DecodeParams = params,
|
Filter=filter,
|
||||||
ColorSpace = colorspace)
|
BitsPerComponent=bits,
|
||||||
|
DecodeParams=params,
|
||||||
|
ColorSpace=colorspace)
|
||||||
|
|
||||||
fp.write("stream\n")
|
fp.write("stream\n")
|
||||||
fp.fp.write(op.getvalue())
|
fp.fp.write(op.getvalue())
|
||||||
|
@ -179,11 +189,14 @@ def _save(im, fp, filename):
|
||||||
|
|
||||||
xref[4] = fp.tell()
|
xref[4] = fp.tell()
|
||||||
_obj(fp, 4)
|
_obj(fp, 4)
|
||||||
fp.write("<<\n/Type /Page\n/Parent 2 0 R\n"\
|
fp.write(
|
||||||
"/Resources <<\n/ProcSet [ /PDF %s ]\n"\
|
"<<\n/Type /Page\n/Parent 2 0 R\n"
|
||||||
"/XObject << /image 3 0 R >>\n>>\n"\
|
"/Resources <<\n/ProcSet [ /PDF %s ]\n"
|
||||||
"/MediaBox [ 0 0 %d %d ]\n/Contents 5 0 R\n>>\n" %\
|
"/XObject << /image 3 0 R >>\n>>\n"
|
||||||
(procset, int(width * 72.0 /resolution) , int(height * 72.0 / resolution)))
|
"/MediaBox [ 0 0 %d %d ]\n/Contents 5 0 R\n>>\n" % (
|
||||||
|
procset,
|
||||||
|
int(width * 72.0 / resolution),
|
||||||
|
int(height * 72.0 / resolution)))
|
||||||
_endobj(fp)
|
_endobj(fp)
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -191,10 +204,13 @@ def _save(im, fp, filename):
|
||||||
|
|
||||||
op = TextWriter(io.BytesIO())
|
op = TextWriter(io.BytesIO())
|
||||||
|
|
||||||
op.write("q %d 0 0 %d 0 0 cm /image Do Q\n" % (int(width * 72.0 / resolution), int(height * 72.0 / resolution)))
|
op.write(
|
||||||
|
"q %d 0 0 %d 0 0 cm /image Do Q\n" % (
|
||||||
|
int(width * 72.0 / resolution),
|
||||||
|
int(height * 72.0 / resolution)))
|
||||||
|
|
||||||
xref[5] = fp.tell()
|
xref[5] = fp.tell()
|
||||||
_obj(fp, 5, Length = len(op.fp.getvalue()))
|
_obj(fp, 5, Length=len(op.fp.getvalue()))
|
||||||
|
|
||||||
fp.write("stream\n")
|
fp.write("stream\n")
|
||||||
fp.fp.write(op.fp.getvalue())
|
fp.fp.write(op.fp.getvalue())
|
||||||
|
|
|
@ -89,33 +89,33 @@ class ChunkStream:
|
||||||
"Fetch a new chunk. Returns header information."
|
"Fetch a new chunk. Returns header information."
|
||||||
|
|
||||||
if self.queue:
|
if self.queue:
|
||||||
cid, pos, len = self.queue[-1]
|
cid, pos, length = self.queue[-1]
|
||||||
del self.queue[-1]
|
del self.queue[-1]
|
||||||
self.fp.seek(pos)
|
self.fp.seek(pos)
|
||||||
else:
|
else:
|
||||||
s = self.fp.read(8)
|
s = self.fp.read(8)
|
||||||
cid = s[4:]
|
cid = s[4:]
|
||||||
pos = self.fp.tell()
|
pos = self.fp.tell()
|
||||||
len = i32(s)
|
length = i32(s)
|
||||||
|
|
||||||
if not is_cid(cid):
|
if not is_cid(cid):
|
||||||
raise SyntaxError("broken PNG file (chunk %s)" % repr(cid))
|
raise SyntaxError("broken PNG file (chunk %s)" % repr(cid))
|
||||||
|
|
||||||
return cid, pos, len
|
return cid, pos, length
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
self.queue = self.crc = self.fp = None
|
self.queue = self.crc = self.fp = None
|
||||||
|
|
||||||
def push(self, cid, pos, len):
|
def push(self, cid, pos, length):
|
||||||
|
|
||||||
self.queue.append((cid, pos, len))
|
self.queue.append((cid, pos, length))
|
||||||
|
|
||||||
def call(self, cid, pos, len):
|
def call(self, cid, pos, length):
|
||||||
"Call the appropriate chunk handler"
|
"Call the appropriate chunk handler"
|
||||||
|
|
||||||
if Image.DEBUG:
|
if Image.DEBUG:
|
||||||
print("STREAM", cid, pos, len)
|
print("STREAM", cid, pos, length)
|
||||||
return getattr(self, "chunk_" + cid.decode('ascii'))(pos, len)
|
return getattr(self, "chunk_" + cid.decode('ascii'))(pos, length)
|
||||||
|
|
||||||
def crc(self, cid, data):
|
def crc(self, cid, data):
|
||||||
"Read and verify checksum"
|
"Read and verify checksum"
|
||||||
|
@ -139,10 +139,10 @@ class ChunkStream:
|
||||||
cids = []
|
cids = []
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
cid, pos, len = self.read()
|
cid, pos, length = self.read()
|
||||||
if cid == endchunk:
|
if cid == endchunk:
|
||||||
break
|
break
|
||||||
self.crc(cid, ImageFile._safe_read(self.fp, len))
|
self.crc(cid, ImageFile._safe_read(self.fp, length))
|
||||||
cids.append(cid)
|
cids.append(cid)
|
||||||
|
|
||||||
return cids
|
return cids
|
||||||
|
@ -190,10 +190,10 @@ class PngStream(ChunkStream):
|
||||||
self.im_tile = None
|
self.im_tile = None
|
||||||
self.im_palette = None
|
self.im_palette = None
|
||||||
|
|
||||||
def chunk_iCCP(self, pos, len):
|
def chunk_iCCP(self, pos, length):
|
||||||
|
|
||||||
# ICC profile
|
# ICC profile
|
||||||
s = ImageFile._safe_read(self.fp, len)
|
s = ImageFile._safe_read(self.fp, length)
|
||||||
# according to PNG spec, the iCCP chunk contains:
|
# according to PNG spec, the iCCP chunk contains:
|
||||||
# Profile name 1-79 bytes (character string)
|
# Profile name 1-79 bytes (character string)
|
||||||
# Null separator 1 byte (null character)
|
# Null separator 1 byte (null character)
|
||||||
|
@ -213,10 +213,10 @@ class PngStream(ChunkStream):
|
||||||
self.im_info["icc_profile"] = icc_profile
|
self.im_info["icc_profile"] = icc_profile
|
||||||
return s
|
return s
|
||||||
|
|
||||||
def chunk_IHDR(self, pos, len):
|
def chunk_IHDR(self, pos, length):
|
||||||
|
|
||||||
# image header
|
# image header
|
||||||
s = ImageFile._safe_read(self.fp, len)
|
s = ImageFile._safe_read(self.fp, length)
|
||||||
self.im_size = i32(s), i32(s[4:])
|
self.im_size = i32(s), i32(s[4:])
|
||||||
try:
|
try:
|
||||||
self.im_mode, self.im_rawmode = _MODES[(i8(s[8]), i8(s[9]))]
|
self.im_mode, self.im_rawmode = _MODES[(i8(s[8]), i8(s[9]))]
|
||||||
|
@ -228,30 +228,30 @@ class PngStream(ChunkStream):
|
||||||
raise SyntaxError("unknown filter category")
|
raise SyntaxError("unknown filter category")
|
||||||
return s
|
return s
|
||||||
|
|
||||||
def chunk_IDAT(self, pos, len):
|
def chunk_IDAT(self, pos, length):
|
||||||
|
|
||||||
# image data
|
# image data
|
||||||
self.im_tile = [("zip", (0,0)+self.im_size, pos, self.im_rawmode)]
|
self.im_tile = [("zip", (0,0)+self.im_size, pos, self.im_rawmode)]
|
||||||
self.im_idat = len
|
self.im_idat = length
|
||||||
raise EOFError
|
raise EOFError
|
||||||
|
|
||||||
def chunk_IEND(self, pos, len):
|
def chunk_IEND(self, pos, length):
|
||||||
|
|
||||||
# end of PNG image
|
# end of PNG image
|
||||||
raise EOFError
|
raise EOFError
|
||||||
|
|
||||||
def chunk_PLTE(self, pos, len):
|
def chunk_PLTE(self, pos, length):
|
||||||
|
|
||||||
# palette
|
# palette
|
||||||
s = ImageFile._safe_read(self.fp, len)
|
s = ImageFile._safe_read(self.fp, length)
|
||||||
if self.im_mode == "P":
|
if self.im_mode == "P":
|
||||||
self.im_palette = "RGB", s
|
self.im_palette = "RGB", s
|
||||||
return s
|
return s
|
||||||
|
|
||||||
def chunk_tRNS(self, pos, len):
|
def chunk_tRNS(self, pos, length):
|
||||||
|
|
||||||
# transparency
|
# transparency
|
||||||
s = ImageFile._safe_read(self.fp, len)
|
s = ImageFile._safe_read(self.fp, length)
|
||||||
if self.im_mode == "P":
|
if self.im_mode == "P":
|
||||||
if _simple_palette.match(s):
|
if _simple_palette.match(s):
|
||||||
i = s.find(b"\0")
|
i = s.find(b"\0")
|
||||||
|
@ -265,17 +265,17 @@ class PngStream(ChunkStream):
|
||||||
self.im_info["transparency"] = i16(s), i16(s[2:]), i16(s[4:])
|
self.im_info["transparency"] = i16(s), i16(s[2:]), i16(s[4:])
|
||||||
return s
|
return s
|
||||||
|
|
||||||
def chunk_gAMA(self, pos, len):
|
def chunk_gAMA(self, pos, length):
|
||||||
|
|
||||||
# gamma setting
|
# gamma setting
|
||||||
s = ImageFile._safe_read(self.fp, len)
|
s = ImageFile._safe_read(self.fp, length)
|
||||||
self.im_info["gamma"] = i32(s) / 100000.0
|
self.im_info["gamma"] = i32(s) / 100000.0
|
||||||
return s
|
return s
|
||||||
|
|
||||||
def chunk_pHYs(self, pos, len):
|
def chunk_pHYs(self, pos, length):
|
||||||
|
|
||||||
# pixels per unit
|
# pixels per unit
|
||||||
s = ImageFile._safe_read(self.fp, len)
|
s = ImageFile._safe_read(self.fp, length)
|
||||||
px, py = i32(s), i32(s[4:])
|
px, py = i32(s), i32(s[4:])
|
||||||
unit = i8(s[8])
|
unit = i8(s[8])
|
||||||
if unit == 1: # meter
|
if unit == 1: # meter
|
||||||
|
@ -285,10 +285,10 @@ class PngStream(ChunkStream):
|
||||||
self.im_info["aspect"] = px, py
|
self.im_info["aspect"] = px, py
|
||||||
return s
|
return s
|
||||||
|
|
||||||
def chunk_tEXt(self, pos, len):
|
def chunk_tEXt(self, pos, length):
|
||||||
|
|
||||||
# text
|
# text
|
||||||
s = ImageFile._safe_read(self.fp, len)
|
s = ImageFile._safe_read(self.fp, length)
|
||||||
try:
|
try:
|
||||||
k, v = s.split(b"\0", 1)
|
k, v = s.split(b"\0", 1)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
@ -301,10 +301,10 @@ class PngStream(ChunkStream):
|
||||||
self.im_info[k] = self.im_text[k] = v
|
self.im_info[k] = self.im_text[k] = v
|
||||||
return s
|
return s
|
||||||
|
|
||||||
def chunk_zTXt(self, pos, len):
|
def chunk_zTXt(self, pos, length):
|
||||||
|
|
||||||
# compressed text
|
# compressed text
|
||||||
s = ImageFile._safe_read(self.fp, len)
|
s = ImageFile._safe_read(self.fp, length)
|
||||||
try:
|
try:
|
||||||
k, v = s.split(b"\0", 1)
|
k, v = s.split(b"\0", 1)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
@ -358,16 +358,16 @@ class PngImageFile(ImageFile.ImageFile):
|
||||||
#
|
#
|
||||||
# get next chunk
|
# get next chunk
|
||||||
|
|
||||||
cid, pos, len = self.png.read()
|
cid, pos, length = self.png.read()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
s = self.png.call(cid, pos, len)
|
s = self.png.call(cid, pos, length)
|
||||||
except EOFError:
|
except EOFError:
|
||||||
break
|
break
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
if Image.DEBUG:
|
if Image.DEBUG:
|
||||||
print(cid, pos, len, "(unknown)")
|
print(cid, pos, length, "(unknown)")
|
||||||
s = ImageFile._safe_read(self.fp, len)
|
s = ImageFile._safe_read(self.fp, length)
|
||||||
|
|
||||||
self.png.crc(cid, s)
|
self.png.crc(cid, s)
|
||||||
|
|
||||||
|
@ -388,7 +388,7 @@ class PngImageFile(ImageFile.ImageFile):
|
||||||
rawmode, data = self.png.im_palette
|
rawmode, data = self.png.im_palette
|
||||||
self.palette = ImagePalette.raw(rawmode, data)
|
self.palette = ImagePalette.raw(rawmode, data)
|
||||||
|
|
||||||
self.__idat = len # used by load_read()
|
self.__idat = length # used by load_read()
|
||||||
|
|
||||||
|
|
||||||
def verify(self):
|
def verify(self):
|
||||||
|
@ -413,7 +413,7 @@ class PngImageFile(ImageFile.ImageFile):
|
||||||
|
|
||||||
ImageFile.ImageFile.load_prepare(self)
|
ImageFile.ImageFile.load_prepare(self)
|
||||||
|
|
||||||
def load_read(self, bytes):
|
def load_read(self, read_bytes):
|
||||||
"internal: read more image data"
|
"internal: read more image data"
|
||||||
|
|
||||||
while self.__idat == 0:
|
while self.__idat == 0:
|
||||||
|
@ -421,23 +421,23 @@ class PngImageFile(ImageFile.ImageFile):
|
||||||
|
|
||||||
self.fp.read(4) # CRC
|
self.fp.read(4) # CRC
|
||||||
|
|
||||||
cid, pos, len = self.png.read()
|
cid, pos, length = self.png.read()
|
||||||
|
|
||||||
if cid not in [b"IDAT", b"DDAT"]:
|
if cid not in [b"IDAT", b"DDAT"]:
|
||||||
self.png.push(cid, pos, len)
|
self.png.push(cid, pos, length)
|
||||||
return b""
|
return b""
|
||||||
|
|
||||||
self.__idat = len # empty chunks are allowed
|
self.__idat = length # empty chunks are allowed
|
||||||
|
|
||||||
# read more data from this chunk
|
# read more data from this chunk
|
||||||
if bytes <= 0:
|
if read_bytes <= 0:
|
||||||
bytes = self.__idat
|
read_bytes = self.__idat
|
||||||
else:
|
else:
|
||||||
bytes = min(bytes, self.__idat)
|
read_bytes = min(read_bytes, self.__idat)
|
||||||
|
|
||||||
self.__idat = self.__idat - bytes
|
self.__idat = self.__idat - read_bytes
|
||||||
|
|
||||||
return self.fp.read(bytes)
|
return self.fp.read(read_bytes)
|
||||||
|
|
||||||
|
|
||||||
def load_end(self):
|
def load_end(self):
|
||||||
|
|
|
@ -36,17 +36,23 @@
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
from PIL import Image, ImageFile
|
from PIL import Image, ImageFile
|
||||||
import os, struct, sys
|
import os
|
||||||
|
import struct
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
def isInt(f):
|
def isInt(f):
|
||||||
try:
|
try:
|
||||||
i = int(f)
|
i = int(f)
|
||||||
if f-i == 0: return 1
|
if f-i == 0:
|
||||||
else: return 0
|
return 1
|
||||||
|
else:
|
||||||
|
return 0
|
||||||
except:
|
except:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
iforms = [1,3,-11,-12,-21,-22]
|
iforms = [1, 3, -11, -12, -21, -22]
|
||||||
|
|
||||||
|
|
||||||
# There is no magic number to identify Spider files, so just check a
|
# There is no magic number to identify Spider files, so just check a
|
||||||
# series of header locations to see if they have reasonable values.
|
# series of header locations to see if they have reasonable values.
|
||||||
|
@ -56,30 +62,32 @@ iforms = [1,3,-11,-12,-21,-22]
|
||||||
def isSpiderHeader(t):
|
def isSpiderHeader(t):
|
||||||
h = (99,) + t # add 1 value so can use spider header index start=1
|
h = (99,) + t # add 1 value so can use spider header index start=1
|
||||||
# header values 1,2,5,12,13,22,23 should be integers
|
# header values 1,2,5,12,13,22,23 should be integers
|
||||||
for i in [1,2,5,12,13,22,23]:
|
for i in [1, 2, 5, 12, 13, 22, 23]:
|
||||||
if not isInt(h[i]): return 0
|
if not isInt(h[i]):
|
||||||
|
return 0
|
||||||
# check iform
|
# check iform
|
||||||
iform = int(h[5])
|
iform = int(h[5])
|
||||||
if not iform in iforms: return 0
|
if iform not in iforms:
|
||||||
|
return 0
|
||||||
# check other header values
|
# check other header values
|
||||||
labrec = int(h[13]) # no. records in file header
|
labrec = int(h[13]) # no. records in file header
|
||||||
labbyt = int(h[22]) # total no. of bytes in header
|
labbyt = int(h[22]) # total no. of bytes in header
|
||||||
lenbyt = int(h[23]) # record length in bytes
|
lenbyt = int(h[23]) # record length in bytes
|
||||||
#print "labrec = %d, labbyt = %d, lenbyt = %d" % (labrec,labbyt,lenbyt)
|
# print "labrec = %d, labbyt = %d, lenbyt = %d" % (labrec,labbyt,lenbyt)
|
||||||
if labbyt != (labrec * lenbyt): return 0
|
if labbyt != (labrec * lenbyt):
|
||||||
|
return 0
|
||||||
# looks like a valid header
|
# looks like a valid header
|
||||||
return labbyt
|
return labbyt
|
||||||
|
|
||||||
|
|
||||||
def isSpiderImage(filename):
|
def isSpiderImage(filename):
|
||||||
fp = open(filename,'rb')
|
fp = open(filename, 'rb')
|
||||||
f = fp.read(92) # read 23 * 4 bytes
|
f = fp.read(92) # read 23 * 4 bytes
|
||||||
fp.close()
|
fp.close()
|
||||||
bigendian = 1
|
t = struct.unpack('>23f', f) # try big-endian first
|
||||||
t = struct.unpack('>23f',f) # try big-endian first
|
|
||||||
hdrlen = isSpiderHeader(t)
|
hdrlen = isSpiderHeader(t)
|
||||||
if hdrlen == 0:
|
if hdrlen == 0:
|
||||||
bigendian = 0
|
t = struct.unpack('<23f', f) # little-endian
|
||||||
t = struct.unpack('<23f',f) # little-endian
|
|
||||||
hdrlen = isSpiderHeader(t)
|
hdrlen = isSpiderHeader(t)
|
||||||
return hdrlen
|
return hdrlen
|
||||||
|
|
||||||
|
@ -96,11 +104,11 @@ class SpiderImageFile(ImageFile.ImageFile):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.bigendian = 1
|
self.bigendian = 1
|
||||||
t = struct.unpack('>27f',f) # try big-endian first
|
t = struct.unpack('>27f', f) # try big-endian first
|
||||||
hdrlen = isSpiderHeader(t)
|
hdrlen = isSpiderHeader(t)
|
||||||
if hdrlen == 0:
|
if hdrlen == 0:
|
||||||
self.bigendian = 0
|
self.bigendian = 0
|
||||||
t = struct.unpack('<27f',f) # little-endian
|
t = struct.unpack('<27f', f) # little-endian
|
||||||
hdrlen = isSpiderHeader(t)
|
hdrlen = isSpiderHeader(t)
|
||||||
if hdrlen == 0:
|
if hdrlen == 0:
|
||||||
raise SyntaxError("not a valid Spider file")
|
raise SyntaxError("not a valid Spider file")
|
||||||
|
@ -141,7 +149,8 @@ class SpiderImageFile(ImageFile.ImageFile):
|
||||||
self.rawmode = "F;32F"
|
self.rawmode = "F;32F"
|
||||||
self.mode = "F"
|
self.mode = "F"
|
||||||
|
|
||||||
self.tile = [("raw", (0, 0) + self.size, offset,
|
self.tile = [
|
||||||
|
("raw", (0, 0) + self.size, offset,
|
||||||
(self.rawmode, 0, 1))]
|
(self.rawmode, 0, 1))]
|
||||||
self.__fp = self.fp # FIXME: hack
|
self.__fp = self.fp # FIXME: hack
|
||||||
|
|
||||||
|
@ -176,6 +185,7 @@ class SpiderImageFile(ImageFile.ImageFile):
|
||||||
from PIL import ImageTk
|
from PIL import ImageTk
|
||||||
return ImageTk.PhotoImage(self.convert2byte(), palette=256)
|
return ImageTk.PhotoImage(self.convert2byte(), palette=256)
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
# Image series
|
# Image series
|
||||||
|
|
||||||
|
@ -200,17 +210,19 @@ def loadImageSeries(filelist=None):
|
||||||
imglist.append(im)
|
imglist.append(im)
|
||||||
return imglist
|
return imglist
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
# For saving images in Spider format
|
# For saving images in Spider format
|
||||||
|
|
||||||
def makeSpiderHeader(im):
|
def makeSpiderHeader(im):
|
||||||
nsam,nrow = im.size
|
nsam, nrow = im.size
|
||||||
lenbyt = nsam * 4 # There are labrec records in the header
|
lenbyt = nsam * 4 # There are labrec records in the header
|
||||||
labrec = 1024 / lenbyt
|
labrec = 1024 / lenbyt
|
||||||
if 1024%lenbyt != 0: labrec += 1
|
if 1024 % lenbyt != 0:
|
||||||
|
labrec += 1
|
||||||
labbyt = labrec * lenbyt
|
labbyt = labrec * lenbyt
|
||||||
hdr = []
|
hdr = []
|
||||||
nvalues = labbyt / 4
|
nvalues = int(labbyt / 4)
|
||||||
for i in range(nvalues):
|
for i in range(nvalues):
|
||||||
hdr.append(0.0)
|
hdr.append(0.0)
|
||||||
|
|
||||||
|
@ -232,9 +244,10 @@ def makeSpiderHeader(im):
|
||||||
# pack binary data into a string
|
# pack binary data into a string
|
||||||
hdrstr = []
|
hdrstr = []
|
||||||
for v in hdr:
|
for v in hdr:
|
||||||
hdrstr.append(struct.pack('f',v))
|
hdrstr.append(struct.pack('f', v))
|
||||||
return hdrstr
|
return hdrstr
|
||||||
|
|
||||||
|
|
||||||
def _save(im, fp, filename):
|
def _save(im, fp, filename):
|
||||||
if im.mode[0] != "F":
|
if im.mode[0] != "F":
|
||||||
im = im.convert('F')
|
im = im.convert('F')
|
||||||
|
@ -250,11 +263,12 @@ def _save(im, fp, filename):
|
||||||
raise IOError("Unable to open %s for writing" % filename)
|
raise IOError("Unable to open %s for writing" % filename)
|
||||||
fp.writelines(hdr)
|
fp.writelines(hdr)
|
||||||
|
|
||||||
rawmode = "F;32NF" #32-bit native floating point
|
rawmode = "F;32NF" # 32-bit native floating point
|
||||||
ImageFile._save(im, fp, [("raw", (0,0)+im.size, 0, (rawmode,0,1))])
|
ImageFile._save(im, fp, [("raw", (0, 0)+im.size, 0, (rawmode, 0, 1))])
|
||||||
|
|
||||||
fp.close()
|
fp.close()
|
||||||
|
|
||||||
|
|
||||||
def _save_spider(im, fp, filename):
|
def _save_spider(im, fp, filename):
|
||||||
# get the filename extension and register it with Image
|
# get the filename extension and register it with Image
|
||||||
fn, ext = os.path.splitext(filename)
|
fn, ext = os.path.splitext(filename)
|
||||||
|
@ -292,5 +306,7 @@ if __name__ == "__main__":
|
||||||
if outfile != "":
|
if outfile != "":
|
||||||
# perform some image operation
|
# perform some image operation
|
||||||
im = im.transpose(Image.FLIP_LEFT_RIGHT)
|
im = im.transpose(Image.FLIP_LEFT_RIGHT)
|
||||||
print("saving a flipped version of %s as %s " % (os.path.basename(filename), outfile))
|
print(
|
||||||
|
"saving a flipped version of %s as %s " %
|
||||||
|
(os.path.basename(filename), outfile))
|
||||||
im.save(outfile, "SPIDER")
|
im.save(outfile, "SPIDER")
|
||||||
|
|
|
@ -859,7 +859,7 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
# libtiff handles the fillmode for us, so 1;IR should
|
# libtiff handles the fillmode for us, so 1;IR should
|
||||||
# actually be 1;I. Including the R double reverses the
|
# actually be 1;I. Including the R double reverses the
|
||||||
# bits, so stripes of the image are reversed. See
|
# bits, so stripes of the image are reversed. See
|
||||||
# https://github.com/python-imaging/Pillow/issues/279
|
# https://github.com/python-pillow/Pillow/issues/279
|
||||||
if fillorder == 2:
|
if fillorder == 2:
|
||||||
key = (
|
key = (
|
||||||
self.tag.prefix, photo, format, 1,
|
self.tag.prefix, photo, format, 1,
|
||||||
|
@ -984,11 +984,7 @@ def _save(im, fp, filename):
|
||||||
|
|
||||||
compression = im.encoderinfo.get('compression',im.info.get('compression','raw'))
|
compression = im.encoderinfo.get('compression',im.info.get('compression','raw'))
|
||||||
|
|
||||||
libtiff = WRITE_LIBTIFF or compression in ["tiff_ccitt", "group3", "group4",
|
libtiff = WRITE_LIBTIFF or compression != 'raw'
|
||||||
"tiff_jpeg", "tiff_adobe_deflate",
|
|
||||||
"tiff_thunderscan", "tiff_deflate",
|
|
||||||
"tiff_sgilog", "tiff_sgilog24",
|
|
||||||
"tiff_raw_16"]
|
|
||||||
|
|
||||||
# required for color libtiff images
|
# required for color libtiff images
|
||||||
ifd[PLANAR_CONFIGURATION] = getattr(im, '_planar_configuration', 1)
|
ifd[PLANAR_CONFIGURATION] = getattr(im, '_planar_configuration', 1)
|
||||||
|
|
|
@ -5,8 +5,8 @@ Pillow
|
||||||
|
|
||||||
Pillow is the "friendly" PIL fork by Alex Clark and Contributors. PIL is the Python Imaging Library by Fredrik Lundh and Contributors.
|
Pillow is the "friendly" PIL fork by Alex Clark and Contributors. PIL is the Python Imaging Library by Fredrik Lundh and Contributors.
|
||||||
|
|
||||||
.. image:: https://travis-ci.org/python-imaging/Pillow.svg?branch=master
|
.. image:: https://travis-ci.org/python-pillow/Pillow.svg?branch=master
|
||||||
:target: https://travis-ci.org/python-imaging/Pillow
|
:target: https://travis-ci.org/python-pillow/Pillow
|
||||||
:alt: Travis CI build status
|
:alt: Travis CI build status
|
||||||
|
|
||||||
.. image:: https://pypip.in/v/Pillow/badge.png
|
.. image:: https://pypip.in/v/Pillow/badge.png
|
||||||
|
@ -17,7 +17,7 @@ Pillow is the "friendly" PIL fork by Alex Clark and Contributors. PIL is the Pyt
|
||||||
:target: https://pypi.python.org/pypi/Pillow/
|
:target: https://pypi.python.org/pypi/Pillow/
|
||||||
:alt: Number of PyPI downloads
|
:alt: Number of PyPI downloads
|
||||||
|
|
||||||
.. image:: https://coveralls.io/repos/python-imaging/Pillow/badge.png?branch=master
|
.. image:: https://coveralls.io/repos/python-pillow/Pillow/badge.png?branch=master
|
||||||
:target: https://coveralls.io/r/python-imaging/Pillow?branch=master
|
:target: https://coveralls.io/r/python-pillow/Pillow?branch=master
|
||||||
|
|
||||||
The documentation is hosted at http://pillow.readthedocs.org/. It contains installation instructions, tutorials, reference, compatibility details, and more.
|
The documentation is hosted at http://pillow.readthedocs.org/. It contains installation instructions, tutorials, reference, compatibility details, and more.
|
||||||
|
|
BIN
Tests/images/binary_preview_map.eps
Executable file
BIN
Tests/images/imagedraw_arc.png
Normal file
After Width: | Height: | Size: 284 B |
BIN
Tests/images/imagedraw_bitmap.png
Normal file
After Width: | Height: | Size: 2.1 KiB |
BIN
Tests/images/imagedraw_chord.png
Normal file
After Width: | Height: | Size: 326 B |
BIN
Tests/images/imagedraw_ellipse.png
Normal file
After Width: | Height: | Size: 491 B |
BIN
Tests/images/imagedraw_floodfill.png
Normal file
After Width: | Height: | Size: 232 B |
BIN
Tests/images/imagedraw_floodfill2.png
Normal file
After Width: | Height: | Size: 212 B |
BIN
Tests/images/imagedraw_line.png
Normal file
After Width: | Height: | Size: 286 B |
BIN
Tests/images/imagedraw_pieslice.png
Normal file
After Width: | Height: | Size: 405 B |
BIN
Tests/images/imagedraw_point.png
Normal file
After Width: | Height: | Size: 124 B |
BIN
Tests/images/imagedraw_polygon.png
Normal file
After Width: | Height: | Size: 292 B |
BIN
Tests/images/imagedraw_rectangle.png
Normal file
After Width: | Height: | Size: 228 B |
BIN
Tests/images/junk_jpeg_header.jpg
Normal file
After Width: | Height: | Size: 105 KiB |
BIN
Tests/images/lena.spider
Normal file
|
@ -1,25 +1,27 @@
|
||||||
from tester import *
|
from tester import *
|
||||||
|
|
||||||
from PIL import Image, EpsImagePlugin
|
from PIL import Image, EpsImagePlugin
|
||||||
import sys
|
|
||||||
import io
|
import io
|
||||||
|
|
||||||
if not EpsImagePlugin.has_ghostscript():
|
if not EpsImagePlugin.has_ghostscript():
|
||||||
skip()
|
skip()
|
||||||
|
|
||||||
#Our two EPS test files (they are identical except for their bounding boxes)
|
# Our two EPS test files (they are identical except for their bounding boxes)
|
||||||
file1 = "Tests/images/zero_bb.eps"
|
file1 = "Tests/images/zero_bb.eps"
|
||||||
file2 = "Tests/images/non_zero_bb.eps"
|
file2 = "Tests/images/non_zero_bb.eps"
|
||||||
|
|
||||||
#Due to palletization, we'll need to convert these to RGB after load
|
# Due to palletization, we'll need to convert these to RGB after load
|
||||||
file1_compare = "Tests/images/zero_bb.png"
|
file1_compare = "Tests/images/zero_bb.png"
|
||||||
file1_compare_scale2 = "Tests/images/zero_bb_scale2.png"
|
file1_compare_scale2 = "Tests/images/zero_bb_scale2.png"
|
||||||
|
|
||||||
file2_compare = "Tests/images/non_zero_bb.png"
|
file2_compare = "Tests/images/non_zero_bb.png"
|
||||||
file2_compare_scale2 = "Tests/images/non_zero_bb_scale2.png"
|
file2_compare_scale2 = "Tests/images/non_zero_bb_scale2.png"
|
||||||
|
|
||||||
|
# EPS test files with binary preview
|
||||||
|
file3 = "Tests/images/binary_preview_map.eps"
|
||||||
|
|
||||||
def test_sanity():
|
def test_sanity():
|
||||||
#Regular scale
|
# Regular scale
|
||||||
image1 = Image.open(file1)
|
image1 = Image.open(file1)
|
||||||
image1.load()
|
image1.load()
|
||||||
assert_equal(image1.mode, "RGB")
|
assert_equal(image1.mode, "RGB")
|
||||||
|
@ -32,7 +34,7 @@ def test_sanity():
|
||||||
assert_equal(image2.size, (360, 252))
|
assert_equal(image2.size, (360, 252))
|
||||||
assert_equal(image2.format, "EPS")
|
assert_equal(image2.format, "EPS")
|
||||||
|
|
||||||
#Double scale
|
# Double scale
|
||||||
image1_scale2 = Image.open(file1)
|
image1_scale2 = Image.open(file1)
|
||||||
image1_scale2.load(scale=2)
|
image1_scale2.load(scale=2)
|
||||||
assert_equal(image1_scale2.mode, "RGB")
|
assert_equal(image1_scale2.mode, "RGB")
|
||||||
|
@ -45,54 +47,96 @@ def test_sanity():
|
||||||
assert_equal(image2_scale2.size, (720, 504))
|
assert_equal(image2_scale2.size, (720, 504))
|
||||||
assert_equal(image2_scale2.format, "EPS")
|
assert_equal(image2_scale2.format, "EPS")
|
||||||
|
|
||||||
|
|
||||||
def test_file_object():
|
def test_file_object():
|
||||||
#issue 479
|
# issue 479
|
||||||
image1 = Image.open(file1)
|
image1 = Image.open(file1)
|
||||||
with open(tempfile('temp_file.eps'), 'wb') as fh:
|
with open(tempfile('temp_file.eps'), 'wb') as fh:
|
||||||
image1.save(fh, 'EPS')
|
image1.save(fh, 'EPS')
|
||||||
|
|
||||||
|
|
||||||
def test_iobase_object():
|
def test_iobase_object():
|
||||||
#issue 479
|
# issue 479
|
||||||
image1 = Image.open(file1)
|
image1 = Image.open(file1)
|
||||||
with io.open(tempfile('temp_iobase.eps'), 'wb') as fh:
|
with io.open(tempfile('temp_iobase.eps'), 'wb') as fh:
|
||||||
image1.save(fh, 'EPS')
|
image1.save(fh, 'EPS')
|
||||||
|
|
||||||
|
|
||||||
def test_render_scale1():
|
def test_render_scale1():
|
||||||
#We need png support for these render test
|
# We need png support for these render test
|
||||||
codecs = dir(Image.core)
|
codecs = dir(Image.core)
|
||||||
if "zip_encoder" not in codecs or "zip_decoder" not in codecs:
|
if "zip_encoder" not in codecs or "zip_decoder" not in codecs:
|
||||||
skip("zip/deflate support not available")
|
skip("zip/deflate support not available")
|
||||||
|
|
||||||
#Zero bounding box
|
# Zero bounding box
|
||||||
image1_scale1 = Image.open(file1)
|
image1_scale1 = Image.open(file1)
|
||||||
image1_scale1.load()
|
image1_scale1.load()
|
||||||
image1_scale1_compare = Image.open(file1_compare).convert("RGB")
|
image1_scale1_compare = Image.open(file1_compare).convert("RGB")
|
||||||
image1_scale1_compare.load()
|
image1_scale1_compare.load()
|
||||||
assert_image_similar(image1_scale1, image1_scale1_compare, 5)
|
assert_image_similar(image1_scale1, image1_scale1_compare, 5)
|
||||||
|
|
||||||
#Non-Zero bounding box
|
# Non-Zero bounding box
|
||||||
image2_scale1 = Image.open(file2)
|
image2_scale1 = Image.open(file2)
|
||||||
image2_scale1.load()
|
image2_scale1.load()
|
||||||
image2_scale1_compare = Image.open(file2_compare).convert("RGB")
|
image2_scale1_compare = Image.open(file2_compare).convert("RGB")
|
||||||
image2_scale1_compare.load()
|
image2_scale1_compare.load()
|
||||||
assert_image_similar(image2_scale1, image2_scale1_compare, 10)
|
assert_image_similar(image2_scale1, image2_scale1_compare, 10)
|
||||||
|
|
||||||
|
|
||||||
def test_render_scale2():
|
def test_render_scale2():
|
||||||
#We need png support for these render test
|
# We need png support for these render test
|
||||||
codecs = dir(Image.core)
|
codecs = dir(Image.core)
|
||||||
if "zip_encoder" not in codecs or "zip_decoder" not in codecs:
|
if "zip_encoder" not in codecs or "zip_decoder" not in codecs:
|
||||||
skip("zip/deflate support not available")
|
skip("zip/deflate support not available")
|
||||||
|
|
||||||
#Zero bounding box
|
# Zero bounding box
|
||||||
image1_scale2 = Image.open(file1)
|
image1_scale2 = Image.open(file1)
|
||||||
image1_scale2.load(scale=2)
|
image1_scale2.load(scale=2)
|
||||||
image1_scale2_compare = Image.open(file1_compare_scale2).convert("RGB")
|
image1_scale2_compare = Image.open(file1_compare_scale2).convert("RGB")
|
||||||
image1_scale2_compare.load()
|
image1_scale2_compare.load()
|
||||||
assert_image_similar(image1_scale2, image1_scale2_compare, 5)
|
assert_image_similar(image1_scale2, image1_scale2_compare, 5)
|
||||||
|
|
||||||
#Non-Zero bounding box
|
# Non-Zero bounding box
|
||||||
image2_scale2 = Image.open(file2)
|
image2_scale2 = Image.open(file2)
|
||||||
image2_scale2.load(scale=2)
|
image2_scale2.load(scale=2)
|
||||||
image2_scale2_compare = Image.open(file2_compare_scale2).convert("RGB")
|
image2_scale2_compare = Image.open(file2_compare_scale2).convert("RGB")
|
||||||
image2_scale2_compare.load()
|
image2_scale2_compare.load()
|
||||||
assert_image_similar(image2_scale2, image2_scale2_compare, 10)
|
assert_image_similar(image2_scale2, image2_scale2_compare, 10)
|
||||||
|
|
||||||
|
|
||||||
|
def test_resize():
|
||||||
|
# Arrange
|
||||||
|
image1 = Image.open(file1)
|
||||||
|
image2 = Image.open(file2)
|
||||||
|
new_size = (100, 100)
|
||||||
|
|
||||||
|
# Act
|
||||||
|
image1 = image1.resize(new_size)
|
||||||
|
image2 = image2.resize(new_size)
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
assert_equal(image1.size, new_size)
|
||||||
|
assert_equal(image2.size, new_size)
|
||||||
|
|
||||||
|
|
||||||
|
def test_thumbnail():
|
||||||
|
# Issue #619
|
||||||
|
# Arrange
|
||||||
|
image1 = Image.open(file1)
|
||||||
|
image2 = Image.open(file2)
|
||||||
|
new_size = (100, 100)
|
||||||
|
|
||||||
|
# Act
|
||||||
|
image1.thumbnail(new_size)
|
||||||
|
image2.thumbnail(new_size)
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
assert_equal(max(image1.size), max(new_size))
|
||||||
|
assert_equal(max(image2.size), max(new_size))
|
||||||
|
|
||||||
|
def test_read_binary_preview():
|
||||||
|
# Issue 302
|
||||||
|
# open image with binary preview
|
||||||
|
image1 = Image.open(file3)
|
||||||
|
|
||||||
|
# End of file
|
||||||
|
|
|
@ -37,7 +37,7 @@ def test_roundtrip():
|
||||||
assert_image_similar(reread.convert('RGB'), im, 50)
|
assert_image_similar(reread.convert('RGB'), im, 50)
|
||||||
|
|
||||||
def test_roundtrip2():
|
def test_roundtrip2():
|
||||||
#see https://github.com/python-imaging/Pillow/issues/403
|
#see https://github.com/python-pillow/Pillow/issues/403
|
||||||
out = tempfile('temp.gif')
|
out = tempfile('temp.gif')
|
||||||
im = Image.open('Images/lena.gif')
|
im = Image.open('Images/lena.gif')
|
||||||
im2 = im.copy()
|
im2 = im.copy()
|
||||||
|
@ -48,7 +48,7 @@ def test_roundtrip2():
|
||||||
|
|
||||||
|
|
||||||
def test_palette_handling():
|
def test_palette_handling():
|
||||||
# see https://github.com/python-imaging/Pillow/issues/513
|
# see https://github.com/python-pillow/Pillow/issues/513
|
||||||
|
|
||||||
im = Image.open('Images/lena.gif')
|
im = Image.open('Images/lena.gif')
|
||||||
im = im.convert('RGB')
|
im = im.convert('RGB')
|
||||||
|
@ -64,7 +64,7 @@ def test_palette_handling():
|
||||||
assert_image_similar(im, reloaded.convert('RGB'), 10)
|
assert_image_similar(im, reloaded.convert('RGB'), 10)
|
||||||
|
|
||||||
def test_palette_434():
|
def test_palette_434():
|
||||||
# see https://github.com/python-imaging/Pillow/issues/434
|
# see https://github.com/python-pillow/Pillow/issues/434
|
||||||
|
|
||||||
def roundtrip(im, *args, **kwargs):
|
def roundtrip(im, *args, **kwargs):
|
||||||
out = tempfile('temp.gif')
|
out = tempfile('temp.gif')
|
||||||
|
|
|
@ -12,6 +12,7 @@ if "jpeg_encoder" not in codecs or "jpeg_decoder" not in codecs:
|
||||||
|
|
||||||
test_file = "Images/lena.jpg"
|
test_file = "Images/lena.jpg"
|
||||||
|
|
||||||
|
|
||||||
def roundtrip(im, **options):
|
def roundtrip(im, **options):
|
||||||
out = BytesIO()
|
out = BytesIO()
|
||||||
im.save(out, "JPEG", **options)
|
im.save(out, "JPEG", **options)
|
||||||
|
@ -23,6 +24,7 @@ def roundtrip(im, **options):
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
def test_sanity():
|
def test_sanity():
|
||||||
|
|
||||||
# internal version number
|
# internal version number
|
||||||
|
@ -34,6 +36,7 @@ def test_sanity():
|
||||||
assert_equal(im.size, (128, 128))
|
assert_equal(im.size, (128, 128))
|
||||||
assert_equal(im.format, "JPEG")
|
assert_equal(im.format, "JPEG")
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
|
|
||||||
def test_app():
|
def test_app():
|
||||||
|
@ -44,6 +47,7 @@ def test_app():
|
||||||
assert_equal(im.applist[1], ("COM", b"Python Imaging Library"))
|
assert_equal(im.applist[1], ("COM", b"Python Imaging Library"))
|
||||||
assert_equal(len(im.applist), 2)
|
assert_equal(len(im.applist), 2)
|
||||||
|
|
||||||
|
|
||||||
def test_cmyk():
|
def test_cmyk():
|
||||||
# Test CMYK handling. Thanks to Tim and Charlie for test data,
|
# Test CMYK handling. Thanks to Tim and Charlie for test data,
|
||||||
# Michael for getting me to look one more time.
|
# Michael for getting me to look one more time.
|
||||||
|
@ -62,6 +66,7 @@ def test_cmyk():
|
||||||
c, m, y, k = [x / 255.0 for x in im.getpixel((im.size[0]-1, im.size[1]-1))]
|
c, m, y, k = [x / 255.0 for x in im.getpixel((im.size[0]-1, im.size[1]-1))]
|
||||||
assert_true(k > 0.9)
|
assert_true(k > 0.9)
|
||||||
|
|
||||||
|
|
||||||
def test_dpi():
|
def test_dpi():
|
||||||
def test(xdpi, ydpi=None):
|
def test(xdpi, ydpi=None):
|
||||||
im = Image.open(test_file)
|
im = Image.open(test_file)
|
||||||
|
@ -72,6 +77,7 @@ def test_dpi():
|
||||||
assert_equal(test(100, 200), (100, 200))
|
assert_equal(test(100, 200), (100, 200))
|
||||||
assert_equal(test(0), None) # square pixels
|
assert_equal(test(0), None) # square pixels
|
||||||
|
|
||||||
|
|
||||||
def test_icc():
|
def test_icc():
|
||||||
# Test ICC support
|
# Test ICC support
|
||||||
im1 = Image.open("Tests/images/rgb.jpg")
|
im1 = Image.open("Tests/images/rgb.jpg")
|
||||||
|
@ -89,6 +95,7 @@ def test_icc():
|
||||||
assert_false(im1.info.get("icc_profile"))
|
assert_false(im1.info.get("icc_profile"))
|
||||||
assert_true(im2.info.get("icc_profile"))
|
assert_true(im2.info.get("icc_profile"))
|
||||||
|
|
||||||
|
|
||||||
def test_icc_big():
|
def test_icc_big():
|
||||||
# Make sure that the "extra" support handles large blocks
|
# Make sure that the "extra" support handles large blocks
|
||||||
def test(n):
|
def test(n):
|
||||||
|
@ -99,39 +106,47 @@ def test_icc_big():
|
||||||
assert len(icc_profile) == n # sanity
|
assert len(icc_profile) == n # sanity
|
||||||
im1 = roundtrip(lena(), icc_profile=icc_profile)
|
im1 = roundtrip(lena(), icc_profile=icc_profile)
|
||||||
assert_equal(im1.info.get("icc_profile"), icc_profile or None)
|
assert_equal(im1.info.get("icc_profile"), icc_profile or None)
|
||||||
test(0); test(1)
|
test(0)
|
||||||
test(3); test(4); test(5)
|
test(1)
|
||||||
|
test(3)
|
||||||
|
test(4)
|
||||||
|
test(5)
|
||||||
test(65533-14) # full JPEG marker block
|
test(65533-14) # full JPEG marker block
|
||||||
test(65533-14+1) # full block plus one byte
|
test(65533-14+1) # full block plus one byte
|
||||||
test(ImageFile.MAXBLOCK) # full buffer block
|
test(ImageFile.MAXBLOCK) # full buffer block
|
||||||
test(ImageFile.MAXBLOCK+1) # full buffer block plus one byte
|
test(ImageFile.MAXBLOCK+1) # full buffer block plus one byte
|
||||||
test(ImageFile.MAXBLOCK*4+3) # large block
|
test(ImageFile.MAXBLOCK*4+3) # large block
|
||||||
|
|
||||||
|
|
||||||
def test_optimize():
|
def test_optimize():
|
||||||
im1 = roundtrip(lena())
|
im1 = roundtrip(lena())
|
||||||
im2 = roundtrip(lena(), optimize=1)
|
im2 = roundtrip(lena(), optimize=1)
|
||||||
assert_image_equal(im1, im2)
|
assert_image_equal(im1, im2)
|
||||||
assert_true(im1.bytes >= im2.bytes)
|
assert_true(im1.bytes >= im2.bytes)
|
||||||
|
|
||||||
|
|
||||||
def test_optimize_large_buffer():
|
def test_optimize_large_buffer():
|
||||||
#https://github.com/python-imaging/Pillow/issues/148
|
# https://github.com/python-pillow/Pillow/issues/148
|
||||||
f = tempfile('temp.jpg')
|
f = tempfile('temp.jpg')
|
||||||
# this requires ~ 1.5x Image.MAXBLOCK
|
# this requires ~ 1.5x Image.MAXBLOCK
|
||||||
im = Image.new("RGB", (4096,4096), 0xff3333)
|
im = Image.new("RGB", (4096, 4096), 0xff3333)
|
||||||
im.save(f, format="JPEG", optimize=True)
|
im.save(f, format="JPEG", optimize=True)
|
||||||
|
|
||||||
|
|
||||||
def test_progressive():
|
def test_progressive():
|
||||||
im1 = roundtrip(lena())
|
im1 = roundtrip(lena())
|
||||||
im2 = roundtrip(lena(), progressive=True)
|
im2 = roundtrip(lena(), progressive=True)
|
||||||
assert_image_equal(im1, im2)
|
assert_image_equal(im1, im2)
|
||||||
assert_true(im1.bytes >= im2.bytes)
|
assert_true(im1.bytes >= im2.bytes)
|
||||||
|
|
||||||
|
|
||||||
def test_progressive_large_buffer():
|
def test_progressive_large_buffer():
|
||||||
f = tempfile('temp.jpg')
|
f = tempfile('temp.jpg')
|
||||||
# this requires ~ 1.5x Image.MAXBLOCK
|
# this requires ~ 1.5x Image.MAXBLOCK
|
||||||
im = Image.new("RGB", (4096,4096), 0xff3333)
|
im = Image.new("RGB", (4096, 4096), 0xff3333)
|
||||||
im.save(f, format="JPEG", progressive=True)
|
im.save(f, format="JPEG", progressive=True)
|
||||||
|
|
||||||
|
|
||||||
def test_progressive_large_buffer_highest_quality():
|
def test_progressive_large_buffer_highest_quality():
|
||||||
f = tempfile('temp.jpg')
|
f = tempfile('temp.jpg')
|
||||||
if py3:
|
if py3:
|
||||||
|
@ -142,11 +157,13 @@ def test_progressive_large_buffer_highest_quality():
|
||||||
# this requires more bytes than pixels in the image
|
# this requires more bytes than pixels in the image
|
||||||
im.save(f, format="JPEG", progressive=True, quality=100)
|
im.save(f, format="JPEG", progressive=True, quality=100)
|
||||||
|
|
||||||
|
|
||||||
def test_large_exif():
|
def test_large_exif():
|
||||||
#https://github.com/python-imaging/Pillow/issues/148
|
# https://github.com/python-pillow/Pillow/issues/148
|
||||||
f = tempfile('temp.jpg')
|
f = tempfile('temp.jpg')
|
||||||
im = lena()
|
im = lena()
|
||||||
im.save(f,'JPEG', quality=90, exif=b"1"*65532)
|
im.save(f, 'JPEG', quality=90, exif=b"1"*65532)
|
||||||
|
|
||||||
|
|
||||||
def test_progressive_compat():
|
def test_progressive_compat():
|
||||||
im1 = roundtrip(lena())
|
im1 = roundtrip(lena())
|
||||||
|
@ -161,17 +178,20 @@ def test_progressive_compat():
|
||||||
assert_true(im3.info.get("progressive"))
|
assert_true(im3.info.get("progressive"))
|
||||||
assert_true(im3.info.get("progression"))
|
assert_true(im3.info.get("progression"))
|
||||||
|
|
||||||
|
|
||||||
def test_quality():
|
def test_quality():
|
||||||
im1 = roundtrip(lena())
|
im1 = roundtrip(lena())
|
||||||
im2 = roundtrip(lena(), quality=50)
|
im2 = roundtrip(lena(), quality=50)
|
||||||
assert_image(im1, im2.mode, im2.size)
|
assert_image(im1, im2.mode, im2.size)
|
||||||
assert_true(im1.bytes >= im2.bytes)
|
assert_true(im1.bytes >= im2.bytes)
|
||||||
|
|
||||||
|
|
||||||
def test_smooth():
|
def test_smooth():
|
||||||
im1 = roundtrip(lena())
|
im1 = roundtrip(lena())
|
||||||
im2 = roundtrip(lena(), smooth=100)
|
im2 = roundtrip(lena(), smooth=100)
|
||||||
assert_image(im1, im2.mode, im2.size)
|
assert_image(im1, im2.mode, im2.size)
|
||||||
|
|
||||||
|
|
||||||
def test_subsampling():
|
def test_subsampling():
|
||||||
def getsampling(im):
|
def getsampling(im):
|
||||||
layer = im.layer
|
layer = im.layer
|
||||||
|
@ -197,6 +217,7 @@ def test_subsampling():
|
||||||
|
|
||||||
assert_exception(TypeError, lambda: roundtrip(lena(), subsampling="1:1:1"))
|
assert_exception(TypeError, lambda: roundtrip(lena(), subsampling="1:1:1"))
|
||||||
|
|
||||||
|
|
||||||
def test_exif():
|
def test_exif():
|
||||||
im = Image.open("Tests/images/pil_sample_rgb.jpg")
|
im = Image.open("Tests/images/pil_sample_rgb.jpg")
|
||||||
info = im._getexif()
|
info = im._getexif()
|
||||||
|
@ -207,3 +228,11 @@ def test_quality_keep():
|
||||||
im = Image.open("Images/lena.jpg")
|
im = Image.open("Images/lena.jpg")
|
||||||
f = tempfile('temp.jpg')
|
f = tempfile('temp.jpg')
|
||||||
assert_no_exception(lambda: im.save(f, quality='keep'))
|
assert_no_exception(lambda: im.save(f, quality='keep'))
|
||||||
|
|
||||||
|
|
||||||
|
def test_junk_jpeg_header():
|
||||||
|
# https://github.com/python-pillow/Pillow/issues/630
|
||||||
|
filename = "Tests/images/junk_jpeg_header.jpg"
|
||||||
|
assert_no_exception(lambda: Image.open(filename))
|
||||||
|
|
||||||
|
# End of file
|
||||||
|
|
|
@ -71,7 +71,7 @@ def test_g4_eq_png():
|
||||||
|
|
||||||
assert_image_equal(g4, png)
|
assert_image_equal(g4, png)
|
||||||
|
|
||||||
# see https://github.com/python-imaging/Pillow/issues/279
|
# see https://github.com/python-pillow/Pillow/issues/279
|
||||||
def test_g4_fillorder_eq_png():
|
def test_g4_fillorder_eq_png():
|
||||||
""" Checking that we're actually getting the data that we expect"""
|
""" Checking that we're actually getting the data that we expect"""
|
||||||
png = Image.open('Tests/images/g4-fillorder-test.png')
|
png = Image.open('Tests/images/g4-fillorder-test.png')
|
||||||
|
@ -258,9 +258,6 @@ def test_compressions():
|
||||||
im = lena('RGB')
|
im = lena('RGB')
|
||||||
out = tempfile('temp.tif')
|
out = tempfile('temp.tif')
|
||||||
|
|
||||||
TiffImagePlugin.READ_LIBTIFF = True
|
|
||||||
TiffImagePlugin.WRITE_LIBTIFF = True
|
|
||||||
|
|
||||||
for compression in ('packbits', 'tiff_lzw'):
|
for compression in ('packbits', 'tiff_lzw'):
|
||||||
im.save(out, compression=compression)
|
im.save(out, compression=compression)
|
||||||
im2 = Image.open(out)
|
im2 = Image.open(out)
|
||||||
|
@ -270,11 +267,6 @@ def test_compressions():
|
||||||
im2 = Image.open(out)
|
im2 = Image.open(out)
|
||||||
assert_image_similar(im, im2, 30)
|
assert_image_similar(im, im2, 30)
|
||||||
|
|
||||||
TiffImagePlugin.READ_LIBTIFF = False
|
|
||||||
TiffImagePlugin.WRITE_LIBTIFF = False
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_cmyk_save():
|
def test_cmyk_save():
|
||||||
im = lena('CMYK')
|
im = lena('CMYK')
|
||||||
|
|
58
Tests/test_file_pdf.py
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
from tester import *
|
||||||
|
import os.path
|
||||||
|
|
||||||
|
|
||||||
|
def helper_save_as_pdf(mode):
|
||||||
|
# Arrange
|
||||||
|
im = lena(mode)
|
||||||
|
outfile = tempfile("temp_" + mode + ".pdf")
|
||||||
|
|
||||||
|
# Act
|
||||||
|
im.save(outfile)
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
assert_true(os.path.isfile(outfile))
|
||||||
|
assert_greater(os.path.getsize(outfile), 0)
|
||||||
|
|
||||||
|
|
||||||
|
def test_monochrome():
|
||||||
|
# Arrange
|
||||||
|
mode = "1"
|
||||||
|
|
||||||
|
# Act / Assert
|
||||||
|
helper_save_as_pdf(mode)
|
||||||
|
|
||||||
|
|
||||||
|
def test_greyscale():
|
||||||
|
# Arrange
|
||||||
|
mode = "L"
|
||||||
|
|
||||||
|
# Act / Assert
|
||||||
|
helper_save_as_pdf(mode)
|
||||||
|
|
||||||
|
|
||||||
|
def test_rgb():
|
||||||
|
# Arrange
|
||||||
|
mode = "RGB"
|
||||||
|
|
||||||
|
# Act / Assert
|
||||||
|
helper_save_as_pdf(mode)
|
||||||
|
|
||||||
|
|
||||||
|
def test_p_mode():
|
||||||
|
# Arrange
|
||||||
|
mode = "P"
|
||||||
|
|
||||||
|
# Act / Assert
|
||||||
|
helper_save_as_pdf(mode)
|
||||||
|
|
||||||
|
|
||||||
|
def test_cmyk_mode():
|
||||||
|
# Arrange
|
||||||
|
mode = "CMYK"
|
||||||
|
|
||||||
|
# Act / Assert
|
||||||
|
helper_save_as_pdf(mode)
|
||||||
|
|
||||||
|
|
||||||
|
# End of file
|
|
@ -101,7 +101,7 @@ def test_bad_text():
|
||||||
assert_equal(im.info, {'spam': 'egg\x00'})
|
assert_equal(im.info, {'spam': 'egg\x00'})
|
||||||
|
|
||||||
def test_bad_ztxt():
|
def test_bad_ztxt():
|
||||||
# Test reading malformed zTXt chunks (python-imaging/Pillow#318)
|
# Test reading malformed zTXt chunks (python-pillow/Pillow#318)
|
||||||
|
|
||||||
im = load(HEAD + chunk(b'zTXt') + TAIL)
|
im = load(HEAD + chunk(b'zTXt') + TAIL)
|
||||||
assert_equal(im.info, {})
|
assert_equal(im.info, {})
|
||||||
|
|
36
Tests/test_file_spider.py
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
from tester import *
|
||||||
|
|
||||||
|
from PIL import Image
|
||||||
|
from PIL import SpiderImagePlugin
|
||||||
|
|
||||||
|
test_file = "Tests/images/lena.spider"
|
||||||
|
|
||||||
|
|
||||||
|
def test_sanity():
|
||||||
|
im = Image.open(test_file)
|
||||||
|
im.load()
|
||||||
|
assert_equal(im.mode, "F")
|
||||||
|
assert_equal(im.size, (128, 128))
|
||||||
|
assert_equal(im.format, "SPIDER")
|
||||||
|
|
||||||
|
|
||||||
|
def test_save():
|
||||||
|
# Arrange
|
||||||
|
temp = tempfile('temp.spider')
|
||||||
|
im = lena()
|
||||||
|
|
||||||
|
# Act
|
||||||
|
im.save(temp, "SPIDER")
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
im2 = Image.open(temp)
|
||||||
|
assert_equal(im2.mode, "F")
|
||||||
|
assert_equal(im2.size, (128, 128))
|
||||||
|
assert_equal(im2.format, "SPIDER")
|
||||||
|
|
||||||
|
|
||||||
|
def test_isSpiderImage():
|
||||||
|
assert_true(SpiderImagePlugin.isSpiderImage(test_file))
|
||||||
|
|
||||||
|
|
||||||
|
# End of file
|
|
@ -6,7 +6,7 @@ tag_ids = dict(zip(TiffTags.TAGS.values(), TiffTags.TAGS.keys()))
|
||||||
def test_rt_metadata():
|
def test_rt_metadata():
|
||||||
""" Test writing arbitray metadata into the tiff image directory
|
""" Test writing arbitray metadata into the tiff image directory
|
||||||
Use case is ImageJ private tags, one numeric, one arbitrary
|
Use case is ImageJ private tags, one numeric, one arbitrary
|
||||||
data. https://github.com/python-imaging/Pillow/issues/291
|
data. https://github.com/python-pillow/Pillow/issues/291
|
||||||
"""
|
"""
|
||||||
|
|
||||||
img = lena()
|
img = lena()
|
||||||
|
|
|
@ -2,6 +2,7 @@ from tester import *
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
|
|
||||||
def test_sanity():
|
def test_sanity():
|
||||||
|
|
||||||
def convert(im, mode):
|
def convert(im, mode):
|
||||||
|
@ -16,6 +17,7 @@ def test_sanity():
|
||||||
for mode in modes:
|
for mode in modes:
|
||||||
yield_test(convert, im, mode)
|
yield_test(convert, im, mode)
|
||||||
|
|
||||||
|
|
||||||
def test_default():
|
def test_default():
|
||||||
|
|
||||||
im = lena("P")
|
im = lena("P")
|
||||||
|
@ -26,26 +28,29 @@ def test_default():
|
||||||
assert_image(im, "RGB", im.size)
|
assert_image(im, "RGB", im.size)
|
||||||
|
|
||||||
|
|
||||||
|
# ref https://github.com/python-pillow/Pillow/issues/274
|
||||||
# ref https://github.com/python-imaging/Pillow/issues/274
|
|
||||||
|
|
||||||
def _test_float_conversion(im):
|
def _test_float_conversion(im):
|
||||||
orig = im.getpixel((5,5))
|
orig = im.getpixel((5, 5))
|
||||||
converted = im.convert('F').getpixel((5,5))
|
converted = im.convert('F').getpixel((5, 5))
|
||||||
assert_equal(orig, converted)
|
assert_equal(orig, converted)
|
||||||
|
|
||||||
|
|
||||||
def test_8bit():
|
def test_8bit():
|
||||||
im = Image.open('Images/lena.jpg')
|
im = Image.open('Images/lena.jpg')
|
||||||
_test_float_conversion(im.convert('L'))
|
_test_float_conversion(im.convert('L'))
|
||||||
|
|
||||||
|
|
||||||
def test_16bit():
|
def test_16bit():
|
||||||
im = Image.open('Tests/images/16bit.cropped.tif')
|
im = Image.open('Tests/images/16bit.cropped.tif')
|
||||||
_test_float_conversion(im)
|
_test_float_conversion(im)
|
||||||
|
|
||||||
|
|
||||||
def test_16bit_workaround():
|
def test_16bit_workaround():
|
||||||
im = Image.open('Tests/images/16bit.cropped.tif')
|
im = Image.open('Tests/images/16bit.cropped.tif')
|
||||||
_test_float_conversion(im.convert('I'))
|
_test_float_conversion(im.convert('I'))
|
||||||
|
|
||||||
|
|
||||||
def test_rgba_p():
|
def test_rgba_p():
|
||||||
im = lena('RGBA')
|
im = lena('RGBA')
|
||||||
im.putalpha(lena('L'))
|
im.putalpha(lena('L'))
|
||||||
|
@ -55,9 +60,10 @@ def test_rgba_p():
|
||||||
|
|
||||||
assert_image_similar(im, comparable, 20)
|
assert_image_similar(im, comparable, 20)
|
||||||
|
|
||||||
|
|
||||||
def test_trns_p():
|
def test_trns_p():
|
||||||
im = lena('P')
|
im = lena('P')
|
||||||
im.info['transparency']=0
|
im.info['transparency'] = 0
|
||||||
|
|
||||||
f = tempfile('temp.png')
|
f = tempfile('temp.png')
|
||||||
|
|
||||||
|
@ -65,11 +71,25 @@ def test_trns_p():
|
||||||
assert_equal(l.info['transparency'], 0) # undone
|
assert_equal(l.info['transparency'], 0) # undone
|
||||||
assert_no_exception(lambda: l.save(f))
|
assert_no_exception(lambda: l.save(f))
|
||||||
|
|
||||||
|
|
||||||
rgb = im.convert('RGB')
|
rgb = im.convert('RGB')
|
||||||
assert_equal(rgb.info['transparency'], (0,0,0)) # undone
|
assert_equal(rgb.info['transparency'], (0, 0, 0)) # undone
|
||||||
assert_no_exception(lambda: rgb.save(f))
|
assert_no_exception(lambda: rgb.save(f))
|
||||||
|
|
||||||
|
|
||||||
|
# ref https://github.com/python-pillow/Pillow/issues/664
|
||||||
|
|
||||||
|
def test_trns_p_rgba():
|
||||||
|
# Arrange
|
||||||
|
im = lena('P')
|
||||||
|
im.info['transparency'] = 128
|
||||||
|
|
||||||
|
# Act
|
||||||
|
rgba = im.convert('RGBA')
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
assert_false('transparency' in rgba.info)
|
||||||
|
|
||||||
|
|
||||||
def test_trns_l():
|
def test_trns_l():
|
||||||
im = lena('L')
|
im = lena('L')
|
||||||
im.info['transparency'] = 128
|
im.info['transparency'] = 128
|
||||||
|
@ -77,7 +97,7 @@ def test_trns_l():
|
||||||
f = tempfile('temp.png')
|
f = tempfile('temp.png')
|
||||||
|
|
||||||
rgb = im.convert('RGB')
|
rgb = im.convert('RGB')
|
||||||
assert_equal(rgb.info['transparency'], (128,128,128)) # undone
|
assert_equal(rgb.info['transparency'], (128, 128, 128)) # undone
|
||||||
assert_no_exception(lambda: rgb.save(f))
|
assert_no_exception(lambda: rgb.save(f))
|
||||||
|
|
||||||
p = im.convert('P')
|
p = im.convert('P')
|
||||||
|
@ -85,19 +105,19 @@ def test_trns_l():
|
||||||
assert_no_exception(lambda: p.save(f))
|
assert_no_exception(lambda: p.save(f))
|
||||||
|
|
||||||
p = assert_warning(UserWarning,
|
p = assert_warning(UserWarning,
|
||||||
lambda: im.convert('P', palette = Image.ADAPTIVE))
|
lambda: im.convert('P', palette=Image.ADAPTIVE))
|
||||||
assert_false('transparency' in p.info)
|
assert_false('transparency' in p.info)
|
||||||
assert_no_exception(lambda: p.save(f))
|
assert_no_exception(lambda: p.save(f))
|
||||||
|
|
||||||
|
|
||||||
def test_trns_RGB():
|
def test_trns_RGB():
|
||||||
im = lena('RGB')
|
im = lena('RGB')
|
||||||
im.info['transparency'] = im.getpixel((0,0))
|
im.info['transparency'] = im.getpixel((0, 0))
|
||||||
|
|
||||||
f = tempfile('temp.png')
|
f = tempfile('temp.png')
|
||||||
|
|
||||||
l = im.convert('L')
|
l = im.convert('L')
|
||||||
assert_equal(l.info['transparency'], l.getpixel((0,0))) # undone
|
assert_equal(l.info['transparency'], l.getpixel((0, 0))) # undone
|
||||||
assert_no_exception(lambda: l.save(f))
|
assert_no_exception(lambda: l.save(f))
|
||||||
|
|
||||||
p = im.convert('P')
|
p = im.convert('P')
|
||||||
|
@ -105,8 +125,6 @@ def test_trns_RGB():
|
||||||
assert_no_exception(lambda: p.save(f))
|
assert_no_exception(lambda: p.save(f))
|
||||||
|
|
||||||
p = assert_warning(UserWarning,
|
p = assert_warning(UserWarning,
|
||||||
lambda: im.convert('P', palette = Image.ADAPTIVE))
|
lambda: im.convert('P', palette=Image.ADAPTIVE))
|
||||||
assert_false('transparency' in p.info)
|
assert_false('transparency' in p.info)
|
||||||
assert_no_exception(lambda: p.save(f))
|
assert_no_exception(lambda: p.save(f))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ def test_basic():
|
||||||
check(mode)
|
check(mode)
|
||||||
|
|
||||||
def test_signedness():
|
def test_signedness():
|
||||||
# see https://github.com/python-imaging/Pillow/issues/452
|
# see https://github.com/python-pillow/Pillow/issues/452
|
||||||
# pixelaccess is using signed int* instead of uint*
|
# pixelaccess is using signed int* instead of uint*
|
||||||
for mode in ("I;16", "I;16B"):
|
for mode in ("I;16", "I;16B"):
|
||||||
check(mode, 2**15-1)
|
check(mode, 2**15-1)
|
||||||
|
|
|
@ -4,7 +4,7 @@ from PIL import Image
|
||||||
|
|
||||||
if hasattr(sys, 'pypy_version_info'):
|
if hasattr(sys, 'pypy_version_info'):
|
||||||
# This takes _forever_ on pypy. Open Bug,
|
# This takes _forever_ on pypy. Open Bug,
|
||||||
# see https://github.com/python-imaging/Pillow/issues/484
|
# see https://github.com/python-pillow/Pillow/issues/484
|
||||||
skip()
|
skip()
|
||||||
|
|
||||||
def test_sanity():
|
def test_sanity():
|
||||||
|
@ -26,7 +26,7 @@ def test_sanity():
|
||||||
|
|
||||||
def test_16bit_lut():
|
def test_16bit_lut():
|
||||||
""" Tests for 16 bit -> 8 bit lut for converting I->L images
|
""" Tests for 16 bit -> 8 bit lut for converting I->L images
|
||||||
see https://github.com/python-imaging/Pillow/issues/440
|
see https://github.com/python-pillow/Pillow/issues/440
|
||||||
"""
|
"""
|
||||||
|
|
||||||
im = lena("I")
|
im = lena("I")
|
||||||
|
|
|
@ -94,7 +94,7 @@ def test_alpha_premult_transform():
|
||||||
|
|
||||||
def test_blank_fill():
|
def test_blank_fill():
|
||||||
# attempting to hit
|
# attempting to hit
|
||||||
# https://github.com/python-imaging/Pillow/issues/254 reported
|
# https://github.com/python-pillow/Pillow/issues/254 reported
|
||||||
#
|
#
|
||||||
# issue is that transforms with transparent overflow area
|
# issue is that transforms with transparent overflow area
|
||||||
# contained junk from previous images, especially on systems with
|
# contained junk from previous images, especially on systems with
|
||||||
|
|
|
@ -9,6 +9,7 @@ except ImportError:
|
||||||
|
|
||||||
SRGB = "Tests/icc/sRGB.icm"
|
SRGB = "Tests/icc/sRGB.icm"
|
||||||
|
|
||||||
|
|
||||||
def test_sanity():
|
def test_sanity():
|
||||||
|
|
||||||
# basic smoke test.
|
# basic smoke test.
|
||||||
|
@ -24,10 +25,19 @@ def test_sanity():
|
||||||
i = ImageCms.profileToProfile(lena(), SRGB, SRGB)
|
i = ImageCms.profileToProfile(lena(), SRGB, SRGB)
|
||||||
assert_image(i, "RGB", (128, 128))
|
assert_image(i, "RGB", (128, 128))
|
||||||
|
|
||||||
|
i = lena()
|
||||||
|
ImageCms.profileToProfile(i, SRGB, SRGB, inPlace=True)
|
||||||
|
assert_image(i, "RGB", (128, 128))
|
||||||
|
|
||||||
t = ImageCms.buildTransform(SRGB, SRGB, "RGB", "RGB")
|
t = ImageCms.buildTransform(SRGB, SRGB, "RGB", "RGB")
|
||||||
i = ImageCms.applyTransform(lena(), t)
|
i = ImageCms.applyTransform(lena(), t)
|
||||||
assert_image(i, "RGB", (128, 128))
|
assert_image(i, "RGB", (128, 128))
|
||||||
|
|
||||||
|
i = lena()
|
||||||
|
t = ImageCms.buildTransform(SRGB, SRGB, "RGB", "RGB")
|
||||||
|
ImageCms.applyTransform(lena(), t, inPlace=True)
|
||||||
|
assert_image(i, "RGB", (128, 128))
|
||||||
|
|
||||||
p = ImageCms.createProfile("sRGB")
|
p = ImageCms.createProfile("sRGB")
|
||||||
o = ImageCms.getOpenProfile(SRGB)
|
o = ImageCms.getOpenProfile(SRGB)
|
||||||
t = ImageCms.buildTransformFromOpenProfiles(p, o, "RGB", "RGB")
|
t = ImageCms.buildTransformFromOpenProfiles(p, o, "RGB", "RGB")
|
||||||
|
@ -41,18 +51,40 @@ def test_sanity():
|
||||||
assert_image(i, "RGB", (128, 128))
|
assert_image(i, "RGB", (128, 128))
|
||||||
|
|
||||||
# test PointTransform convenience API
|
# test PointTransform convenience API
|
||||||
im = lena().point(t)
|
lena().point(t)
|
||||||
|
|
||||||
|
|
||||||
def test_name():
|
def test_name():
|
||||||
# get profile information for file
|
# get profile information for file
|
||||||
assert_equal(ImageCms.getProfileName(SRGB).strip(),
|
assert_equal(ImageCms.getProfileName(SRGB).strip(),
|
||||||
'IEC 61966-2.1 Default RGB colour space - sRGB')
|
'IEC 61966-2.1 Default RGB colour space - sRGB')
|
||||||
def x_test_info():
|
|
||||||
|
|
||||||
|
def test_info():
|
||||||
assert_equal(ImageCms.getProfileInfo(SRGB).splitlines(),
|
assert_equal(ImageCms.getProfileInfo(SRGB).splitlines(),
|
||||||
['sRGB IEC61966-2.1', '',
|
['sRGB IEC61966-2.1', '',
|
||||||
'Copyright (c) 1998 Hewlett-Packard Company', '',
|
'Copyright (c) 1998 Hewlett-Packard Company', ''])
|
||||||
'WhitePoint : D65 (daylight)', '',
|
|
||||||
'Tests/icc/sRGB.icm'])
|
|
||||||
|
def test_copyright():
|
||||||
|
assert_equal(ImageCms.getProfileCopyright(SRGB).strip(),
|
||||||
|
'Copyright (c) 1998 Hewlett-Packard Company')
|
||||||
|
|
||||||
|
|
||||||
|
def test_manufacturer():
|
||||||
|
assert_equal(ImageCms.getProfileManufacturer(SRGB).strip(),
|
||||||
|
'IEC http://www.iec.ch')
|
||||||
|
|
||||||
|
|
||||||
|
def test_model():
|
||||||
|
assert_equal(ImageCms.getProfileModel(SRGB).strip(),
|
||||||
|
'IEC 61966-2.1 Default RGB colour space - sRGB')
|
||||||
|
|
||||||
|
|
||||||
|
def test_description():
|
||||||
|
assert_equal(ImageCms.getProfileDescription(SRGB).strip(),
|
||||||
|
'sRGB IEC61966-2.1')
|
||||||
|
|
||||||
|
|
||||||
def test_intent():
|
def test_intent():
|
||||||
assert_equal(ImageCms.getDefaultIntent(SRGB), 0)
|
assert_equal(ImageCms.getDefaultIntent(SRGB), 0)
|
||||||
|
@ -60,6 +92,7 @@ def test_intent():
|
||||||
SRGB, ImageCms.INTENT_ABSOLUTE_COLORIMETRIC,
|
SRGB, ImageCms.INTENT_ABSOLUTE_COLORIMETRIC,
|
||||||
ImageCms.DIRECTION_INPUT), 1)
|
ImageCms.DIRECTION_INPUT), 1)
|
||||||
|
|
||||||
|
|
||||||
def test_profile_object():
|
def test_profile_object():
|
||||||
# same, using profile object
|
# same, using profile object
|
||||||
p = ImageCms.createProfile("sRGB")
|
p = ImageCms.createProfile("sRGB")
|
||||||
|
@ -72,6 +105,7 @@ def test_profile_object():
|
||||||
p, ImageCms.INTENT_ABSOLUTE_COLORIMETRIC,
|
p, ImageCms.INTENT_ABSOLUTE_COLORIMETRIC,
|
||||||
ImageCms.DIRECTION_INPUT), 1)
|
ImageCms.DIRECTION_INPUT), 1)
|
||||||
|
|
||||||
|
|
||||||
def test_extensions():
|
def test_extensions():
|
||||||
# extensions
|
# extensions
|
||||||
i = Image.open("Tests/images/rgb.jpg")
|
i = Image.open("Tests/images/rgb.jpg")
|
||||||
|
@ -79,12 +113,21 @@ def test_extensions():
|
||||||
assert_equal(ImageCms.getProfileName(p).strip(),
|
assert_equal(ImageCms.getProfileName(p).strip(),
|
||||||
'IEC 61966-2.1 Default RGB colour space - sRGB')
|
'IEC 61966-2.1 Default RGB colour space - sRGB')
|
||||||
|
|
||||||
|
|
||||||
def test_exceptions():
|
def test_exceptions():
|
||||||
# the procedural pyCMS API uses PyCMSError for all sorts of errors
|
# the procedural pyCMS API uses PyCMSError for all sorts of errors
|
||||||
assert_exception(ImageCms.PyCMSError, lambda: ImageCms.profileToProfile(lena(), "foo", "bar"))
|
assert_exception(
|
||||||
assert_exception(ImageCms.PyCMSError, lambda: ImageCms.buildTransform("foo", "bar", "RGB", "RGB"))
|
ImageCms.PyCMSError,
|
||||||
assert_exception(ImageCms.PyCMSError, lambda: ImageCms.getProfileName(None))
|
lambda: ImageCms.profileToProfile(lena(), "foo", "bar"))
|
||||||
assert_exception(ImageCms.PyCMSError, lambda: ImageCms.isIntentSupported(SRGB, None, None))
|
assert_exception(
|
||||||
|
ImageCms.PyCMSError,
|
||||||
|
lambda: ImageCms.buildTransform("foo", "bar", "RGB", "RGB"))
|
||||||
|
assert_exception(
|
||||||
|
ImageCms.PyCMSError,
|
||||||
|
lambda: ImageCms.getProfileName(None))
|
||||||
|
assert_exception(
|
||||||
|
ImageCms.PyCMSError,
|
||||||
|
lambda: ImageCms.isIntentSupported(SRGB, None, None))
|
||||||
|
|
||||||
|
|
||||||
def test_display_profile():
|
def test_display_profile():
|
||||||
|
@ -93,37 +136,37 @@ def test_display_profile():
|
||||||
|
|
||||||
|
|
||||||
def test_lab_color_profile():
|
def test_lab_color_profile():
|
||||||
pLab = ImageCms.createProfile("LAB", 5000)
|
ImageCms.createProfile("LAB", 5000)
|
||||||
pLab = ImageCms.createProfile("LAB", 6500)
|
ImageCms.createProfile("LAB", 6500)
|
||||||
|
|
||||||
|
|
||||||
def test_simple_lab():
|
def test_simple_lab():
|
||||||
i = Image.new('RGB', (10,10), (128,128,128))
|
i = Image.new('RGB', (10, 10), (128, 128, 128))
|
||||||
|
|
||||||
pLab = ImageCms.createProfile("LAB")
|
pLab = ImageCms.createProfile("LAB")
|
||||||
t = ImageCms.buildTransform(SRGB, pLab, "RGB", "LAB")
|
t = ImageCms.buildTransform(SRGB, pLab, "RGB", "LAB")
|
||||||
|
|
||||||
i_lab = ImageCms.applyTransform(i, t)
|
i_lab = ImageCms.applyTransform(i, t)
|
||||||
|
|
||||||
|
|
||||||
assert_equal(i_lab.mode, 'LAB')
|
assert_equal(i_lab.mode, 'LAB')
|
||||||
|
|
||||||
k = i_lab.getpixel((0,0))
|
k = i_lab.getpixel((0, 0))
|
||||||
assert_equal(k, (137,128,128)) # not a linear luminance map. so L != 128
|
assert_equal(k, (137, 128, 128)) # not a linear luminance map. so L != 128
|
||||||
|
|
||||||
L = i_lab.getdata(0)
|
L = i_lab.getdata(0)
|
||||||
a = i_lab.getdata(1)
|
a = i_lab.getdata(1)
|
||||||
b = i_lab.getdata(2)
|
b = i_lab.getdata(2)
|
||||||
|
|
||||||
assert_equal(list(L), [137]*100)
|
assert_equal(list(L), [137] * 100)
|
||||||
assert_equal(list(a), [128]*100)
|
assert_equal(list(a), [128] * 100)
|
||||||
assert_equal(list(b), [128]*100)
|
assert_equal(list(b), [128] * 100)
|
||||||
|
|
||||||
|
|
||||||
def test_lab_color():
|
def test_lab_color():
|
||||||
pLab = ImageCms.createProfile("LAB")
|
pLab = ImageCms.createProfile("LAB")
|
||||||
t = ImageCms.buildTransform(SRGB, pLab, "RGB", "LAB")
|
t = ImageCms.buildTransform(SRGB, pLab, "RGB", "LAB")
|
||||||
# need to add a type mapping for some PIL type to TYPE_Lab_8 in findLCMSType,
|
# Need to add a type mapping for some PIL type to TYPE_Lab_8 in
|
||||||
# and have that mapping work back to a PIL mode. (likely RGB)
|
# findLCMSType, and have that mapping work back to a PIL mode (likely RGB).
|
||||||
i = ImageCms.applyTransform(lena(), t)
|
i = ImageCms.applyTransform(lena(), t)
|
||||||
assert_image(i, "LAB", (128, 128))
|
assert_image(i, "LAB", (128, 128))
|
||||||
|
|
||||||
|
@ -133,6 +176,7 @@ def test_lab_color():
|
||||||
|
|
||||||
assert_image_similar(i, target, 30)
|
assert_image_similar(i, target, 30)
|
||||||
|
|
||||||
|
|
||||||
def test_lab_srgb():
|
def test_lab_srgb():
|
||||||
pLab = ImageCms.createProfile("LAB")
|
pLab = ImageCms.createProfile("LAB")
|
||||||
t = ImageCms.buildTransform(pLab, SRGB, "LAB", "RGB")
|
t = ImageCms.buildTransform(pLab, SRGB, "LAB", "RGB")
|
||||||
|
@ -145,6 +189,7 @@ def test_lab_srgb():
|
||||||
|
|
||||||
assert_image_similar(lena(), img_srgb, 30)
|
assert_image_similar(lena(), img_srgb, 30)
|
||||||
|
|
||||||
|
|
||||||
def test_lab_roundtrip():
|
def test_lab_roundtrip():
|
||||||
# check to see if we're at least internally consistent.
|
# check to see if we're at least internally consistent.
|
||||||
pLab = ImageCms.createProfile("LAB")
|
pLab = ImageCms.createProfile("LAB")
|
||||||
|
@ -156,5 +201,3 @@ def test_lab_roundtrip():
|
||||||
out = ImageCms.applyTransform(i, t2)
|
out = ImageCms.applyTransform(i, t2)
|
||||||
|
|
||||||
assert_image_similar(lena(), out, 2)
|
assert_image_similar(lena(), out, 2)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,27 @@
|
||||||
from tester import *
|
from tester import *
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
from PIL import ImageColor
|
||||||
from PIL import ImageDraw
|
from PIL import ImageDraw
|
||||||
|
|
||||||
|
# Image size
|
||||||
|
w, h = 100, 100
|
||||||
|
|
||||||
|
# Bounding box points
|
||||||
|
x0 = int(w / 4)
|
||||||
|
x1 = int(x0 * 3)
|
||||||
|
y0 = int(h / 4)
|
||||||
|
y1 = int(x0 * 3)
|
||||||
|
|
||||||
|
# Two kinds of bounding box
|
||||||
|
bbox1 = [(x0, y0), (x1, y1)]
|
||||||
|
bbox2 = [x0, y0, x1, y1]
|
||||||
|
|
||||||
|
# Two kinds of coordinate sequences
|
||||||
|
points1 = [(10, 10), (20, 40), (30, 30)]
|
||||||
|
points2 = [10, 10, 20, 40, 30, 30]
|
||||||
|
|
||||||
|
|
||||||
def test_sanity():
|
def test_sanity():
|
||||||
|
|
||||||
im = lena("RGB").copy()
|
im = lena("RGB").copy()
|
||||||
|
@ -17,6 +36,7 @@ def test_sanity():
|
||||||
|
|
||||||
success()
|
success()
|
||||||
|
|
||||||
|
|
||||||
def test_deprecated():
|
def test_deprecated():
|
||||||
|
|
||||||
im = lena().copy()
|
im = lena().copy()
|
||||||
|
@ -26,3 +46,220 @@ def test_deprecated():
|
||||||
assert_warning(DeprecationWarning, lambda: draw.setink(0))
|
assert_warning(DeprecationWarning, lambda: draw.setink(0))
|
||||||
assert_warning(DeprecationWarning, lambda: draw.setfill(0))
|
assert_warning(DeprecationWarning, lambda: draw.setfill(0))
|
||||||
|
|
||||||
|
|
||||||
|
def helper_arc(bbox):
|
||||||
|
# Arrange
|
||||||
|
im = Image.new("RGB", (w, h))
|
||||||
|
draw = ImageDraw.Draw(im)
|
||||||
|
|
||||||
|
# Act
|
||||||
|
# FIXME Fill param should be named outline.
|
||||||
|
draw.arc(bbox, 0, 180)
|
||||||
|
del draw
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
assert_image_equal(im, Image.open("Tests/images/imagedraw_arc.png"))
|
||||||
|
|
||||||
|
|
||||||
|
def test_arc1():
|
||||||
|
helper_arc(bbox1)
|
||||||
|
|
||||||
|
|
||||||
|
def test_arc2():
|
||||||
|
helper_arc(bbox2)
|
||||||
|
|
||||||
|
|
||||||
|
def test_bitmap():
|
||||||
|
# Arrange
|
||||||
|
small = Image.open("Tests/images/pil123rgba.png").resize((50, 50))
|
||||||
|
im = Image.new("RGB", (w, h))
|
||||||
|
draw = ImageDraw.Draw(im)
|
||||||
|
|
||||||
|
# Act
|
||||||
|
draw.bitmap((10, 10), small)
|
||||||
|
del draw
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
assert_image_equal(im, Image.open("Tests/images/imagedraw_bitmap.png"))
|
||||||
|
|
||||||
|
|
||||||
|
def helper_chord(bbox):
|
||||||
|
# Arrange
|
||||||
|
im = Image.new("RGB", (w, h))
|
||||||
|
draw = ImageDraw.Draw(im)
|
||||||
|
|
||||||
|
# Act
|
||||||
|
draw.chord(bbox, 0, 180, fill="red", outline="yellow")
|
||||||
|
del draw
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
assert_image_equal(im, Image.open("Tests/images/imagedraw_chord.png"))
|
||||||
|
|
||||||
|
|
||||||
|
def test_chord1():
|
||||||
|
helper_chord(bbox1)
|
||||||
|
|
||||||
|
|
||||||
|
def test_chord2():
|
||||||
|
helper_chord(bbox2)
|
||||||
|
|
||||||
|
|
||||||
|
def helper_ellipse(bbox):
|
||||||
|
# Arrange
|
||||||
|
im = Image.new("RGB", (w, h))
|
||||||
|
draw = ImageDraw.Draw(im)
|
||||||
|
|
||||||
|
# Act
|
||||||
|
draw.ellipse(bbox, fill="green", outline="blue")
|
||||||
|
del draw
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
assert_image_equal(im, Image.open("Tests/images/imagedraw_ellipse.png"))
|
||||||
|
|
||||||
|
|
||||||
|
def test_ellipse1():
|
||||||
|
helper_ellipse(bbox1)
|
||||||
|
|
||||||
|
|
||||||
|
def test_ellipse2():
|
||||||
|
helper_ellipse(bbox2)
|
||||||
|
|
||||||
|
|
||||||
|
def helper_line(points):
|
||||||
|
# Arrange
|
||||||
|
im = Image.new("RGB", (w, h))
|
||||||
|
draw = ImageDraw.Draw(im)
|
||||||
|
|
||||||
|
# Act
|
||||||
|
draw.line(points1, fill="yellow", width=2)
|
||||||
|
del draw
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
assert_image_equal(im, Image.open("Tests/images/imagedraw_line.png"))
|
||||||
|
|
||||||
|
|
||||||
|
def test_line1():
|
||||||
|
helper_line(points1)
|
||||||
|
|
||||||
|
|
||||||
|
def test_line2():
|
||||||
|
helper_line(points2)
|
||||||
|
|
||||||
|
|
||||||
|
def helper_pieslice(bbox):
|
||||||
|
# Arrange
|
||||||
|
im = Image.new("RGB", (w, h))
|
||||||
|
draw = ImageDraw.Draw(im)
|
||||||
|
|
||||||
|
# Act
|
||||||
|
draw.pieslice(bbox, -90, 45, fill="white", outline="blue")
|
||||||
|
del draw
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
assert_image_equal(im, Image.open("Tests/images/imagedraw_pieslice.png"))
|
||||||
|
|
||||||
|
|
||||||
|
def test_pieslice1():
|
||||||
|
helper_pieslice(bbox1)
|
||||||
|
|
||||||
|
|
||||||
|
def test_pieslice2():
|
||||||
|
helper_pieslice(bbox2)
|
||||||
|
|
||||||
|
|
||||||
|
def helper_point(points):
|
||||||
|
# Arrange
|
||||||
|
im = Image.new("RGB", (w, h))
|
||||||
|
draw = ImageDraw.Draw(im)
|
||||||
|
|
||||||
|
# Act
|
||||||
|
draw.point(points1, fill="yellow")
|
||||||
|
del draw
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
assert_image_equal(im, Image.open("Tests/images/imagedraw_point.png"))
|
||||||
|
|
||||||
|
|
||||||
|
def test_point1():
|
||||||
|
helper_point(points1)
|
||||||
|
|
||||||
|
|
||||||
|
def test_point2():
|
||||||
|
helper_point(points2)
|
||||||
|
|
||||||
|
|
||||||
|
def helper_polygon(points):
|
||||||
|
# Arrange
|
||||||
|
im = Image.new("RGB", (w, h))
|
||||||
|
draw = ImageDraw.Draw(im)
|
||||||
|
|
||||||
|
# Act
|
||||||
|
draw.polygon(points1, fill="red", outline="blue")
|
||||||
|
del draw
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
assert_image_equal(im, Image.open("Tests/images/imagedraw_polygon.png"))
|
||||||
|
|
||||||
|
|
||||||
|
def test_polygon1():
|
||||||
|
helper_polygon(points1)
|
||||||
|
|
||||||
|
|
||||||
|
def test_polygon2():
|
||||||
|
helper_polygon(points2)
|
||||||
|
|
||||||
|
|
||||||
|
def helper_rectangle(bbox):
|
||||||
|
# Arrange
|
||||||
|
im = Image.new("RGB", (w, h))
|
||||||
|
draw = ImageDraw.Draw(im)
|
||||||
|
|
||||||
|
# Act
|
||||||
|
draw.rectangle(bbox, fill="black", outline="green")
|
||||||
|
del draw
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
assert_image_equal(im, Image.open("Tests/images/imagedraw_rectangle.png"))
|
||||||
|
|
||||||
|
|
||||||
|
def test_rectangle1():
|
||||||
|
helper_rectangle(bbox1)
|
||||||
|
|
||||||
|
|
||||||
|
def test_rectangle2():
|
||||||
|
helper_rectangle(bbox2)
|
||||||
|
|
||||||
|
|
||||||
|
def test_floodfill():
|
||||||
|
# Arrange
|
||||||
|
im = Image.new("RGB", (w, h))
|
||||||
|
draw = ImageDraw.Draw(im)
|
||||||
|
draw.rectangle(bbox2, outline="yellow", fill="green")
|
||||||
|
centre_point = (int(w/2), int(h/2))
|
||||||
|
|
||||||
|
# Act
|
||||||
|
ImageDraw.floodfill(im, centre_point, ImageColor.getrgb("red"))
|
||||||
|
del draw
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
assert_image_equal(im, Image.open("Tests/images/imagedraw_floodfill.png"))
|
||||||
|
|
||||||
|
|
||||||
|
def test_floodfill_border():
|
||||||
|
# Arrange
|
||||||
|
im = Image.new("RGB", (w, h))
|
||||||
|
draw = ImageDraw.Draw(im)
|
||||||
|
draw.rectangle(bbox2, outline="yellow", fill="green")
|
||||||
|
centre_point = (int(w/2), int(h/2))
|
||||||
|
|
||||||
|
# Act
|
||||||
|
ImageDraw.floodfill(
|
||||||
|
im, centre_point, ImageColor.getrgb("red"),
|
||||||
|
border=ImageColor.getrgb("black"))
|
||||||
|
del draw
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
assert_image_equal(im, Image.open("Tests/images/imagedraw_floodfill2.png"))
|
||||||
|
|
||||||
|
|
||||||
|
# End of file
|
||||||
|
|
|
@ -56,7 +56,7 @@ def test_parser():
|
||||||
assert_image(im1, im2.mode, im2.size)
|
assert_image(im1, im2.mode, im2.size)
|
||||||
|
|
||||||
# XXX Why assert exception and why does it fail?
|
# XXX Why assert exception and why does it fail?
|
||||||
# https://github.com/python-imaging/Pillow/issues/78
|
# https://github.com/python-pillow/Pillow/issues/78
|
||||||
#assert_exception(IOError, lambda: roundtrip("PDF"))
|
#assert_exception(IOError, lambda: roundtrip("PDF"))
|
||||||
|
|
||||||
def test_ico():
|
def test_ico():
|
||||||
|
|
|
@ -3,7 +3,7 @@ from PIL import Image
|
||||||
|
|
||||||
import locale
|
import locale
|
||||||
|
|
||||||
# ref https://github.com/python-imaging/Pillow/issues/272
|
# ref https://github.com/python-pillow/Pillow/issues/272
|
||||||
## on windows, in polish locale:
|
## on windows, in polish locale:
|
||||||
|
|
||||||
## import locale
|
## import locale
|
||||||
|
|
|
@ -108,7 +108,7 @@ def test_to_array():
|
||||||
|
|
||||||
|
|
||||||
def test_point_lut():
|
def test_point_lut():
|
||||||
# see https://github.com/python-imaging/Pillow/issues/439
|
# see https://github.com/python-pillow/Pillow/issues/439
|
||||||
|
|
||||||
data = list(range(256))*3
|
data = list(range(256))*3
|
||||||
lut = numpy.array(data, dtype='uint8')
|
lut = numpy.array(data, dtype='uint8')
|
||||||
|
|
70
Tests/test_pickle.py
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
from tester import *
|
||||||
|
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
|
|
||||||
|
def helper_test_pickle_file(pickle, protocol=0):
|
||||||
|
im = Image.open('Images/lena.jpg')
|
||||||
|
filename = tempfile('temp.pkl')
|
||||||
|
|
||||||
|
# Act
|
||||||
|
with open(filename, 'wb') as f:
|
||||||
|
pickle.dump(im, f, protocol)
|
||||||
|
with open(filename, 'rb') as f:
|
||||||
|
loaded_im = pickle.load(f)
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
assert_image_completely_equal(im, loaded_im)
|
||||||
|
|
||||||
|
|
||||||
|
def helper_test_pickle_string(pickle, protocol=0, file='Images/lena.jpg'):
|
||||||
|
im = Image.open(file)
|
||||||
|
|
||||||
|
# Act
|
||||||
|
dumped_string = pickle.dumps(im, protocol)
|
||||||
|
loaded_im = pickle.loads(dumped_string)
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
assert_image_completely_equal(im, loaded_im)
|
||||||
|
|
||||||
|
|
||||||
|
def test_pickle_image():
|
||||||
|
# Arrange
|
||||||
|
import pickle
|
||||||
|
|
||||||
|
# Act / Assert
|
||||||
|
for protocol in range(0, pickle.HIGHEST_PROTOCOL + 1):
|
||||||
|
helper_test_pickle_string(pickle, protocol)
|
||||||
|
helper_test_pickle_file(pickle, protocol)
|
||||||
|
|
||||||
|
|
||||||
|
def test_cpickle_image():
|
||||||
|
# Arrange
|
||||||
|
try:
|
||||||
|
import cPickle
|
||||||
|
except ImportError:
|
||||||
|
return
|
||||||
|
|
||||||
|
# Act / Assert
|
||||||
|
for protocol in range(0, cPickle.HIGHEST_PROTOCOL + 1):
|
||||||
|
helper_test_pickle_string(cPickle, protocol)
|
||||||
|
helper_test_pickle_file(cPickle, protocol)
|
||||||
|
|
||||||
|
|
||||||
|
def test_pickle_p_mode():
|
||||||
|
# Arrange
|
||||||
|
import pickle
|
||||||
|
|
||||||
|
# Act / Assert
|
||||||
|
for file in [
|
||||||
|
"Tests/images/test-card.png",
|
||||||
|
"Tests/images/zero_bb.png",
|
||||||
|
"Tests/images/zero_bb_scale2.png",
|
||||||
|
"Tests/images/non_zero_bb.png",
|
||||||
|
"Tests/images/non_zero_bb_scale2.png",
|
||||||
|
"Tests/images/p_trns_single.png",
|
||||||
|
"Tests/images/pil123p.png"
|
||||||
|
]:
|
||||||
|
helper_test_pickle_string(pickle, file=file)
|
||||||
|
|
||||||
|
# End of file
|
|
@ -242,7 +242,13 @@ def assert_image_equal(a, b, msg=None):
|
||||||
failure(msg or "got size %r, expected %r" % (a.size, b.size))
|
failure(msg or "got size %r, expected %r" % (a.size, b.size))
|
||||||
elif a.tobytes() != b.tobytes():
|
elif a.tobytes() != b.tobytes():
|
||||||
failure(msg or "got different content")
|
failure(msg or "got different content")
|
||||||
# generate better diff?
|
else:
|
||||||
|
success()
|
||||||
|
|
||||||
|
|
||||||
|
def assert_image_completely_equal(a, b, msg=None):
|
||||||
|
if a != b:
|
||||||
|
failure(msg or "images different")
|
||||||
else:
|
else:
|
||||||
success()
|
success()
|
||||||
|
|
||||||
|
|
95
_imaging.c
|
@ -2399,17 +2399,35 @@ _draw_ink(ImagingDrawObject* self, PyObject* args)
|
||||||
static PyObject*
|
static PyObject*
|
||||||
_draw_arc(ImagingDrawObject* self, PyObject* args)
|
_draw_arc(ImagingDrawObject* self, PyObject* args)
|
||||||
{
|
{
|
||||||
int x0, y0, x1, y1;
|
double* xy;
|
||||||
|
int n;
|
||||||
|
|
||||||
|
PyObject* data;
|
||||||
int ink;
|
int ink;
|
||||||
int start, end;
|
int start, end;
|
||||||
int op = 0;
|
int op = 0;
|
||||||
if (!PyArg_ParseTuple(args, "(iiii)iii|i",
|
if (!PyArg_ParseTuple(args, "Oiii|i", &data, &start, &end, &ink))
|
||||||
&x0, &y0, &x1, &y1,
|
|
||||||
&start, &end, &ink))
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (ImagingDrawArc(self->image->image, x0, y0, x1, y1, start, end,
|
n = PyPath_Flatten(data, &xy);
|
||||||
&ink, op) < 0)
|
if (n < 0)
|
||||||
|
return NULL;
|
||||||
|
if (n != 2) {
|
||||||
|
PyErr_SetString(PyExc_TypeError,
|
||||||
|
"coordinate list must contain exactly 2 coordinates"
|
||||||
|
);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
n = ImagingDrawArc(self->image->image,
|
||||||
|
(int) xy[0], (int) xy[1],
|
||||||
|
(int) xy[2], (int) xy[3],
|
||||||
|
start, end, &ink, op
|
||||||
|
);
|
||||||
|
|
||||||
|
free(xy);
|
||||||
|
|
||||||
|
if (n < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
|
@ -2455,15 +2473,35 @@ _draw_bitmap(ImagingDrawObject* self, PyObject* args)
|
||||||
static PyObject*
|
static PyObject*
|
||||||
_draw_chord(ImagingDrawObject* self, PyObject* args)
|
_draw_chord(ImagingDrawObject* self, PyObject* args)
|
||||||
{
|
{
|
||||||
int x0, y0, x1, y1;
|
double* xy;
|
||||||
|
int n;
|
||||||
|
|
||||||
|
PyObject* data;
|
||||||
int ink, fill;
|
int ink, fill;
|
||||||
int start, end;
|
int start, end;
|
||||||
if (!PyArg_ParseTuple(args, "(iiii)iiii",
|
if (!PyArg_ParseTuple(args, "Oiiii",
|
||||||
&x0, &y0, &x1, &y1, &start, &end, &ink, &fill))
|
&data, &start, &end, &ink, &fill))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (ImagingDrawChord(self->image->image, x0, y0, x1, y1,
|
n = PyPath_Flatten(data, &xy);
|
||||||
start, end, &ink, fill, self->blend) < 0)
|
if (n < 0)
|
||||||
|
return NULL;
|
||||||
|
if (n != 2) {
|
||||||
|
PyErr_SetString(PyExc_TypeError,
|
||||||
|
"coordinate list must contain exactly 2 coordinates"
|
||||||
|
);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
n = ImagingDrawChord(self->image->image,
|
||||||
|
(int) xy[0], (int) xy[1],
|
||||||
|
(int) xy[2], (int) xy[3],
|
||||||
|
start, end, &ink, fill, self->blend
|
||||||
|
);
|
||||||
|
|
||||||
|
free(xy);
|
||||||
|
|
||||||
|
if (n < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
|
@ -2656,15 +2694,34 @@ _draw_outline(ImagingDrawObject* self, PyObject* args)
|
||||||
static PyObject*
|
static PyObject*
|
||||||
_draw_pieslice(ImagingDrawObject* self, PyObject* args)
|
_draw_pieslice(ImagingDrawObject* self, PyObject* args)
|
||||||
{
|
{
|
||||||
int x0, y0, x1, y1;
|
double* xy;
|
||||||
|
int n;
|
||||||
|
|
||||||
|
PyObject* data;
|
||||||
int ink, fill;
|
int ink, fill;
|
||||||
int start, end;
|
int start, end;
|
||||||
if (!PyArg_ParseTuple(args, "(iiii)iiii",
|
if (!PyArg_ParseTuple(args, "Oiiii", &data, &start, &end, &ink, &fill))
|
||||||
&x0, &y0, &x1, &y1, &start, &end, &ink, &fill))
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (ImagingDrawPieslice(self->image->image, x0, y0, x1, y1,
|
n = PyPath_Flatten(data, &xy);
|
||||||
start, end, &ink, fill, self->blend) < 0)
|
if (n < 0)
|
||||||
|
return NULL;
|
||||||
|
if (n != 2) {
|
||||||
|
PyErr_SetString(PyExc_TypeError,
|
||||||
|
"coordinate list must contain exactly 2 coordinates"
|
||||||
|
);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
n = ImagingDrawPieslice(self->image->image,
|
||||||
|
(int) xy[0], (int) xy[1],
|
||||||
|
(int) xy[2], (int) xy[3],
|
||||||
|
start, end, &ink, fill, self->blend
|
||||||
|
);
|
||||||
|
|
||||||
|
free(xy);
|
||||||
|
|
||||||
|
if (n < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
|
@ -3350,7 +3407,7 @@ extern PyObject* PyImaging_ZipEncoderNew(PyObject* self, PyObject* args);
|
||||||
extern PyObject* PyImaging_LibTiffEncoderNew(PyObject* self, PyObject* args);
|
extern PyObject* PyImaging_LibTiffEncoderNew(PyObject* self, PyObject* args);
|
||||||
|
|
||||||
/* Display support etc (in display.c) */
|
/* Display support etc (in display.c) */
|
||||||
#ifdef WIN32
|
#ifdef _WIN32
|
||||||
extern PyObject* PyImaging_CreateWindowWin32(PyObject* self, PyObject* args);
|
extern PyObject* PyImaging_CreateWindowWin32(PyObject* self, PyObject* args);
|
||||||
extern PyObject* PyImaging_DisplayWin32(PyObject* self, PyObject* args);
|
extern PyObject* PyImaging_DisplayWin32(PyObject* self, PyObject* args);
|
||||||
extern PyObject* PyImaging_DisplayModeWin32(PyObject* self, PyObject* args);
|
extern PyObject* PyImaging_DisplayModeWin32(PyObject* self, PyObject* args);
|
||||||
|
@ -3423,14 +3480,14 @@ static PyMethodDef functions[] = {
|
||||||
|
|
||||||
/* Memory mapping */
|
/* Memory mapping */
|
||||||
#ifdef WITH_MAPPING
|
#ifdef WITH_MAPPING
|
||||||
#ifdef WIN32
|
#ifdef _WIN32
|
||||||
{"map", (PyCFunction)PyImaging_Mapper, 1},
|
{"map", (PyCFunction)PyImaging_Mapper, 1},
|
||||||
#endif
|
#endif
|
||||||
{"map_buffer", (PyCFunction)PyImaging_MapBuffer, 1},
|
{"map_buffer", (PyCFunction)PyImaging_MapBuffer, 1},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Display support */
|
/* Display support */
|
||||||
#ifdef WIN32
|
#ifdef _WIN32
|
||||||
{"display", (PyCFunction)PyImaging_DisplayWin32, 1},
|
{"display", (PyCFunction)PyImaging_DisplayWin32, 1},
|
||||||
{"display_mode", (PyCFunction)PyImaging_DisplayModeWin32, 1},
|
{"display_mode", (PyCFunction)PyImaging_DisplayModeWin32, 1},
|
||||||
{"grabscreen", (PyCFunction)PyImaging_GrabScreenWin32, 1},
|
{"grabscreen", (PyCFunction)PyImaging_GrabScreenWin32, 1},
|
||||||
|
|
|
@ -28,12 +28,6 @@ http://www.cazabon.com\n\
|
||||||
#include "Imaging.h"
|
#include "Imaging.h"
|
||||||
#include "py3.h"
|
#include "py3.h"
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
#include <windows.h>
|
|
||||||
#include <windef.h>
|
|
||||||
#include <wingdi.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define PYCMSVERSION "1.0.0 pil"
|
#define PYCMSVERSION "1.0.0 pil"
|
||||||
|
|
||||||
/* version history */
|
/* version history */
|
||||||
|
@ -450,7 +444,7 @@ cms_profile_is_intent_supported(CmsProfileObject *self, PyObject *args)
|
||||||
return PyInt_FromLong(result != 0);
|
return PyInt_FromLong(result != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef _WIN32
|
||||||
static PyObject *
|
static PyObject *
|
||||||
cms_get_display_profile_win32(PyObject* self, PyObject* args)
|
cms_get_display_profile_win32(PyObject* self, PyObject* args)
|
||||||
{
|
{
|
||||||
|
@ -496,7 +490,7 @@ static PyMethodDef pyCMSdll_methods[] = {
|
||||||
{"createProfile", createProfile, 1},
|
{"createProfile", createProfile, 1},
|
||||||
|
|
||||||
/* platform specific tools */
|
/* platform specific tools */
|
||||||
#ifdef WIN32
|
#ifdef _WIN32
|
||||||
{"get_display_profile_win32", cms_get_display_profile_win32, 1},
|
{"get_display_profile_win32", cms_get_display_profile_win32, 1},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
3
decode.c
|
@ -433,9 +433,6 @@ PyImaging_TiffLzwDecoderNew(PyObject* self, PyObject* args)
|
||||||
#include "TiffDecode.h"
|
#include "TiffDecode.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#ifdef __WIN32__
|
|
||||||
#define strcasecmp(s1, s2) stricmp(s1, s2)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
PyObject*
|
PyObject*
|
||||||
PyImaging_LibTiffDecoderNew(PyObject* self, PyObject* args)
|
PyImaging_LibTiffDecoderNew(PyObject* self, PyObject* args)
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
/* Windows DIB support */
|
/* Windows DIB support */
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef _WIN32
|
||||||
|
|
||||||
#include "ImDib.h"
|
#include "ImDib.h"
|
||||||
|
|
||||||
|
@ -864,4 +864,4 @@ error:
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
2
docs/_templates/sidebarhelp.html
vendored
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
If you've discovered a bug, you can
|
If you've discovered a bug, you can
|
||||||
<a href="https://github.com/python-imaging/Pillow/issues/new">open an issue
|
<a href="https://github.com/python-pillow/Pillow/issues/new">open an issue
|
||||||
on Github</a>.
|
on Github</a>.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|
|
@ -11,8 +11,8 @@ The fork authors' goal is to foster active development of PIL through:
|
||||||
- Regular releases to the `Python Package Index`_
|
- Regular releases to the `Python Package Index`_
|
||||||
- Solicitation for community contributions and involvement on `Image-SIG`_
|
- Solicitation for community contributions and involvement on `Image-SIG`_
|
||||||
|
|
||||||
.. _Travis CI: https://travis-ci.org/python-imaging/Pillow
|
.. _Travis CI: https://travis-ci.org/python-pillow/Pillow
|
||||||
.. _GitHub: https://github.com/python-imaging/Pillow
|
.. _GitHub: https://github.com/python-pillow/Pillow
|
||||||
.. _Python Package Index: https://pypi.python.org/pypi/Pillow
|
.. _Python Package Index: https://pypi.python.org/pypi/Pillow
|
||||||
.. _Image-SIG: http://mail.python.org/mailman/listinfo/image-sig
|
.. _Image-SIG: http://mail.python.org/mailman/listinfo/image-sig
|
||||||
|
|
||||||
|
@ -60,6 +60,6 @@ announcement. So if you still want to support PIL, please
|
||||||
|
|
||||||
.. _report issues here first: https://bitbucket.org/effbot/pil-2009-raclette/issues
|
.. _report issues here first: https://bitbucket.org/effbot/pil-2009-raclette/issues
|
||||||
|
|
||||||
.. _open the corresponding Pillow tickets here: https://github.com/python-imaging/Pillow/issues
|
.. _open the corresponding Pillow tickets here: https://github.com/python-pillow/Pillow/issues
|
||||||
|
|
||||||
Please provide a link to the PIL ticket so we can track the issue(s) upstream.
|
Please provide a link to the PIL ticket so we can track the issue(s) upstream.
|
||||||
|
|
|
@ -4,8 +4,8 @@ Pillow
|
||||||
Pillow is the 'friendly' PIL fork by Alex Clark and Contributors. PIL is the
|
Pillow is the 'friendly' PIL fork by Alex Clark and Contributors. PIL is the
|
||||||
Python Imaging Library by Fredrik Lundh and Contributors.
|
Python Imaging Library by Fredrik Lundh and Contributors.
|
||||||
|
|
||||||
.. image:: https://travis-ci.org/python-imaging/Pillow.svg?branch=master
|
.. image:: https://travis-ci.org/python-pillow/Pillow.svg?branch=master
|
||||||
:target: https://travis-ci.org/python-imaging/Pillow
|
:target: https://travis-ci.org/python-pillow/Pillow
|
||||||
:alt: Travis CI build status
|
:alt: Travis CI build status
|
||||||
|
|
||||||
.. image:: https://pypip.in/v/Pillow/badge.png
|
.. image:: https://pypip.in/v/Pillow/badge.png
|
||||||
|
@ -16,15 +16,15 @@ Python Imaging Library by Fredrik Lundh and Contributors.
|
||||||
:target: https://pypi.python.org/pypi/Pillow/
|
:target: https://pypi.python.org/pypi/Pillow/
|
||||||
:alt: Number of PyPI downloads
|
:alt: Number of PyPI downloads
|
||||||
|
|
||||||
.. image:: https://coveralls.io/repos/python-imaging/Pillow/badge.png?branch=master
|
.. image:: https://coveralls.io/repos/python-pillow/Pillow/badge.png?branch=master
|
||||||
:target: https://coveralls.io/r/python-imaging/Pillow?branch=master
|
:target: https://coveralls.io/r/python-pillow/Pillow?branch=master
|
||||||
:alt: Test coverage
|
:alt: Test coverage
|
||||||
|
|
||||||
To start using Pillow, please read the :doc:`installation
|
To start using Pillow, please read the :doc:`installation
|
||||||
instructions <installation>`.
|
instructions <installation>`.
|
||||||
|
|
||||||
You can get the source and contribute at
|
You can get the source and contribute at
|
||||||
https://github.com/python-imaging/Pillow. You can download archives
|
https://github.com/python-pillow/Pillow. You can download archives
|
||||||
and old versions from `PyPI <https://pypi.python.org/pypi/Pillow>`_.
|
and old versions from `PyPI <https://pypi.python.org/pypi/Pillow>`_.
|
||||||
|
|
||||||
.. toctree::
|
.. toctree::
|
||||||
|
@ -42,7 +42,7 @@ Support Pillow!
|
||||||
|
|
||||||
PIL needs you! Please help us maintain the Python Imaging Library here:
|
PIL needs you! Please help us maintain the Python Imaging Library here:
|
||||||
|
|
||||||
- `GitHub <https://github.com/python-imaging/Pillow>`_
|
- `GitHub <https://github.com/python-pillow/Pillow>`_
|
||||||
- `Freenode <irc://irc.freenode.net#pil>`_
|
- `Freenode <irc://irc.freenode.net#pil>`_
|
||||||
- `Image-SIG <http://mail.python.org/mailman/listinfo/image-sig>`_
|
- `Image-SIG <http://mail.python.org/mailman/listinfo/image-sig>`_
|
||||||
|
|
||||||
|
|
|
@ -185,6 +185,25 @@ to a specific version:
|
||||||
|
|
||||||
$ pip install --use-wheel Pillow==2.3.0
|
$ pip install --use-wheel Pillow==2.3.0
|
||||||
|
|
||||||
|
FreeBSD installation
|
||||||
|
---------------------
|
||||||
|
|
||||||
|
.. Note:: Only FreeBSD 10 tested
|
||||||
|
|
||||||
|
|
||||||
|
Make sure you have Python's development libraries installed.::
|
||||||
|
|
||||||
|
$ sudo pkg install python2
|
||||||
|
|
||||||
|
Or for Python 3::
|
||||||
|
|
||||||
|
$ sudo pkg install python3
|
||||||
|
|
||||||
|
Prerequisites are installed on **FreeBSD 10** with::
|
||||||
|
|
||||||
|
$ sudo pkg install jpeg tiff webp lcms2 freetype2
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Platform support
|
Platform support
|
||||||
----------------
|
----------------
|
||||||
|
@ -224,6 +243,8 @@ current versions of Linux, OS X, and Windows.
|
||||||
+----------------------------------+-------------+------------------------------+------------------------------+-----------------------+
|
+----------------------------------+-------------+------------------------------+------------------------------+-----------------------+
|
||||||
| Gentoo Linux |Yes | 2.7,3.2 | 2.1.0 |x86-64 |
|
| Gentoo Linux |Yes | 2.7,3.2 | 2.1.0 |x86-64 |
|
||||||
+----------------------------------+-------------+------------------------------+------------------------------+-----------------------+
|
+----------------------------------+-------------+------------------------------+------------------------------+-----------------------+
|
||||||
|
| FreeBSD 10 |Yes | 2.7,3.4 | 2.4,2.3.1 |x86-64 |
|
||||||
|
+----------------------------------+-------------+------------------------------+------------------------------+-----------------------+
|
||||||
| Windows 7 Pro |Yes | 2.7,3.2,3.3 | 2.2.1 |x86-64 |
|
| Windows 7 Pro |Yes | 2.7,3.2,3.3 | 2.2.1 |x86-64 |
|
||||||
+----------------------------------+-------------+------------------------------+------------------------------+-----------------------+
|
+----------------------------------+-------------+------------------------------+------------------------------+-----------------------+
|
||||||
| Windows Server 2008 R2 Enterprise|Yes | 3.3 | |x86-64 |
|
| Windows Server 2008 R2 Enterprise|Yes | 3.3 | |x86-64 |
|
||||||
|
@ -232,4 +253,3 @@ current versions of Linux, OS X, and Windows.
|
||||||
+----------------------------------+-------------+------------------------------+------------------------------+-----------------------+
|
+----------------------------------+-------------+------------------------------+------------------------------+-----------------------+
|
||||||
| Windows 8.1 Pro |Yes | 2.6,2.7,3.2,3.3,3.4 | 2.3.0, 2.4.0 |x86,x86-64 |
|
| Windows 8.1 Pro |Yes | 2.6,2.7,3.2,3.3,3.4 | 2.3.0, 2.4.0 |x86,x86-64 |
|
||||||
+----------------------------------+-------------+------------------------------+------------------------------+-----------------------+
|
+----------------------------------+-------------+------------------------------+------------------------------+-----------------------+
|
||||||
|
|
||||||
|
|
|
@ -91,9 +91,12 @@ Methods
|
||||||
Draws an arc (a portion of a circle outline) between the start and end
|
Draws an arc (a portion of a circle outline) between the start and end
|
||||||
angles, inside the given bounding box.
|
angles, inside the given bounding box.
|
||||||
|
|
||||||
:param xy: Four points to define the bounding box. Sequence of either
|
:param xy: Four points to define the bounding box. Sequence of
|
||||||
``[(x0, y0), (x1, y1)]`` or ``[x0, y0, x1, y1]``.
|
``[(x0, y0), (x1, y1)]`` or ``[x0, y0, x1, y1]``.
|
||||||
:param outline: Color to use for the outline.
|
:param start: Starting angle, in degrees. Angles are measured from
|
||||||
|
3 o'clock, increasing clockwise.
|
||||||
|
:param end: Ending angle, in degrees.
|
||||||
|
:param fill: Color to use for the arc.
|
||||||
|
|
||||||
.. py:method:: PIL.ImageDraw.Draw.bitmap(xy, bitmap, fill=None)
|
.. py:method:: PIL.ImageDraw.Draw.bitmap(xy, bitmap, fill=None)
|
||||||
|
|
||||||
|
@ -111,7 +114,7 @@ Methods
|
||||||
Same as :py:meth:`~PIL.ImageDraw.Draw.arc`, but connects the end points
|
Same as :py:meth:`~PIL.ImageDraw.Draw.arc`, but connects the end points
|
||||||
with a straight line.
|
with a straight line.
|
||||||
|
|
||||||
:param xy: Four points to define the bounding box. Sequence of either
|
:param xy: Four points to define the bounding box. Sequence of
|
||||||
``[(x0, y0), (x1, y1)]`` or ``[x0, y0, x1, y1]``.
|
``[(x0, y0), (x1, y1)]`` or ``[x0, y0, x1, y1]``.
|
||||||
:param outline: Color to use for the outline.
|
:param outline: Color to use for the outline.
|
||||||
:param fill: Color to use for the fill.
|
:param fill: Color to use for the fill.
|
||||||
|
@ -144,7 +147,7 @@ Methods
|
||||||
Same as arc, but also draws straight lines between the end points and the
|
Same as arc, but also draws straight lines between the end points and the
|
||||||
center of the bounding box.
|
center of the bounding box.
|
||||||
|
|
||||||
:param xy: Four points to define the bounding box. Sequence of either
|
:param xy: Four points to define the bounding box. Sequence of
|
||||||
``[(x0, y0), (x1, y1)]`` or ``[x0, y0, x1, y1]``.
|
``[(x0, y0), (x1, y1)]`` or ``[x0, y0, x1, y1]``.
|
||||||
:param outline: Color to use for the outline.
|
:param outline: Color to use for the outline.
|
||||||
:param fill: Color to use for the fill.
|
:param fill: Color to use for the fill.
|
||||||
|
|
3
encode.c
|
@ -670,9 +670,6 @@ PyImaging_JpegEncoderNew(PyObject* self, PyObject* args)
|
||||||
#include "TiffDecode.h"
|
#include "TiffDecode.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#ifdef __WIN32__
|
|
||||||
#define strcasecmp(s1, s2) stricmp(s1, s2)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
PyObject*
|
PyObject*
|
||||||
PyImaging_LibTiffEncoderNew(PyObject* self, PyObject* args)
|
PyImaging_LibTiffEncoderNew(PyObject* self, PyObject* args)
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
#include "Imaging.h"
|
#include "Imaging.h"
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef _WIN32
|
||||||
|
|
||||||
#include "ImDib.h"
|
#include "ImDib.h"
|
||||||
|
|
||||||
|
@ -308,4 +308,4 @@ ImagingDeleteDIB(ImagingDIB dib)
|
||||||
free(dib->info);
|
free(dib->info);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
|
@ -59,7 +59,7 @@ typedef struct {
|
||||||
unsigned char buffer[GIFTABLE];
|
unsigned char buffer[GIFTABLE];
|
||||||
|
|
||||||
/* Symbol table */
|
/* Symbol table */
|
||||||
unsigned INT16 link[GIFTABLE];
|
UINT16 link[GIFTABLE];
|
||||||
unsigned char data[GIFTABLE];
|
unsigned char data[GIFTABLE];
|
||||||
int next;
|
int next;
|
||||||
|
|
||||||
|
|
|
@ -10,20 +10,9 @@
|
||||||
* See the README file for information on usage and redistribution.
|
* See the README file for information on usage and redistribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef _WIN32
|
||||||
|
|
||||||
#if (defined(_MSC_VER) && _MSC_VER >= 1200) || (defined __GNUC__)
|
#include "ImPlatform.h"
|
||||||
/* already defined in basetsd.h */
|
|
||||||
#undef INT8
|
|
||||||
#undef UINT8
|
|
||||||
#undef INT16
|
|
||||||
#undef UINT16
|
|
||||||
#undef INT32
|
|
||||||
#undef INT64
|
|
||||||
#undef UINT32
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <windows.h>
|
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
|
@ -17,26 +17,22 @@
|
||||||
#error Sorry, this library requires ANSI header files.
|
#error Sorry, this library requires ANSI header files.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER) && !defined(__GNUC__)
|
||||||
#ifndef WIN32
|
#define inline __inline
|
||||||
#define WIN32
|
|
||||||
#endif
|
|
||||||
/* VC++ 4.0 is a bit annoying when it comes to precision issues (like
|
|
||||||
claiming that "float a = 0.0;" would lead to loss of precision). I
|
|
||||||
don't like to see warnings from my code, but since I still want to
|
|
||||||
keep it readable, I simply switch off a few warnings instead of adding
|
|
||||||
the tons of casts that VC++ seem to require. This code is compiled
|
|
||||||
with numerous other compilers as well, so any real errors are likely
|
|
||||||
to be catched anyway. */
|
|
||||||
#pragma warning(disable: 4244) /* conversion from 'float' to 'int' */
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
#if !defined(PIL_USE_INLINE)
|
||||||
#define inline __inline
|
|
||||||
#elif !defined(USE_INLINE)
|
|
||||||
#define inline
|
#define inline
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <Windows.h>
|
||||||
|
|
||||||
|
#else
|
||||||
|
/* For System that are not Windows, we'll need to define these. */
|
||||||
|
|
||||||
#if SIZEOF_SHORT == 2
|
#if SIZEOF_SHORT == 2
|
||||||
#define INT16 short
|
#define INT16 short
|
||||||
#elif SIZEOF_INT == 2
|
#elif SIZEOF_INT == 2
|
||||||
|
@ -61,12 +57,16 @@
|
||||||
#define INT64 long
|
#define INT64 long
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* assume IEEE; tweak if necessary (patches are welcome) */
|
|
||||||
#define FLOAT32 float
|
|
||||||
#define FLOAT64 double
|
|
||||||
|
|
||||||
#define INT8 signed char
|
#define INT8 signed char
|
||||||
#define UINT8 unsigned char
|
#define UINT8 unsigned char
|
||||||
|
|
||||||
#define UINT16 unsigned INT16
|
#define UINT16 unsigned INT16
|
||||||
#define UINT32 unsigned INT32
|
#define UINT32 unsigned INT32
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* assume IEEE; tweak if necessary (patches are welcome) */
|
||||||
|
#define FLOAT32 float
|
||||||
|
#define FLOAT64 double
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,6 @@
|
||||||
two cases. */
|
two cases. */
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <windows.h>
|
|
||||||
#include <process.h>
|
#include <process.h>
|
||||||
#else
|
#else
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
|
@ -45,7 +45,7 @@ typedef struct {
|
||||||
unsigned char buffer[LZWTABLE];
|
unsigned char buffer[LZWTABLE];
|
||||||
|
|
||||||
/* Symbol table */
|
/* Symbol table */
|
||||||
unsigned INT16 link[LZWTABLE];
|
UINT16 link[LZWTABLE];
|
||||||
unsigned char data[LZWTABLE];
|
unsigned char data[LZWTABLE];
|
||||||
int next;
|
int next;
|
||||||
|
|
||||||
|
|
18
map.c
|
@ -22,18 +22,6 @@
|
||||||
|
|
||||||
#include "Imaging.h"
|
#include "Imaging.h"
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
#define WIN32_LEAN_AND_MEAN
|
|
||||||
#undef INT8
|
|
||||||
#undef UINT8
|
|
||||||
#undef INT16
|
|
||||||
#undef UINT16
|
|
||||||
#undef INT32
|
|
||||||
#undef INT64
|
|
||||||
#undef UINT32
|
|
||||||
#include "windows.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "py3.h"
|
#include "py3.h"
|
||||||
|
|
||||||
/* compatibility wrappers (defined in _imaging.c) */
|
/* compatibility wrappers (defined in _imaging.c) */
|
||||||
|
@ -48,7 +36,7 @@ typedef struct {
|
||||||
char* base;
|
char* base;
|
||||||
int size;
|
int size;
|
||||||
int offset;
|
int offset;
|
||||||
#ifdef WIN32
|
#ifdef _WIN32
|
||||||
HANDLE hFile;
|
HANDLE hFile;
|
||||||
HANDLE hMap;
|
HANDLE hMap;
|
||||||
#endif
|
#endif
|
||||||
|
@ -71,7 +59,7 @@ PyImaging_MapperNew(const char* filename, int readonly)
|
||||||
mapper->base = NULL;
|
mapper->base = NULL;
|
||||||
mapper->size = mapper->offset = 0;
|
mapper->size = mapper->offset = 0;
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef _WIN32
|
||||||
mapper->hFile = (HANDLE)-1;
|
mapper->hFile = (HANDLE)-1;
|
||||||
mapper->hMap = (HANDLE)-1;
|
mapper->hMap = (HANDLE)-1;
|
||||||
|
|
||||||
|
@ -114,7 +102,7 @@ PyImaging_MapperNew(const char* filename, int readonly)
|
||||||
static void
|
static void
|
||||||
mapping_dealloc(ImagingMapperObject* mapper)
|
mapping_dealloc(ImagingMapperObject* mapper)
|
||||||
{
|
{
|
||||||
#ifdef WIN32
|
#ifdef _WIN32
|
||||||
if (mapper->base != 0)
|
if (mapper->base != 0)
|
||||||
UnmapViewOfFile(mapper->base);
|
UnmapViewOfFile(mapper->base);
|
||||||
if (mapper->hMap != (HANDLE)-1)
|
if (mapper->hMap != (HANDLE)-1)
|
||||||
|
|
28
setup.py
|
@ -206,22 +206,28 @@ class pil_build_ext(build_ext):
|
||||||
_add_directory(library_dirs, "/opt/local/lib")
|
_add_directory(library_dirs, "/opt/local/lib")
|
||||||
_add_directory(include_dirs, "/opt/local/include")
|
_add_directory(include_dirs, "/opt/local/include")
|
||||||
|
|
||||||
# if homebrew is installed, use its lib and include directories
|
# if Homebrew is installed, use its lib and include directories
|
||||||
import subprocess
|
import subprocess
|
||||||
try:
|
try:
|
||||||
prefix = subprocess.check_output(['brew', '--prefix'])
|
prefix = subprocess.check_output(['brew', '--prefix']).strip()
|
||||||
|
except:
|
||||||
|
# Homebrew not installed
|
||||||
|
prefix = None
|
||||||
|
|
||||||
|
ft_prefix = None
|
||||||
|
|
||||||
if prefix:
|
if prefix:
|
||||||
prefix = prefix.strip()
|
# add Homebrew's include and lib directories
|
||||||
_add_directory(library_dirs, os.path.join(prefix, 'lib'))
|
_add_directory(library_dirs, os.path.join(prefix, 'lib'))
|
||||||
_add_directory(include_dirs, os.path.join(prefix, 'include'))
|
_add_directory(include_dirs, os.path.join(prefix, 'include'))
|
||||||
|
ft_prefix = os.path.join(prefix, 'opt', 'freetype')
|
||||||
|
|
||||||
# freetype2 is a key-only brew under opt/
|
if ft_prefix and os.path.isdir(ft_prefix):
|
||||||
_add_directory(library_dirs, os.path.join(prefix, 'opt', 'freetype', 'lib'))
|
# freetype might not be linked into Homebrew's prefix
|
||||||
_add_directory(include_dirs, os.path.join(prefix, 'opt', 'freetype', 'include'))
|
_add_directory(library_dirs, os.path.join(ft_prefix, 'lib'))
|
||||||
except:
|
_add_directory(include_dirs, os.path.join(ft_prefix, 'include'))
|
||||||
pass # homebrew not installed
|
else:
|
||||||
|
# fall back to freetype from XQuartz if Homebrew's freetype is missing
|
||||||
# freetype2 ships with X11 (after homebrew, so that homebrew freetype is preferred)
|
|
||||||
_add_directory(library_dirs, "/usr/X11/lib")
|
_add_directory(library_dirs, "/usr/X11/lib")
|
||||||
_add_directory(include_dirs, "/usr/X11/include")
|
_add_directory(include_dirs, "/usr/X11/include")
|
||||||
|
|
||||||
|
@ -654,7 +660,7 @@ setup(
|
||||||
_read('CHANGES.rst')).decode('utf-8'),
|
_read('CHANGES.rst')).decode('utf-8'),
|
||||||
author='Alex Clark (fork author)',
|
author='Alex Clark (fork author)',
|
||||||
author_email='aclark@aclark.net',
|
author_email='aclark@aclark.net',
|
||||||
url='http://python-imaging.github.io/',
|
url='http://python-pillow.github.io/',
|
||||||
classifiers=[
|
classifiers=[
|
||||||
"Development Status :: 6 - Mature",
|
"Development Status :: 6 - Mature",
|
||||||
"Topic :: Multimedia :: Graphics",
|
"Topic :: Multimedia :: Graphics",
|
||||||
|
|