Merge branch 'master' into winbuild

This commit is contained in:
wiredfool 2014-04-04 13:40:32 -07:00
commit 9c29819941
16 changed files with 669 additions and 491 deletions

View File

@ -1,9 +1,15 @@
Changelog (Pillow)
==================
2.4.0 (unreleased)
2.4.0 (2014-04-01)
------------------
- Indexed Transparency handled for conversions between L, RGB, and P modes. Fixes #510
[wiredfool]
- Conversions enabled from RGBA->P, Fixes #544
[wiredfool]
- Improved icns support
[al45tair]

View File

@ -9,6 +9,7 @@ include tox.ini
recursive-include Images *.bdf
recursive-include Images *.fli
recursive-include Images *.gif
recursive-include Images *.icns
recursive-include Images *.ico
recursive-include Images *.jpg
recursive-include Images *.pbm
@ -34,7 +35,9 @@ recursive-include Tests *.gif
recursive-include Tests *.gnuplot
recursive-include Tests *.html
recursive-include Tests *.icm
recursive-include Tests *.icns
recursive-include Tests *.ico
recursive-include Tests *.jp2
recursive-include Tests *.jpg
recursive-include Tests *.pcf
recursive-include Tests *.pcx
@ -47,6 +50,7 @@ recursive-include Tests *.ttf
recursive-include Tests *.txt
recursive-include Tk *.c
recursive-include Tk *.txt
recursive-include depends *.sh
recursive-include docs *.bat
recursive-include docs *.gitignore
recursive-include docs *.html

View File

@ -735,21 +735,65 @@ class Image:
im = self.im.convert_matrix(mode, matrix)
return self._new(im)
if mode == "P" and self.mode == "RGBA":
return self.quantize(colors)
trns = None
delete_trns = False
# transparency handling
if "transparency" in self.info and self.info['transparency'] is not None:
if self.mode in ('L', 'RGB') and mode == 'RGBA':
# Use transparent conversion to promote from transparent
# color to an alpha channel.
return self._new(self.im.convert_transparent(
mode, self.info['transparency']))
elif self.mode in ('L', 'RGB', 'P') and mode in ('L', 'RGB', 'P'):
t = self.info['transparency']
if isinstance(t, bytes):
# Dragons. This can't be represented by a single color
warnings.warn('Palette images with Transparency expressed '+
' in bytes should be converted to RGBA images')
delete_trns = True
else:
# get the new transparency color.
# use existing conversions
trns_im = Image()._new(core.new(self.mode, (1,1)))
if self.mode == 'P':
trns_im.putpalette(self.palette)
trns_im.putpixel((0,0), t)
if mode in ('L','RGB'):
trns_im = trns_im.convert(mode)
else:
# can't just retrieve the palette number, got to do it
# after quantization.
trns_im = trns_im.convert('RGB')
trns = trns_im.getpixel((0,0))
if mode == "P" and palette == ADAPTIVE:
im = self.im.quantize(colors)
new = self._new(im)
from PIL import ImagePalette
new.palette = ImagePalette.raw("RGB", new.im.getpalette("RGB"))
if delete_trns:
# This could possibly happen if we requantize to fewer colors.
# The transparency would be totally off in that case.
del(new.info['transparency'])
if trns is not None:
try:
new.info['transparency'] = new.palette.getcolor(trns)
except:
# if we can't make a transparent color, don't leave the old
# transparency hanging around to mess us up.
del(new.info['transparency'])
warnings.warn("Couldn't allocate palette entry for transparency")
return new
# colorspace conversion
if dither is None:
dither = FLOYDSTEINBERG
# Use transparent conversion to promote from transparent color to an alpha channel.
if self.mode in ("L", "RGB") and mode == "RGBA" and "transparency" in self.info:
return self._new(self.im.convert_transparent(mode, self.info['transparency']))
try:
im = self.im.convert(mode, dither)
except ValueError:
@ -760,9 +804,22 @@ class Image:
except KeyError:
raise ValueError("illegal conversion")
return self._new(im)
new_im = self._new(im)
if delete_trns:
#crash fail if we leave a bytes transparency in an rgb/l mode.
del(new.info['transparency'])
if trns is not None:
if new_im.mode == 'P':
try:
new_im.info['transparency'] = new_im.palette.getcolor(trns)
except:
del(new_im.info['transparency'])
warnings.warn("Couldn't allocate palette entry for transparency")
else:
new_im.info['transparency'] = trns
return new_im
def quantize(self, colors=256, method=0, kmeans=0, palette=None):
def quantize(self, colors=256, method=None, kmeans=0, palette=None):
# methods:
# 0 = median cut
@ -773,7 +830,18 @@ class Image:
# quantizer interface in a later version of PIL.
self.load()
if method is None:
# defaults:
method = 0
if self.mode == 'RGBA':
method = 2
if self.mode == 'RGBA' and method != 2:
# Caller specified an invalid mode.
raise ValueError('Fast Octree (method == 2) is the ' +
' only valid method for quantizing RGBA images')
if palette:
# use palette from reference image
palette.load()

File diff suppressed because it is too large Load Diff

View File

@ -12,7 +12,7 @@
# ;-)
VERSION = '1.1.7' # PIL version
PILLOW_VERSION = '2.3.0' # Pillow
PILLOW_VERSION = '2.4.0' # Pillow
_plugins = ['ArgImagePlugin',
'BmpImagePlugin',

View File

@ -14,3 +14,9 @@ else:
# Checks if an object is a string, and that it points to a directory.
def isDirectory(f):
return isPath(f) and os.path.isdir(f)
class import_err(object):
def __init__(self, ex):
self.ex = ex
def __getattr__(self, elt):
raise self.ex

View File

@ -46,5 +46,67 @@ def test_16bit_workaround():
im = Image.open('Tests/images/16bit.cropped.tif')
_test_float_conversion(im.convert('I'))
def test_rgba_p():
im = lena('RGBA')
im.putalpha(lena('L'))
converted = im.convert('P')
comparable = converted.convert('RGBA')
assert_image_similar(im, comparable, 20)
def test_trns_p():
im = lena('P')
im.info['transparency']=0
f = tempfile('temp.png')
l = im.convert('L')
assert_equal(l.info['transparency'], 0) # undone
assert_no_exception(lambda: l.save(f))
rgb = im.convert('RGB')
assert_equal(rgb.info['transparency'], (0,0,0)) # undone
assert_no_exception(lambda: rgb.save(f))
def test_trns_l():
im = lena('L')
im.info['transparency'] = 128
f = tempfile('temp.png')
rgb = im.convert('RGB')
assert_equal(rgb.info['transparency'], (128,128,128)) # undone
assert_no_exception(lambda: rgb.save(f))
p = im.convert('P')
assert_true('transparency' in p.info)
assert_no_exception(lambda: p.save(f))
p = assert_warning(UserWarning,
lambda: im.convert('P', palette = Image.ADAPTIVE))
assert_false('transparency' in p.info)
assert_no_exception(lambda: p.save(f))
def test_trns_RGB():
im = lena('RGB')
im.info['transparency'] = im.getpixel((0,0))
f = tempfile('temp.png')
l = im.convert('L')
assert_equal(l.info['transparency'], l.getpixel((0,0))) # undone
assert_no_exception(lambda: l.save(f))
p = im.convert('P')
assert_true('transparency' in p.info)
assert_no_exception(lambda: p.save(f))
p = assert_warning(UserWarning,
lambda: im.convert('P', palette = Image.ADAPTIVE))
assert_false('transparency' in p.info)
assert_no_exception(lambda: p.save(f))

View File

@ -19,4 +19,9 @@ def test_octree_quantize():
im = im.quantize(100, Image.FASTOCTREE)
assert_image(im, "P", im.size)
assert len(im.getcolors()) == 100
assert len(im.getcolors()) == 100
def test_rgba_quantize():
im = lena('RGBA')
assert_no_exception(lambda: im.quantize())
assert_exception(Exception, lambda: im.quantize(method=0))

View File

@ -3,6 +3,7 @@ from tester import *
from PIL import Image
try:
from PIL import ImageCms
ImageCms.core.profile_open
except ImportError:
skip()

View File

@ -121,9 +121,9 @@ def assert_no_exception(func):
def assert_warning(warn_class, func):
# note: this assert calls func three times!
import warnings
def warn_error(message, category, **options):
def warn_error(message, category=UserWarning, **options):
raise category(message)
def warn_ignore(message, category, **options):
def warn_ignore(message, category=UserWarning, **options):
pass
warn = warnings.warn
result = None

View File

@ -71,7 +71,7 @@
* See the README file for information on usage and redistribution.
*/
#define PILLOW_VERSION "2.3.0"
#define PILLOW_VERSION "2.4.0"
#include "Python.h"

View File

@ -156,6 +156,8 @@ The :py:meth:`~PIL.Image.Image.save` method supports the following options:
JPEG 2000
^^^^^^^^^
.. versionadded:: 2.4.0
PIL reads and writes JPEG 2000 files containing ``L``, ``LA``, ``RGB`` or
``RGBA`` data. It can also read files containing ``YCbCr`` data, which it
converts on read into ``RGB`` or ``RGBA`` depending on whether or not there is

View File

@ -18,12 +18,9 @@ Python Imaging Library by Fredrik Lundh and Contributors.
To start using Pillow, please read the :doc:`installation
instructions <installation>`.
If you can't find the information you need, try the old `PIL Handbook`_, but be
aware that it was last updated for PIL 1.1.5. You can download archives and old
versions from `PyPI <https://pypi.python.org/pypi/Pillow>`_. You can get the
source and contribute at https://github.com/python-imaging/Pillow.
.. _PIL Handbook: http://effbot.org/imagingbook/pil-index.htm
You can get the source and contribute at
https://github.com/python-imaging/Pillow. You can download archives
and old versions from `PyPI <https://pypi.python.org/pypi/Pillow>`_.
.. toctree::
:maxdepth: 2

View File

@ -66,10 +66,15 @@ Many of Pillow's features require external libraries:
* **libwebp** provides the Webp format.
* Pillow has been tested with version **0.1.3**, which does not read
transparent webp files. Version **0.3.0** supports transparency.
transparent webp files. Versions **0.3.0** and **0.4.0** support
transparency.
* **tcl/tk** provides support for tkinter bitmap and photo images.
* **openjpeg** provides JPEG 2000 functionality.
* Pillow has been tested with openjpeg **2.0.0**.
If the prerequisites are installed in the standard library locations for your
machine (e.g. :file:`/usr` or :file:`/usr/local`), no additional configuration
should be required. If they are installed in a non-standard location, you may
@ -225,6 +230,6 @@ current versions of Linux, OS X, and Windows.
+----------------------------------+-------------+------------------------------+------------------------------+-----------------------+
| Windows 8 Pro |Yes | 2.6,2.7,3.2,3.3,3.4a3 | 2.2.0 |x86,x86-64 |
+----------------------------------+-------------+------------------------------+------------------------------+-----------------------+
| Windows 8.1 Pro |Yes | 2.6,2.7,3.2,3.3,3.4 | 2.3.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 |
+----------------------------------+-------------+------------------------------+------------------------------+-----------------------+

View File

@ -1,7 +1,7 @@
# requirements for working on docs
# install pillow from master if you're into that, but RtD needs this
pillow>=2.2.1
pillow>=2.4.0
Jinja2==2.7.1
MarkupSafe==0.18

View File

@ -87,7 +87,7 @@ except (ImportError, OSError):
NAME = 'Pillow'
VERSION = '2.3.0'
VERSION = '2.4.0'
TCL_ROOT = None
JPEG_ROOT = None
JPEG2K_ROOT = None
@ -226,45 +226,50 @@ class pil_build_ext(build_ext):
_add_directory(include_dirs, "/usr/X11/include")
elif sys.platform.startswith("linux"):
for platform_ in (plat.architecture()[0], plat.processor()):
if not platform_:
continue
if platform_ in ["x86_64", "64bit"]:
_add_directory(library_dirs, "/lib64")
_add_directory(library_dirs, "/usr/lib64")
_add_directory(library_dirs, "/usr/lib/x86_64-linux-gnu")
break
elif platform_ in ["i386", "i686", "32bit"]:
_add_directory(library_dirs, "/usr/lib/i386-linux-gnu")
break
elif platform_ in ["aarch64"]:
_add_directory(library_dirs, "/usr/lib64")
_add_directory(library_dirs, "/usr/lib/aarch64-linux-gnu")
break
elif platform_ in ["arm", "armv7l"]:
_add_directory(library_dirs, "/usr/lib/arm-linux-gnueabi")
break
elif platform_ in ["ppc64"]:
_add_directory(library_dirs, "/usr/lib64")
_add_directory(library_dirs, "/usr/lib/ppc64-linux-gnu")
_add_directory(library_dirs, "/usr/lib/powerpc64-linux-gnu")
break
elif platform_ in ["ppc"]:
_add_directory(library_dirs, "/usr/lib/ppc-linux-gnu")
_add_directory(library_dirs, "/usr/lib/powerpc-linux-gnu")
break
elif platform_ in ["s390x"]:
_add_directory(library_dirs, "/usr/lib64")
_add_directory(library_dirs, "/usr/lib/s390x-linux-gnu")
break
elif platform_ in ["s390"]:
_add_directory(library_dirs, "/usr/lib/s390-linux-gnu")
break
arch_tp = (plat.processor(), plat.architecture()[0])
if arch_tp == ("x86_64","32bit"):
# 32 bit build on 64 bit machine.
_add_directory(library_dirs, "/usr/lib/i386-linux-gnu")
else:
raise ValueError(
"Unable to identify Linux platform: `%s`" % platform_)
for platform_ in arch_tp:
if not platform_:
continue
if platform_ in ["x86_64", "64bit"]:
_add_directory(library_dirs, "/lib64")
_add_directory(library_dirs, "/usr/lib64")
_add_directory(library_dirs, "/usr/lib/x86_64-linux-gnu")
break
elif platform_ in ["i386", "i686", "32bit"]:
_add_directory(library_dirs, "/usr/lib/i386-linux-gnu")
break
elif platform_ in ["aarch64"]:
_add_directory(library_dirs, "/usr/lib64")
_add_directory(library_dirs, "/usr/lib/aarch64-linux-gnu")
break
elif platform_ in ["arm", "armv7l"]:
_add_directory(library_dirs, "/usr/lib/arm-linux-gnueabi")
break
elif platform_ in ["ppc64"]:
_add_directory(library_dirs, "/usr/lib64")
_add_directory(library_dirs, "/usr/lib/ppc64-linux-gnu")
_add_directory(library_dirs, "/usr/lib/powerpc64-linux-gnu")
break
elif platform_ in ["ppc"]:
_add_directory(library_dirs, "/usr/lib/ppc-linux-gnu")
_add_directory(library_dirs, "/usr/lib/powerpc-linux-gnu")
break
elif platform_ in ["s390x"]:
_add_directory(library_dirs, "/usr/lib64")
_add_directory(library_dirs, "/usr/lib/s390x-linux-gnu")
break
elif platform_ in ["s390"]:
_add_directory(library_dirs, "/usr/lib/s390-linux-gnu")
break
else:
raise ValueError(
"Unable to identify Linux platform: `%s`" % platform_)
# XXX Kludge. Above /\ we brute force support multiarch. Here we
# try Barry's more general approach. Afterward, something should