U
    ڲg                     @  sJ   d dl mZ d dlmZ ddlmZ G dd dZddd	d
dddZdS )    )annotations)Callable   )Imagec                   @  sJ   e Zd ZdZddddZddddd	Zd d
ddZdd
ddZdS )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.
    zImage.Image)imc                 C  s0   t |dsd}t||| _t| jdd| _d S )Nseekzim must have seek methodZ
_min_framer   )hasattrAttributeErrorr   getattrposition)selfr   msg r   5/tmp/pip-unpacked-wheel-xela2va7/PIL/ImageSequence.py__init__$   s
    
zIterator.__init__int)ixreturnc              
   C  sJ   z| j | | j W S  tk
rD } zd}t||W 5 d }~X Y nX d S )Nend of sequence)r   r   EOFError
IndexError)r   r   er   r   r   r   __getitem__+   s    zIterator.__getitem__)r   c                 C  s   | S )Nr   )r   r   r   r   __iter__3   s    zIterator.__iter__c              
   C  sZ   z$| j | j |  jd7  _| j W S  tk
rT } zd}t||W 5 d }~X Y nX d S )Nr   r   )r   r   r   r   StopIteration)r   r   r   r   r   r   __next__6   s    zIterator.__next__N)__name__
__module____qualname____doc__r   r   r   r   r   r   r   r   r      s
   r   NzImage.Image | list[Image.Image]z+Callable[[Image.Image], Image.Image] | Nonezlist[Image.Image])r   funcr   c                   s`   t | ts| g} g }| D ],}| }|dd t|D 7 }|| q r\ fdd|D S |S )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.
    c                 S  s   g | ]}|  qS r   )copy).0Zim_framer   r   r   
<listcomp>S   s     zall_frames.<locals>.<listcomp>c                   s   g | ]} |qS r   r   )r#   r   r!   r   r   r$   V   s     )
isinstancelisttellr   r   )r   r!   ZimsZ
imSequencecurrentr   r%   r   
all_frames@   s    
r*   )N)
__future__r   typingr    r   r   r*   r   r   r   r   <module>   s
   * 