
    W|h_                     d    S SK r S SKJr  S SKJr  S SKrS SKJr  S SK	J
r
  \ " S S\
5      5       rg)    N)	dataclass)Union)Image)Effectc                   j    \ rS rSr% SrSr\\\\	4   \
S'   Sr\\
S'   Sr\\
S'   Sr\\
S'   S	 rS
 rSrg)Resize   a  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                     [        [        [        U5      5      n[        R                  " U5      nUR                  U[        R                  R                  5      n[        R                  " U5      $ )zResize the image using PIL.)
listmapintr   	fromarrayresize
ResamplingLANCZOSnparray)selfpicr
   pil_imgresized_pils        Q/home/james-whalen/.local/lib/python3.13/site-packages/moviepy/video/fx/Resize.pyresizerResize.resizer0   sL    C*+//#&nnXu/?/?/G/GHxx$$    c                   ^ ^^^	^
 UR                   u  m
mT R                  b  UU
4S jm	[        T R                  S5      (       a  U U	4S jmUR                  (       a  UU 4S jnOUU 4S jnUR	                  UST R
                  (       a  S/O/ S9nT R
                  (       a@  UR                  b3  UR                  R                  [        T R                  S	S
9/5      Ul        U$ T	" T R                  5      T l        OT R                  ba  [        T R                  S5      (       a"  UU 4S jnUR                  [        U5      /5      $ T
T R                  -  T-  T R                  /T l        OyT R                  ba  [        T R                  S5      (       a"  U U
4S jnUR                  [        U5      /5      $ T R                  TT R                  -  T
-  /T l        O[        S5      eUR                  (       a  U 4S jnOU 4S jnUR                  U5      nT R
                  (       a@  UR                  b3  UR                  R                  [        T R                  S	S
9/5      Ul        U$ )zApply the effect to the clip.c                 Z   > [        U [        R                  5      (       a
  U T-  U T-  /$ U $ )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_size(Resize.apply.<locals>.translate_new_size=   s/    
 i88%M9q=99$$r   __call__c                 2   > T" TR                  U 5      5      $ )Nr
   )tr   r(   s    r   get_new_size"Resize.apply.<locals>.get_new_sizeJ   s    -dmmA.>??r   c                 j   > TR                  SU " U5      -  R                  S5      T" U5      5      S-  $ )N   uint8     o@r   astype	get_framer-   r.   r   s     r   filterResize.apply.<locals>.filterO   s<     LL!$y|!3 ; ;G DlSTo $$r   c                 ^   > TR                  U " U5      R                  S5      T" U5      5      $ Nr2   r4   r6   s     r   r8   r9   Y   s,    #||%aL//8,q/  r   Tmask)keep_durationapply_toF)r   c                 D   > S[        TR                  U 5      5      -  T-  $ N      ?)r   r   )r-   r&   r   s    r   funcResize.apply.<locals>.funcp   s     T[[^!44q88r   c                 2   > STR                  U 5      -  T-  $ r@   )r   )r-   r   r'   s    r   rB   rC   {   s    A.22r   z9You must provide either 'new_size' or 'height' or 'width'c                 l   > STR                  SU -  R                  S5      TR                  5      -  S-  $ )NrA   r1   r2   r3   r   r5   r
   r   r   s    r   image_filter"Resize.apply.<locals>.image_filter   s:    llC#I#5#5g#>NOr   c                 Z   > TR                  U R                  S5      TR                  5      $ r;   rF   rG   s    r   rH   rI      s!    ||CJJw$7GGr   )sizer
   hasattris_mask	transformr   r<   with_effectsr   r   r   
ValueErrorimage_transform)r   clipr8   newcliprB   rH   new_clipr.   r&   r(   r'   s   `      @@@@r   applyResize.apply7   s   yy1==$% t}}j11@ <<
 .."&*.*<*<vh" ) 
 %%$))*?#'99#9#9UCD$GL  !34== A[[$t{{J//9 ((&,88 "#T[[1!4dkk BZZ#tzz:..3 ((&,88 "&Q^a-? @K  <<H ''5$))"7 II22U;<HM r   r,   )__name__
__module____qualname____firstlineno____doc__r
   r   tuplefloatcallable__annotations__r   r   r   r   boolr   rU   __static_attributes__ r   r   r   r      sH    < /3HeE5(*+2FCE3M4%gr   r   )r#   dataclassesr   typingr   numpyr   PILr   moviepy.Effectr   r   rb   r   r   <module>rh      s5     !    ! RV R Rr   