From bab068a337a1dc7d556870a5514807637c1896e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20Cuenca=20Abela?= Date: Mon, 27 Jan 2014 20:27:03 +0100 Subject: [PATCH 01/13] Improve heuristic used when saving progressive and optimized JPEGs with high quality values. --- PIL/JpegImagePlugin.py | 5 ++++- Tests/test_file_jpeg.py | 13 ++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/PIL/JpegImagePlugin.py b/PIL/JpegImagePlugin.py index 90d3b5194..9563f9723 100644 --- a/PIL/JpegImagePlugin.py +++ b/PIL/JpegImagePlugin.py @@ -566,7 +566,10 @@ def _save(im, fp, filename): # https://github.com/jdriscoll/django-imagekit/issues/50 bufsize=0 if "optimize" in info or "progressive" in info or "progression" in info: - bufsize = im.size[0]*im.size[1] + if quality >= 95: + bufsize = 2 * im.size[0] * im.size[1] + else: + bufsize = im.size[0] * im.size[1] # The exif info needs to be written as one block, + APP1, + one spare byte. # Ensure that our buffer is big enough diff --git a/Tests/test_file_jpeg.py b/Tests/test_file_jpeg.py index de1c3f0e1..de91c2b63 100644 --- a/Tests/test_file_jpeg.py +++ b/Tests/test_file_jpeg.py @@ -1,5 +1,8 @@ from tester import * +import array +import random + from PIL import Image from PIL import ImageFile @@ -132,13 +135,21 @@ def test_progressive_large_buffer(): im = Image.new("RGB", (4096,4096), 0xff3333) im.save(f, format="JPEG", progressive=True) +def test_progressive_large_buffer_highest_quality(): + f = tempfile('temp.jpg') + a = array.array('B') + a.extend(random.randint(0, 255) for _ in xrange(256 * 256 * 3)) + im = Image.frombuffer("RGB", (256, 256), a, "raw", "RGB", 0, 1) + # this requires more bytes than pixels in the image + im.save(f, format="JPEG", progressive=True, quality=100) + def test_large_exif(): #https://github.com/python-imaging/Pillow/issues/148 f = tempfile('temp.jpg') im = lena() im.save(f,'JPEG', quality=90, exif=b"1"*65532) -def test_progressive(): +def test_progressive_compat(): im1 = roundtrip(lena()) im2 = roundtrip(lena(), progressive=1) im3 = roundtrip(lena(), progression=1) # compatibility From a0af87e5246aae3cb39ee45aa4ea39408cc9f9e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20Cuenca=20Abela?= Date: Tue, 28 Jan 2014 08:48:40 +0100 Subject: [PATCH 02/13] Make test_file_jpeg compatible with Python 3 --- Tests/test_file_jpeg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/test_file_jpeg.py b/Tests/test_file_jpeg.py index de91c2b63..4bb6f1e92 100644 --- a/Tests/test_file_jpeg.py +++ b/Tests/test_file_jpeg.py @@ -138,7 +138,7 @@ def test_progressive_large_buffer(): def test_progressive_large_buffer_highest_quality(): f = tempfile('temp.jpg') a = array.array('B') - a.extend(random.randint(0, 255) for _ in xrange(256 * 256 * 3)) + a.extend(random.randint(0, 255) for _ in range(256 * 256 * 3)) im = Image.frombuffer("RGB", (256, 256), a, "raw", "RGB", 0, 1) # this requires more bytes than pixels in the image im.save(f, format="JPEG", progressive=True, quality=100) From 97b23af7e51b56783a5fc7f384164e2e657d49e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20Cuenca=20Abela?= Date: Tue, 4 Feb 2014 17:23:29 +0100 Subject: [PATCH 03/13] Try to fix test_file_jpeg in Python3 --- Tests/test_file_jpeg.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Tests/test_file_jpeg.py b/Tests/test_file_jpeg.py index 4bb6f1e92..ef974cfe7 100644 --- a/Tests/test_file_jpeg.py +++ b/Tests/test_file_jpeg.py @@ -1,6 +1,5 @@ from tester import * -import array import random from PIL import Image @@ -137,8 +136,7 @@ def test_progressive_large_buffer(): def test_progressive_large_buffer_highest_quality(): f = tempfile('temp.jpg') - a = array.array('B') - a.extend(random.randint(0, 255) for _ in range(256 * 256 * 3)) + a = b''.join(chr(random.randint(0, 255)) for _ in range(256 * 256 * 3)) im = Image.frombuffer("RGB", (256, 256), a, "raw", "RGB", 0, 1) # this requires more bytes than pixels in the image im.save(f, format="JPEG", progressive=True, quality=100) From 96ca9ff6fffa054ba9f8be539dcfaab1412778e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20Cuenca=20Abela?= Date: Tue, 4 Feb 2014 17:37:18 +0100 Subject: [PATCH 04/13] Another attempt to achieve python 3 compatibility. --- Tests/test_file_jpeg.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Tests/test_file_jpeg.py b/Tests/test_file_jpeg.py index ef974cfe7..07a7c9f96 100644 --- a/Tests/test_file_jpeg.py +++ b/Tests/test_file_jpeg.py @@ -136,7 +136,10 @@ def test_progressive_large_buffer(): def test_progressive_large_buffer_highest_quality(): f = tempfile('temp.jpg') - a = b''.join(chr(random.randint(0, 255)) for _ in range(256 * 256 * 3)) + if py3: + a = bytes(random.randint(0, 255) for _ in range(256 * 256 * 3)) + else: + a = b''.join(chr(random.randint(0, 255)) for _ in range(256 * 256 * 3)) im = Image.frombuffer("RGB", (256, 256), a, "raw", "RGB", 0, 1) # this requires more bytes than pixels in the image im.save(f, format="JPEG", progressive=True, quality=100) From df87d7d46e9a2ac2bbf49dcc94ed6843b882d830 Mon Sep 17 00:00:00 2001 From: Alex Clark Date: Mon, 10 Feb 2014 07:24:50 -0500 Subject: [PATCH 05/13] Add history --- CHANGES.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index ae917acb1..8cb39c8dd 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,9 @@ Changelog (Pillow) 2.4.0 (2014-04-01 est.) ------------------ +- Improve heuristic used when saving progressive and optimized JPEGs with high quality values + [e98cuenc] + - Fixed DOS with invalid palette size or invalid image size in BMP file [wiredfool] From 43dd0683ad763024b00c34c59a44754a5484c672 Mon Sep 17 00:00:00 2001 From: Alex Clark Date: Wed, 19 Feb 2014 18:31:14 -0500 Subject: [PATCH 06/13] Wording [ci skip] --- CHANGES.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 8cb39c8dd..8c28bc415 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,7 +1,7 @@ Changelog (Pillow) ================== -2.4.0 (2014-04-01 est.) +2.4.0 (unreleased) ------------------ - Improve heuristic used when saving progressive and optimized JPEGs with high quality values From 05070b089fefc073157f8c17a3a6514eea1e80a0 Mon Sep 17 00:00:00 2001 From: Alex Clark Date: Wed, 19 Feb 2014 18:37:56 -0500 Subject: [PATCH 07/13] Add license info --- docs/about.rst | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/about.rst b/docs/about.rst index dfd88b605..5af5e8aa2 100644 --- a/docs/about.rst +++ b/docs/about.rst @@ -45,3 +45,21 @@ announcement. So if you still want to support PIL, please .. _open the corresponding Pillow tickets here: https://github.com/python-imaging/Pillow/issues Please provide a link to the PIL ticket so we can track the issue(s) upstream. + +License +------- + +Pillow, like PIL itself, is licensed under the `PIL Software License `:: + + Software License + + The Python Imaging Library (PIL) is + + Copyright © 1997-2011 by Secret Labs AB + Copyright © 1995-2011 by Fredrik Lundh + + By obtaining, using, and/or copying this software and/or its associated documentation, you agree that you have read, understood, and will comply with the following terms and conditions: + + Permission to use, copy, modify, and distribute this software and its associated documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appears in all copies, and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of Secret Labs AB or the author not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. + + SECRET LABS AB AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL SECRET LABS AB OR THE AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. From 1d7bfa5a9256dce38069c7be3eee52144bb6e59c Mon Sep 17 00:00:00 2001 From: Alex Clark Date: Wed, 19 Feb 2014 18:39:20 -0500 Subject: [PATCH 08/13] Wording [ci skip] --- docs/about.rst | 60 +++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/docs/about.rst b/docs/about.rst index 5af5e8aa2..26ee4b782 100644 --- a/docs/about.rst +++ b/docs/about.rst @@ -16,36 +16,6 @@ The fork authors' goal is to foster active development of PIL through: .. _Python Package Index: https://pypi.python.org/pypi/Pillow .. _Image-SIG: http://mail.python.org/mailman/listinfo/image-sig -Why a fork? ------------ - -PIL is not setuptools compatible. Please see `this Image-SIG post`_ for a more -detailed explanation. Also, PIL's current bi-yearly (or greater) release -schedule is too infrequent to accomodate the large number and frequency of -issues reported. - -.. _this Image-SIG post: https://mail.python.org/pipermail/image-sig/2010-August/006480.html - -What about the official PIL? ----------------------------- - -.. note:: - - Prior to Pillow 2.0.0, very few image code changes were made. Pillow 2.0.0 - added Python 3 support and includes many bug fixes from many contributors. - -As more time passes since the last PIL release, the likelyhood of a new PIL -release decreases. However, we've yet to hear an official "PIL is dead" -announcement. So if you still want to support PIL, please -`report issues here first`_, then -`open the corresponding Pillow tickets here`_. - -.. _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 - -Please provide a link to the PIL ticket so we can track the issue(s) upstream. - License ------- @@ -63,3 +33,33 @@ Pillow, like PIL itself, is licensed under the `PIL Software License Date: Fri, 21 Feb 2014 04:46:05 -0500 Subject: [PATCH 09/13] Update license info --- docs/about.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/about.rst b/docs/about.rst index 26ee4b782..b6ae2eaf9 100644 --- a/docs/about.rst +++ b/docs/about.rst @@ -19,7 +19,7 @@ The fork authors' goal is to foster active development of PIL through: License ------- -Pillow, like PIL itself, is licensed under the `PIL Software License `:: +like PIL itself, Pillow is licensed under the MIT-like `PIL Software License `:: Software License From f848993c89753304911830cd14d553db59cf4eac Mon Sep 17 00:00:00 2001 From: David Schmidt Date: Tue, 25 Feb 2014 09:50:42 +0100 Subject: [PATCH 10/13] fixes #528 Accept 0 as transparency value. --- PIL/PngImagePlugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PIL/PngImagePlugin.py b/PIL/PngImagePlugin.py index a6038d9f2..18abf27d3 100644 --- a/PIL/PngImagePlugin.py +++ b/PIL/PngImagePlugin.py @@ -561,7 +561,7 @@ def _save(im, fp, filename, chunk=putchunk, check=0): transparency = im.encoderinfo.get('transparency',im.info.get('transparency', None)) - if transparency: + if transparency or transparency == 0: if im.mode == "P": # limit to actual palette size alpha_bytes = 2**bits From 37f4aea0d089dab4f396ce37e908900de2e09ec3 Mon Sep 17 00:00:00 2001 From: David Schmidt Date: Tue, 25 Feb 2014 09:56:49 +0100 Subject: [PATCH 11/13] fixes #529 doc fix --- PIL/Image.py | 1 - 1 file changed, 1 deletion(-) diff --git a/PIL/Image.py b/PIL/Image.py index e71e2ad5f..b93ce24a4 100644 --- a/PIL/Image.py +++ b/PIL/Image.py @@ -1098,7 +1098,6 @@ class Image: third, the box defaults to (0, 0), and the second argument is interpreted as a mask image. :param mask: An optional mask image. - :returns: An :py:class:`~PIL.Image.Image` object. """ if isImageType(box) and mask is None: From 0d453d9805f203989ac58815fc88358dadb16a8a Mon Sep 17 00:00:00 2001 From: wiredfool Date: Fri, 28 Feb 2014 16:29:34 -0800 Subject: [PATCH 12/13] Added test for Palette transparency=0 --- Tests/test_file_png.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Tests/test_file_png.py b/Tests/test_file_png.py index e8d2a1208..c17829194 100644 --- a/Tests/test_file_png.py +++ b/Tests/test_file_png.py @@ -251,6 +251,20 @@ def test_trns_rgb(): im = roundtrip(im, transparency=(0, 1, 2)) assert_equal(im.info["transparency"], (0, 1, 2)) +def test_trns_p(): + # Check writing a transparency of 0, issue #528 + im = lena('P') + im.info['transparency']=0 + + f = tempfile("temp.png") + im.save(f) + + im2 = Image.open(f) + assert_true('transparency' in im2.info) + + assert_image_equal(im2.convert('RGBA'), im.convert('RGBA')) + + def test_save_icc_profile_none(): # check saving files with an ICC profile set to None (omit profile) in_file = "Tests/images/icc_profile_none.png" From 7baaf296d27b0a380357efdbbd3789c6e89b37e2 Mon Sep 17 00:00:00 2001 From: wiredfool Date: Fri, 28 Feb 2014 16:32:55 -0800 Subject: [PATCH 13/13] Updated changes --- CHANGES.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 8c28bc415..abdf73b33 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,9 @@ Changelog (Pillow) 2.4.0 (unreleased) ------------------ +- Fixed saving mode P image as a PNG with transparency = palette color 0 + [d-schmidt] + - Improve heuristic used when saving progressive and optimized JPEGs with high quality values [e98cuenc]