a
    V$cF                     @   s   d dl mZmZmZmZmZ d dlmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZ d dlZd dlZd dlZd dlZdadadd ZG dd dejZdd	 ZeZdddZeZh dZ e! Z"dd Z#e#Z$dd Z%e%Z&dd Z'e'Z(dd Z)e)Z*dd Z+e+Z,dS )    )divisionabsolute_importwith_statementprint_functionunicode_literals)PY2
basestringbchrbordchropenpystrrangeroundstrtobytesunicodeNc                  C   s   t ddd} |  att }|jtd tj	dkrV|d |d |d |d f}n|d |d |d |d f}t ddd|at ddd|d	d d
 a
tjjt
t d	S )zR
    This rebuilds the sample surfaces, to ones that use the given
    masks.
    )
   r   r       )keybig         N)r   )pygameSurfaceconvert_alphasample_alphalist	get_maskssortabssys	byteordersample_noalpharenpyaudiosample_surfaces)smasks r*   renpy/display\pgrender.pyset_rgba_masks*   s    
r,   c                   @   s4   e Zd ZdZdddZdddZdd Zd	d
 ZdS )r   z_
    This allows us to wrap around pygame's surface, to change
    its mode, as necessary.
    Nc                 C   s
   t | dS )NT)copy_surface_unscaledselfsurfacer*   r*   r+   r   Q   s    zSurface.convert_alphac                 C   s
   t | dS )NFcopy_surfacer.   r*   r*   r+   convertT   s    zSurface.convertc                 C   s
   t | | S Nr1   )r/   r*   r*   r+   copyW   s    zSurface.copyc                 C   s   t j| |}|S r4   )r   r   
subsurface)r/   rectrvr*   r*   r+   r6   Z   s    zSurface.subsurface)N)N)__name__
__module____qualname____doc__r   r3   r5   r6   r*   r*   r*   r+   r   K   s
   

r   c                 C   sp   | \}}t |tjr | d }|r*t}nt}|du rFtdtjd}t|d |d fd|}|dd||fS )z
    Constructs a new surface. The allocated surface is actually a subsurface
    of a surface that has a 2 pixel border in all directions.

    `alpha` - True if the new surface should have an alpha channel.
    r   N)   r=   r   r=   r   r   )
isinstancer   r   r   r   r$   SRCALPHAr6   )r7   alphawidthheightsamplesurfr*   r*   r+   r0   _   s    r0   Tc                 C   s"   t |  |}tjj| | |S )z(
    Creates a copy of the surface.
    )surface_unscaledget_sizer%   displayaccelerator
nogil_copy)rD   r@   r8   r*   r*   r+   r2   {   s    r2   >   webpjpgjpegpngc              
   C   s   | d\}}}zb| tv r6tj| tj|}n:t	& tj| tj|}W d    n1 sf0    Y  W n4 t
y } zt
d||W Y d }~n
d }~0 0 t|}|S )N.zCould not load image {!r}: {!r})
rpartitionlowersafe_formatsr   imageloadr%   exportsfsencodeimage_load_lock	Exceptionformatr-   )ffilename	_basename_dotextrD   er8   r*   r*   r+   
load_image   s    8&r_   c                 C   s   t j| ||} t| S r4   )r   	transformflipr-   )rD   
horizontalverticalr*   r*   r+   ra      s    ra   c                 C   s   t j| ||} t| S r4   )r   r`   rotozoomr-   )rD   anglezoomr*   r*   r+   rd      s    rd   c                 C   s   t j| |} t| | S r4   )r   r`   scaler-   )rD   sizer*   r*   r+   transform_scale   s    ri   c                 C   s   t j| |} t| S r4   )r   r`   rotater2   )rD   re   r*   r*   r+   transform_rotate   s    rk   )T)-
__future__r   r   r   r   r   renpy.compatr   r   r	   r
   r   r   r   r   r   r   r   r   r"   	threadingpygame_sdl2r   r%   r   r$   r,   r   r0   rE   r2   r-   rQ   RLockrV   r_   load_image_unscaledra   flip_unscaledrd   rotozoom_unscaledri   transform_scale_unscaledrk   transform_rotate_unscaledr*   r*   r*   r+   <module>   s2   8!

