o
    sÇh˜  ã                   @  sD   d dl mZ d dlmZ ddlmZ G dd„ dƒZ	dddd„ZdS )é    )Úannotations)ÚCallableé   )ÚImagec                   @  s8   e Zd ZdZddd„Zdd
d„Zddd„Z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.
    ÚimúImage.ImageÚreturnÚNonec                 C  s0   t |dƒsd}t|ƒ‚|| _t| jddƒ| _d S )NÚseekzim must have seek methodÚ
_min_framer   )ÚhasattrÚAttributeErrorr   ÚgetattrÚposition)Úselfr   Úmsg© r   úe/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/PIL/ImageSequence.pyÚ__init__$   s
   
zIterator.__init__ÚixÚintc              
   C  s<   z
| j  |¡ | j W S  ty } zd}t|ƒ|‚d }~ww )Núend of sequence)r   r   ÚEOFErrorÚ
IndexError)r   r   Úer   r   r   r   Ú__getitem__+   s   
€þzIterator.__getitem__c                 C  s   | S ©Nr   )r   r   r   r   Ú__iter__3   s   zIterator.__iter__c              
   C  sL   z| j  | j¡ |  jd7  _| j W S  ty% } zd}t|ƒ|‚d }~ww )Nr   r   )r   r   r   r   ÚStopIteration)r   r   r   r   r   r   Ú__next__6   s   
€þzIterator.__next__N)r   r   r	   r
   )r   r   r	   r   )r	   r   )r	   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r    r   r   r   r   r      s    


r   Nr   úImage.Image | list[Image.Image]Úfuncú+Callable[[Image.Image], Image.Image] | Noner	   úlist[Image.Image]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)Ú.0Úim_framer   r   r   Ú
<listcomp>S   ó    zall_frames.<locals>.<listcomp>c                   s   g | ]}ˆ |ƒ‘qS r   r   )r*   r   ©r&   r   r   r,   V   r-   )Ú
isinstanceÚlistÚtellr   r   )r   r&   ÚimsÚ
imSequenceÚcurrentr   r.   r   Ú
all_frames@   s   
r5   r   )r   r%   r&   r'   r	   r(   )Ú
__future__r   Útypingr   Ú r   r   r5   r   r   r   r   Ú<module>   s   *þ