U
    a¨+dº  ã                   @   s~   d dl Z d dlZd dlZd dlZd dlmZmZ d dl	m
Z
 e ¡  ej d¡ ddd„Zedd	d
„ƒZeeddd„ƒƒZdS )é    N)Úconvert_masks_to_RGBÚrequires_duration)ÚcvsecsZMoviePyc                 C   sV   t j |  dd¡¡}|dkr<t j | jdd… ddd… ¡}| |d¡ t j ¡  dS )z:Splashes the given image array on the given pygame screen r   é   Né   éÿÿÿÿ©r   r   )	ÚpgZ	surfarrayZmake_surfaceZswapaxesÚdisplayÚset_modeÚshapeZblitZflip)ZimarrayÚscreenÚa© r   ú</tmp/pip-unpacked-wheel-0yp4gafk/moviepy/video/io/preview.pyÚ	imdisplay   s
     r   TFc                 C   s  t |tƒrt|Ž }|rJ| jdk	rJddlm  m  m} | |  d¡g¡} |  	|¡}t
|ƒ |rg }tj ¡ D ]†}|jtjkrž|jtjkrötdƒ |  S qp|jtjkrptj ¡ \}}	||	|f }
| ||	f|
dœ¡ tddt||	fƒt|
ƒf ƒ qpt d¡ qfdS )	a  
    Splashes the frame of clip corresponding to time ``t``.
    
    Parameters
    ------------
    
    t
      Time in seconds of the frame to display.
    
    with_mask
      ``False`` if the clip has a mask but you want to see the clip
      without the mask.
    
    Nr   r   zKeyboard interrupt)ÚpositionÚcolorzposition, color : z%s, %sg¸…ëQ¸ž?)Ú
isinstanceÚtupler   ÚmaskZ,moviepy.video.compositing.CompositeVideoClipÚvideoZcompositingZCompositeVideoClipZset_positionÚ	get_framer   r	   ÚeventÚgetÚtypeÚKEYDOWNÚkeyÚK_ESCAPEÚprintÚMOUSEBUTTONDOWNÚmouseÚget_posÚappendÚstrÚtimeÚsleep)ÚclipÚtZ	with_maskÚinteractiveZcvcÚimgÚresultr   ÚxÚyÚrgbr   r   r   Úshow   s,    


ÿr/   é   é"V  é¸  r   c              	   C   sª  |rt j}nd}t j | j|¡}|o,| jdk	}|rft ¡ }	t ¡ }
tj| jj	||||
|	fd}| 
¡  |  d¡}t||ƒ |rŽ|	 ¡  |
 ¡  g }t ¡ }t d| | jd d| ¡D ]î}|  |¡}t j ¡ D ]ª}|jt jksú|jt jkr|jt jkr|r|	 ¡  tdƒ |    S |jt jkrÎt j ¡ \}}|||f }| |||f|dœ¡ tdd	|t ||fƒt |ƒf ƒ qÎt ¡ }t !t"d|||  ƒ¡ t||ƒ q¶dS )
a¾   
    Displays the clip in a window, at the given frames per second
    (of movie) rate. It will avoid that the clip be played faster
    than normal, but it cannot avoid the clip to be played slower
    than normal if the computations are complex. In this case, try
    reducing the ``fps``.
    
    Parameters
    ------------
    
    fps
      Number of frames per seconds in the displayed video.
        
    audio
      ``True`` (default) if you want the clip's audio be played during
      the preview.
        
    audio_fps
      The frames per second to use when generating the audio sound.
      
    fullscreen
      ``True`` if you want the preview to be displayed fullscreen.
      
    r   N)ÚtargetÚargsg      ð?gü©ñÒMbP?Z	Interrupt)r%   r   r   ztime, position, color : z%.03f, %s, %s)#r	   Z
FULLSCREENr
   r   ÚsizeÚaudioÚ	threadingÚEventÚThreadÚpreviewÚstartr   r   ÚsetÚwaitr%   ÚnpZarangeÚdurationr   r   r   ZQUITr   r   r   Úclearr   r    r!   r"   r#   r$   r&   Úmax)r'   Zfpsr6   Z	audio_fpsZaudio_buffersizeZaudio_nbytesZ
fullscreenÚflagsr   Z	videoFlagZ	audioFlagZaudiothreadr*   r+   Út0r(   r   r,   r-   r.   Út1r   r   r   r:   B   s`    
 ýÿ

 

ÿ
ÿÿÿr:   )N)r   TF)r0   Tr1   r2   r   F)r7   r%   Znumpyr>   Zpygamer	   Zmoviepy.decoratorsr   r   Zmoviepy.toolsr   Úinitr
   Zset_captionr   r/   r:   r   r   r   r   Ú<module>   s    
	*    ÿ