U
    <þjg˜  ã                   @  sl   d dl mZ ddlmZmZ ddlmZ dddœdd	„ZG d
d„ dejƒZ	e 
e	je	e¡ e e	jd¡ dS )é    )Úannotationsé   )ÚImageÚ	ImageFile)Úi32beÚbytesÚbool)ÚprefixÚreturnc                 C  s(   t | ƒdko&t| dƒdko&t| dƒdkS )Né   r   é   é   ©r   é   )ÚlenÚi32)r	   © r   ú6/tmp/pip-unpacked-wheel-f170kk4x/PIL/GbrImagePlugin.pyÚ_accept    s    r   c                   @  s*   e Zd ZdZdZddœdd„Zdd„ Zd	S )
ÚGbrImageFileZGBRzGIMP brush fileÚNone)r
   c           
      C  sb  t | j d¡ƒ}|dk r$d}t|ƒ‚t | j d¡ƒ}|dkrNd|› }t|ƒ‚t | j d¡ƒ}t | j d¡ƒ}t | j d¡ƒ}|dksŽ|dkršd}t|ƒ‚|dkr´d|› }t|ƒ‚|d	krÆ|d }n>|d
 }| j d¡}|dkrîd}t|ƒ‚t | j d¡ƒ| jd< | j |¡d d… }	|d	kr*d| _nd| _||f| _|	| jd< t | j	¡ || | | _
d S )Nr   r   znot a GIMP brushr   z Unsupported GIMP brush version: r   )r   r   z$Unsupported GIMP brush color depth: r   é   s   GIMPz"not a GIMP brush, bad magic numberÚspacingéÿÿÿÿÚLZRGBAÚcomment)r   ÚfpÚreadÚSyntaxErrorÚinfoÚ_modeÚ_sizer   Z_decompression_bomb_checkÚsizeÚ
_data_size)
ÚselfÚheader_sizeÚmsgÚversionÚwidthÚheightZcolor_depthZcomment_lengthZmagic_numberr   r   r   r   Ú_open,   sB    





zGbrImageFile._openc                 C  s:   | j s.tj | j| j¡| _ |  | j | j	¡¡ tj 
| ¡S )N)Zimr   ÚcoreÚnewÚmoder"   Z	frombytesr   r   r#   Úload)r$   r   r   r   r.   [   s    zGbrImageFile.loadN)Ú__name__Ú
__module__Ú__qualname__ÚformatÚformat_descriptionr*   r.   r   r   r   r   r   (   s   /r   z.gbrN)Ú
__future__r   Ú r   r   Ú_binaryr   r   r   r   Zregister_openr2   Zregister_extensionr   r   r   r   Ú<module>   s   >