
    -i_                     r    d dl Z d dlmZ d dlmZ d dlZd dlmZ d dl	m
Z
 e G d de
                      ZdS )    N)	dataclass)Union)Image)Effectc                   j    e Zd ZU dZdZeeeef         e	d<   dZ
ee	d<   dZee	d<   dZee	d<   d Zd	 ZdS )
Resizea  Effect returning a video clip that is a resized version of the clip.

    Parameters
    ----------

    new_size : tuple or float or function, optional
        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.

    height : int, optional
        Height of the new clip in pixels. The width is then computed so
        that the width/height ratio is conserved.

    width : int, optional
        Width of the new clip in pixels. The height is then computed so
        that the width/height ratio is conserved.

    Examples
    --------

    .. code:: python

        clip.with_effects([vfx.Resize((460,720))]) # New resolution: (460,720)
        clip.with_effects([vfx.Resize(0.6)]) # width and height multiplied by 0.6
        clip.with_effects([vfx.Resize(width=800)]) # height computed automatically.
        clip.with_effects([vfx.Resize(lambda t : 1+0.02*t)]) # slow clip swelling
    Nnew_sizeheightwidthTapply_to_maskc                     t          t          t          |                    }t          j        |          }|                    |t          j        j                  }t          j	        |          S )zResize the image using PIL.)
listmapintr   	fromarrayresize
ResamplingLANCZOSnparray)selfpicr	   pil_imgresized_pils        U/var/www/html/speakWrite/venv/lib/python3.11/site-packages/moviepy/video/fx/Resize.pyresizerzResize.resizer0   sQ    C**++/#&&nnXu/?/GHHx$$$    c                     	
 |j         \  
 j        
fd	t           j        d          r 	fd|j        r fd}n fd}|                    |d j        rdgng 	          } j        r;|j        4|j                            t           j        d
          g          |_        |S  	 j                   _        n͉ j	        Xt           j	        d          r) fd}|                    t          |          g          S 
 j	        z  z   j	        g _        nn j
        Xt           j
        d          r) 
fd}|                    t          |          g          S  j
         j
        z  
z  g _        nt          d          |j        r fd}n fd}|                    |          } j        r;|j        4|j                            t           j        d
          g          |_        |S )zApply the effect to the clip.Nc                 P    t          | t          j                  r
| z  | z  gS | S )zReturns a [w, h] pair from `new_size_`. If `new_size_` is a
                scalar, then work out the correct pair using the clip's size.
                Otherwise just return `new_size_`
                )
isinstancenumbersNumber)	new_size_hws    r   translate_new_sizez(Resize.apply.<locals>.translate_new_size=   s2    
 i88 %%M9q=99$$r   __call__c                 @                          |                     S )N)r	   )tr   r&   s    r   get_new_sizez"Resize.apply.<locals>.get_new_sizeJ   s     --dmmA.>.>???r   c                                          d | |          z                      d           |                    dz  S )N   uint8     o@r   astype	get_framer)   r*   r   s     r   filterzResize.apply.<locals>.filterO   sL     LL!$yy||!3 ; ;G D DllSToo  $$r   c                 z                          | |                              d           |                    S Nr-   r/   r1   s     r   r3   zResize.apply.<locals>.filterY   s<    #||%IaLL//88,,q//    r   Tmask)keep_durationapply_toF)r   c                 T    dt                              |                     z  z  S N      ?)r   r
   )r)   r$   r   s    r   funczResize.apply.<locals>.funcp   s%    T[[^^!4!44q88r   c                 :    d                     |           z  z  S r:   )r   )r)   r   r%   s    r   r<   zResize.apply.<locals>.func{   s    A.22r   z9You must provide either 'new_size' or 'height' or 'width'c                 r    d                     d| z                      d          j                  z  dz  S )Nr;   r,   r-   r.   r   r0   r	   r   r   s    r   image_filterz"Resize.apply.<locals>.image_filter   s>    llC#I#5#5g#>#>NNOr   c                 `                         |                     d          j                  S r5   r?   r@   s    r   rA   z"Resize.apply.<locals>.image_filter   s%    ||CJJw$7$7GGGr   )sizer	   hasattris_mask	transformr   r6   with_effectsr   r
   r   
ValueErrorimage_transform)r   clipr3   newclipr<   rA   new_clipr*   r$   r&   r%   s   `      @@@@r   applyzResize.apply7   s   y1=$% % % % % % t}j11 $B@ @ @ @ @ @ <            
 .."&*.*<Dvhh" )  
 % $)*?#'9#9#9UCCCD$ $GL  !3 24= A A[$t{J// C9 9 9 9 9 9 ((&,,888 "#T[1!4dk BZ#tz:.. A3 3 3 3 3 3 ((&,,888 "&Q^a-? @K   < 	H     H H H H H ''55 	$)"7 I22U;;;< HM r   )__name__
__module____qualname____doc__r	   r   tuplefloatcallable__annotations__r
   r   r   r   boolr   rM    r   r   r   r      s          < /3HeE5(*+222FCE3M4% % %g g g g gr   r   )r!   dataclassesr   typingr   numpyr   PILr   moviepy.Effectr   r   rW   r   r   <module>r]      s     ! ! ! ! ! !                 ! ! ! ! ! ! R R R R RV R R R R Rr   