U
    a¨+d\  ã                   @   s<   d dl Z d dlZd dlmZ ddlmZ G dd„ deƒZdS )é    N©Úimreadé   )Ú	VideoClipc                   @   s   e Zd ZdZddd„ZdS )ÚImageSequenceClipa¸  
    
    A VideoClip made from a series of images.
    

    Parameters
    -----------

    sequence
      Can be one of these:
      - The name of a folder (containing only pictures). The pictures
        will be considered in alphanumerical order.
      - A list of names of image files. In this case you can choose to
        load the pictures in memory pictures 
      - A list of Numpy arrays representing images. In this last case,
        masks are not supported currently.

    fps
      Number of picture frames to read per second. Instead, you can provide
      the duration of each image with durations (see below)

    durations
      List of the duration of each picture.

    with_mask
      Should the alpha layer of PNG images be considered as a mask ?

    ismask
      Will this sequence of pictures be used as an animated mask.

    Notes
    ------

    If your sequence is made of image files, the only image kept in 


    
    NTFc                    sˆ  ˆd kr|d krt dƒ‚tjˆ|d d}tˆtƒrftˆd tƒr`|rZdd„ ˆD ƒ‰d}qdd}q†d}n d}t‡fdd„t ˆ¡D ƒƒ‰tˆd tƒr¤t	ˆd ƒj
}n
ˆd j
}ˆD ],}	|	}
t|	tƒrÌt	|	ƒ}
||
j
kr²td	ƒ‚q²ˆˆ_ˆd k	r ‡fd
d„ˆD ƒ}‡fdd„ttˆƒƒD ƒˆ_ndgtt |¡ƒ ˆ_|ˆ_t|ƒˆ_ˆjˆ_ˆˆ_‡fdd„‰ |rôd ˆ_d ˆ_‡ ‡fdd„}|r`t	ˆjd ƒj
d dkr`tddˆ_d ˆj_d ˆj_‡ ‡fdd„}|ˆj_|dƒj
d d… d d d… ˆj_nl‡ ‡fdd„}|r`ˆjd j
d dkr`tddˆ_‡ ‡fdd„}|ˆj_|dƒj
d d… d d d… ˆj_|ˆ_|dƒj
d d… d d d… ˆ_d S )Nz+Please provide either 'fps' or 'durations'.)ÚismaskTr   c                 S   s   g | ]}t |ƒ‘qS © r   ©Ú.0Úfr   r   úF/tmp/pip-unpacked-wheel-0yp4gafk/moviepy/video/io/ImageSequenceClip.pyÚ
<listcomp>B   s     z.ImageSequenceClip.__init__.<locals>.<listcomp>Fc                    s   g | ]}t j ˆ |¡‘qS r   )ÚosÚpathÚjoinr	   ©Úsequencer   r   r   L   s   ÿzBMoviepy: ImageSequenceClip requires all images to be the same sizec                    s   g | ]}d ˆ  ‘qS ©ç      ð?r   )r
   Úimage©Úfpsr   r   r   `   s     c                    s&   g | ]}d | ˆ  t  t j¡j ‘qS r   )ÚnpZfinfoZfloat32Zeps©r
   Úir   r   r   r   a   s     c                    s"   t ‡‡ fdd„ttˆjƒƒD ƒƒS )Nc                    s   g | ]}ˆ j | ˆkr|‘qS r   )Úimages_startsr   )ÚselfÚtr   r   r   j   s    ÿzHImageSequenceClip.__init__.<locals>.find_image_index.<locals>.<listcomp>)ÚmaxÚrangeÚlenr   ©r   )r   r!   r   Úfind_image_indexi   s    z4ImageSequenceClip.__init__.<locals>.find_image_indexc                    sD   ˆ | ƒ}|ˆj kr>tˆj| ƒd d …d d …d d…f ˆ_|ˆ_ ˆjS ©Né   )Ú	lastindexr   r   Ú	lastimage©r   Úindex©r"   r   r   r   Ú
make_framer   s
    
&z.ImageSequenceClip.__init__.<locals>.make_framer   é   c                    sV   ˆ | ƒ}|ˆj jkrNtˆj| ƒd d …d d …df }| t¡d ˆj _|ˆj _ˆj jS )Nr$   éÿ   )Úmaskr%   r   r   ZastypeÚfloatr&   )r   r(   Úframer)   r   r   Úmask_make_frame‚   s     z3ImageSequenceClip.__init__.<locals>.mask_make_frameéÿÿÿÿc                    s(   ˆ | ƒ}ˆj | d d …d d …d d…f S r#   r   r'   r)   r   r   r*   ’   s    c                    s,   ˆ | ƒ}dˆj | d d …d d …df  d S )Nr   r$   r,   r   r'   r)   r   r   r0   ›   s    )Ú
ValueErrorr   Ú__init__Ú
isinstanceÚlistÚstrÚsortedr   Úlistdirr   ÚshapeÚ	Exceptionr   r   r    r   r   ZcumsumÚ	durationsÚsumÚdurationÚendr   r%   r&   r-   r*   Úsize)r   r   r   r;   Z	with_maskr   Zload_imagesZ	fromfilesr?   r   Zimage1r*   r0   r   )r"   r   r   r   r   r3   2   sj    
ÿ






 
" zImageSequenceClip.__init__)NNTFF)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r3   r   r   r   r   r   	   s
   (    ÿr   )r   Znumpyr   Zimageior   r   r   r   r   r   r   Ú<module>   s   