mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 01:47:47 +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")
 | 
			
		||||
 | 
			
		||||
    try:
 | 
			
		||||
        GifImagePlugin.PALETTE_TO_RGB = GifImagePlugin.ModeStrategy.ALWAYS
 | 
			
		||||
        GifImagePlugin.LOADING_STRATEGY = GifImagePlugin.LoadingStrategy.RGB_ALWAYS
 | 
			
		||||
        with Image.open("Tests/images/chi.gif") as im:
 | 
			
		||||
            assert im.mode == "RGB"
 | 
			
		||||
            assert_image_equal(im, expected_zero)
 | 
			
		||||
 | 
			
		||||
        GifImagePlugin.PALETTE_TO_RGB = (
 | 
			
		||||
            GifImagePlugin.ModeStrategy.DIFFERENT_PALETTE_ONLY
 | 
			
		||||
        GifImagePlugin.LOADING_STRATEGY = (
 | 
			
		||||
            GifImagePlugin.LoadingStrategy.RGB_AFTER_DIFFERENT_PALETTE_ONLY
 | 
			
		||||
        )
 | 
			
		||||
        # Stay in P mode with only a global palette
 | 
			
		||||
        with Image.open("Tests/images/chi.gif") as im:
 | 
			
		||||
| 
						 | 
				
			
			@ -101,7 +101,7 @@ def test_strategy():
 | 
			
		|||
            im.seek(1)
 | 
			
		||||
            assert im.mode == "RGB"
 | 
			
		||||
    finally:
 | 
			
		||||
        GifImagePlugin.PALETTE_TO_RGB = GifImagePlugin.ModeStrategy.AFTER_FIRST
 | 
			
		||||
        GifImagePlugin.LOADING_STRATEGY = GifImagePlugin.LoadingStrategy.RGB_AFTER_FIRST
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_optimize():
 | 
			
		||||
| 
						 | 
				
			
			@ -429,10 +429,10 @@ def test_dispose_background_transparency():
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
@pytest.mark.parametrize(
 | 
			
		||||
    "mode_strategy, expected_colors",
 | 
			
		||||
    "loading_strategy, expected_colors",
 | 
			
		||||
    (
 | 
			
		||||
        (
 | 
			
		||||
            GifImagePlugin.ModeStrategy.AFTER_FIRST,
 | 
			
		||||
            GifImagePlugin.LoadingStrategy.RGB_AFTER_FIRST,
 | 
			
		||||
            (
 | 
			
		||||
                (2, 1, 2),
 | 
			
		||||
                ((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),
 | 
			
		||||
                (0, 1, 0),
 | 
			
		||||
| 
						 | 
				
			
			@ -449,8 +449,8 @@ def test_dispose_background_transparency():
 | 
			
		|||
        ),
 | 
			
		||||
    ),
 | 
			
		||||
)
 | 
			
		||||
def test_transparent_dispose(mode_strategy, expected_colors):
 | 
			
		||||
    GifImagePlugin.PALETTE_TO_RGB = mode_strategy
 | 
			
		||||
def test_transparent_dispose(loading_strategy, expected_colors):
 | 
			
		||||
    GifImagePlugin.LOADING_STRATEGY = loading_strategy
 | 
			
		||||
    try:
 | 
			
		||||
        with Image.open("Tests/images/transparent_dispose.gif") as img:
 | 
			
		||||
            for frame in range(3):
 | 
			
		||||
| 
						 | 
				
			
			@ -459,7 +459,7 @@ def test_transparent_dispose(mode_strategy, expected_colors):
 | 
			
		|||
                    color = img.getpixel((x, 0))
 | 
			
		||||
                    assert color == expected_colors[frame][x]
 | 
			
		||||
    finally:
 | 
			
		||||
        GifImagePlugin.PALETTE_TO_RGB = GifImagePlugin.ModeStrategy.AFTER_FIRST
 | 
			
		||||
        GifImagePlugin.LOADING_STRATEGY = GifImagePlugin.LoadingStrategy.RGB_AFTER_FIRST
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_dispose_previous():
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -118,7 +118,7 @@ every ``P`` frame is converted to ``RGB`` or ``RGBA`` mode, there is a setting
 | 
			
		|||
available::
 | 
			
		||||
 | 
			
		||||
    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
 | 
			
		||||
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::
 | 
			
		||||
 | 
			
		||||
    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
 | 
			
		||||
:py:attr:`~PIL.Image.Image.info` properties:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -36,16 +36,16 @@ from ._binary import o8
 | 
			
		|||
from ._binary import o16le as o16
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class ModeStrategy(IntEnum):
 | 
			
		||||
class LoadingStrategy(IntEnum):
 | 
			
		||||
    """.. versionadded:: 9.1.0"""
 | 
			
		||||
 | 
			
		||||
    AFTER_FIRST = 0
 | 
			
		||||
    ALWAYS = 1
 | 
			
		||||
    DIFFERENT_PALETTE_ONLY = 2
 | 
			
		||||
    RGB_AFTER_FIRST = 0
 | 
			
		||||
    RGB_AFTER_DIFFERENT_PALETTE_ONLY = 1
 | 
			
		||||
    RGB_ALWAYS = 2
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#: .. versionadded:: 9.1.0
 | 
			
		||||
PALETTE_TO_RGB = ModeStrategy.AFTER_FIRST
 | 
			
		||||
LOADING_STRATEGY = LoadingStrategy.RGB_AFTER_FIRST
 | 
			
		||||
 | 
			
		||||
# --------------------------------------------------------------------
 | 
			
		||||
# Identify/read GIF files
 | 
			
		||||
| 
						 | 
				
			
			@ -292,7 +292,9 @@ class GifImageFile(ImageFile.ImageFile):
 | 
			
		|||
        self._frame_palette = palette or self.global_palette
 | 
			
		||||
        if frame == 0:
 | 
			
		||||
            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:
 | 
			
		||||
                self.mode = "L"
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -304,7 +306,10 @@ class GifImageFile(ImageFile.ImageFile):
 | 
			
		|||
        else:
 | 
			
		||||
            self._frame_transparency = frame_transparency
 | 
			
		||||
            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
 | 
			
		||||
                    if "transparency" in self.info:
 | 
			
		||||
                        self.im.putpalettealpha(self.info["transparency"], 0)
 | 
			
		||||
| 
						 | 
				
			
			@ -412,7 +417,7 @@ class GifImageFile(ImageFile.ImageFile):
 | 
			
		|||
 | 
			
		||||
    def load_end(self):
 | 
			
		||||
        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.im = self.im.convert("RGB", Image.Dither.FLOYDSTEINBERG)
 | 
			
		||||
            return
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user