
    @OOf 3                         d dl Z d dl mZmZmZ d dlmZ  ee dd      dk  r ede j                  z         G d de      Z	y)	    N)KaitaiStructKaitaiStreamBytesIO)EnumAPI_VERSION)r   	   zPIncompatible Kaitai Struct Python API: 0.9 or later is required, but you have %sc                   h   e Zd ZdZ G d de      Z G d de      Zd#dZd Z G d	 d
e	      Z
 G d de	      Z G d de	      Z G d de	      Z G d de	      Z G d de	      Z G d de	      Z G d de	      Z G d de	      Z G d de	      Z G d de	      Z G d d e	      Z G d! d"e	      Zy)$GifaH  GIF (Graphics Interchange Format) is an image file format, developed
    in 1987. It became popular in 1990s as one of the main image formats
    used in World Wide Web.
    
    GIF format allows encoding of palette-based images up to 256 colors
    (each of the colors can be chosen from a 24-bit RGB
    colorspace). Image data stream uses LZW (Lempel-Ziv-Welch) lossless
    compression.
    
    Over the years, several version of the format were published and
    several extensions to it were made, namely, a popular Netscape
    extension that allows to store several images in one file, switching
    between them, which produces crude form of animation.
    
    Structurally, format consists of several mandatory headers and then
    a stream of blocks follows. Blocks can carry additional
    metainformation or image data.
    c                       e Zd ZdZdZdZy)Gif.BlockType!   ,   ;   N)__name__
__module____qualname__	extensionlocal_image_descriptorend_of_file     c/var/www/premiumrankchecker/venv/lib/python3.12/site-packages/mitmproxy/contrib/kaitaistruct/gif.py	BlockTyper      s    	!#r   r   c                       e Zd ZdZdZdZy)Gif.ExtensionLabel         N)r   r   r   graphic_controlcommentapplicationr   r   r   ExtensionLabelr   $   s    r   r"   Nc                 V    || _         || _        |r|n| | _        | j                          y N_io_parent_root_readselfr&   r'   r(   s       r   __init__zGif.__init__(   s$    #U


r   c                    t         j                  | j                  | | j                        | _        t         j                  | j                  | | j                        | _        | j                  j                  r{| j                  j                  | j                  j                  dz        | _
        t        t        | j                              }t         j                  || | j                        | _        g | _        d}	 t         j!                  | j                  | | j                        }| j                  j#                  |       | j                  j%                         s'|j&                  t         j(                  j*                  k(  ry |dz  })N   r      )r
   Headerr&   r(   hdrLogicalScreenDescriptorStructlogical_screen_descriptorhas_color_table
read_bytescolor_table_size_raw_global_color_tabler   r   
ColorTableglobal_color_tableblocksBlockappendis_eof
block_typer   r   )r+   _io__raw_global_color_tablei_s       r   r)   z	Gif._read.   s   ::dhhdjj9),)J)J488UY[_[e[e)f&))99+/88+>+>@^@^@o@ors@s+uD(*6wt?[?[7\*]'&)nn5PRVX\XbXb&cD#		$((D$**5AKKq!((//#9R9R)RFA r   c                       e Zd ZdZddZd Zy)Gif.ImageDatazh
        .. seealso::
           - section 22 - https://www.w3.org/Graphics/GIF/spec-gif89a.txt
        Nc                 V    || _         || _        |r|n| | _        | j                          y r$   r%   r*   s       r   r,   zGif.ImageData.__init__D   $    DH"DL"'TDJJJLr   c                     | j                   j                         | _        t        j	                  | j                   | | j
                        | _        y r$   )r&   read_u1lzw_min_code_sizer
   	Subblocksr(   	subblocksr+   s    r   r)   zGif.ImageData._readJ   s3    %)XX%5%5%7D" ]]488T4::FDNr   NNr   r   r   __doc__r,   r)   r   r   r   	ImageDatarC   ?   s    			Gr   rO   c                       e Zd ZddZd Zy)Gif.ColorTableEntryNc                 V    || _         || _        |r|n| | _        | j                          y r$   r%   r*   s       r   r,   zGif.ColorTableEntry.__init__P   rE   r   c                     | j                   j                         | _        | j                   j                         | _        | j                   j                         | _        y r$   )r&   rG   redgreenbluerK   s    r   r)   zGif.ColorTableEntry._readV   s>    xx'')DH))+DJ((*DIr   rL   r   r   r   r,   r)   r   r   r   ColorTableEntryrQ   O   s    		+r   rX   c                   >    e Zd ZdZddZd Zed        Zed        Zy)!Gif.LogicalScreenDescriptorStructzh
        .. seealso::
           - section 18 - https://www.w3.org/Graphics/GIF/spec-gif89a.txt
        Nc                 V    || _         || _        |r|n| | _        | j                          y r$   r%   r*   s       r   r,   z*Gif.LogicalScreenDescriptorStruct.__init__a   rE   r   c                 :   | j                   j                         | _        | j                   j                         | _        | j                   j	                         | _        | j                   j	                         | _        | j                   j	                         | _        y r$   )r&   	read_u2lescreen_widthscreen_heightrG   flagsbg_color_indexpixel_aspect_ratiorK   s    r   r)   z'Gif.LogicalScreenDescriptorStruct._readg   sj     $ 2 2 4D!%!3!3!5D))+DJ"&(("2"2"4D&*hh&6&6&8D#r   c                 z    t        | d      r| j                  S | j                  dz  dk7  | _        t        | dd       S N_m_has_color_table   r   hasattrre   r`   getattrrK   s    r   r4   z1Gif.LogicalScreenDescriptorStruct.has_color_tablen   ?    t12...'+zzC'7A&=D#4!5t<<r   c                 z    t        | d      r| j                  S d| j                  dz  z  | _        t        | dd       S N_m_color_table_size      rh   rm   r`   ri   rK   s    r   r6   z2Gif.LogicalScreenDescriptorStruct.color_table_sizev   >    t23///()djj1n(=D$4!6==r   rL   )	r   r   r   rN   r,   r)   propertyr4   r6   r   r   r   r2   rZ   \   s9    			9 
	= 
	= 
	> 
	>r   r2   c                   Z    e Zd ZddZd Zed        Zed        Zed        Zed        Z	y)	Gif.LocalImageDescriptorNc                 V    || _         || _        |r|n| | _        | j                          y r$   r%   r*   s       r   r,   z!Gif.LocalImageDescriptor.__init__   rE   r   c                    | j                   j                         | _        | j                   j                         | _        | j                   j                         | _        | j                   j                         | _        | j                   j                         | _        | j                  rq| j                   j                  | j                  dz        | _        t        t        | j                              }t        j                  || | j                         | _        t        j%                  | j                   | | j                         | _        y )Nr.   )r&   r]   lefttopwidthheightrG   r`   r4   r5   r6   _raw_local_color_tabler   r   r
   r8   r(   local_color_tablerO   
image_data)r+   _io__raw_local_color_tables     r   r)   zGif.LocalImageDescriptor._read   s    **,DIxx))+DH++-DJ((,,.DK))+DJ##.2hh.A.A4CXCX[\C\.^+-9'$B]B]:^-_*),8RTXZ^ZdZd)e&!mmDHHdDJJGDOr   c                 z    t        | d      r| j                  S | j                  dz  dk7  | _        t        | dd       S rd   rg   rK   s    r   r4   z(Gif.LocalImageDescriptor.has_color_table   rj   r   c                 z    t        | d      r| j                  S | j                  dz  dk7  | _        t        | dd       S )N_m_has_interlace@   r   )rh   r   r`   ri   rK   s    r   has_interlacez&Gif.LocalImageDescriptor.has_interlace   s>    t/0,,,%)ZZ"_$:D!4!3T::r   c                 z    t        | d      r| j                  S | j                  dz  dk7  | _        t        | dd       S )N_m_has_sorted_color_table    r   )rh   r   r`   ri   rK   s    r   has_sorted_color_tablez/Gif.LocalImageDescriptor.has_sorted_color_table   s>    t89555.2jj2o!-CD*4!<dCCr   c                 z    t        | d      r| j                  S d| j                  dz  z  | _        t        | dd       S rl   rp   rK   s    r   r6   z)Gif.LocalImageDescriptor.color_table_size   rq   r   rL   )
r   r   r   r,   r)   rr   r4   r   r   r6   r   r   r   LocalImageDescriptorrt      s_    		H 
	= 
	= 
	; 
	; 
	D 
	D 
	> 
	>r   r   c                       e Zd ZddZd Zy)	Gif.BlockNc                 V    || _         || _        |r|n| | _        | j                          y r$   r%   r*   s       r   r,   zGif.Block.__init__   rE   r   c                    t        j                  t        j                  | j                  j                               | _        | j                  }|t        j                  j                  k(  r1t        j                  | j                  | | j                        | _
        y |t        j                  j                  k(  r1t        j                  | j                  | | j                        | _
        y y r$   )r   resolve_enumr
   r   r&   rG   r>   r   	Extensionr(   bodyr   r   r+   _ons     r   r)   zGif.Block._read   s    *77txxGWGWGYZDO//Ccmm---MM$((D$**E	<<<44TXXtTZZP	 =r   rL   rW   r   r   r   r;   r      s    		Qr   r;   c                       e Zd ZdZddZd Zy)Gif.ColorTablezh
        .. seealso::
           - section 19 - https://www.w3.org/Graphics/GIF/spec-gif89a.txt
        Nc                 V    || _         || _        |r|n| | _        | j                          y r$   r%   r*   s       r   r,   zGif.ColorTable.__init__   rE   r   c                    g | _         d}| j                  j                         se| j                   j                  t        j                  | j                  | | j                               |dz  }| j                  j                         sdy y Nr   r/   )entriesr&   r=   r<   r
   rX   r(   )r+   r@   s     r   r)   zGif.ColorTable._read   s^    DLAhhoo'##C$7$7$

$STQ hhoo'r   rL   rM   r   r   r   r8   r      s    			r   r8   c                       e Zd ZdZddZd Zy)
Gif.Headerzh
        .. seealso::
           - section 17 - https://www.w3.org/Graphics/GIF/spec-gif89a.txt
        Nc                 V    || _         || _        |r|n| | _        | j                          y r$   r%   r*   s       r   r,   zGif.Header.__init__   rE   r   c                    | j                   j                  d      | _        | j                  dk(  s,t        j                  d| j                  | j                   d      | j                   j                  d      j                  d      | _        y )Nr.   s   GIFz/types/header/seq/0ASCII)r&   r5   magickaitaistructValidationNotEqualErrordecodeversionrK   s    r   r)   zGif.Header._read   sh    ,,Q/DJ::0"::?DJJX\X`X`bxyy HH//2::8DDLr   rL   rM   r   r   r   r0   r      s    			Er   r0   c                   >    e Zd ZdZddZd Zed        Zed        Zy)Gif.ExtGraphicControlzh
        .. seealso::
           - section 23 - https://www.w3.org/Graphics/GIF/spec-gif89a.txt
        Nc                 V    || _         || _        |r|n| | _        | j                          y r$   r%   r*   s       r   r,   zGif.ExtGraphicControl.__init__   rE   r   c                 *   | j                   j                  d      | _        | j                  dk(  s,t        j                  d| j                  | j                   d      | j                   j                         | _        | j                   j                         | _        | j                   j                         | _	        | j                   j                  d      | _
        | j                  dk(  s,t        j                  d| j                  | j                   d      y )Nr/      z /types/ext_graphic_control/seq/0    z /types/ext_graphic_control/seq/4)r&   r5   
block_sizer   r   rG   r`   r]   
delay_timetransparent_idx
terminatorrK   s    r   r)   zGif.ExtGraphicControl._read   s    "hh11!4DO??g-"::7DOOUYU]U]  `C  D  D))+DJ"hh002DO#'88#3#3#5D "hh11!4DO??g-"::7DOOUYU]U]  `C  D  D .r   c                 z    t        | d      r| j                  S | j                  dz  dk7  | _        t        | dd       S )N_m_transparent_color_flagr/   r   )rh   r   r`   ri   rK   s    r   transparent_color_flagz,Gif.ExtGraphicControl.transparent_color_flag   s>    t89555.2jj1n-BD*4!<dCCr   c                 z    t        | d      r| j                  S | j                  dz  dk7  | _        t        | dd       S )N_m_user_input_flagrn   r   )rh   r   r`   ri   rK   s    r   user_input_flagz%Gif.ExtGraphicControl.user_input_flag  s>    t12...'+zzA~!&;D#4!5t<<r   rL   )	r   r   r   rN   r,   r)   rr   r   r   r   r   r   ExtGraphicControlr      s<    				D 
	D 
	D 
	= 
	=r   r   c                       e Zd ZddZd Zy)Gif.SubblockNc                 V    || _         || _        |r|n| | _        | j                          y r$   r%   r*   s       r   r,   zGif.Subblock.__init__  rE   r   c                     | j                   j                         | _        | j                   j                  | j                        | _        y r$   )r&   rG   	len_bytesr5   bytesrK   s    r   r)   zGif.Subblock._read  s0    !XX--/DN,,T^^<DJr   rL   rW   r   r   r   Subblockr     s    		=r   r   c                       e Zd ZddZd Zy)Gif.ApplicationIdNc                 V    || _         || _        |r|n| | _        | j                          y r$   r%   r*   s       r   r,   zGif.ApplicationId.__init__  rE   r   c                 V   | j                   j                         | _        | j                  dk(  s,t        j                  d| j                  | j                   d      | j                   j                  d      j                  d      | _        | j                   j                  d      | _        y )N   z/types/application_id/seq/0   r   r.   )	r&   rG   r   r   r   r5   r   application_identifierapplication_auth_coderK   s    r   r)   zGif.ApplicationId._read$  s{    !XX--/DN>>R'"::2t~~txxYwxx+/88+>+>q+A*I*I(*SD')-)<)<Q)?D&r   rL   rW   r   r   r   ApplicationIdr     s    		@r   r   c                       e Zd ZddZd Zy)Gif.ExtApplicationNc                 V    || _         || _        |r|n| | _        | j                          y r$   r%   r*   s       r   r,   zGif.ExtApplication.__init__-  rE   r   c                 .   t         j                  | j                  | | j                        | _        g | _        d}	 t         j                  | j                  | | j                        }| j
                  j                  |       |j                  dk(  ry |dz  }\r   )	r
   r   r&   r(   application_idrJ   r   r<   r   r+   r@   rA   s      r   r)   zGif.ExtApplication._read3  sy    "%"3"3DHHdDJJ"ODDNALL4<%%a(;;!#Q r   rL   rW   r   r   r   ExtApplicationr   ,  s    			r   r   c                       e Zd ZddZd Zy)Gif.SubblocksNc                 V    || _         || _        |r|n| | _        | j                          y r$   r%   r*   s       r   r,   zGif.Subblocks.__init__@  rE   r   c                     g | _         d}	 t        j                  | j                  | | j                        }| j                   j                  |       |j                  dk(  ry |dz  }\r   )r   r
   r   r&   r(   r<   r   r   s      r   r)   zGif.Subblocks._readF  sZ    DLALL4<##A&;;!#Q r   rL   rW   r   r   r   rI   r   ?  s    		r   rI   c                       e Zd ZddZd Zy)Gif.ExtensionNc                 V    || _         || _        |r|n| | _        | j                          y r$   r%   r*   s       r   r,   zGif.Extension.__init__R  rE   r   c                    t        j                  t        j                  | j                  j                               | _        | j                  }|t        j                  j                  k(  r1t        j                  | j                  | | j                        | _
        y |t        j                  j                  k(  r1t        j                  | j                  | | j                        | _
        y |t        j                  j                  k(  r1t        j                  | j                  | | j                        | _
        y t        j                  | j                  | | j                        | _
        y r$   )r   r   r
   r"   r&   rG   labelr!   r   r(   r   r    rI   r   r   r   s     r   r)   zGif.Extension._readX  s    %2233E3EtxxGWGWGYZDJ**Cc((444..txxtzzJ	**222MM$((D$**E	**:::11$((D$**M	MM$((D$**E	r   rL   rW   r   r   r   r   r   Q  s    	
	Fr   r   rL   )r   r   r   rN   r   r   r"   r,   r)   r   rO   rX   r2   r   r;   r8   r0   r   r   r   r   rI   r   r   r   r   r
   r
      s    &D 
 "GL G 
+, 
+ >  >F2>| 2>jQ Q \ (E E$$=L $=N	=< 	=@ @ &L $FL Fr   r
   )
r   r   r   r   enumr   ri   	Exception__version__r
   r   r   r   <module>r      s_     < <  </&8
fjv  kC  kC  D  E  EWF, WFr   