Skip to content

Commit 9640b48

Browse files
committed
Merge branch 'master' of github.com:python-pillow/Pillow into winbuild-rewrite
# Conflicts: # .github/workflows/test-windows.yml # winbuild/config.py # winbuild/build_prepare.py
2 parents 713ed87 + 7fb21bc commit 9640b48

96 files changed

Lines changed: 2718 additions & 1459 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,9 @@ repos:
3030
hooks:
3131
- id: check-merge-conflict
3232
- id: check-yaml
33+
34+
- repo: https://github.com/Lucas-C/pre-commit-hooks
35+
rev: v1.1.7
36+
hooks:
37+
- id: remove-tabs
38+
exclude: (Makefile$|\.bat$|\.cmake$|\.eps$|\.fits$|\.opt$)

CHANGES.rst

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ Changelog (Pillow)
55
7.2.0 (unreleased)
66
------------------
77

8+
- Fix repeatedly loading .gbr #4620
9+
[ElinksFr, radarhere]
10+
11+
- JPEG: Truncate icclist instead of setting to None #4613
12+
[homm]
13+
14+
- Fixes default offset for Exif #4594
15+
[rodrigob, radarhere]
16+
817
- Fixed bug when unpickling TIFF images #4565
918
[radarhere]
1019

@@ -5310,23 +5319,23 @@ Pre-fork
53105319
+ Added keyword options to the "save" method. The following options
53115320
are currently supported:
53125321

5313-
format option description
5322+
Format Option Description
53145323
--------------------------------------------------------
5315-
JPEG optimize minimize output file at the
5316-
expense of compression speed.
5324+
JPEG optimize Minimize output file at the
5325+
expense of compression speed.
53175326

5318-
JPEG progressive enable progressive output. the
5319-
option value is ignored.
5327+
JPEG progressive Enable progressive output.
5328+
The option value is ignored.
53205329

5321-
JPEG quality set compression quality (1-100).
5322-
the default value is 75.
5330+
JPEG quality Set compression quality (1-100).
5331+
The default value is 75.
53235332

5324-
JPEG smooth smooth dithered images. value
5325-
is strength (1-100). default is
5326-
off (0).
5333+
JPEG smooth Smooth dithered images.
5334+
Value is strength (1-100).
5335+
Default is off (0).
53275336

5328-
PNG optimize minimize output file at the
5329-
expense of compression speed.
5337+
PNG optimize Minimize output file at the
5338+
expense of compression speed.
53305339

53315340
Expect more options in future releases. Also note that
53325341
file writers silently ignore unknown options.
@@ -5347,31 +5356,31 @@ Pre-fork
53475356
+ Various improvements to the sample scripts:
53485357

53495358
"pilconvert" Carries out some extra tricks in order to make
5350-
the resulting file as small as possible.
5359+
the resulting file as small as possible.
53515360

5352-
"explode" (NEW) Split an image sequence into individual frames.
5361+
"explode" (NEW) Split an image sequence into individual frames.
53535362

5354-
"gifmaker" (NEW) Convert a sequence file into a GIF animation.
5355-
Note that the GIF encoder create "uncompressed" GIF
5356-
files, so animations created by this script are
5357-
rather large (typically 2-5 times the compressed
5358-
sizes).
5363+
"gifmaker" (NEW) Convert a sequence file into a GIF animation.
5364+
Note that the GIF encoder create "uncompressed" GIF
5365+
files, so animations created by this script are
5366+
rather large (typically 2-5 times the compressed
5367+
sizes).
53595368

5360-
"image2py" (NEW) Convert a single image to a python module. See
5361-
comments in this script for details.
5369+
"image2py" (NEW) Convert a single image to a python module. See
5370+
comments in this script for details.
53625371

5363-
"player" If multiple images are given on the command line,
5364-
they are interpreted as frames in a sequence. The
5365-
script assumes that they all have the same size.
5366-
Also note that this script now can play FLI/FLC
5367-
and GIF animations.
5372+
"player" If multiple images are given on the command line,
5373+
they are interpreted as frames in a sequence. The
5374+
script assumes that they all have the same size.
5375+
Also note that this script now can play FLI/FLC
5376+
and GIF animations.
53685377

53695378
This player can also execute embedded Python
53705379
animation applets (ARG format only).
53715380

5372-
"viewer" Transparent images ("P" with transparency property,
5373-
and "RGBA") are superimposed on the standard Tk back-
5374-
ground.
5381+
"viewer" Transparent images ("P" with transparency property,
5382+
and "RGBA") are superimposed on the standard Tk back-
5383+
ground.
53755384

53765385
+ Fixed colour argument to "new". For multilayer images, pass a
53775386
tuple: (Red, Green, Blue), (Red, Green, Blue, Alpha), or (Cyan,

Tests/images/icc-after-SOF.jpg

212 Bytes
Loading

Tests/test_file_gbr.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,11 @@ def test_gbr_file():
1515
with Image.open("Tests/images/gbr.gbr") as im:
1616
with Image.open("Tests/images/gbr.png") as target:
1717
assert_image_equal(target, im)
18+
19+
20+
def test_multiple_load_operations():
21+
with Image.open("Tests/images/gbr.gbr") as im:
22+
im.load()
23+
im.load()
24+
with Image.open("Tests/images/gbr.png") as target:
25+
assert_image_equal(target, im)

Tests/test_file_jpeg.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ def _n_qtables_helper(n, test_file):
500500
def test_load_djpeg(self):
501501
with Image.open(TEST_FILE) as img:
502502
img.load_djpeg()
503-
assert_image_similar(img, Image.open(TEST_FILE), 0)
503+
assert_image_similar(img, Image.open(TEST_FILE), 5)
504504

505505
@pytest.mark.skipif(not cjpeg_available(), reason="cjpeg not available")
506506
def test_save_cjpeg(self, tmp_path):
@@ -689,6 +689,10 @@ def test_photoshop_malformed_and_multiple(self):
689689
apps_13_lengths = [len(v) for k, v in im.applist if k == "APP13"]
690690
assert [65504, 24] == apps_13_lengths
691691

692+
def test_icc_after_SOF(self):
693+
with Image.open("Tests/images/icc-after-SOF.jpg") as im:
694+
assert im.info["icc_profile"] == b"profile"
695+
692696

693697
@pytest.mark.skipif(not is_win32(), reason="Windows only")
694698
@skip_unless_feature("jpg")

Tests/test_image_reduce.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,10 @@ def assert_compare_images(a, b, max_average_diff, max_diff=255):
174174
average_diff = sum(i * num for i, num in enumerate(ch_hist)) / (
175175
a.size[0] * a.size[1]
176176
)
177-
msg = "average pixel value difference {:.4f} > expected {:.4f} "
178-
"for '{}' band".format(average_diff, max_average_diff, band)
177+
msg = (
178+
"average pixel value difference {:.4f} > expected {:.4f} "
179+
"for '{}' band".format(average_diff, max_average_diff, band)
180+
)
179181
assert max_average_diff >= average_diff, msg
180182

181183
last_diff = [i for i, num in enumerate(ch_hist) if num > 0][-1]

Tests/test_imagefile.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,9 @@ def test_exif_jpeg(self, tmp_path):
261261
with Image.open(out) as reloaded:
262262
reloaded_exif = reloaded.getexif()
263263
assert reloaded_exif[258] == 8
264-
assert 40960 not in exif
264+
assert 40960 not in reloaded_exif
265265
assert reloaded_exif[40963] == 455
266-
assert exif[11] == "Pillow test"
266+
assert reloaded_exif[11] == "Pillow test"
267267

268268
with Image.open("Tests/images/no-dpi-in-exif.jpg") as im: # Big endian
269269
exif = im.getexif()
@@ -281,9 +281,9 @@ def test_exif_jpeg(self, tmp_path):
281281
with Image.open(out) as reloaded:
282282
reloaded_exif = reloaded.getexif()
283283
assert reloaded_exif[258] == 8
284-
assert 40960 not in exif
284+
assert 34665 not in reloaded_exif
285285
assert reloaded_exif[40963] == 455
286-
assert exif[305] == "Pillow test"
286+
assert reloaded_exif[305] == "Pillow test"
287287

288288
@skip_unless_feature("webp")
289289
@skip_unless_feature("webp_anim")
@@ -302,7 +302,7 @@ def check_exif():
302302
reloaded_exif = reloaded.getexif()
303303
assert reloaded_exif[258] == 8
304304
assert reloaded_exif[40963] == 455
305-
assert exif[305] == "Pillow test"
305+
assert reloaded_exif[305] == "Pillow test"
306306

307307
im.save(out, exif=exif)
308308
check_exif()

depends/install_extra_test_images.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
# Use SVN to just fetch a single Git subdirectory
55
svn_export()
66
{
7-
if [ ! -z $1 ]; then
8-
echo ""
9-
echo "Retrying svn export..."
10-
echo ""
11-
fi
7+
if [ ! -z $1 ]; then
8+
echo ""
9+
echo "Retrying svn export..."
10+
echo ""
11+
fi
1212

13-
svn export --force https://github.com/python-pillow/pillow-depends/trunk/test_images ../Tests/images
13+
svn export --force https://github.com/python-pillow/pillow-depends/trunk/test_images ../Tests/images
1414
}
1515
svn_export || svn_export retry || svn_export retry || svn_export retry

docs/handbook/writing-your-own-file-decoder.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ itself. Such plug-ins usually have names like
1717
Pillow decodes files in 2 stages:
1818

1919
1. It loops over the available image plugins in the loaded order, and
20-
calls the plugin's ``accept`` function with the first 16 bytes of
21-
the file. If the ``accept`` function returns true, the plugin's
20+
calls the plugin's ``_accept`` function with the first 16 bytes of
21+
the file. If the ``_accept`` function returns true, the plugin's
2222
``_open`` method is called to set up the image metadata and image
2323
tiles. The ``_open`` method is not for decoding the actual image
2424
data.
@@ -53,19 +53,19 @@ true color.
5353

5454
from PIL import Image, ImageFile
5555

56+
57+
def _accept(prefix):
58+
return prefix[:4] == b"SPAM"
59+
60+
5661
class SpamImageFile(ImageFile.ImageFile):
5762

5863
format = "SPAM"
5964
format_description = "Spam raster image"
6065

6166
def _open(self):
6267

63-
# check header
64-
header = self.fp.read(128)
65-
if header[:4] != b"SPAM":
66-
raise SyntaxError("not a SPAM file")
67-
68-
header = header.split()
68+
header = self.fp.read(128).split()
6969

7070
# size in pixels (width, height)
7171
self._size = int(header[1]), int(header[2])
@@ -86,7 +86,7 @@ true color.
8686
("raw", (0, 0) + self.size, 128, (self.mode, 0, 1))
8787
]
8888

89-
Image.register_open(SpamImageFile.format, SpamImageFile)
89+
Image.register_open(SpamImageFile.format, SpamImageFile, _accept)
9090

9191
Image.register_extension(SpamImageFile.format, ".spam")
9292
Image.register_extension(SpamImageFile.format, ".spa") # dos version
@@ -179,7 +179,7 @@ complete list, see the table in the :py:mod:`Unpack.c` module. The following
179179
table describes some commonly used **raw modes**:
180180

181181
+-----------+-----------------------------------------------------------------+
182-
| mode | description |
182+
| mode | description |
183183
+===========+=================================================================+
184184
| ``1`` | 1-bit bilevel, stored with the leftmost pixel in the most |
185185
| | significant bit. 0 means black, 1 means white. |
@@ -223,7 +223,7 @@ You can use the ``raw`` decoder to read images where data is packed in any
223223
standard machine data type, using one of the following raw modes:
224224

225225
============ =======================================
226-
mode description
226+
mode description
227227
============ =======================================
228228
``F`` 32-bit native floating point.
229229
``F;8`` 8-bit unsigned integer.

docs/installation.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ In Fedora, the command is::
329329

330330
.. Note:: ``redhat-rpm-config`` is required on Fedora 23, but not earlier versions.
331331

332-
Prerequisites are installed on **Ubuntu 16.04 LTS** with::
332+
Prerequisites for **Ubuntu 16.04 LTS - 20.04 LTS** are installed with::
333333

334334
sudo apt-get install libtiff5-dev libjpeg8-dev libopenjp2-7-dev zlib1g-dev \
335335
libfreetype6-dev liblcms2-dev libwebp-dev tcl8.6-dev tk8.6-dev python3-tk \
@@ -434,7 +434,7 @@ These platforms have been reported to work at the versions mentioned.
434434
+----------------------------------+------------------------------+--------------------------------+-----------------------+
435435
|**Operating system** |**Tested Python versions** |**Latest tested Pillow version**|**Tested processors** |
436436
+----------------------------------+------------------------------+--------------------------------+-----------------------+
437-
| macOS 10.15 Catalina | 3.5, 3.6, 3.7, 3.8 | 7.0.0 |x86-64 |
437+
| macOS 10.15 Catalina | 3.5, 3.6, 3.7, 3.8 | 7.1.2 |x86-64 |
438438
+----------------------------------+------------------------------+--------------------------------+-----------------------+
439439
| macOS 10.14 Mojave | 2.7, 3.5, 3.6, 3.7 | 6.0.0 |x86-64 |
440440
| +------------------------------+--------------------------------+ +

0 commit comments

Comments
 (0)