
    e6-                       d dl mZ d dlZd dlmZ d dlmZmZ ddlm	Z	m
Z
mZmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ dZd Zd Z G d d      Z G d dej                        Z e
j8                  ej:                  ee        e
j<                  ej:                  e        e
j>                  ej:                  d        e
j@                  ej:                  d       y)    )annotationsN)BytesIO)ceillog   )BmpImagePluginImage	ImageFilePngImagePlugin)i16le)i32le)o8)o16le)o32les      c           	        |j                  t               | j                  j                  d      dk(  }| j                  j                  dg d      }g }| g| j                  j                  dg       z   }| j                  \  }}t        t        |            D ]  }	|	d   |kD  s|	d   |kD  s|	d   dkD  s|	d   dkD  r%|D ]  }
|
j                  |	k7  r|j                  |
       |rt        j                  |
j                     d   }|g}|D ]Y  }|j                  |	k7  rt        j                  |j                     d   }||vs8|j                  |       |j                  |       [   
j                         }|j                  |	t        j                  j                  d 	       |j                  |         |j                  t!        t#        |                   |j%                         t#        |      d
z  z   }|D ]   }|j                  \  }}|j                  t'        |dk  r|nd             |j                  t'        |dk  r|nd             |r t        j                  |j                     dd  nd\  }}|j                  t'        |             |j                  d       |j                  d       |j                  t!        |             t)               }|rM|j+                  |d       |dk7  rHt        j,                  d	      }t/        j0                  ||dd|	z   ddfg       n|j+                  |d       |j3                  d       |j5                         }|r|d d t7        |dz        z   |dd  z   }t#        |      }|j                  t7        |             |j                  t7        |             |j%                         }|j3                  |       |j                  |       ||z   }|j3                  |        y )Nbitmap_formatbmpsizes))   r   )   r   )    r   )0   r   )@   r   )   r   )   r   append_imagesr   r   r   )reducing_gapr   )r   r       s     dibr   1rawr   r   )r    r   png         )write_MAGICencoderinfogetsizesortedsetappendr   SAVEmodecopy	thumbnailr	   
ResamplingLANCZOSo16lentellr   r   savenewr
   _saveseekreado32)imfpfilenamer   r   framesprovided_imswidthheightr,   provided_imbits	bits_usedother_imframeoffsetcolorsimage_ioand_maskimage_bytes	bytes_lencurrents                         4/usr/lib/python3/dist-packages/PIL/IcoImagePlugin.pyr;   r;   *   s}   HHV
..

_
-
6CNNRE F4"..,,_bAALGGME6s5z" !7U?d1g.$q'C-47S=' 	!K4'MM+&%**;+;+;<Q?!F	 , /H}}, )..x}}=a@D9, h/!((./ !	!&  $$&EOOD%"2"2":":ONMM% 3!4 HHSVWWYVr))F "

v
US[Ea01
fslF23>A~**5::6qr:wf
F


T9JJx'rz 99S$/h%$<)P(Q JJx'ammo%bq/C
O;k"#>NNK$	
Y 
V'')

)#
E"    c                    | d d t         k(  S )N   )r)   )prefixs    rR   _acceptrW   u   s    "1:rS   c                  .    e Zd Zd Zd ZddZddZd Zy)IcoFilec                   |j                  d      }t        |      sd}t        |      || _        g | _        t        |d      | _        t        | j                        D ]  }|j                  d      }|d   |d   |d   |d   t        |d      t        |d      t        |d	      t        |d
      d}dD ]  }||   r	d||<    |d   xs& |d   dk7  xr t        t        |d   d            xs d|d<   |d   |d   f|d<   |d   |d   z  |d<   | j                  j                  |        t        | j                  d       | _        t        | j                  d d      | _        y)zL
        Parse image from file-like object containing ico file data
           znot an ICO filerU   r   r   r   r&      r%   r'   )rD   rE   nb_colorreservedplanesbppr,   rK   )rD   rE   r   r`   r]   color_depthrD   rE   dimsquarec                    | d   S )Nra    xs    rR   <lambda>z"IcoFile.__init__.<locals>.<lambda>   s    a6F rS   )keyc                    | d   S )Nrc   re   rf   s    rR   rh   z"IcoFile.__init__.<locals>.<lambda>   s
    ak rS   T)ri   reverseN)r=   rW   SyntaxErrorbufentryi16nb_itemsrangei32r   r   r/   r-   )selfrm   smsgiicon_headerjs          rR   __init__zIcoFile.__init__z   s    HHQKqz#Cc""
 Aq	 t}}% !	+AA 1A$aDaDa)1ayAq	a*	K ) )"1~%(KN) E" 
+q0 >SZ!8!<=
  & #.g"6H8M!NK$/$8;x;P$PK!JJk*C!	+F DJJ,FG
DJJ,A4P
rS   c                P    | j                   D ch c]  }|d   |d   f c}S c c}w )zJ
        Get a list of all available icon sizes and color depths.
        rD   rE   )rn   )rs   hs     rR   r   zIcoFile.sizes   s)     48::>a7Qx[)>>>s   #c                p    t        | j                        D ]  \  }}||d   k(  s|du s	||d   k(  s|c S  y)Nrb   Fra   r   )	enumeratern   )rs   r,   r`   rv   r{   s        rR   getentryindexzIcoFile.getentryindex   sF    djj) 	DAqqxSE\SAm<L5L	 rS   c                D    | j                  | j                  ||            S )z,
        Get an image from the icon
        )rJ   r~   )rs   r,   r`   s      rR   getimagezIcoFile.getimage   s      zz$,,T3788rS   c                   | j                   |   }| j                  j                  |d          | j                  j                  d      }| j                  j                  |d          |dd t        j
                  k(  r@t	        j                  | j                        }t        j                  |j                         |S t        j                  | j                        }t        j                  |j                         |j                  d   t        |j                  d   dz        f|_        |j                  d   \  }}}}|d|j                  z   ||f|j                  d<   |d   }	d	|	k(  r| j                  j                  |       | j                  j                  |j                  d   |j                  d   z  d
z        ddd
   }
t        j                  d|j                  |
dd      }n|j                  d   }|d	z  dkD  r|d	|j                  d   d	z  z
  z  }t        ||j                  d   z  dz        }|d   |d   z   |z
  }| j                  j                  |       | j                  j                  |      }t        j                  d|j                  |ddt        |dz        df      }|j!                  d      }|j#                  |       |S )z-
        Get an image from frame idx
        rK   r%   Nr   r   r&   r"   r`   r   rU   r\   Lr!   )r   r   r#   r,   r    z1;Ir#   RGBA)rn   rm   r<   r=   r   r)   PngImageFiler	   _decompression_bomb_checkr,   r   DibImageFileint_sizetile
frombufferconvertputalpha)rs   idxheaderdatar?   deoar`   alpha_bytesmaskwtotal_bytesand_mask_offset	mask_datas                   rR   rJ   zIcoFile.frame   st   
 CfX&'xx}}QfX&'8~,,,,,TXX6B++BGG4~ 	y  ,,TXX6B++BGG4 
C
Q$78BHJAq!QFRWW,a2BGGAJ -CSy a "hhmmBGGAJ,Ca,GHAN ''GG  GGAJFa<rwwqzB//A
 "1rwwqz>Q"67"("2VF^"Ck"Qo. HHMM+6	 ''GGCAJ+ F#BKK	rS   N)F)__name__
__module____qualname__ry   r   r~   r   rJ   re   rS   rR   rY   rY   y   s    7Qr?9MrS   rY   c                  ^    e Zd ZdZdZdZd Zed        Zej                  d        Zd Z
d Zy	)
IcoImageFilea  
    PIL read-only image support for Microsoft Windows .ico files.

    By default the largest resolution image in the file will be loaded. This
    can be changed by altering the 'size' attribute before calling 'load'.

    The info dictionary has a key 'sizes' that is a list of the sizes available
    in the icon file.

    Handles classic, XP and Vista icon formats.

    When saving, PNG compression is used. Support for this was only added in
    Windows Vista. If you are unable to view the icon in Windows, convert the
    image to "RGBA" mode before saving.

    This plugin is a refactored version of Win32IconImagePlugin by Bryan Davis
    <casadebender@gmail.com>.
    https://code.google.com/archive/p/casadebender/wikis/Win32IconImagePlugin.wiki
    ICOzWindows Iconc                    t        | j                        | _        | j                  j                         | j                  d<   | j                  j
                  d   d   | _        | j                          y )Nr   r   rb   )rY   r@   icor   inforn   r,   loadrs   s    rR   _openzIcoImageFile._open1  sM    477#!XX^^-		'HHNN1%e,			rS   c                    | j                   S N)r   r   s    rR   r,   zIcoImageFile.size7  s    zzrS   c                N    || j                   d   vrd}t        |      || _        y )Nr   z2This is not one of the allowed sizes of this image)r   
ValueErrorr   )rs   valueru   s      rR   r,   zIcoImageFile.size;  s)    		'**FCS/!
rS   c                   | j                   B| j                   j                  | j                  k(  rt        j                  j                  |       S | j                  j                  | j                        }|j                          |j                   | _         d | _        |j                  | _        |j                  | j                  k7  rt        j                  d       | j                  j                  | j                        }t        | j                  d         }|j                  ||<   t        |      | j                  d<   |j                  | _        y y )NzImage was not the expected sizer   )r?   r,   r	   r   r   r   pyaccessr1   _modewarningswarnr~   listr   r.   )rs   r?   indexr   s       rR   r   zIcoImageFile.loadB  s    77477<<499#<;;##D))XXtyy)
	%%WW
77diiMM;<HH**4995E7+,E77E%L!$UDIIgDI  rS   c                     y r   re   r   s    rR   	load_seekzIcoImageFile.load_seekV  s     	rS   N)r   r   r   __doc__formatformat_descriptionr   propertyr,   setterr   r   re   rS   rR   r   r     sO    ( F'   
[[  (rS   r   z.icozimage/x-icon)!
__future__r   r   ior   mathr   r    r   r	   r
   r   _binaryr   ro   r   rr   r   r   r6   r   r>   r)   r;   rW   rY   r   register_openr   register_saveregister_extensionregister_mimere   rS   rR   <module>r      s   . #    > > ! !  ! !
 
HV Y Y@@9&& @N   L''w ?   L'' /   ,,f 5   L'' 8rS   