U
    [OhN                     @   s   d Z z"ddlZddlZdd Zde_W n ek
r   z&ddlmZ ddlZdd Zde_W nL ek
r   zdd	l	m
Z
 d
d Zde_W n ek
r   dZ Y nX Y nX Y nX ddlmZ dddZe sejZdddZee_dS )T    Nc                 C   s`   t |d t |d  }}|| jd ks6|| jd kr>tj}ntj}tj| d
 ||f|dS )Nr      uint8)interpolation)intshapecv2ZINTER_LINEARZ
INTER_AREAresizeastype)picnewsizelxZlyr    r   I/var/www/html/venv/lib/python3.8/site-packages/moviepy/video/fx/resize.pyresizer   s    r   r   )Imagec                 C   s~   t tt|d d d }| j}t|dkrB|d |d |d f}n|d |d f}t| }||d d d tj}t	
|S )N   r   r      )listmapr   r   lenr   Z	fromarrayr   Z	ANTIALIASnparray)r
   r   r   ZnewshapeZpilimZresized_pilr   r   r   r      s    
PIL)imresizec                 C   s   t | tt|d d d S )Nr   )r   r   r   )r
   r   r   r   r   <lambda>0   s   r   ZScipyFapply_to_maskc                    sF  | j \ dk	r| fddtdrrfdd| jrLfdd}nfdd}| j|d	|rjd
gng dS nvdk	rtdr fdd}t| |S    gn:dk	rtdrfdd}t| |S    g| jrfdd}nfdd}| |}|rB| jdk	rBt| jdd|_|S )a   
    Returns a video clip that is a resized version of the clip.
    
    Parameters
    ------------
    
    newsize:
      Can be either 
        - ``(width,height)`` in pixels or a float representing
        - A scaling factor, like 0.5
        - A function of time returning one of these.
            
    width:
      width of the new clip in pixel. The height is then computed so
      that the width/height ratio is conserved. 
            
    height:
      height of the new clip in pixel. The width is then computed so
      that the width/height ratio is conserved.
    
    Examples
    ----------
             
    >>> myClip.resize( (460,720) ) # New resolution: (460,720)
    >>> myClip.resize(0.6) # width and heigth multiplied by 0.6
    >>> myClip.resize(width=800) # height computed automatically.
    >>> myClip.resize(lambda t : 1+0.02*t) # slow swelling of the clip
    
    Nc                    s&   t | ttfr|  |   gS | S d S N)
isinstancer   float)ns)hwr   r   trans_newsize`   s    zresize.<locals>.trans_newsize__call__c                    s    | S r   r   t)r   r$   r   r   r   i       zresize.<locals>.<lambda>c                    s$   dt d| | d | d S )N      ?   r   r   r	   Zgfr'   newsize2r   r   r   m   s   c                    s   t | |d |S Nr   r+   r,   r-   r   r   r   q   s   Tmask)Zkeep_durationZapply_toc                    s   dt |    S Nr)   )r   r&   )r"   heightr   r   r      r(   c                    s   d|    S r1   r   r&   )r#   widthr   r   r      r(   c                    s   dt d|  d  d S )Nr)   r*   r   g     o@r+   r
   r   r   r   r      r(   c                    s   t | d S r/   r+   r4   r5   r   r   r      r(   Fr   )sizehasattrZismaskflr   Zfl_imager0   )clipr   r2   r3   r   Zfunr8   Znewclipr   )r"   r2   r   r.   r$   r#   r3   r   r   =   s:    







r   c                 C   s   t dd S )Nz&fx resize needs OpenCV or Scipy or PIL)ImportError)r9   r   r2   r3   r   r   r   r      s    )NNNT)NNN)Zresize_possibler   numpyr   r   originr:   r   r   Z
scipy.miscr   Zmoviepy.decoratorsr   r   __doc__docr   r   r   r   <module>   s0   



c
