
    :h                    R    d dl mZ d dlmZ ddlmZ  G d d      Z	 d		 	 	 	 	 d
dZy)    )annotations)Callable   )Imagec                  0    e Zd ZdZddZddZd	dZd
dZy)Iteratora-  
    This class implements an iterator object that can be used to loop
    over an image sequence.

    You can use the ``[]`` operator to access elements by index. This operator
    will raise an :py:exc:`IndexError` if you try to access a nonexistent
    frame.

    :param im: An image object.
    c                |    t        |d      sd}t        |      || _        t        | j                  dd      | _        y )Nseekzim must have seek method
_min_framer   )hasattrAttributeErrorimgetattrposition)selfr   msgs      O/var/www/urcfiles/bundle/venv/lib/python3.12/site-packages/PIL/ImageSequence.py__init__zIterator.__init__$   s7    r6",C %%q9    c                    	 | j                   j                  |       | j                   S # t        $ r}d}t        |      |d }~ww xY w)Nend of sequence)r   r
   EOFError
IndexError)r   ixer   s       r   __getitem__zIterator.__getitem__+   sA    	)GGLL77N 	)#CS/q(	)s   &) 	AA  Ac                    | S N )r   s    r   __iter__zIterator.__iter__3   s    r   c                    	 | j                   j                  | j                         | xj                  dz  c_        | j                   S # t        $ r}d}t	        |      |d }~ww xY w)Nr   r   )r   r
   r   r   StopIteration)r   r   r   s      r   __next__zIterator.__next__6   sT    	,GGLL'MMQM77N 	,#C$!+	,s   AA 	A$AA$N)r   Image.ImagereturnNone)r   intr%   r$   )r%   r   )r%   r$   )__name__
__module____qualname____doc__r   r   r    r#   r   r   r   r   r      s    	:),r   r   Nc                   t        | t              s| g} g }| D ]M  }|j                         }|t        |      D cg c]  }|j	                          c}z  }|j                  |       O |r|D  cg c]
  }  ||        c} S |S c c}w c c} w )a  
    Applies a given function to all frames in an image or a list of images.
    The frames are returned as a list of separate images.

    :param im: An image, or a list of images.
    :param func: The function to apply to all of the image frames.
    :returns: A list of images.
    )
isinstancelisttellr   copyr
   )r   funcims
imSequencecurrentim_frames         r   
all_framesr6   @   s     b$T
C
//#0DE0DH0DEE   (,s#sDHs#44 F $s   B.Br   )r   zImage.Image | list[Image.Image]r1   z+Callable[[Image.Image], Image.Image] | Noner%   zlist[Image.Image])
__future__r   typingr    r   r   r6   r   r   r   <module>r:      s?   " #  %, %,T 9=5'5
55 5r   