Skip to content

Commit

Permalink
[lib] Changed ImageIterator's caching criteria
Browse files Browse the repository at this point in the history
- Change: `ImageIterator` no longer uses frame count to determine frame caching status.
  - This is due to the bad performance of `PIL.GifImagePlugin.GifImageFile.nframes` with large (high frame-count) GIFs.

NOTE: This change is temporary and will be reverted as soon as a Pillow version including the improvements in python-pillow/Pillow#6077 is released.
  • Loading branch information
AnonymouX47 committed Mar 10, 2022
1 parent f6c0555 commit ea6f74b
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions term_img/image.py
Expand Up @@ -1354,12 +1354,8 @@ class ImageIterator:
cached: Determines if the :term:`rendered` frames will be cached (for speed up
of subsequent renders) or not.
- If a ``bool``, it directly sets if the frames will be cached or not.
- If an ``int``, caching is enabled only if the number of frames in the image
is less than or equal to the given number.
- If *repeat* equals ``1``, caching is disabled.
NOTE:
- If *repeat* equals ``1``, caching is disabled.
- The iterator has immediate response to changes in the image
:term:`render size` and :term:`scale`.
- If the :term:`render size` is :ref:`unset <unset-size>`, it's automatically
Expand All @@ -1373,7 +1369,7 @@ def __init__(
image: TermImage,
repeat: int = -1,
format: str = "",
cached: Union[bool, int] = 100,
cached: bool = False,
):
if not isinstance(image, TermImage):
raise TypeError(f"Invalid type for 'image' (got: {type(image).__name__})")
Expand All @@ -1391,15 +1387,13 @@ def __init__(
)
*fmt, alpha = image._check_format_spec(format)

if not isinstance(cached, (bool, int)):
if not isinstance(cached, bool):
raise TypeError(f"Invalid type for 'cached' (got: {type(cached).__name__})")

self._image = image
self._repeat = repeat
self._format = format
self._cached = (
cached if isinstance(cached, bool) else image.n_frames <= cached
) and repeat != 1
self._cached = cached and repeat != 1
self._animator = image._renderer(self._animate, alpha, fmt, check_size=False)

def __iter__(self):
Expand Down

0 comments on commit ea6f74b

Please sign in to comment.