a
    H^iF                     @   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audioZsample_surfaces)smasks r)   ZC:\Program Files (x86)\Steam\steamapps\common\Selene ~Apoptosis~\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 Nr0   )r.   r)   r)   r*   copyW   s    zSurface.copyc                 C   s   t j| |}|S r3   )r   r   
subsurface)r.   rectrvr)   r)   r*   r5   Z   s    zSurface.subsurface)N)N)__name__
__module____qualname____doc__r   r2   r4   r5   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$   SRCALPHAr5   )r6   alphawidthheightsamplesurfr)   r)   r*   r/   _   s    r/   Tc                 C   s"   t |  |}tjj| | |S )z(
    Creates a copy of the surface.
    )surface_unscaledget_sizer%   displayZacceleratorZ
nogil_copy)rC   r?   r7   r)   r)   r*   r1   {   s    r1   >   ZjpegZjpgpngZwebpc              
   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	_basenameZ_dotextrC   er7   r)   r)   r*   
load_image   s    8&rX   c                 C   s   t j| ||} t| S r3   )r   	transformflipr,   )rC   Z
horizontalverticalr)   r)   r*   rZ      s    rZ   c                 C   s   t j| ||} t| S r3   )r   rY   rotozoomr,   )rC   angleZzoomr)   r)   r*   r\      s    r\   c                 C   s   t j| |} t| | S r3   )r   rY   scaler,   )rC   sizer)   r)   r*   transform_scale   s    r`   c                 C   s   t j| |} t| S r3   )r   rY   rotater1   )rC   r]   r)   r)   r*   transform_rotate   s    rb   )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   r/   rD   r1   r,   rK   RLockrP   rX   Zload_image_unscaledrZ   Zflip_unscaledr\   Zrotozoom_unscaledr`   Ztransform_scale_unscaledrb   Ztransform_rotate_unscaledr)   r)   r)   r*   <module>   s2   8!

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