Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 17 additions & 23 deletions src/PIL/WebPImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,26 @@ def _open(self) -> None:
self._decoder = _webp.WebPAnimDecoder(self.fp.read())

# Get info from decoder
self._size, loop_count, bgcolor, frame_count, mode = self._decoder.get_info()
self.info["loop"] = loop_count
bg_a, bg_r, bg_g, bg_b = (
(bgcolor >> 24) & 0xFF,
(bgcolor >> 16) & 0xFF,
(bgcolor >> 8) & 0xFF,
bgcolor & 0xFF,
self._size, self.info["loop"], bgcolor, self.n_frames, self.rawmode = (
self._decoder.get_info()
)
self.info["background"] = (
(bgcolor >> 16) & 0xFF, # R
(bgcolor >> 8) & 0xFF, # G
bgcolor & 0xFF, # B
(bgcolor >> 24) & 0xFF, # A
)
self.info["background"] = (bg_r, bg_g, bg_b, bg_a)
self.n_frames = frame_count
self.is_animated = self.n_frames > 1
self._mode = "RGB" if mode == "RGBX" else mode
self.rawmode = mode
self._mode = "RGB" if self.rawmode == "RGBX" else self.rawmode

# Attempt to read ICC / EXIF / XMP chunks from file
icc_profile = self._decoder.get_chunk("ICCP")
exif = self._decoder.get_chunk("EXIF")
xmp = self._decoder.get_chunk("XMP ")
if icc_profile:
self.info["icc_profile"] = icc_profile
if exif:
self.info["exif"] = exif
if xmp:
self.info["xmp"] = xmp
for key, chunk_name in {
"icc_profile": "ICCP",
"exif": "EXIF",
"xmp": "XMP ",
}.items():
if value := self._decoder.get_chunk(chunk_name):
self.info[key] = value

# Initialize seek state
self._reset(reset=False)
Expand Down Expand Up @@ -129,9 +125,7 @@ def load(self) -> Image.core.PixelAccess | None:
self._seek(self.__logical_frame)

# We need to load the image data for this frame
data, timestamp, duration = self._get_next()
self.info["timestamp"] = timestamp
self.info["duration"] = duration
data, self.info["timestamp"], self.info["duration"] = self._get_next()
self.__loaded = self.__logical_frame

# Set tile
Expand Down
Loading