
     f.                       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	 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          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   )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 ]i}|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)                      }|rP|                    |d           |dk    r3t          j        d|	          }t/          j        ||dd|	z   ddfg           n|                    |d           |                    d           |                                }|r(|d d         t7          |dz            z   |dd          z   }t#          |          }|                     t7          |                     |                     t7          |                     |                                }|                    |           |                     |           ||z   }|                    |           kd 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seekreado32)r   r   r   r   r   framesprovided_imswidthheightr5   provided_imbits	bits_usedother_imframeoffsetcolorsimage_ioand_maskimage_bytes	bytes_lencurrents                         U/var/www/api.educacionweb.es/myenv/lib/python3.11/site-packages/PIL/IcoImagePlugin.pyrD   rD   +   s\   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$//h%$<)P(Q   JJx'''ammoo 	O%bqb/C
OO;k"##>NNK$$	
Y   
V''))

)#
E" "    prefixbytesboolc                (    | d d         t           k    S )N   )r2   )rZ   s    rX   _acceptr_   v   s    "1":rY   c                  2    e Zd Zd Zd ZddZddZdd
ZdS )IcoFilec                X   |                     d          }t          |          sd}t          |          || _        g | _        t          |d          | _        t          | j                  D ]}|                     d          }|d         |d         |d         |d         t          |d          t          |d          t          |d	          t          |d
          d}dD ]}||         sd||<   |d         p0|d         dk    o"t          t          |d         d                    pd|d<   |d         |d         f|d<   |d         |d         z  |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/      r.   r0   )rJ   rK   nb_colorreservedplanesbppr5   rQ   rJ   rK   r$   rh   re   color_depthrJ   rK   dimsquarec                    | d         S )Nrj    xs    rX   <lambda>z"IcoFile.__init__.<locals>.<lambda>   s    a6F rY   )keyc                    | d         S )Nrl   rn   ro   s    rX   rq   z"IcoFile.__init__.<locals>.<lambda>   s
    ak rY   T)rr   reverseN)rF   r_   SyntaxErrorbufentryi16nb_itemsrangei32r   r   r8   r6   )selfrv   smsgiicon_headerjs          rX   __init__zIcoFile.__init__{   s    HHQKKqzz 	##Cc"""
 Aq		 t}%% !	+ !	+AA 1A$aDaDa))1ayyAq		a**	 	K ) ) )"1~ )%(KN
 E" 
+q0 >SZ!8!<<==
  & #.g"6H8M!NK$/$8;x;P$PK!Jk****DJ,F,FGGG
DJ,A,A4PPP


rY   c                $    d | j         D             S )zJ
        Get a list of all available icon sizes and color depths.
        c                .    h | ]}|d          |d         fS ri   rn   ).0hs     rX   	<setcomp>z IcoFile.sizes.<locals>.<setcomp>   s%    >>>a7Qx[)>>>rY   )rw   r|   s    rX   r   zIcoFile.sizes   s     ?>4:>>>>rY   Fc                z    t          | j                  D ]%\  }}||d         k    r|du s||d         k    r|c S &dS )Nrk   Frj   r   )	enumeraterw   )r|   r5   rh   r   r   s        rX   getentryindexzIcoFile.getentryindex   sT    dj)) 	 	DAqqxSE\\SAm<L5L5LqrY   c                T    |                      |                     ||                    S )z,
        Get an image from the icon
        )rP   r   )r|   r5   rh   s      rX   getimagezIcoFile.getimage   s&     zz$,,T377888rY   idxintr   r   c                d   | j         |         }| j                            |d                    | j                            d          }| j                            |d                    |dd         t          j        k    r4t	          j        | j                  }t          j        |j	                   nt          j        | j                  }t          j        |j	                   |j	        d         t          |j	        d         dz            f|_        |j        d         \  }}}}|d|j	        z   ||f|j        d<   |d         }	d	|	k    rw| j                            |           | j                            |j	        d         |j	        d         z  d
z            ddd
         }
t          j        d|j	        |
dd          }n|j	        d         }|d	z  dk    r|d	|j	        d         d	z  z
  z  }t          ||j	        d         z  dz            }|d         |d         z   |z
  }| j                            |           | j                            |          }t          j        d|j	        |ddt          |dz            df          }|                    d          }|                    |           |S )z-
        Get an image from frame idx
        rQ   r.   Nr   r   r/   r+   rh   r    r^   rd   Lr*   )r   r   r,   r5   r)   z1;Ir,   RGBA)rw   rv   rE   rF   r   r2   PngImageFiler
   _decompression_bomb_checkr5   r	   DibImageFiler   _sizetile
frombufferconvertputalpha)r|   r   headerdatar   deoarh   alpha_bytesmaskwtotal_bytesand_mask_offset	mask_datas                   rX   rP   zIcoFile.frame   s   
 CfX&'''x}}QfX&''' 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2BGAJ -CSyy a   "hmmBGAJ,Ca,GHHAN 'G   GAJFa<<rwqzB//A
 "1rwqz>Q"677"("2VF^"Ck"Qo... HMM+66	 'GCAJJ+  F##BKK	rY   N)F)r   r   r   r   )__name__
__module____qualname__r   r   r   r   rP   rn   rY   rX   ra   ra   z   sx        7Q 7Q 7Qr? ? ?   9 9 9 9N N N N N NrY   ra   c                  f    e Zd ZdZdZdZddZed             Zej	        d             Z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         d         | _        |                                  d S )Nr   r   rk   )ra   r   icor   inforw   r5   loadr   s    rX   _openzIcoImageFile._open3  sQ    47##!X^^--	'HN1%e,			rY   c                    | j         S N)r   r   s    rX   r5   zIcoImageFile.size9  s
    zrY   c                T    || j         d         vrd}t          |          || _        d S )Nr   z2This is not one of the allowed sizes of this image)r   
ValueErrorr   )r|   valuer~   s      rX   r5   zIcoImageFile.size=  s0    	'***FCS//!


rY   c                ^   | j         4| j         j        | j        k    rt          j                            |           S | j                            | j                  }|                                 |j         | _         d | _        |j        | _        |j	        r|j	        | _	        |j        | j        k    r|t          j        d           | j                            | j                  }t          | j        d                   }|j        ||<   t          |          | j        d<   |j        | _        d S d S )NzImage was not the expected sizer   )r   r5   r
   r   r   r   pyaccessr:   _modepalettewarningswarnr   listr   r7   )r|   r   indexr   s       rX   r   zIcoImageFile.loadD  s    747<49#<#<;##D)))Xty))
			%W
: 	&:DL7diM;<<<H**4955E7+,,E7E%L!$UDIgDIII  rY   posr   c                    d S r   rn   )r|   r   s     rX   	load_seekzIcoImageFile.load_seekZ  s	     	rY   N)r   r   )r   r   r   r   )r   r   r   __doc__formatformat_descriptionr   propertyr5   setterr   r   rn   rY   rX   r   r     s         ( F'      X 
[  [     ,     rY   r   z.icozimage/x-icon)r   r   r   r   r   r   r   r   )rZ   r[   r   r\   )#
__future__r   r   ior   mathr   r   typingr    r	   r
   r   r   _binaryr   rx   r   r{   r   r   r?   r   rG   r2   rD   r_   ra   r   register_openr   register_saveregister_extensionregister_mimern   rY   rX   <module>r      s  . # " " " " "                      > > > > > > > > > > > > ! ! ! ! ! ! ! ! ! ! ! !       ! ! ! ! ! ! ! ! ! ! ! !
 
H H H HV       Z Z Z Z Z Z Z ZBB B B B B9& B B BR  L'w ? ? ?  L' / / /  ,f 5 5 5  L' 8 8 8 8 8rY   