U
    Ú²gë
  ã                   @  s~   d Z ddlmZ ddlmZ ddlmZmZmZ ddl	m
Z ddl	mZ ddlmZ G d	d
„ d
ejƒZdddd
dœdd„ZdS )a‚  
.. note::
    This format cannot be automatically recognized, so the
    class is not registered for use with :py:func:`PIL.Image.open()`.  To open a
    gd file, use the :py:func:`PIL.GdImageFile.open()` function instead.

.. warning::
    THE GD FORMAT IS NOT DESIGNED FOR DATA INTERCHANGE.  This
    implementation is provided for convenience and demonstrational
    purposes only.
é    )Úannotations)ÚIOé   )Ú	ImageFileÚImagePaletteÚUnidentifiedImageError)Úi16be)Úi32be)ÚStrOrBytesPathc                   @  s&   e Zd ZdZdZdZddœdd„ZdS )	ÚGdImageFilea%  
    Image plugin for the GD uncompressed format.  Note that this format
    is not supported by the standard :py:func:`PIL.Image.open()` function.  To use
    this plugin, you have to import the :py:mod:`PIL.GdImageFile` module and
    use the :py:func:`PIL.GdImageFile.open()` function.
    ZGDzGD uncompressed imagesÚNone)Úreturnc                 C  sÒ   | j d k	st‚| j  d¡}t|ƒdkr2d}t|ƒ‚d| _t|dƒt|dƒf| _|d }|r^dnd}t|d	| ƒ}|d
k r‚|| jd< t	 
d|d	| d d	| d d … ¡| _dd| j d	| d d dfg| _d S )Ni  )iþÿ  iÿÿ  zNot a valid GD 2.x .gd fileÚLé   é   é   r   é   é   ZtransparencyZXBGRi   Úraw)r   r   )r   r   r   )ÚfpÚAssertionErrorÚreadÚi16ÚSyntaxErrorÚ_modeÚ_sizeÚi32Úinfor   r   ZpaletteÚsizeZtile)ÚselfÚsÚmsgZ
true_colorZtrue_color_offsetZtindex© r"   ú3/tmp/pip-unpacked-wheel-xela2va7/PIL/GdImageFile.pyÚ_open1   s,    
 ÿüÿzGdImageFile._openN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚformatÚformat_descriptionr$   r"   r"   r"   r#   r   &   s   r   ÚrzStrOrBytesPath | IO[bytes]Ústr)r   Úmoder   c              
   C  sT   |dkrd}t |ƒ‚z
t| ƒW S  tk
rN } zd}t|ƒ|‚W 5 d}~X Y nX dS )a#  
    Load texture from a GD image file.

    :param fp: GD file name, or an opened file handle.
    :param mode: Optional mode.  In this version, if the mode argument
        is given, it must be "r".
    :returns: An image instance.
    :raises OSError: If the image could not be read.
    r+   zbad modezcannot identify this image fileN)Ú
ValueErrorr   r   r   )r   r-   r!   Úer"   r"   r#   ÚopenT   s    

r0   N)r+   )r(   Ú
__future__r   Útypingr   Ú r   r   r   Ú_binaryr   r   r	   r   Ú_typingr
   r   r0   r"   r"   r"   r#   Ú<module>   s   .