
    i8"                     8    d Z ddlZddZ	 	 ddZ	 	 d	dZd
dZy)z
This module deals with making images (np arrays). It provides drawing
methods that are difficult to do with the existing Python libraries.
    Nc                 x   |ddg}|\  }}t        d|       }t        d|       }| j                  dd \  }	}
|j                  dd \  }}t        |||
z         }t        |||	z         }t        |
||z
        }t        |	||z
        }t        d|      }t        d|      }||k\  s||k\  r|S | ||||f   }|}|||||||f<   na|||||f   }t        | j                        dk(  rt	        j
                  d|gz        }|||||f   }d|z  |z  d|z
  |z  z   |||||f<   |s|j                  d      S |S )z Blit an image over another.
    
    Blits ``im1`` on ``im2`` as position ``pos=(x,y)``, using the
    ``mask`` if provided. If ``im1`` and ``im2`` are mask pictures
    (2D float arrays) then ``ismask`` must be ``True``.
    Nr               ?uint8)maxshapeminlennpdstackastype)im1im2posmaskismaskxpypx1y1h1w1h2w2xp2yp2x2y2xp1yp1blittednew_im2blit_regions                         Y/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/moviepy/video/tools/drawing.pyblitr&   	   s    {!f FB	QB	QBYYr]FBYYr]FB
b"r'
C
b"r'
C	Rb	B	Rb	B
a*C
a*Cs
s

"R%B,GdG|$+CS !BrE2b5L!syy>Q99Q$Z(Dc#gs3w./%(4Z'%9S4Z;<V%VCS !+17>>'"??    c	                 r   | \  }	}
t        j                  |      j                  t              }t        j                  |      j                  t              }|dk(  r|+t        j                  |      t        j                  |      z
  }|| fD cg c]  }t	        | ||ddd|       c}\  }}t        j
                  ||      }|j                  dkD  rt        j                  d|gz        }||z  d|z
  |z  z   S t        j                  |ddd	         j                  t              }|#|r!t        j                  |ddd	         }||z
  }n t        j                  |ddd	         }||z   }|rt         j                  j                  |      }t        j                  t        j                  t        |	      t        |
            ddd	         j                  t              }|dk(  r|d
z  z  }|||z  z   }||z
  j                  |      d|z
  z  }t        j                  dt        j
                  d|            }|j                  dkD  rt        j                  d|gz        }||z  d|z
  |z  z   S |dk(  r|}|dk(  rt        j                  |
|	f      }nft        j                  ||z
  d
z  j!                  d
            ||z  z
  }|d|z
  |z  z  }t        j                  dt        j
                  d|            }|j                  dkD  rt        j                  d|gz        }d|z
  |z  ||z  z   S yc c}w )aa  Draw a linear, bilinear, or radial gradient.
    
    The result is a picture of size ``size``, whose color varies
    gradually from color `col1` in position ``p1`` to color ``col2``
    in position ``p2``.
    
    If it is a RGB picture the result must be transformed into
    a 'uint8' array to be displayed normally:
     
     
    Parameters
    ------------      
    
    size
        Size (width, height) in pixels of the final picture/array.
    
    p1, p2
        Coordinates (x,y) in pixels of the limit point for ``col1``
        and ``col2``. The color 'before' ``p1`` is ``col1`` and it
        gradually changes in the direction of ``p2`` until it is ``col2``
        when it reaches ``p2``.
    
    vector
        A vector [x,y] in pixels that can be provided instead of ``p2``.
        ``p2`` is then defined as (p1 + vector).
    
    col1, col2
        Either floats between 0 and 1 (for gradients used in masks)
        or [R,G,B] arrays (for colored gradients).
                         
    shape
        'linear', 'bilinear', or 'circular'.
        In a linear gradient the color varies in one direction,
        from point ``p1`` to point ``p2``.
        In a bilinear gradient it also varies symetrically form ``p1``
        in the other direction.
        In a circular gradient it goes from ``col1`` to ``col2`` in all
        directions.
    
    offset
        Real number between 0 and 1 indicating the fraction of the vector
        at which the gradient actually starts. For instance if ``offset``
        is 0.9 in a gradient going from p1 to p2, then the gradient will
        only occur near p2 (before that everything is of color ``col1``)
        If the offset is 0.9 in a radial gradient, the gradient will
        occur in the region located between 90% and 100% of the radius,
        this creates a blurry disc of radius d(p1,p2).  
    
    Returns
    --------
    
    image
        An Numpy array of dimensions (W,H,ncolors) of type float
        representing the image of the gradient.
        
    
    Examples
    ---------
    
    >>> grad = color_gradient(blabla).astype('uint8')
    
    bilinearNr   r   linear)vectorcol1col2r	   offset   r   r   radial)axis)r   arrayr   floatcolor_gradientmaximumsizer   linalgnormmeshgridrangedotminimumonessqrtsum)r7   p1p2r+   rr,   r-   r	   r.   whvm1m2arrr9   Mn_vecs                     r%   r5   r5   5   s   D CAa88D>  'D88D>  'D
>XXb\BHHRL0F '-fW%57 ! "$1S)16C 7B jjR 99q=))AseG$C4x1S5$,&& 
"TrT(		"	"5	)B~"XXb2hB&2,'&[yy~~f%
		"++eAhuQx0267>>uEAtQw&-"ukk% !F(+jj2::a,-99q=))AseG$C4x1S5$,&&	(	916''1Q%.C77QVM..A.676A:EC!F(A&C**S"**Q"45C99q=))AseG$C#t|c$h&& 
G7s   L4c	                    |s|||,t        j                  |      t        j                  |      z
  }na|/t        j                  ddg      }t        j                  |dg      }n0|.t        j                  ddg      }t        j                  d|g      }|\  }}t        j                  || g      j                  d      }t         j                  j	                  |      }	t        d|      |z  |	z  }t        | ||||d	      S | \  }
}t        j                  |      r||
fn||
t        |      f}t        j                  |      }|r||ddd|f<   ||dd|df<   |S |r
||d| |||d |S )
aE  Make an image splitted in 2 colored regions.
    
    Returns an array of size ``size`` divided in two regions called 1 and
    2 in wht follows, and which will have colors col& and col2
    respectively.
    
    Parameters
    -----------
    
    x: (int)
        If provided, the image is splitted horizontally in x, the left
        region being region 1.
            
    y: (int)
        If provided, the image is splitted vertically in y, the top region
        being region 1.
    
    p1,p2:
        Positions (x1,y1),(x2,y2) in pixels, where the numbers can be
        floats. Region 1 is defined as the whole region on the left when
        going from ``p1`` to ``p2``.
    
    p1, vector:
        ``p1`` is (x1,y1) and vector (v1,v2), where the numbers can be
        floats. Region 1 is then the region on the left when starting
        in position ``p1`` and going in the direction given by ``vector``.
         
    gradient_width
        If not zero, the split is not sharp, but gradual over a region of
        width ``gradient_width`` (in pixels). This is preferable in many
        situations (for instance for antialiasing). 
     
    
    Examples
    ---------
    
    >>> size = [200,200]
    >>> # an image with all pixels with x<50 =0, the others =1
    >>> color_split(size, x=50, col1=0, col2=1)
    >>> # an image with all pixels with y<50 red, the others green
    >>> color_split(size, x=50, col1=[255,0,0], col2=[0,255,0])
    >>> # An image splitted along an arbitrary line (see below) 
    >>> color_split(size, p1=[20,50], p2=[25,70] col1=0, col2=1)
            
    Nr   g      r   g        r4   g?r*   )r+   r,   r-   r	   )r   r3   r   r8   r9   r   r5   isscalarr   zerosprint)r7   xyrA   rB   r+   r,   r-   
grad_widthr9   rD   rE   r	   rI   s                 r%   color_splitrS      so   ` 		>hhrlRXXb\1F]XXqh'F1a&!B]XXsCj)F1Q%B!1aR&!((1yy~~f%S*%.5d2V%)$hH 	H 1++d+A!QD	1BhhuoC"1"IC!"I 
 CGCG
r'   c           	      D    |rd||z
  z  |z  nd}t        | ||||d|      S )a   Draw an image with a circle.
    
    Draws a circle of color ``col1``, on a background of color ``col2``,
    on a screen of size ``screensize`` at the position ``center=(x,y)``,
    with a radius ``radius`` but slightly blurred on the border by ``blur``
    pixels
    r   r   r1   )rA   rC   r,   r-   r	   r.   )r5   )
screensizecenterradiusr,   r-   blurr.   s          r%   circlerY     s9     *0S&+v%QF*d#8FD Dr'   )NNF)NNNr   r   r*   r   )NNNNNr   r   r   )r   r   r/   )__doc__numpyr   r&   r5   rS   rY    r'   r%   <module>r]      s<   
 (@X EH,-{'| ;?9:N
`
Dr'   