Merge branch 'python-pillow:main' into main

This commit is contained in:
Jonathan Woolf 2022-09-27 07:05:10 -06:00 committed by GitHub
commit ce07c0b811
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 139 additions and 56 deletions

View File

@ -25,8 +25,8 @@ install:
- mv c:\pillow-depends-main c:\pillow-depends - mv c:\pillow-depends-main c:\pillow-depends
- xcopy /S /Y c:\pillow-depends\test_images\* c:\pillow\tests\images - xcopy /S /Y c:\pillow-depends\test_images\* c:\pillow\tests\images
- 7z x ..\pillow-depends\nasm-2.15.05-win64.zip -oc:\ - 7z x ..\pillow-depends\nasm-2.15.05-win64.zip -oc:\
- ..\pillow-depends\gs9561w32.exe /S - ..\pillow-depends\gs1000w32.exe /S
- path c:\nasm-2.15.05;C:\Program Files (x86)\gs\gs9.56.1\bin;%PATH% - path c:\nasm-2.15.05;C:\Program Files (x86)\gs\gs10.0.0\bin;%PATH%
- cd c:\pillow\winbuild\ - cd c:\pillow\winbuild\
- ps: | - ps: |
c:\python37\python.exe c:\pillow\winbuild\build_prepare.py -v --depends=C:\pillow-depends\ c:\python37\python.exe c:\pillow\winbuild\build_prepare.py -v --depends=C:\pillow-depends\

View File

@ -14,6 +14,10 @@ on:
permissions: permissions:
contents: read contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs: jobs:
Fuzzing: Fuzzing:
runs-on: ubuntu-latest runs-on: ubuntu-latest

View File

@ -5,6 +5,10 @@ on: [push, pull_request, workflow_dispatch]
permissions: permissions:
contents: read contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs: jobs:
build: build:
@ -16,7 +20,7 @@ jobs:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: pre-commit cache - name: pre-commit cache
uses: actions/cache@v2 uses: actions/cache@v3
with: with:
path: ~/.cache/pre-commit path: ~/.cache/pre-commit
key: lint-pre-commit-${{ hashFiles('**/.pre-commit-config.yaml') }} key: lint-pre-commit-${{ hashFiles('**/.pre-commit-config.yaml') }}
@ -24,7 +28,7 @@ jobs:
lint-pre-commit- lint-pre-commit-
- name: Set up Python - name: Set up Python
uses: actions/setup-python@v3 uses: actions/setup-python@v4
with: with:
python-version: "3.10" python-version: "3.10"
cache: pip cache: pip

View File

@ -10,6 +10,10 @@ on:
permissions: permissions:
contents: read contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs: jobs:
update_release_draft: update_release_draft:
permissions: permissions:

View File

@ -8,6 +8,10 @@ on:
permissions: permissions:
issues: write issues: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs: jobs:
stale: stale:
if: github.repository_owner == 'python-pillow' if: github.repository_owner == 'python-pillow'
@ -16,7 +20,7 @@ jobs:
steps: steps:
- name: "Check issues" - name: "Check issues"
uses: actions/stale@v5 uses: actions/stale@v6
with: with:
repo-token: ${{ secrets.GITHUB_TOKEN }} repo-token: ${{ secrets.GITHUB_TOKEN }}
only-labels: "Awaiting OP Action" only-labels: "Awaiting OP Action"

View File

@ -5,6 +5,10 @@ on: [push, pull_request, workflow_dispatch]
permissions: permissions:
contents: read contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs: jobs:
build: build:
runs-on: windows-latest runs-on: windows-latest
@ -44,7 +48,7 @@ jobs:
qt5-devel-tools subversion xorg-server-extra zlib-devel qt5-devel-tools subversion xorg-server-extra zlib-devel
- name: Add Lapack to PATH - name: Add Lapack to PATH
uses: egor-tensin/cleanup-path@v1 uses: egor-tensin/cleanup-path@v2
with: with:
dirs: 'C:\cygwin\bin;C:\cygwin\lib\lapack' dirs: 'C:\cygwin\bin;C:\cygwin\lib\lapack'

View File

@ -5,6 +5,10 @@ on: [push, pull_request, workflow_dispatch]
permissions: permissions:
contents: read contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs: jobs:
build: build:
@ -79,7 +83,7 @@ jobs:
MATRIX_DOCKER: ${{ matrix.docker }} MATRIX_DOCKER: ${{ matrix.docker }}
- name: Upload coverage - name: Upload coverage
uses: codecov/codecov-action@v1 uses: codecov/codecov-action@v3
with: with:
flags: GHA_Docker flags: GHA_Docker
name: ${{ matrix.docker }} name: ${{ matrix.docker }}

View File

@ -5,6 +5,10 @@ on: [push, pull_request, workflow_dispatch]
permissions: permissions:
contents: read contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs: jobs:
build: build:
runs-on: windows-latest runs-on: windows-latest
@ -73,11 +77,11 @@ jobs:
python3 -m pytest -vx --cov PIL --cov Tests --cov-report term --cov-report xml Tests python3 -m pytest -vx --cov PIL --cov Tests --cov-report term --cov-report xml Tests
- name: Upload coverage - name: Upload coverage
run: | uses: codecov/codecov-action@v3
python3 -m pip install codecov with:
bash <(curl -s https://codecov.io/bash) -F GHA_Windows file: ./coverage.xml
env: flags: GHA_Windows
CODECOV_NAME: ${{ matrix.name }} name: ${{ matrix.name }}
success: success:
permissions: permissions:

View File

@ -16,6 +16,10 @@ on:
permissions: permissions:
contents: read contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs: jobs:
build: build:

View File

@ -5,6 +5,10 @@ on: [push, pull_request, workflow_dispatch]
permissions: permissions:
contents: read contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs: jobs:
build: build:
runs-on: windows-latest runs-on: windows-latest
@ -36,7 +40,7 @@ jobs:
# sets env: pythonLocation # sets env: pythonLocation
- name: Set up Python - name: Set up Python
uses: actions/setup-python@v3 uses: actions/setup-python@v4
with: with:
python-version: ${{ matrix.python-version }} python-version: ${{ matrix.python-version }}
architecture: ${{ matrix.architecture }} architecture: ${{ matrix.architecture }}
@ -55,8 +59,8 @@ jobs:
7z x winbuild\depends\nasm-2.15.05-win64.zip "-o$env:RUNNER_WORKSPACE\" 7z x winbuild\depends\nasm-2.15.05-win64.zip "-o$env:RUNNER_WORKSPACE\"
echo "$env:RUNNER_WORKSPACE\nasm-2.15.05" >> $env:GITHUB_PATH echo "$env:RUNNER_WORKSPACE\nasm-2.15.05" >> $env:GITHUB_PATH
winbuild\depends\gs9561w32.exe /S winbuild\depends\gs1000w32.exe /S
echo "C:\Program Files (x86)\gs\gs9.56.1\bin" >> $env:GITHUB_PATH echo "C:\Program Files (x86)\gs\gs10.0.0\bin" >> $env:GITHUB_PATH
xcopy /S /Y winbuild\depends\test_images\* Tests\images\ xcopy /S /Y winbuild\depends\test_images\* Tests\images\
@ -66,7 +70,7 @@ jobs:
- name: Cache build - name: Cache build
id: build-cache id: build-cache
uses: actions/cache@v2 uses: actions/cache@v3
with: with:
path: winbuild\build path: winbuild\build
key: key:
@ -171,7 +175,7 @@ jobs:
shell: pwsh shell: pwsh
- name: Upload coverage - name: Upload coverage
uses: codecov/codecov-action@v1 uses: codecov/codecov-action@v3
with: with:
file: ./coverage.xml file: ./coverage.xml
flags: GHA_Windows flags: GHA_Windows

View File

@ -5,6 +5,10 @@ on: [push, pull_request, workflow_dispatch]
permissions: permissions:
contents: read contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs: jobs:
build: build:
@ -30,11 +34,6 @@ jobs:
REVERSE: "--reverse" REVERSE: "--reverse"
- python-version: "3.8" - python-version: "3.8"
PYTHONOPTIMIZE: 2 PYTHONOPTIMIZE: 2
# Include new variables for Codecov
- os: ubuntu-latest
codecov-flag: GHA_Ubuntu
- os: macos-latest
codecov-flag: GHA_macOS
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
name: ${{ matrix.os }} Python ${{ matrix.python-version }} name: ${{ matrix.os }} Python ${{ matrix.python-version }}
@ -43,7 +42,7 @@ jobs:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }} - name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3 uses: actions/setup-python@v4
with: with:
python-version: ${{ matrix.python-version }} python-version: ${{ matrix.python-version }}
cache: pip cache: pip
@ -99,7 +98,6 @@ jobs:
- name: Docs - name: Docs
if: startsWith(matrix.os, 'ubuntu') && matrix.python-version == 3.10 if: startsWith(matrix.os, 'ubuntu') && matrix.python-version == 3.10
run: | run: |
python3 -m pip install furo sphinx-copybutton sphinx-issues sphinx-removed-in sphinxext-opengraph
make doccheck make doccheck
- name: After success - name: After success
@ -107,9 +105,11 @@ jobs:
.ci/after_success.sh .ci/after_success.sh
- name: Upload coverage - name: Upload coverage
run: bash <(curl -s https://codecov.io/bash) -F ${{ matrix.codecov-flag }} uses: codecov/codecov-action@v3
env: with:
CODECOV_NAME: ${{ matrix.os }} Python ${{ matrix.python-version }} file: ./coverage.xml
flags: ${{ matrix.os == 'macos-latest' && 'GHA_macOS' || 'GHA_Ubuntu' }}
name: ${{ matrix.os }} Python ${{ matrix.python-version }}
success: success:
permissions: permissions:

View File

@ -1,4 +1,5 @@
name: Tidelift Align name: Tidelift Align
on: on:
schedule: schedule:
- cron: "30 2 * * *" # daily at 02:30 UTC - cron: "30 2 * * *" # daily at 02:30 UTC
@ -15,6 +16,10 @@ on:
permissions: permissions:
contents: read contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs: jobs:
build: build:
if: github.repository_owner == 'python-pillow' if: github.repository_owner == 'python-pillow'

View File

@ -5,6 +5,15 @@ Changelog (Pillow)
9.3.0 (unreleased) 9.3.0 (unreleased)
------------------ ------------------
- Improved ImageOps palette handling #6596
[PososikTeam, radarhere]
- Defer parsing of palette into colors #6567
[radarhere]
- Apply transparency to P images in ImageTk.PhotoImage #6559
[radarhere]
- Use rounding in ImageOps contain() and pad() #6522 - Use rounding in ImageOps contain() and pad() #6522
[bibinhashley, radarhere] [bibinhashley, radarhere]

View File

@ -17,11 +17,12 @@ coverage:
.PHONY: doc .PHONY: doc
doc: doc:
python3 -c "import PIL" > /dev/null 2>&1 || python3 -m pip install .
$(MAKE) -C docs html $(MAKE) -C docs html
.PHONY: doccheck .PHONY: doccheck
doccheck: doccheck:
$(MAKE) -C docs html $(MAKE) doc
# Don't make our tests rely on the links in the docs being up every single build. # Don't make our tests rely on the links in the docs being up every single build.
# We don't control them. But do check, and update them to the target of their redirects. # We don't control them. But do check, and update them to the target of their redirects.
$(MAKE) -C docs linkcheck || true $(MAKE) -C docs linkcheck || true

View File

@ -149,6 +149,21 @@ def test_pad_round():
assert new_im.load()[0, 2] == 1 assert new_im.load()[0, 2] == 1
@pytest.mark.parametrize("mode", ("P", "PA"))
def test_palette(mode):
im = hopper(mode)
# Expand
expanded_im = ImageOps.expand(im)
assert_image_equal(im.convert("RGB"), expanded_im.convert("RGB"))
# Pad
padded_im = ImageOps.pad(im, (256, 128), centering=(0, 0))
assert_image_equal(
im.convert("RGB"), padded_im.convert("RGB").crop((0, 0, 128, 128))
)
def test_pil163(): def test_pil163():
# Division by zero in equalize if < 255 pixels in image (@PIL163) # Division by zero in equalize if < 255 pixels in image (@PIL163)

View File

@ -69,6 +69,13 @@ def test_photoimage():
assert_image_equal(reloaded, im.convert("RGBA")) assert_image_equal(reloaded, im.convert("RGBA"))
def test_photoimage_apply_transparency():
with Image.open("Tests/images/pil123p.png") as im:
im_tk = ImageTk.PhotoImage(im)
reloaded = ImageTk.getimage(im_tk)
assert_image_equal(reloaded, im.convert("RGBA"))
def test_photoimage_blank(): def test_photoimage_blank():
# test a image using mode/size: # test a image using mode/size:
for mode in TK_MODES: for mode in TK_MODES:

View File

@ -43,8 +43,7 @@ clean:
-rm -rf $(BUILDDIR)/* -rm -rf $(BUILDDIR)/*
install-sphinx: install-sphinx:
$(PYTHON) -c "import sphinx" > /dev/null 2>&1 || $(PYTHON) -m pip install sphinx $(PYTHON) -m pip install --quiet sphinx sphinx-copybutton sphinx-issues sphinx-removed-in sphinxext-opengraph furo olefile
$(PYTHON) -c "import furo" > /dev/null 2>&1 || $(PYTHON) -m pip install furo
html: html:
$(MAKE) install-sphinx $(MAKE) install-sphinx

View File

@ -253,7 +253,7 @@ Support for FreeType 2.7 has been removed.
We recommend upgrading to at least `FreeType`_ 2.10.4, which fixed a severe We recommend upgrading to at least `FreeType`_ 2.10.4, which fixed a severe
vulnerability introduced in FreeType 2.6 (:cve:`CVE-2020-15999`). vulnerability introduced in FreeType 2.6 (:cve:`CVE-2020-15999`).
.. _FreeType: https://www.freetype.org .. _FreeType: https://freetype.org/
im.offset im.offset
~~~~~~~~~ ~~~~~~~~~

View File

@ -184,7 +184,7 @@ Many of Pillow's features require external libraries:
loads libfribidi at runtime if it is installed. loads libfribidi at runtime if it is installed.
On Windows this requires compiling FriBiDi and installing ``fribidi.dll`` On Windows this requires compiling FriBiDi and installing ``fribidi.dll``
into a directory listed in the `Dynamic-Link Library Search Order (Microsoft Docs) into a directory listed in the `Dynamic-Link Library Search Order (Microsoft Docs)
<https://docs.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order#search-order-for-desktop-applications>`_ <https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order#search-order-for-desktop-applications>`_
(``fribidi-0.dll`` or ``libfribidi-0.dll`` are also detected). (``fribidi-0.dll`` or ``libfribidi-0.dll`` are also detected).
See `Build Options`_ to see how to build this version. See `Build Options`_ to see how to build this version.
* Previous versions of Pillow (5.0.0 to 8.1.2) linked libraqm dynamically at runtime. * Previous versions of Pillow (5.0.0 to 8.1.2) linked libraqm dynamically at runtime.

View File

@ -731,4 +731,4 @@ Methods
homogeneous, but similar, colors. homogeneous, but similar, colors.
.. _BCP 47 language code: https://www.w3.org/International/articles/language-tags/ .. _BCP 47 language code: https://www.w3.org/International/articles/language-tags/
.. _OpenType docs: https://docs.microsoft.com/en-us/typography/opentype/spec/featurelist .. _OpenType docs: https://learn.microsoft.com/en-us/typography/opentype/spec/featurelist

View File

@ -105,7 +105,7 @@ Resolve confusion getting PIL / Pillow version string
Re: "version constants deprecated" listed above, as user gnbl notes in #3082: Re: "version constants deprecated" listed above, as user gnbl notes in #3082:
- it's confusing that PIL.VERSION returns the version string of the former PIL instead of Pillow's - it's confusing that PIL.VERSION returns the version string of the former PIL instead of Pillow's
- there does not seem to be documentation on this version number (why this, will it ever change, ..) e.g. at https://pillow.readthedocs.io/en/5.1.x/about.html#why-a-fork - ReadTheDocs documentation is missing for some version branches (why is this, will it ever change, ...)
- it's confusing that PIL.version is a module and does not return the version information directly or hints on how to get it - it's confusing that PIL.version is a module and does not return the version information directly or hints on how to get it
- the package information header is essentially useless (placeholder, does not even mention Pillow, nor the version) - the package information header is essentially useless (placeholder, does not even mention Pillow, nor the version)
- PIL._version module documentation comment could explain how to access the version information - PIL._version module documentation comment could explain how to access the version information

View File

@ -11,7 +11,7 @@ Pillow follows `Semantic Versioning <https://semver.org/>`_:
2. MINOR version when you add functionality in a backwards compatible manner, and 2. MINOR version when you add functionality in a backwards compatible manner, and
3. PATCH version when you make backwards compatible bug fixes. 3. PATCH version when you make backwards compatible bug fixes.
Quarterly releases ("`Main Release <https://github.com/python-pillow/Pillow/blob/main/RELEASING.md#main-release>`_") Quarterly releases ("`Main Release <https://github.com/python-pillow/Pillow/blob/main/RELEASING.md#user-content-main-release>`_")
bump at least the MINOR version, as new functionality has likely been added in the bump at least the MINOR version, as new functionality has likely been added in the
prior three months. prior three months.
@ -21,8 +21,8 @@ these occur every 12-18 months, guided by
`Python's EOL schedule <https://devguide.python.org/#status-of-python-branches>`_, and `Python's EOL schedule <https://devguide.python.org/#status-of-python-branches>`_, and
any APIs that have been deprecated for at least a year are removed at the same time. any APIs that have been deprecated for at least a year are removed at the same time.
PATCH versions ("`Point Release <https://github.com/python-pillow/Pillow/blob/main/RELEASING.md#point-release>`_" PATCH versions ("`Point Release <https://github.com/python-pillow/Pillow/blob/main/RELEASING.md#user-content-point-release>`_"
or "`Embargoed Release <https://github.com/python-pillow/Pillow/blob/main/RELEASING.md#embargoed-release>`_") or "`Embargoed Release <https://github.com/python-pillow/Pillow/blob/main/RELEASING.md#user-content-embargoed-release>`_")
are for security, installation or critical bug fixes. These are less common as it is are for security, installation or critical bug fixes. These are less common as it is
preferred to stick to quarterly releases. preferred to stick to quarterly releases.

View File

@ -338,7 +338,7 @@ class FreeTypeFont:
example '-liga' to disable ligatures or '-kern' example '-liga' to disable ligatures or '-kern'
to disable kerning. To get all supported to disable kerning. To get all supported
features, see features, see
https://docs.microsoft.com/en-us/typography/opentype/spec/featurelist https://learn.microsoft.com/en-us/typography/opentype/spec/featurelist
Requires libraqm. Requires libraqm.
:param language: Language of the text. Different languages may use :param language: Language of the text. Different languages may use
@ -391,7 +391,7 @@ class FreeTypeFont:
example '-liga' to disable ligatures or '-kern' example '-liga' to disable ligatures or '-kern'
to disable kerning. To get all supported to disable kerning. To get all supported
features, see features, see
https://docs.microsoft.com/en-us/typography/opentype/spec/featurelist https://learn.microsoft.com/en-us/typography/opentype/spec/featurelist
Requires libraqm. Requires libraqm.
:param language: Language of the text. Different languages may use :param language: Language of the text. Different languages may use
@ -456,7 +456,7 @@ class FreeTypeFont:
example '-liga' to disable ligatures or '-kern' example '-liga' to disable ligatures or '-kern'
to disable kerning. To get all supported to disable kerning. To get all supported
features, see features, see
https://docs.microsoft.com/en-us/typography/opentype/spec/featurelist https://learn.microsoft.com/en-us/typography/opentype/spec/featurelist
Requires libraqm. Requires libraqm.
.. versionadded:: 4.2.0 .. versionadded:: 4.2.0
@ -520,7 +520,7 @@ class FreeTypeFont:
example '-liga' to disable ligatures or '-kern' example '-liga' to disable ligatures or '-kern'
to disable kerning. To get all supported to disable kerning. To get all supported
features, see features, see
https://docs.microsoft.com/en-us/typography/opentype/spec/featurelist https://learn.microsoft.com/en-us/typography/opentype/spec/featurelist
Requires libraqm. Requires libraqm.
:param language: Language of the text. Different languages may use :param language: Language of the text. Different languages may use
@ -610,7 +610,7 @@ class FreeTypeFont:
example '-liga' to disable ligatures or '-kern' example '-liga' to disable ligatures or '-kern'
to disable kerning. To get all supported to disable kerning. To get all supported
features, see features, see
https://docs.microsoft.com/en-us/typography/opentype/spec/featurelist https://learn.microsoft.com/en-us/typography/opentype/spec/featurelist
Requires libraqm. Requires libraqm.
.. versionadded:: 4.2.0 .. versionadded:: 4.2.0
@ -702,7 +702,7 @@ class FreeTypeFont:
example '-liga' to disable ligatures or '-kern' example '-liga' to disable ligatures or '-kern'
to disable kerning. To get all supported to disable kerning. To get all supported
features, see features, see
https://docs.microsoft.com/en-us/typography/opentype/spec/featurelist https://learn.microsoft.com/en-us/typography/opentype/spec/featurelist
Requires libraqm. Requires libraqm.
.. versionadded:: 4.2.0 .. versionadded:: 4.2.0

View File

@ -21,7 +21,7 @@ import functools
import operator import operator
import re import re
from . import Image from . import Image, ImagePalette
# #
# helpers # helpers
@ -291,6 +291,8 @@ def pad(image, size, method=Image.Resampling.BICUBIC, color=None, centering=(0.5
out = resized out = resized
else: else:
out = Image.new(image.mode, size, color) out = Image.new(image.mode, size, color)
if resized.palette:
out.putpalette(resized.getpalette())
if resized.width != size[0]: if resized.width != size[0]:
x = round((size[0] - resized.width) * max(0, min(centering[0], 1))) x = round((size[0] - resized.width) * max(0, min(centering[0], 1)))
out.paste(resized, (x, 0)) out.paste(resized, (x, 0))
@ -396,9 +398,8 @@ def expand(image, border=0, fill=0):
width = left + image.size[0] + right width = left + image.size[0] + right
height = top + image.size[1] + bottom height = top + image.size[1] + bottom
color = _color(fill, image.mode) color = _color(fill, image.mode)
if image.mode == "P" and image.palette: if image.palette:
image.load() palette = ImagePalette.ImagePalette(palette=image.getpalette())
palette = image.palette.copy()
if isinstance(color, tuple): if isinstance(color, tuple):
color = palette.getcolor(color) color = palette.getcolor(color)
else: else:

View File

@ -50,15 +50,24 @@ class ImagePalette:
@palette.setter @palette.setter
def palette(self, palette): def palette(self, palette):
self._colors = None
self._palette = palette self._palette = palette
mode_len = len(self.mode) @property
self.colors = {} def colors(self):
for i in range(0, len(self.palette), mode_len): if self._colors is None:
color = tuple(self.palette[i : i + mode_len]) mode_len = len(self.mode)
if color in self.colors: self._colors = {}
continue for i in range(0, len(self.palette), mode_len):
self.colors[color] = i // mode_len color = tuple(self.palette[i : i + mode_len])
if color in self._colors:
continue
self._colors[color] = i // mode_len
return self._colors
@colors.setter
def colors(self, colors):
self._colors = colors
def copy(self): def copy(self):
new = ImagePalette() new = ImagePalette()

View File

@ -107,6 +107,7 @@ class PhotoImage:
mode = image.mode mode = image.mode
if mode == "P": if mode == "P":
# palette mapped data # palette mapped data
image.apply_transparency()
image.load() image.load()
try: try:
mode = image.palette.mode mode = image.palette.mode

View File

@ -24,7 +24,7 @@
* *
* This cast is safe, as the top 32-bits of HFILE are guaranteed to be zero, * This cast is safe, as the top 32-bits of HFILE are guaranteed to be zero,
* see * see
* https://docs.microsoft.com/en-us/windows/win32/winprog64/interprocess-communication * https://learn.microsoft.com/en-us/windows/win32/winprog64/interprocess-communication
*/ */
#ifndef USE_WIN32_FILEIO #ifndef USE_WIN32_FILEIO
#define fd_to_tiff_fd(fd) (fd) #define fd_to_tiff_fd(fd) (fd)

View File

@ -81,5 +81,5 @@ The following projects have patches to support complex text layout using Raqm:
[1]: https://github.com/fribidi/fribidi [1]: https://github.com/fribidi/fribidi
[2]: https://github.com/Tehreer/SheenBidi [2]: https://github.com/Tehreer/SheenBidi
[3]: https://github.com/harfbuzz/harfbuzz [3]: https://github.com/harfbuzz/harfbuzz
[4]: https://www.freetype.org [4]: https://freetype.org/
[5]: https://www.gtk.org/gtk-doc [5]: https://www.gtk.org/gtk-doc