o
    Y+i¾  ã                   @   s6   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u rˆjsˆ ¡ ‰|dur| ‰ ‰ ‰‰ ‡ ‡‡‡‡‡‡fdd„‰tˆtƒrNˆˆjˆjƒ‰ˆjˆˆˆˆj …ˆˆˆj …f< ˆ ‡fdd„¡S ‡‡‡fd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                    sl   | ˆ ˆ |ˆ ˆ  }}ˆj r$||f}t ˆ||f¡ t¡ |¡}|S ||df}t ˆ||f¡ |¡}|S )Né   )ÚismaskÚnpÚtileÚastypeÚfloatÚreshape)ÚwÚhÚnew_wÚnew_hÚshapeÚbg)ÚbottomÚclipÚcolorÚleftÚopacityÚrightÚtop© úJ/var/www/html/venv/lib/python3.10/site-packages/moviepy/video/fx/margin.pyÚmake_bg    s   þ
þzmargin.<locals>.make_bgc                    s   ˆ S )Nr   )Úpic)Úimr   r   Ú<lambda>0   s    zmargin.<locals>.<lambda>c                    sD   | |ƒ}|j d d… \}}ˆ||ƒ}||ˆˆ| …ˆ ˆ | …f< |S )Né   )r   )ÚgfÚtr   r   r   r   )r   r   r   r   r   Úfl4   s
   
zmargin.<locals>.fl)
Úmaskr   Úadd_maskÚ
isinstancer   r   r   ÚimgÚ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   )Únumpyr   Úmoviepy.decoratorsr   Úmoviepy.video.VideoClipr   r*   r   r   r   r   Ú<module>   s    ÿ