
    zvg0                       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
 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#dZd$dZ G d de
          Z G d d          Z G d d ej                  Z ej         ej!        ee            ej"        ej!        e            ej#        ej!        d!            ej$        ej!        d"           dS )%    )annotationsN)BytesIO)ceillog)IO
NamedTuple   )BmpImagePluginImage	ImageFilePngImagePlugin)i16le)i32le)o8)o16le)o32les      imImage.Imagefp	IO[bytes]filenamestr | bytesreturnNonec                <	   |                     t                     | j                            d          dk    }| j                            dg d          }g }| g| j                            dg           z   }| j        \  }}t          t          |                    D ])}	|	d         |k    s$|	d         |k    s|	d         dk    s|	d         dk    r4|D ]}
|
j        |	k    r|                    |
           |r|t          j	        |
j
                 d         }|g}|D ]Y}|j        |	k    rt          j	        |j
                 d         }||vr*|                    |           |                    |           Z nP|
                                }|                    |	t          j        j        d 	           |                    |           +|                     t!          t#          |                               |                                t#          |          d
z  z   }|D ]z}|j        \  }}|                     t'          |dk     r|nd                     |                     t'          |dk     r|nd                     |rt          j	        |j
                 dd          nd\  }}|                     t'          |                     |                     d           |                     d           |                     t!          |                     t)                      }|ra|                    |d           |dk    rDt          j        d|	          }t/          j        ||t/          j        dd|	z   dd          g           n|                    |d           |                    d           |                                }|r(|d d         t9          |dz            z   |dd          z   }t#          |          }|                     t9          |                     |                     t9          |                     |                                }|                    |           |                     |           ||z   }|                    |           |d S )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_Tileseekreado32)r   r   r   r   r   framesprovided_imswidthheightr6   provided_imbits	bits_usedother_imframeoffsetcolorsimage_ioand_maskimage_bytes	bytes_lencurrents                         O/var/www/pixelcanvas.ch/venv/lib/python3.11/site-packages/PIL/IcoImagePlugin.pyrE   rE   +   se   HHV
.

_
-
-
6CNRRR E F4".,,_bAAALGME6s5zz"" ! !7U??d1g..$q'C--47S==' 	! 	!K4''MM+&&& /%*;+;<Q?!F	 , / /H},, ).x}=a@D9,, h///!((...E  $$&&EOOD%"2":ONNNMM%   HHSVWWYYVr))F $ $
v
US[[EEa00111
fsllFF22333>AN~*5:6qrr::wf
F


T99 	(JJx'''rzz 9S$//_UFTM1lKKL   JJx'''ammoo 	O%bqb/C
OO;k"##>NNK$$	
Y   
V''))

)#
I$ $    prefixbytesboolc                (    | d d         t           k    S )N   )r3   )r\   s    rZ   _acceptra   x   s    "1":r[   c                  ~    e Zd ZU ded<   ded<   ded<   ded<   ded<   ded<   ded<   ded	<   d
ed<   ded<   ded<   dS )
IconHeaderintrL   rM   nb_colorreservedplanesbppr6   rS   tuple[int, int]dimsquarecolor_depthN)__name__
__module____qualname____annotations__ r[   rZ   rc   rc   |   s{         JJJKKKMMMMMMKKKHHHIIIKKKKKKr[   rc   c                  :    e Zd ZddZddZdddZdddZddZdS )IcoFilebufr   r   r   c                   |                     d          }t          |          sd}t          |          || _        g | _        t          |d          | _        t          | j                  D ]}|                     d          }|d         pd}|d         pd}|d         }t          |d          }t          ||||d	         t          |d          t          |d          t          |d
          t          |d          ||f||z  |p$|dk    rt          t          |d                    pd          }	| j                            |	           t          | j        d           | _        t          | j        d d          | _        dS )zL
        Parse image from file-like object containing ico file data
           znot an ICO filer`   r   r   r%   r	   r0      r/   r1   )rL   rM   re   rf   rg   rh   r6   rS   rj   rk   rl   c                    | j         S N)rl   xs    rZ   <lambda>z"IcoFile.__init__.<locals>.<lambda>   s    am r[   )keyc                    | j         S ry   )rk   rz   s    rZ   r|   z"IcoFile.__init__.<locals>.<lambda>   s    ah r[   T)r}   reverseN)rH   ra   SyntaxErrorrt   entryi16nb_itemsrangerc   i32r   r   r9   r7   )
selfrt   smsgirL   rM   re   rh   icon_headers
             rZ   __init__zIcoFile.__init__   s    HHQKKqzz 	##Cc"""
 Aq		 t}%% 	+ 	+AA aDKCEqT[SF tHa))C$!11ayy1IIAYY1bzzFOv~  THM$Ld3x;K;K6L6LTQT  K  Jk****DJ,C,CDDD
DJ,>,>MMM


r[   set[tuple[int, int]]c                $    d | j         D             S )zI
        Get a set of all available icon sizes and color depths.
        c                *    h | ]}|j         |j        fS rq   )rL   rM   ).0hs     rZ   	<setcomp>z IcoFile.sizes.<locals>.<setcomp>   s!    888!(#888r[   )r   r   s    rZ   r   zIcoFile.sizes   s     98TZ8888r[   Fr6   ri   rh   
int | boolrd   c                v    t          | j                  D ]#\  }}||j        k    r|du s||j        k    r|c S $dS )NFr   )	enumerater   rj   rl   )r   r6   rh   r   r   s        rZ   getentryindexzIcoFile.getentryindex   sM    dj)) 	 	DAqqu}}#,,#2F2Fqr[   r   c                T    |                      |                     ||                    S )z,
        Get an image from the icon
        )rR   r   )r   r6   rh   s      rZ   getimagezIcoFile.getimage   s&     zz$,,T377888r[   idxc                   | j         |         }| j                            |j                   | j                            d          }| j                            |j                   |dd         t
          j        k    r4t          j        | j                  }t          j	        |j
                   nNt          j        | j                  }t          j	        |j
                   |j
        d         t          |j
        d         dz            f|_        |j        d         \  }}}}t!          j        |d|j
        z   ||          |j        d<   |j        dk    r| j                            |           | j                            |j
        d         |j
        d         z  dz            d	dd         }		 t          j        d
|j
        |	dd          }
n# t(          $ r t           j        rd}
n Y nw xY w|j
        d         }|dz  dk    r|d|j
        d         dz  z
  z  }t          ||j
        d         z  dz            }|j        |j
        z   |z
  }| j                            |           | j                            |          }	 t          j        d|j
        |ddt          |dz            df          }
n # t(          $ r t           j        rd}
n Y nw xY w|
r*|                    d          }|                    |
           |S )z-
        Get an image from frame idx
        r/   Nr   r	   r0   r,   r!   r`   rw   Lr+   )r   r   r-   r*   z1;Ir-   RGBA)r   rt   rG   rS   rH   r   r3   PngImageFiler   _decompression_bomb_checkr6   r
   DibImageFilerd   _sizetiler   rF   rh   
frombuffer
ValueErrorLOAD_TRUNCATED_IMAGESconvertputalpha)r   r   headerdatar   deoaalpha_bytesmaskwtotal_bytesand_mask_offset	mask_datas                  rZ   rR   zIcoFile.frame   s   
 Cfm$$$x}}Qfm$$$ 8~,,,,TX66B+BG4444  ,TX66B+BG444 
C
Q$7$78BHJAq!Q"FRW,<aCCBGAJ zR a   "hmmBGAJ,Ca,GHHAN +#$ DD "    6 #  GAJFa<<rwqzB//A
 "1rwqz>Q"677"(-&+"="Ko... HMM+66	 +!AE

B/ DD "    6 #   "ZZ''D!!!	s$   1G G-,G-0J4 4KKN)rt   r   r   r   )r   r   )F)r6   ri   rh   r   r   rd   )r6   ri   rh   r   r   r   )r   rd   r   r   )rm   rn   ro   r   r   r   r   rR   rq   r[   rZ   rs   rs      s        0N 0N 0N 0Nd9 9 9 9    9 9 9 9 9Z Z Z Z Z Zr[   rs   c                  l    e Zd ZdZdZdZddZedd            Zej	        dd
            ZddZ
ddZdS )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 Iconr   r   c                    t          | j                  | _        | j                                        | j        d<   | j        j        d         j        | _        |                                  d S )Nr   r   )	rs   r   icor   infor   rj   r6   loadr   s    rZ   _openzIcoImageFile._openH  sO    47##!X^^--	'HN1%)			r[   ri   c                    | j         S ry   )r   r   s    rZ   r6   zIcoImageFile.sizeN  s
    zr[   valuec                T    || j         d         vrd}t          |          || _        d S )Nr   z2This is not one of the allowed sizes of this image)r   r   r   )r   r   r   s      rZ   r6   zIcoImageFile.sizeR  s0    	'***FCS//!


r[   Image.core.PixelAccess | Nonec                L   | j         4| j        j        | j        k    rt          j                            |           S | j                            | j                  }|                                 |j        | _        |j        | _        |j	        r|j	        | _	        |j        | j        k    rzt          j        d           | j                            | j                  }t          | j        d                   }|j        ||<   t          |          | j        d<   |j        | _        d S )NzImage was not the expected sizer   )_imr   r6   r   r   r   r   r;   _modepalettewarningswarnr   listr   r8   )r   r   indexr   s       rZ   r   zIcoImageFile.loadY  s    8DGLDI$=$=;##D)))Xty))
			%W
: 	&:DL7diM;<<<H**4955E7+,,E7E%L!$UDIgDItr[   posrd   c                    d S ry   rq   )r   r   s     rZ   	load_seekzIcoImageFile.load_seeko  s	     	r[   N)r   r   )r   ri   )r   ri   r   r   )r   r   )r   rd   r   r   )rm   rn   ro   __doc__formatformat_descriptionr   propertyr6   setterr   r   rq   r[   rZ   r   r   0  s         ( F'       X 
[   [   ,     r[   r   z.icozimage/x-icon)r   r   r   r   r   r   r   r   )r\   r]   r   r^   )%
__future__r   r   ior   mathr   r   typingr   r    r
   r   r   r   _binaryr   r   r   r   r   r   r@   r   rI   r3   rE   ra   rc   rs   r   register_openr   register_saveregister_extensionregister_mimerq   r[   rZ   <module>r      s  . # " " " " "                ! ! ! ! ! ! ! ! > > > > > > > > > > > > ! ! ! ! ! ! ! ! ! ! ! !       ! ! ! ! ! ! ! ! ! ! ! !
 
J J J JZ              _ _ _ _ _ _ _ _LB B B B B9& B B BR  L'w ? ? ?  L' / / /  ,f 5 5 5  L' 8 8 8 8 8r[   