
    g'                     d    d dl Z d dlmZ d dlZd dlmZ d dlmZ d dl	m
Z
 e G d de
             Zy)    N)	dataclass)Image)Clip)Effectc                       e Zd ZU dZeed<   dZeed<   dZeed<   dZ	e
ed<   d	Zeed
<   d	Zeed<   d	Zeed<   dedefdZy	)Rotatea  
    Rotates the specified clip by ``angle`` degrees (or radians) anticlockwise
    If the angle is not a multiple of 90 (degrees) or ``center``, ``translate``,
    and ``bg_color`` are not ``None``, there will be black borders.
    You can make them transparent with:

    >>> new_clip = clip.with_mask().rotate(72)

    Parameters
    ----------

    clip : VideoClip
    A video clip.

    angle : float
    Either a value or a function angle(t) representing the angle of rotation.

    unit : str, optional
    Unit of parameter `angle` (either "deg" for degrees or "rad" for radians).

    resample : str, optional
    An optional resampling filter. One of "nearest", "bilinear", or "bicubic".

    expand : bool, optional
    If true, expands the output image to make it large enough to hold the
    entire rotated image. If false or omitted, make the output image the same
    size as the input image.

    translate : tuple, optional
    An optional post-rotate translation (a 2-tuple).

    center : tuple, optional
    Optional center of rotation (a 2-tuple). Origin is the upper left corner.

    bg_color : tuple, optional
    An optional color for area outside the rotated image. Only has effect if
    ``expand`` is true.
    angledegunitbicubicresampleTexpandNcenter	translatebg_colorclipreturnc                 :    	 t         j                  t         j                  t         j                  d j                     t         j                  d      r j                  n fd fd}|j                  |dg      S # t
        $ r t        d      w xY w)zApply the effect to the clip.)bilinearnearestr   zE'resample' argument must be either 'bilinear', 'nearest' or 'bicubic'__call__c                     j                   S )N)r	   )tselfs    `/var/www/it7/html/youtubeDownloader/venv/lib/python3.12/site-packages/moviepy/video/fx/Rotate.py<lambda>zRotate.apply.<locals>.<lambda>L   s    $**     c           	      &    |      } | |      }	j                   dk(  rt        j                  |      }|dz  }	j                  s	j                  s݉	j
                  s|dk(  r	j                  r|S |dk(  rI	j                  r=t        |j                        dk(  rddgng d}t        j                  ||      d d d	   S |d
k(  rM	j                  rAt        |j                        dk(  rddgng d}t        j                  ||      d d d d d	f   S |dk(  r	j                  r|d d d	d d d	f   S i }	j
                  	j
                  |d<   	j                  	j                  |d<   	j                  	j                  |d<   |j                  dk(  rd}nd}t        j                   t        j                  t        j                  ||z        j                  t        j                               j"                  |f	j                  d|      |z  S )Nradih  r   Z         )r"   r   r!   )axesi     	fillcolorr   r   float64g     o@)r   r   )r   mathdegreesr   r   r   r   lenshapenp	transposedtypearrayr   	fromarrayastypeuint8rotate)
	get_framer   r	   imr-   pillow_kwargsa	get_angler   r   s
          r   filterzRotate.apply.<locals>.filterN   s   aLE1ByyE!U+SLE;;t~~dmmQJDKKIRKT[[*-bhh-1*<A)I<<;DbDAAsl*-bhh-1*<A)I<<;AttGDDslddDbDj>)M}}(-1]]k*{{&*.++h'~~)-1^^k*
 xx9$ MEOOBHHQV$4$;$;BHH$EFMM&*kkHHU
 r   mask)apply_to)
r   BILINEARNEARESTBICUBICr   KeyError
ValueErrorhasattrr	   	transform)r   r   r9   r8   r   s   `  @@r   applyzRotate.apply<   s    		!NN == == mm	H 4::z*

I,I0	d ~~fx~88y  	W 	s   =B B)__name__
__module____qualname____doc__float__annotations__r   strr   r   boolr   tupler   r   r   rC    r   r   r   r      sa    %N LD#HcFDFEIuHeD9$ D94 D9r   r   )r(   dataclassesr   numpyr,   PILr   moviepy.Clipr   moviepy.Effectr   r   rM   r   r   <module>rS      s5     !    ! t9V t9 t9r   