mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-06-30 09:53:39 +03:00
Renamed setting
This commit is contained in:
parent
33022eef16
commit
e22a4395d3
|
@ -78,13 +78,13 @@ def test_strategy():
|
||||||
expected_one = im.convert("RGB")
|
expected_one = im.convert("RGB")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
GifImagePlugin.PALETTE_TO_RGB = GifImagePlugin.ModeStrategy.ALWAYS
|
GifImagePlugin.LOADING_STRATEGY = GifImagePlugin.LoadingStrategy.RGB_ALWAYS
|
||||||
with Image.open("Tests/images/chi.gif") as im:
|
with Image.open("Tests/images/chi.gif") as im:
|
||||||
assert im.mode == "RGB"
|
assert im.mode == "RGB"
|
||||||
assert_image_equal(im, expected_zero)
|
assert_image_equal(im, expected_zero)
|
||||||
|
|
||||||
GifImagePlugin.PALETTE_TO_RGB = (
|
GifImagePlugin.LOADING_STRATEGY = (
|
||||||
GifImagePlugin.ModeStrategy.DIFFERENT_PALETTE_ONLY
|
GifImagePlugin.LoadingStrategy.RGB_AFTER_DIFFERENT_PALETTE_ONLY
|
||||||
)
|
)
|
||||||
# Stay in P mode with only a global palette
|
# Stay in P mode with only a global palette
|
||||||
with Image.open("Tests/images/chi.gif") as im:
|
with Image.open("Tests/images/chi.gif") as im:
|
||||||
|
@ -101,7 +101,7 @@ def test_strategy():
|
||||||
im.seek(1)
|
im.seek(1)
|
||||||
assert im.mode == "RGB"
|
assert im.mode == "RGB"
|
||||||
finally:
|
finally:
|
||||||
GifImagePlugin.PALETTE_TO_RGB = GifImagePlugin.ModeStrategy.AFTER_FIRST
|
GifImagePlugin.LOADING_STRATEGY = GifImagePlugin.LoadingStrategy.RGB_AFTER_FIRST
|
||||||
|
|
||||||
|
|
||||||
def test_optimize():
|
def test_optimize():
|
||||||
|
@ -429,10 +429,10 @@ def test_dispose_background_transparency():
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"mode_strategy, expected_colors",
|
"loading_strategy, expected_colors",
|
||||||
(
|
(
|
||||||
(
|
(
|
||||||
GifImagePlugin.ModeStrategy.AFTER_FIRST,
|
GifImagePlugin.LoadingStrategy.RGB_AFTER_FIRST,
|
||||||
(
|
(
|
||||||
(2, 1, 2),
|
(2, 1, 2),
|
||||||
((0, 255, 24, 255), (0, 0, 255, 255), (0, 255, 24, 255)),
|
((0, 255, 24, 255), (0, 0, 255, 255), (0, 255, 24, 255)),
|
||||||
|
@ -440,7 +440,7 @@ def test_dispose_background_transparency():
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
GifImagePlugin.ModeStrategy.DIFFERENT_PALETTE_ONLY,
|
GifImagePlugin.LoadingStrategy.RGB_AFTER_DIFFERENT_PALETTE_ONLY,
|
||||||
(
|
(
|
||||||
(2, 1, 2),
|
(2, 1, 2),
|
||||||
(0, 1, 0),
|
(0, 1, 0),
|
||||||
|
@ -449,8 +449,8 @@ def test_dispose_background_transparency():
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
def test_transparent_dispose(mode_strategy, expected_colors):
|
def test_transparent_dispose(loading_strategy, expected_colors):
|
||||||
GifImagePlugin.PALETTE_TO_RGB = mode_strategy
|
GifImagePlugin.LOADING_STRATEGY = loading_strategy
|
||||||
try:
|
try:
|
||||||
with Image.open("Tests/images/transparent_dispose.gif") as img:
|
with Image.open("Tests/images/transparent_dispose.gif") as img:
|
||||||
for frame in range(3):
|
for frame in range(3):
|
||||||
|
@ -459,7 +459,7 @@ def test_transparent_dispose(mode_strategy, expected_colors):
|
||||||
color = img.getpixel((x, 0))
|
color = img.getpixel((x, 0))
|
||||||
assert color == expected_colors[frame][x]
|
assert color == expected_colors[frame][x]
|
||||||
finally:
|
finally:
|
||||||
GifImagePlugin.PALETTE_TO_RGB = GifImagePlugin.ModeStrategy.AFTER_FIRST
|
GifImagePlugin.LOADING_STRATEGY = GifImagePlugin.LoadingStrategy.RGB_AFTER_FIRST
|
||||||
|
|
||||||
|
|
||||||
def test_dispose_previous():
|
def test_dispose_previous():
|
||||||
|
|
|
@ -118,7 +118,7 @@ every ``P`` frame is converted to ``RGB`` or ``RGBA`` mode, there is a setting
|
||||||
available::
|
available::
|
||||||
|
|
||||||
from PIL import GifImagePlugin
|
from PIL import GifImagePlugin
|
||||||
GifImagePlugin.PALETTE_TO_RGB = GifImagePlugin.ModeStrategy.ALWAYS
|
GifImagePlugin.LOADING_STRATEGY = GifImagePlugin.LoadingStrategy.RGB_ALWAYS
|
||||||
|
|
||||||
GIF frames do not always contain individual palettes however. If there is only
|
GIF frames do not always contain individual palettes however. If there is only
|
||||||
a global palette, then all of the colors can fit within ``P`` mode. If you would
|
a global palette, then all of the colors can fit within ``P`` mode. If you would
|
||||||
|
@ -126,7 +126,7 @@ prefer the frames to be kept as ``P`` in that case, there is also a setting
|
||||||
available::
|
available::
|
||||||
|
|
||||||
from PIL import GifImagePlugin
|
from PIL import GifImagePlugin
|
||||||
GifImagePlugin.PALETTE_TO_RGB = GifImagePlugin.ModeStrategy.DIFFERENT_PALETTE_ONLY
|
GifImagePlugin.LOADING_STRATEGY = GifImagePlugin.LoadingStrategy.RGB_AFTER_DIFFERENT_PALETTE_ONLY
|
||||||
|
|
||||||
The :py:meth:`~PIL.Image.open` method sets the following
|
The :py:meth:`~PIL.Image.open` method sets the following
|
||||||
:py:attr:`~PIL.Image.Image.info` properties:
|
:py:attr:`~PIL.Image.Image.info` properties:
|
||||||
|
|
|
@ -36,16 +36,16 @@ from ._binary import o8
|
||||||
from ._binary import o16le as o16
|
from ._binary import o16le as o16
|
||||||
|
|
||||||
|
|
||||||
class ModeStrategy(IntEnum):
|
class LoadingStrategy(IntEnum):
|
||||||
""".. versionadded:: 9.1.0"""
|
""".. versionadded:: 9.1.0"""
|
||||||
|
|
||||||
AFTER_FIRST = 0
|
RGB_AFTER_FIRST = 0
|
||||||
ALWAYS = 1
|
RGB_AFTER_DIFFERENT_PALETTE_ONLY = 1
|
||||||
DIFFERENT_PALETTE_ONLY = 2
|
RGB_ALWAYS = 2
|
||||||
|
|
||||||
|
|
||||||
#: .. versionadded:: 9.1.0
|
#: .. versionadded:: 9.1.0
|
||||||
PALETTE_TO_RGB = ModeStrategy.AFTER_FIRST
|
LOADING_STRATEGY = LoadingStrategy.RGB_AFTER_FIRST
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
# Identify/read GIF files
|
# Identify/read GIF files
|
||||||
|
@ -292,7 +292,9 @@ class GifImageFile(ImageFile.ImageFile):
|
||||||
self._frame_palette = palette or self.global_palette
|
self._frame_palette = palette or self.global_palette
|
||||||
if frame == 0:
|
if frame == 0:
|
||||||
if self._frame_palette:
|
if self._frame_palette:
|
||||||
self.mode = "RGB" if PALETTE_TO_RGB == ModeStrategy.ALWAYS else "P"
|
self.mode = (
|
||||||
|
"RGB" if LOADING_STRATEGY == LoadingStrategy.RGB_ALWAYS else "P"
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
self.mode = "L"
|
self.mode = "L"
|
||||||
|
|
||||||
|
@ -304,7 +306,10 @@ class GifImageFile(ImageFile.ImageFile):
|
||||||
else:
|
else:
|
||||||
self._frame_transparency = frame_transparency
|
self._frame_transparency = frame_transparency
|
||||||
if self.mode == "P":
|
if self.mode == "P":
|
||||||
if PALETTE_TO_RGB != ModeStrategy.DIFFERENT_PALETTE_ONLY or palette:
|
if (
|
||||||
|
LOADING_STRATEGY != LoadingStrategy.RGB_AFTER_DIFFERENT_PALETTE_ONLY
|
||||||
|
or palette
|
||||||
|
):
|
||||||
self.pyaccess = None
|
self.pyaccess = None
|
||||||
if "transparency" in self.info:
|
if "transparency" in self.info:
|
||||||
self.im.putpalettealpha(self.info["transparency"], 0)
|
self.im.putpalettealpha(self.info["transparency"], 0)
|
||||||
|
@ -412,7 +417,7 @@ class GifImageFile(ImageFile.ImageFile):
|
||||||
|
|
||||||
def load_end(self):
|
def load_end(self):
|
||||||
if self.__frame == 0:
|
if self.__frame == 0:
|
||||||
if self.mode == "P" and PALETTE_TO_RGB == ModeStrategy.ALWAYS:
|
if self.mode == "P" and LOADING_STRATEGY == LoadingStrategy.RGB_ALWAYS:
|
||||||
self.mode = "RGB"
|
self.mode = "RGB"
|
||||||
self.im = self.im.convert("RGB", Image.Dither.FLOYDSTEINBERG)
|
self.im = self.im.convert("RGB", Image.Dither.FLOYDSTEINBERG)
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue
Block a user