U
    a¨+d¾  ã                   @   s2   d dl Zd dlmZ d dlmZ eddd„ƒZdS )	é    N)Úapply_to_mask)Ú	ImageClip©r   r   r   ç      ð?c           	         sº   ˆdkr ˆj dkr ˆjs ˆ ¡ ‰|dk	r8| ‰ ‰ ‰‰ ‡ ‡‡‡‡‡‡fdd„‰tˆtƒrœˆˆjˆjƒ‰ˆjˆˆˆˆj …ˆˆˆj …f< ˆ ‡fdd„¡S ‡‡‡fdd„}ˆ 	|¡S dS )	aÛ  
    Draws an external margin all around the frame.
    
    :param mar: if not ``None``, then the new clip has a margin of
        size ``mar`` in pixels on the left, right, top, and bottom.
        
    :param left, right, top, bottom: width of the margin in pixel
        in these directions.
        
    :param color: color of the margin.
    
    :param mask_margin: value of the mask on the margin. Setting
        this value to 0 yields transparent margins.
    
    r   Nc                    sj   | ˆ ˆ |ˆ ˆ   }}ˆj rF||f}t ˆ||f¡ t¡ |¡}n ||df}t ˆ||f¡ |¡}|S )Né   )ÚismaskÚnpZtileZastypeÚfloatZreshape)ÚwÚhZnew_wZnew_hÚshapeÚbg)ÚbottomÚclipÚcolorÚleftÚopacityÚrightÚtop© ú;/tmp/pip-unpacked-wheel-0yp4gafk/moviepy/video/fx/margin.pyÚmake_bg    s    ÿþ
zmargin.<locals>.make_bgc                    s   ˆ S )Nr   )Úpic)Úimr   r   Ú<lambda>0   ó    zmargin.<locals>.<lambda>c                    sD   | |ƒ}|j d d… \}}ˆ||ƒ}||ˆˆ| …ˆ ˆ | …f< |S )Né   )r   )ZgfÚtr   r   r
   r   )r   r   r   r   r   Úfl4   s
    
zmargin.<locals>.fl)
Úmaskr   Zadd_maskÚ
isinstancer   r
   r   ÚimgZfl_imager   )	r   Úmarr   r   r   r   r   r   r   r   )	r   r   r   r   r   r   r   r   r   r   Úmargin   s    
"r#   )Nr   r   r   r   r   r   )Znumpyr   Zmoviepy.decoratorsr   Zmoviepy.video.VideoClipr   r#   r   r   r   r   Ú<module>   s         ÿ