
    }f                       d dl mZ d dlZddlmZmZ ddlmZ d Z	 G d dej                  Z
 G d	 d
ej                  Z ej        e
j        e
e	            ej        de            ej        e
j        d           dS )    )annotationsN   )Image	ImageFile)i32bec                    | d d         dk    S )N   s   qoif )prefixs    K/var/www/rtfcompare/venv/lib/python3.11/site-packages/PIL/QoiImagePlugin.py_acceptr      s    "1":      c                      e Zd ZdZdZd ZdS )QoiImageFileQOIzQuite OK Imagec                    t           j                            d                    sd}t          |          t	           fdt          d          D                        _         j                            d          d         }|dk    rdnd	 _         j                            dt          j
                   d
d j        z    j                                        d fg _        d S )Nr	   znot a QOI filec              3  f   K   | ]+}t          j                            d                     V  ,dS )r	   N)i32fpread).0iselfs     r   	<genexpr>z%QoiImageFile._open.<locals>.<genexpr>   s7      BBA3tw||A//BBBBBBr      r   r      RGBRGBAqoi)r   r   )r   r   r   SyntaxErrortuplerange_size_modeseekosSEEK_CURtelltile)r   msgchannelss   `  r   _openzQoiImageFile._open   s    tw||A'' 	#"Cc"""BBBBqBBBBB
7<<??1%&!mmUU
Q$$$Vdj0$',,..$GH			r   N)__name__
__module____qualname__formatformat_descriptionr,   r
   r   r   r   r      s3        F)I I I I Ir   r   c                      e Zd ZdZd Zd ZdS )
QoiDecoderTc                j    || _         |\  }}}}|dz  |dz  z   |dz  z   |dz  z   dz  }|| j        |<   d S )Nr            @   )_previous_pixel_previously_seen_pixels)r   valuergba
hash_values          r   _add_to_previous_pixelsz"QoiDecoder._add_to_previous_pixels)   sR    $
1a!ea!ema!e+a"f4:
38$Z000r   c           
         i  _         d  _                             t          d                     t                      }t	          j         j                  } j        j         j        j	        z  |z  }t          |          |k     r% j                            d          d         }|dk    r9t           j                            d                     j        dd          z   }n|dk    r j                            d          }nf|dz	  }|dk    r/|d	z  } j                             |t          d
                    }n,|dk    rjt           j        d         |dz  dz	  z   dz
  dz   j        d         |dz  dz	  z   dz
  dz   j        d         |dz  z   dz
  dz   j        d         f          }n|dk    r j                            d          d         }	|d	z  dz
  |	dz  dz	  dz
  }
|	dz  dz
  }t          t           fdt          |
d|f          D                                 }| j        dd          z  }n/|dk    r)|d	z  dz   } j        }|dk    r
|d d         }|||z  z  }                     |           |dk    r
|d d         }||z  }t          |          |k     %                     |           dS )N)r   r   r      r   r      r   rC   r	      ?   )r   r   r   r   0   r                      c              3  J   K   | ]\  }}j         |         z   |z   d z  V  dS )rH   N)r9   )r   r   diff
diff_greenr   s      r   r   z$QoiDecoder.decode.<locals>.<genexpr>W   sR         '4 "1!4zADHCO     r   )r   )r:   r9   rA   	bytearrayr   getmodebandsmodestatexsizeysizelenfdr   getr!   	enumerate
set_as_raw)r   bufferdatabandsdest_lengthbyter;   opop_indexsecond_bytediff_red	diff_blue
run_lengthrP   s   `            @r   decodezQoiDecoder.decode0   s+   ')$#$$Y~%>%>???{{"49--j&)99EA$ii+%%7<<??1%Dz!!!$',,q//22T5I!""5MM##QQY77#j0H 8<< )L"9"9 EE 1WW%!1!4
9Jq8PQTUU!"!1!4
9Jq8PQTUU!"!1!4z8IJQNRUU 03	 	EE 1WW"&',,q//!"4K"&"3r!9J!,z!9a ?1DH!,z!9Q >I%     +4h95M+N+N     E T1!""55EE1WW"&"3q!8J 0Ezz %bqb	EJ..D((///zzbqb	EMDa $ii+%%b 	ur   N)r-   r.   r/   	_pulls_fdrA   rh   r
   r   r   r3   r3   &   s7        I9 9 9: : : : :r   r3   r   z.qoi)
__future__r   r&    r   r   _binaryr   r   r   r   	PyDecoderr3   register_openr0   register_decoderregister_extensionr
   r   r   <module>rq      s   # " " " " " 				         ! ! ! ! ! !! ! !I I I I I9& I I I$D D D D D$ D D DN  L'w ? ? ?  uj ) ) )  ,f 5 5 5 5 5r   