o
    OZhE8                     @   s  d Z ddlmZmZmZmZ ddlZddlm	Z
mZmZmZ ddlZdd d D Zee h dZg d	Zd
d Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Z dd Z!d d! Z"d"d# Z#d$d% Z$d&d' Z%d(d) Zd*d+ Z&d,d- Z'd.d/ Z(dS )0a  pygame module for accessing surface pixel data using array interfaces

Functions to convert between NumPy arrays and Surface objects. This module
will only be functional when pygame can use the external NumPy package.
If NumPy can't be imported, surfarray becomes a MissingModule object.

Every pixel is stored as a single integer value to represent the red,
green, and blue colors. The 8bit images use a value that looks into a
colormap. Pixels with higher depth use a bit packing process to place
three or four values into a single number.

The arrays are indexed by the X axis first, followed by the Y
axis. Arrays that treat the pixels as a single integer are referred to
as 2D arrays. This module can also separate the red, green, and blue
color values into separate indices. These types of arrays are referred
to as 3D arrays, and the last index is 0 for red, 1 for green, and 2 for
blue.
    )array_to_surfacesurface_to_array	map_arraymake_surfaceN)arrayemptyuint32ndarrayc                 C   s    g | ]}t t|rtt|qS  )hasattrnumpygetattr).0	type_namer
   r
   ?/var/www/auris/lib/python3.10/site-packages/pygame/surfarray.py
<listcomp>;   s    r   zfloat32 float64 float96>             )array2darray3darray_alpha
array_bluearray_colorkeyarray_green	array_redr   
blit_arrayget_arraytypeget_arraytypesr   r   pixels2dpixels3dpixels_alphapixels_bluepixels_green
pixels_redr   use_arraytypec                 C   s.   t |tr|jtv r|dt}t| |S )a  pygame.surfarray.blit_array(Surface, array): return None

    Blit directly from a array values.

    Directly copy values from an array into a Surface. This is faster than
    converting the array into a Surface and blitting. The array must be the
    same dimensions as the Surface and will completely replace all pixel
    values. Only integer, ascii character and record arrays are accepted.

    This function will temporarily lock the Surface as the new values are
    copied.
    r   )
isinstancenumpy_ndarraydtypenumpy_floatsroundastypenumpy_uint32r   )surfacer   r
   r
   r   r   a   s   
r   c                 C   s,   t | tr| jtv r| dt} t| S )zpygame.surfarray.make_surface (array): return Surface

    Copy an array to a new surface.

    Create a new Surface that best resembles the data and format on the
    array. The array can be 2D or 3D with any sized integer values.
    r   )r&   r'   r(   r)   r*   r+   r,   pix_make_surface)r   r
   r
   r   r   s   s   r   c                 C   sn   |   }ztjtjtjtjf|d  }W n ty%   td|d  dw |  }t||}t	||  |S )a  pygame.surfarray.array2d(Surface): return array

    copy pixels into a 2d array

    Copy the pixels from a Surface into a 2D array. The bit depth of the
    surface will control the size of the integer values, and will work
    for any type of pixel format.

    This function will temporarily lock the Surface as pixels are copied
    (see the Surface.lock - lock the Surface memory for pixel access
    method).
       zunsupported bit depth r   z for 2D array)
Zget_bytesizer   uint8Zuint16int32
IndexError
ValueErrorget_sizer   r   )r-   Zbppr(   sizer   r
   r
   r   r      s    
r   c              	   C   sP   |   tvr
tdz
t| dddW S  ttfy'   td|    dw )a.  pygame.surfarray.pixels2d(Surface): return array

    reference pixels into a 2d array

    Create a new 2D array that directly references the pixel values in a
    Surface. Any changes to the array will affect the pixels in the
    Surface. This is a fast operation since no data is copied.

    Pixels from a 24-bit Surface cannot be referenced, but all other
    Surface bit depths can.

    The Surface this references will remain locked for the lifetime of
    the array (see the Surface.lock - lock the Surface memory for pixel
    access method).
    z,unsupported bit depth for 2D reference array2Fcopyz
bit depth z# unsupported for 2D reference array)Zget_bitsize_pixel2d_bitdepthsr3   numpy_arrayget_view	TypeErrorr-   r
   r
   r   r      s   r   c                 C   s.   |   \}}t||dftj}t||  |S )a  pygame.surfarray.array3d(Surface): return array

    copy pixels into a 3d array

    Copy the pixels from a Surface into a 3D array. The bit depth of the
    surface will control the size of the integer values, and will work
    for any type of pixel format.

    This function will temporarily lock the Surface as pixels are copied
    (see the Surface.lock - lock the Surface memory for pixel access
    method).
       r4   r   r   r0   r   )r-   widthheightr   r
   r
   r   r      s   
r   c                 C   s   t | dddS )aC  pygame.surfarray.pixels3d(Surface): return array

    reference pixels into a 3d array

    Create a new 3D array that directly references the pixel values in a
    Surface. Any changes to the array will affect the pixels in the
    Surface. This is a fast operation since no data is copied.

    This will only work on Surfaces that have 24-bit or 32-bit
    formats. Lower pixel formats cannot be referenced.

    The Surface this references will remain locked for the lifetime of
    the array (see the Surface.lock - lock the Surface memory for pixel
    access method).
    3Fr7   )r:   r;   r=   r
   r
   r   r       s   r    c                 C   &   |   }t|tj}t|| d |S )a  pygame.surfarray.array_alpha(Surface): return array

    copy pixel alphas into a 2d array

    Copy the pixel alpha values (degree of transparency) from a Surface
    into a 2D array. This will work for any type of Surface
    format. Surfaces without a pixel alpha will return an array with all
    opaque values.

    This function will temporarily lock the Surface as pixels are copied
    (see the Surface.lock - lock the Surface memory for pixel access
    method).
    Ar?   r-   r5   r   r
   r
   r   r      s   r   c                 C      t j| dddS )a  pygame.surfarray.pixels_alpha(Surface): return array

    reference pixel alphas into a 2d array

    Create a new 2D array that directly references the alpha values
    (degree of transparency) in a Surface. Any changes to the array will
    affect the pixels in the Surface. This is a fast operation since no
    data is copied.

    This can only work on 32-bit Surfaces with a per-pixel alpha value.

    The Surface this array references will remain locked for the
    lifetime of the array.
    rD   Fr7   r   r   r;   r=   r
   r
   r   r!      s   r!   c                 C   rF   )a  pygame.surfarray.pixels_red(Surface): return array

    Reference pixel red into a 2d array.

    Create a new 2D array that directly references the red values
    in a Surface. Any changes to the array will affect the pixels
    in the Surface. This is a fast operation since no data is copied.

    This can only work on 24-bit or 32-bit Surfaces.

    The Surface this array references will remain locked for the
    lifetime of the array.
    RFr7   rG   r=   r
   r
   r   r$         r$   c                 C   rC   )ah  pygame.surfarray.array_red(Surface): return array

    copy pixel red into a 2d array

    Copy the pixel red values from a Surface into a 2D array. This will work
    for any type of Surface format.

    This function will temporarily lock the Surface as pixels are copied
    (see the Surface.lock - lock the Surface memory for pixel access
    method).
    rH   r?   rE   r
   r
   r   r        r   c                 C   rF   )a  pygame.surfarray.pixels_green(Surface): return array

    Reference pixel green into a 2d array.

    Create a new 2D array that directly references the green values
    in a Surface. Any changes to the array will affect the pixels
    in the Surface. This is a fast operation since no data is copied.

    This can only work on 24-bit or 32-bit Surfaces.

    The Surface this array references will remain locked for the
    lifetime of the array.
    GFr7   rG   r=   r
   r
   r   r#   !  rI   r#   c                 C   rC   )an  pygame.surfarray.array_green(Surface): return array

    copy pixel green into a 2d array

    Copy the pixel green values from a Surface into a 2D array. This will work
    for any type of Surface format.

    This function will temporarily lock the Surface as pixels are copied
    (see the Surface.lock - lock the Surface memory for pixel access
    method).
    rK   r?   rE   r
   r
   r   r   2  rJ   r   c                 C   rF   )a  pygame.surfarray.pixels_blue(Surface): return array

    Reference pixel blue into a 2d array.

    Create a new 2D array that directly references the blue values
    in a Surface. Any changes to the array will affect the pixels
    in the Surface. This is a fast operation since no data is copied.

    This can only work on 24-bit or 32-bit Surfaces.

    The Surface this array references will remain locked for the
    lifetime of the array.
    BFr7   rG   r=   r
   r
   r   r"   D  rI   r"   c                 C   rC   )ak  pygame.surfarray.array_blue(Surface): return array

    copy pixel blue into a 2d array

    Copy the pixel blue values from a Surface into a 2D array. This will work
    for any type of Surface format.

    This function will temporarily lock the Surface as pixels are copied
    (see the Surface.lock - lock the Surface memory for pixel access
    method).
    rL   r?   rE   r
   r
   r   r   U  rJ   r   c                 C   rC   )a  pygame.surfarray.array_colorkey(Surface): return array

    copy the colorkey values into a 2d array

    Create a new array with the colorkey transparency value from each
    pixel. If the pixel matches the colorkey it will be fully
    transparent; otherwise it will be fully opaque.

    This will work on any type of Surface format. If the image has no
    colorkey a solid opaque array will be returned.

    This function will temporarily lock the Surface as pixels are
    copied.
    Cr?   rE   r
   r
   r   r   g  s   r   c                 C   sP   |j dkr	td|j}|d dkrtdt|dd tj}t|||  |S )a  pygame.surfarray.map_array(Surface, array3d): return array2d

    map a 3d array into a 2d array

    Convert a 3D array into a 2D array. This will use the given Surface
    format to control the conversion.

    Note: arrays do not need to be 3D, as long as the minor axis has
    three elements giving the component colours, any array shape can be
    used (for example, a single colour can be mapped, or an array of
    colours). The array shape is limited to eleven dimensions maximum,
    including the three element minor axis.
    r   z$array must have at least 1 dimensionr>   z.array must be a 3d array of 3-value color dataN)ndimr3   shapenumpy_emptyr   r1   pix_map_array)r-   r   rP   targetr
   r
   r   r   |  s   
r   c                 C   s*   t td |  } | dkrtddS )zrpygame.surfarray.use_arraytype(arraytype): return None

    DEPRECATED - only numpy arrays are now supported.
    donly numpy arrays are now supported, this function will be removed in a future version of the moduler   zinvalid array typeN)warningswarnDeprecationWarninglowerr3   )Z	arraytyper
   r
   r   r%     s   r%   c                   C      t td dS )zhpygame.surfarray.get_arraytype(): return str

    DEPRECATED - only numpy arrays are now supported.
    rT   r   rU   rV   rW   r
   r
   r
   r   r        r   c                   C   rY   )zkpygame.surfarray.get_arraytypes(): return tuple

    DEPRECATED - only numpy arrays are now supported.
    rT   )r   rZ   r
   r
   r
   r   r     r[   r   ))__doc__Zpygame.pixelcopyr   r   r   rR   r   r.   r   r   r:   r   rQ   r   r,   r	   r'   rU   splitr)   appendfloatr9   __all__r   r   r   r   r    r   r!   r$   r   r#   r   r"   r   r   r%   r   r   r
   r
   r
   r   <module>   s<   
