
    g
                     \    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)    )	dataclassN)Clip)Effect)	ImageClipc                       e Zd ZU dZ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fdZdedefdZy)MarginaK  Draws an external margin all around the frame.

    Parameters
    ----------

    margin_size : int, optional
      If not ``None``, then the new clip has a margin size of
      size ``margin_size`` in pixels on the left, right, top, and bottom.

    left : int, optional
      If ``margin_size=None``, margin size for the new clip in left direction.

    right : int, optional
      If ``margin_size=None``, margin size for the new clip in right direction.

    top : int, optional
      If ``margin_size=None``, margin size for the new clip in top direction.

    bottom : int, optional
      If ``margin_size=None``, margin size for the new clip in bottom direction.

    color : tuple, optional
      Color of the margin.

    opacity : float, optional
      Opacity of the margin. Setting this value to 0 yields transparent margins.
    Nmargin_sizer   leftrighttopbottom)r   r   r   color      ?opacityclipc                 F     j                   dk7  r(j                  j                  sj                          j                  & j                  x _        x _        x _         _         fdt        t              r j                  j                        j                   j                   j                  j                  z    j
                   j
                  j                  z   f<   j                  fd      S  fd}j                  |      S )zAdd margins to the clip.r   c                    | j                   z   j                  z   |j                  z   j                  z   }}j                  rJ||f}t        j                  j                  ||f      j                  t              j                  |      }|S ||df}t        j                  j                  ||f      j                  |      }|S )N   )r
   r   r   r   is_masknptiler   astypefloatreshaper   )whnew_wnew_hshapebgr   selfs         `/var/www/it7/html/youtubeDownloader/venv/lib/python3.12/site-packages/moviepy/video/fx/Margin.pymake_bgz"Margin.add_margin.<locals>.make_bg8   s    tyy=4::5q488|dkk7Q5E||WWT\\E5>:AA%HPPQVW I q)WWTZZ%8@@GI    c                     S )N )picims    r"   <lambda>z#Margin.add_margin.<locals>.<lambda>E   s    B r$   c                      | |      }|j                   d d \  }} ||      }||j                  j                  |z   j                  j                  |z   f<   |S )N   )r   r   r
   )	get_frametr'   r   r   r(   r#   r!   s         r"   filterz!Margin.add_margin.<locals>.filterI   s`    lyy!}1Q]IL488dhhl*DII		A,EEF	r$   )r   maskr   	with_maskr	   r
   r   r   r   
isinstancer   r   r   imgimage_transform	transform)r!   r   r.   r(   r#   s   `` @@r"   
add_marginzMargin.add_margin0   s    LLCdii&7$,,>>#D'>B>N>NNDIN
NTX	 dI&(BOSxxBtxx$((TVV++TYYTVV9K-KKL''77 >>&))r$   returnc                     | j                  |      }|j                  r!| j                  |j                        |_        |S )zApply the effect to the clip.)r   )r5   r/   )r!   r   s     r"   applyzMargin.applyR   s6     D)99TYY7DIr$   )__name__
__module____qualname____doc__r	   int__annotations__r
   r   r   r   r   tupler   r   r   r5   r8   r&   r$   r"   r   r   
   sk    8 KD#ME3NCLFCOE5GU *t  *D$ 4 r$   r   )dataclassesr   numpyr   moviepy.Clipr   moviepy.Effectr   moviepy.video.VideoClipr   r   r&   r$   r"   <module>rE      s2    !   ! - OV O Or$   