HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib/python3.10/site-packages/cairocffi/__pycache__/pixbuf.cpython-310.pyc
o

*weL�@sdZddlZddlmZddlmZddlmZddlmZm	Z	m
Z
mZddlm
Zd	gZeed
d�Zeedd
�Zeedd�Zzeedd�ZWneyRdZYnwe��Gdd�de�Zdd�ZGdd�de�Zd!dd�Zd!dd	�Zdd�Zdd�Zdd �ZdS)"z�
    cairocffi.pixbuf
    ~~~~~~~~~~~~~~~~

    Loading various image formats with GDK-PixBuf

    :copyright: Copyright 2013-2019 by Simon Sapin
    :license: BSD, see LICENSE for details.

�N)�array)�partial)�BytesIO�)�Context�ImageSurface�	constants�dlopen)�
ffi_pixbuf�decode_to_image_surface)zgdk_pixbuf-2.0zlibgdk_pixbuf-2.0-0)zlibgdk_pixbuf-2.0.so.0zlibgdk_pixbuf-2.0.0.dylibzlibgdk_pixbuf-2.0-0.dll)zgobject-2.0zlibgobject-2.0-0)zlibgobject-2.0.so.0zlibgobject-2.0.dylibzlibgobject-2.0-0.dll)zglib-2.0z
libglib-2.0-0)zlibglib-2.0.so.0zlibglib-2.0.dylibzlibglib-2.0-0.dll)zgdk-3z
libgdk-3-0)z
libgdk-3.so.0zlibgdk-3.0.dylibzlibgdk-3-0.dllc@seZdZdZdS)�ImageLoadingErrorz`PixBuf returned an error when loading an image.

    The image data is probably corrupted.

    N)�__name__�
__module__�__qualname__�__doc__�rr�I/home/arjun/projects/env/lib/python3.10/site-packages/cairocffi/pixbuf.pyr*srcCsh|d}t|�|tjkksJ�|tjkr2|jtjkr'dt�|j��dd�}nd}t�|�t|��dS)zZConvert a ``GError**`` to a Python :exception:`ImageLoadingError`,
    and raise it.

    rzPixbuf error: �utf8�replacezPixbuf errorN)	�bool�ffi�NULL�message�string�decode�glib�g_error_freer)�error�return_valuerrrr�handle_g_error2s
�
�rc@s eZdZdZdd�Zdd�ZdS)�Pixbufz2Wrap a ``GdkPixbuf`` pointer and simulate methods.cCst�|�t�|tj�|_dS)N)�gobject�g_object_refr�gc�g_object_unref�_pointer)�self�pointerrrr�__init__Es
zPixbuf.__init__cCsttd|�}t||j�S)N�gdk_pixbuf_)�getattr�
gdk_pixbufrr%)r&�name�functionrrr�__getattr__IszPixbuf.__getattr__N)r
rrrr(r.rrrrr Csr cCs�t�t��tj�}t�d�}|r|rt�|||�t|t�	||t
|�|��t|t�||��t�|�}|tj
krDt�t�|���d�nd}t�|�}|tj
krTtd��t|�|fS)a�Decode an image from memory with GDK-PixBuf.
    The file format is detected automatically.

    :param image_data: A byte string
    :param width: Integer width in pixels or None
    :param height: Integer height in pixels or None
    :returns:
        A tuple of a new :class:`PixBuf` object
        and the name of the detected image format.
    :raises:
        :exc:`ImageLoadingError` if the image data is invalid
        or in an unsupported format.

    �	GError **�asciiNz*Not enough image data (got a NULL pixbuf.))rr#r+�gdk_pixbuf_loader_newr!r$�new�gdk_pixbuf_loader_set_sizer�gdk_pixbuf_loader_write�len�gdk_pixbuf_loader_close�gdk_pixbuf_loader_get_formatrr�gdk_pixbuf_format_get_namer�gdk_pixbuf_loader_get_pixbufrr )�
image_data�width�height�loaderr�format_�format_name�pixbufrrr�decode_to_pixbufNs(
�
�

��

rAcCs@t|||�\}}tdurt|�n|��st|�nt|�}||fS)a�Decode an image from memory into a cairo surface.
    The file format is detected automatically.

    :param image_data: A byte string
    :param width: Integer width in pixels or None
    :param height: Integer height in pixels or None
    :returns:
        A tuple of a new :class:`~cairocffi.ImageSurface` object
        and the name of the detected image format.
    :raises:
        :exc:`ImageLoadingError` if the image data is invalid
        or in an unsupported format.

    N)rA�gdk�pixbuf_to_cairo_gdk�
get_has_alpha�pixbuf_to_cairo_slices�pixbuf_to_cairo_png)r:r;r<r@r?�surfacerrrrrs�cCs2tttjdd��}t�|j|jdd�|����S)zrConvert from PixBuf to ImageSurface, using GDK.

    This method is fastest but GDK is not always available.

    rr)	rrr�
FORMAT_ARGB32rB�gdk_cairo_set_source_pixbufr%�
get_source�get_surface)r@�
dummy_contextrrrrC�s
�rCcCs�|��tjks	J�|��dksJ�|��dksJ�|��}|��}|��}t�	|�
�|���}|dd�}t�
tj|�}t||�}tjdk}|d}|d}	d|}
t|�D]r}||}||}
|||
d�}||d|
d�}||d|
d�}||}||	}
|r�|
|||
d�<|||d|
d�<|||d|
d�<|||d|
d�<qW|
||d|
d�<|||d|
d�<|||d|
d�<||||
d�<qWtd	|�}ttj||||�S)
z�Convert from PixBuf to ImageSurface, using slice-based byte swapping.

    This method is 2~5x slower than GDK but does not support an alpha channel.
    (cairo uses pre-multiplied alpha, but not Pixbuf.)

    ��N�big���r��B)�get_colorspacer+�GDK_COLORSPACE_RGB�get_n_channels�get_bits_per_sample�	get_width�
get_height�
get_rowstrider�buffer�
get_pixels�get_byte_lengthr�format_stride_for_widthr�FORMAT_RGB24�	bytearray�sys�	byteorder�ranger)r@r;r<�	rowstride�pixels�cairo_stride�data�
big_endian�pixbuf_row_length�cairo_row_length�alpha�y�offset�end�red�green�bluerrrrE�sJ�

�rEc
Csvt�d�}t�d�}t�d�}t||�||t�dd�|t�dd�t�dd�tj��t�|d|d�}t�t|��S)	z�Convert from PixBuf to ImageSurface, by going through the PNG format.

    This method is 10~30x slower than GDK but always works.

    zgchar **zgsize *r/zchar[]spngscompression�0r)	rr2r�save_to_bufferrr[r�create_from_pngr)r@�buffer_pointer�buffer_sizer�	png_bytesrrrrF�s


�rF)NN)rrar�	functoolsr�ior�rrrr	rr
�__all__r+r!rrB�OSError�g_type_init�
ValueErrorrr�objectr rArrCrErFrrrr�<module>sJ�����

$2