o
    Wf                     @  s   d dl mZ d dlZddlmZmZ ddlmZ dd Z	G dd	 d	ejZ
G d
d dejZee
je
e	 ede ee
jd dS )    )annotationsN   )Image	ImageFile)i32bec                 C  s   | d d dkS )N   s   qoif )prefixr   r   z/media/darth/New Volume E/PROJECTS/DRIVERZZ/DRIVERZZ_CUSTOMER_APIS/venv/lib/python3.10/site-packages/PIL/QoiImagePlugin.py_accept   s   r   c                   @  s   e Zd ZdZdZdd ZdS )QoiImageFileQOIzQuite OK Imagec                   s   t  jdsd}t|t fddtdD  _ jdd }|dkr*d	nd
 _ jdt	j
 dd j  j d fg _d S )Nr   znot a QOI filec                 3  s     | ]}t  jd V  qdS )r   N)i32fpread).0iselfr   r
   	<genexpr>   s    z%QoiImageFile._open.<locals>.<genexpr>   r   r      RGBRGBAqoi)r   r   )r   r   r   SyntaxErrortuplerange_size_modeseekosSEEK_CURtelltile)r   msgchannelsr   r   r
   _open   s    zQoiImageFile._openN)__name__
__module____qualname__formatformat_descriptionr'   r   r   r   r
   r      s    r   c                   @  s    e Zd ZdZdd Zdd ZdS )
QoiDecoderTc                 C  sD   || _ |\}}}}|d |d  |d  |d  d }|| j|< d S )Nr            @   )_previous_pixel_previously_seen_pixels)r   valuergba
hash_valuer   r   r
   _add_to_previous_pixels)   s   $z"QoiDecoder._add_to_previous_pixelsc                   s*  i _ d _td t }tj}jjjj	 | }t
||k rjdd }|dkrCtjdjdd   }n|dkrNjd}n|d? }|dkrd|d	@ }j |td
}n|dkrtjd |d@ d?  d d jd |d@ d?  d d jd |d@  d d jd f}n[|dkrֈjdd }	|d	@ d  |	d@ d? d }
|	d@ d }tt fddt|
d|fD }|jdd  7 }n|dkr|d	@ d }j}|dkr|d d }||| 7 }q | |dkr|d d }||7 }t
||k s'| dS )N)r   r   r      r   r      r   r;   r      ?   )r   r   r   r   0   r                      c                 3  s*    | ]\}}j |   | d  V  qdS )r@   N)r2   )r   r   diff
diff_greenr   r   r
   r   W   s
    
z$QoiDecoder.decode.<locals>.<genexpr>)r   )r3   r2   r:   	bytearrayr   getmodebandsmodestatexsizeysizelenfdr   getr   	enumerate
set_as_raw)r   bufferdatabandsdest_lengthbyter4   opop_indexsecond_bytediff_red	diff_blue
run_lengthr   rG   r
   decode0   sn    



1zQoiDecoder.decodeN)r(   r)   r*   	_pulls_fdr:   r`   r   r   r   r
   r-   &   s    r-   r   z.qoi)
__future__r   r!    r   r   _binaryr   r   r   r   	PyDecoderr-   register_openr+   register_decoderregister_extensionr   r   r   r
   <module>   s   G