mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-12 18:26:17 +03:00
Move common conversion in _convert_frame
This commit is contained in:
parent
31d36e6b70
commit
1d5b330758
|
@ -149,6 +149,13 @@ class WebPImageFile(ImageFile.ImageFile):
|
||||||
return self.__logical_frame
|
return self.__logical_frame
|
||||||
|
|
||||||
|
|
||||||
|
def _convert_frame(im: Image.Image) -> Image.Image:
|
||||||
|
# Make sure image mode is supported
|
||||||
|
if im.mode not in ("RGBX", "RGBA", "RGB"):
|
||||||
|
im = im.convert("RGBA" if im.has_transparency_data else "RGB")
|
||||||
|
return im
|
||||||
|
|
||||||
|
|
||||||
def _save_all(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
|
def _save_all(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
|
||||||
encoderinfo = im.encoderinfo.copy()
|
encoderinfo = im.encoderinfo.copy()
|
||||||
append_images = list(encoderinfo.get("append_images", []))
|
append_images = list(encoderinfo.get("append_images", []))
|
||||||
|
@ -240,12 +247,7 @@ def _save_all(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
|
||||||
for idx in range(nfr):
|
for idx in range(nfr):
|
||||||
ims.seek(idx)
|
ims.seek(idx)
|
||||||
|
|
||||||
# Make sure image mode is supported
|
frame = _convert_frame(ims)
|
||||||
frame = ims
|
|
||||||
if frame.mode not in ("RGBX", "RGBA", "RGB"):
|
|
||||||
frame = frame.convert(
|
|
||||||
"RGBA" if frame.has_transparency_data else "RGB"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Append the frame to the animation encoder
|
# Append the frame to the animation encoder
|
||||||
enc.add(
|
enc.add(
|
||||||
|
@ -293,8 +295,7 @@ def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
|
||||||
method = im.encoderinfo.get("method", 4)
|
method = im.encoderinfo.get("method", 4)
|
||||||
exact = 1 if im.encoderinfo.get("exact") else 0
|
exact = 1 if im.encoderinfo.get("exact") else 0
|
||||||
|
|
||||||
if im.mode not in ("RGBX", "RGBA", "RGB"):
|
im = _convert_frame(im)
|
||||||
im = im.convert("RGBA" if im.has_transparency_data else "RGB")
|
|
||||||
|
|
||||||
data = _webp.WebPEncode(
|
data = _webp.WebPEncode(
|
||||||
im.getim(),
|
im.getim(),
|
||||||
|
|
Loading…
Reference in New Issue
Block a user