§
    £”j   ã                   ó   — d dl mZmZ d dlmZ d dlmZmZ d dlm	Z	  G d„ de	¦  «        Z
 G d„ d¦  «        Z G d	„ d
¦  «        Z G d„ d¦  «        Zd„ Z G d„ d¦  «        Z G d„ de¦  «        Z G d„ de¦  «        ZdS )é   )Ú	MIME_TYPEÚPNG_CHUNK_TYPE)ÚInvalidImageStreamError)Ú
BIG_ENDIANÚStreamReader)ÚBaseImageHeaderc                   óT   — e Zd ZdZed„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         ZdS )ÚPngz#Image header parser for PNG images.c                 ó   — t           j        S )zUMIME content type for this image, unconditionally `image/png` for PNG
        images.)r   ÚPNG©Úselfs    ú]/var/www/finuniver-perm.ru/html/portfolio/venv/lib/python3.11/site-packages/docx/image/png.pyÚcontent_typezPng.content_type
   s   € õ Œ}Ðó    c                 ó   — dS )z8Default filename extension, always 'png' for PNG images.Úpng© r   s    r   Údefault_extzPng.default_ext   s	   € ð ˆur   c                 óŠ   — t                                |¦  «        }|j        }|j        }|j        }|j        } | ||||¦  «        S )zWReturn a |Png| instance having header properties parsed from image in
        `stream`.)Ú
_PngParserÚparseÚpx_widthÚ	px_heightÚhorz_dpiÚvert_dpi)ÚclsÚstreamÚparserr   r   r   r   s          r   Úfrom_streamzPng.from_stream   sJ   € õ ×!Ò! &Ñ)Ô)ˆà”?ˆØÔ$ˆ	Ø”?ˆØ”?ˆàˆs�8˜Y¨°(Ñ;Ô;Ð;r   N)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úpropertyr   r   Úclassmethodr    r   r   r   r
   r
      si   € € € € € Ø-Ð-àðð ñ „Xðð
 ðð ñ „Xðð ð
<ð 
<ñ „[ð
<ð 
<ð 
<r   r
   c                   ó¦   ‡ — e Zd ZdZˆ fd„Zed„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         Z	ed„ ¦   «         Z
ed„ ¦   «         Zed„ ¦   «         Zˆ xZS )	r   zNParses a PNG image stream to extract the image properties found in its chunks.c                 ód   •— t          t          | ¦  «                             ¦   «          || _        d S ©N)Úsuperr   Ú__init__Ú_chunks)r   ÚchunksÚ	__class__s     €r   r+   z_PngParser.__init__&   s*   ø€ Ý�j˜$ÑÔ×(Ò(Ñ*Ô*Ð*ØˆŒˆˆr   c                 óL   — t                                |¦  «        } | |¦  «        S )znReturn a |_PngParser| instance containing the header properties parsed from
        the PNG image in `stream`.)Ú_Chunksr    )r   r   r-   s      r   r   z_PngParser.parse*   s%   € õ ×$Ò$ VÑ,Ô,ˆØˆs�6‰{Œ{Ðr   c                 ó(   — | j         j        }|j        S )z.The number of pixels in each row of the image.)r,   ÚIHDRr   ©r   r2   s     r   r   z_PngParser.px_width1   s   € ð Œ|Ô ˆØŒ}Ðr   c                 ó(   — | j         j        }|j        S )z2The number of stacked rows of pixels in the image.)r,   r2   r   r3   s     r   r   z_PngParser.px_height7   s   € ð Œ|Ô ˆØŒ~Ðr   c                 ób   — | j         j        }|€dS |                      |j        |j        ¦  «        S )z‡Integer dots per inch for the width of this image.

        Defaults to 72 when not present in the file, as is often the case.
        NéH   )r,   ÚpHYsÚ_dpiÚunits_specifierÚhorz_px_per_unit©r   r7   s     r   r   z_PngParser.horz_dpi=   ó2   € ð Œ|Ô ˆØˆ<Ø�2Ø�yŠy˜Ô-¨tÔ/DÑEÔEÐEr   c                 ób   — | j         j        }|€dS |                      |j        |j        ¦  «        S )zˆInteger dots per inch for the height of this image.

        Defaults to 72 when not present in the file, as is often the case.
        Nr6   )r,   r7   r8   r9   Úvert_px_per_unitr;   s     r   r   z_PngParser.vert_dpiH   r<   r   c                 óT   — | dk    r!|rt          t          |dz  ¦  «        ¦  «        S dS )zWReturn dots per inch value calculated from `units_specifier` and
        `px_per_unit`.r   g¦
F%uš?r6   )ÚintÚround)r9   Úpx_per_units     r   r8   z_PngParser._dpiS   s4   € ð ˜aÒÐ KÐÝ•u˜[¨6Ñ1Ñ2Ô2Ñ3Ô3Ð3Øˆrr   )r!   r"   r#   r$   r+   r&   r   r%   r   r   r   r   Ústaticmethodr8   Ú__classcell__©r.   s   @r   r   r   #   sæ   ø€ € € € € ØXÐXðð ð ð ð ð ðð ñ „[ðð ðð ñ „Xðð
 ðð ñ „Xðð
 ðFð Fñ „XðFð ðFð Fñ „XðFð ðð ñ „\ðð ð ð ð r   r   c                   ój   ‡ — e Zd ZdZˆ fd„Zed„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         Z	d„ Z
ˆ xZS )r0   z8Collection of the chunks parsed from a PNG image stream.c                 ó~   •— t          t          | ¦  «                             ¦   «          t          |¦  «        | _        d S r)   )r*   r0   r+   Úlistr,   )r   Úchunk_iterabler.   s     €r   r+   z_Chunks.__init___   s2   ø€ Ý�g�tÑÔ×%Ò%Ñ'Ô'Ð'Ý˜NÑ+Ô+ˆŒˆˆr   c                 óŽ   — t                                |¦  «        }t          |                     ¦   «         ¦  «        } | |¦  «        S )zBReturn a |_Chunks| instance containing the PNG chunks in `stream`.)Ú_ChunkParserr    rH   Úiter_chunks)r   r   Úchunk_parserr-   s       r   r    z_Chunks.from_streamc   s>   € õ $×/Ò/°Ñ7Ô7ˆÝ�l×.Ò.Ñ0Ô0Ñ1Ô1ˆØˆs�6‰{Œ{Ðr   c                 óX   — d„ }|                       |¦  «        }|€t          d¦  «        ‚|S )zIHDR chunk in PNG image.c                 ó,   — | j         t          j        k    S r)   )Ú	type_namer   r2   ©Úchunks    r   ú<lambda>z_Chunks.IHDR.<locals>.<lambda>m   ó   € ˜eœoµÔ1DÒD€ r   Nzno IHDR chunk in PNG image)Ú_find_firstr   )r   Úmatchr2   s      r   r2   z_Chunks.IHDRj   s9   € ð EÐDˆØ×Ò Ñ&Ô&ˆØˆ<Ý)Ð*FÑGÔGÐGØˆr   c                 ó2   — d„ }|                       |¦  «        S )z2PHYs chunk in PNG image, or |None| if not present.c                 ó,   — | j         t          j        k    S r)   )rP   r   r7   rQ   s    r   rS   z_Chunks.pHYs.<locals>.<lambda>v   rT   r   )rU   )r   rV   s     r   r7   z_Chunks.pHYss   s!   € ð EÐDˆØ×Ò Ñ&Ô&Ð&r   c                 ó8   — | j         D ]} ||¦  «        r|c S ŒdS )zGReturn first chunk in stream order returning True for function `match`.N)r,   )r   rV   rR   s      r   rU   z_Chunks._find_firsty   s6   € à”\ð 	ð 	ˆEØˆu�U‰|Œ|ð Ø���ðàˆtr   )r!   r"   r#   r$   r+   r&   r    r%   r2   r7   rU   rD   rE   s   @r   r0   r0   \   sž   ø€ € € € € ØBÐBð,ð ,ð ,ð ,ð ,ð ðð ñ „[ðð ðð ñ „Xðð ð'ð 'ñ „Xð'ð
ð ð ð ð ð ð r   r0   c                   óD   ‡ — e Zd ZdZˆ fd„Zed„ ¦   «         Zd„ Zd„ Zˆ xZ	S )rK   z(Extracts chunks from a PNG image stream.c                 ód   •— t          t          | ¦  «                             ¦   «          || _        d S r)   )r*   rK   r+   Ú_stream_rdr)r   Ú
stream_rdrr.   s     €r   r+   z_ChunkParser.__init__„   s-   ø€ Ý�l˜DÑ!Ô!×*Ò*Ñ,Ô,Ð,Ø%ˆÔÐÐr   c                 óB   — t          |t          ¦  «        } | |¦  «        S )zdReturn a |_ChunkParser| instance that can extract the chunks from the PNG
        image in `stream`.)r   r   )r   r   r]   s      r   r    z_ChunkParser.from_streamˆ   s!   € õ " &­*Ñ5Ô5ˆ
Øˆs�:‰ŒÐr   c              #   ór   K  — |                       ¦   «         D ]\  }}t          || j        |¦  «        }|V — Œ dS )z�Generate a |_Chunk| subclass instance for each chunk in this parser's PNG
        stream, in the order encountered in the stream.N)Ú_iter_chunk_offsetsÚ_ChunkFactoryr\   )r   Ú
chunk_typeÚoffsetrR   s       r   rL   z_ChunkParser.iter_chunks�   sQ   è è € ð #'×":Ò":Ñ"<Ô"<ð 	ð 	ÑˆJ˜Ý! *¨dÔ.>ÀÑGÔGˆEØˆKˆKˆKˆKð	ð 	r   c              #   ó¶   K  — d}	 | j                              |¦  «        }| j                              d|d¦  «        }|dz   }||fV — |dk    rdS |d|z   dz   z  }ŒU)z©Generate a (chunk_type, chunk_offset) 2-tuple for each of the chunks in the
        PNG image stream.

        Iteration stops after the IEND chunk is returned.
        é   Té   ÚIENDN)r\   Ú	read_longÚread_str)r   Úchunk_offsetÚchunk_data_lenrb   Údata_offsets        r   r`   z _ChunkParser._iter_chunk_offsets–   s†   è è € ð ˆð	7Ø!Ô-×7Ò7¸ÑEÔEˆNØÔ)×2Ò2°1°lÀAÑFÔFˆJØ&¨Ñ*ˆKØ˜kÐ)Ð)Ð)Ð)Ø˜VÒ#Ð#Ø�à˜E NÑ2°QÑ6Ñ6ˆLð	7r   )
r!   r"   r#   r$   r+   r&   r    rL   r`   rD   rE   s   @r   rK   rK   �   sw   ø€ € € € € Ø2Ð2ð&ð &ð &ð &ð &ð ðð ñ „[ððð ð ð7ð 7ð 7ð 7ð 7ð 7ð 7r   rK   c                 ó®   — t           j        t          t           j        t          i}|                     | t          ¦  «        }|                     | ||¦  «        S )ziReturn a |_Chunk| subclass instance appropriate to `chunk_type` parsed from
    `stream_rdr` at `offset`.)r   r2   Ú
_IHDRChunkr7   Ú
_pHYsChunkÚgetÚ_ChunkÚfrom_offset)rb   r]   rc   Úchunk_cls_mapÚ	chunk_clss        r   ra   ra   ¨   sJ   € õ 	Ô�ZÝÔ�Zð€Mð ×!Ò! *­fÑ5Ô5€IØ× Ò  ¨Z¸Ñ@Ô@Ð@r   c                   óN   ‡ — e Zd ZdZˆ fd„Zed„ ¦   «         Zed„ ¦   «         Zˆ xZ	S )rq   zUBase class for specific chunk types.

    Also serves as the default chunk type.
    c                 ód   •— t          t          | ¦  «                             ¦   «          || _        d S r)   )r*   rq   r+   Ú_chunk_type)r   rb   r.   s     €r   r+   z_Chunk.__init__¹   s-   ø€ Ý�f�dÑÔ×$Ò$Ñ&Ô&Ð&Ø%ˆÔÐÐr   c                 ó   —  | |¦  «        S )z@Return a default _Chunk instance that only knows its chunk type.r   )r   rb   r]   rc   s       r   rr   z_Chunk.from_offset½   s   € ð ˆs�:‰ŒÐr   c                 ó   — | j         S )z.The chunk type name, e.g. 'IHDR', 'pHYs', etc.)rw   r   s    r   rP   z_Chunk.type_nameÂ   s   € ð ÔÐr   )
r!   r"   r#   r$   r+   r&   rr   r%   rP   rD   rE   s   @r   rq   rq   ³   sx   ø€ € € € € ðð ð
&ð &ð &ð &ð &ð ðð ñ „[ðð ð ð  ñ „Xð ð  ð  ð  ð  r   rq   c                   ód   ‡ — e Zd ZdZˆ fd„Zed„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         Z	ˆ xZ
S )rn   z*IHDR chunk, contains the image dimensions.c                 ót   •— t          t          | ¦  «                             |¦  «         || _        || _        d S r)   )r*   rn   r+   Ú	_px_widthÚ
_px_height)r   rb   r   r   r.   s       €r   r+   z_IHDRChunk.__init__Ë   s3   ø€ Ý�j˜$ÑÔ×(Ò(¨Ñ4Ô4Ð4Ø!ˆŒØ#ˆŒˆˆr   c                 ór   — |                      |¦  «        }|                      |d¦  «        } | |||¦  «        S )z|Return an _IHDRChunk instance containing the image dimensions extracted from
        the IHDR chunk in `stream` at `offset`.rf   )rh   )r   rb   r]   rc   r   r   s         r   rr   z_IHDRChunk.from_offsetÐ   s@   € ð ×'Ò'¨Ñ/Ô/ˆØ×(Ò(¨°Ñ3Ô3ˆ	Øˆs�:˜x¨Ñ3Ô3Ð3r   c                 ó   — | j         S r)   )r|   r   s    r   r   z_IHDRChunk.px_widthØ   s
   € àŒ~Ðr   c                 ó   — | j         S r)   )r}   r   s    r   r   z_IHDRChunk.px_heightÜ   s
   € àŒÐr   )r!   r"   r#   r$   r+   r&   rr   r%   r   r   rD   rE   s   @r   rn   rn   È   s�   ø€ € € € € Ø4Ð4ð$ð $ð $ð $ð $ð
 ð4ð 4ñ „[ð4ð ðð ñ „Xðð ðð ñ „Xðð ð ð ð r   rn   c                   óz   ‡ — e Zd ZdZˆ fd„Zed„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         Z	ed„ ¦   «         Z
ˆ xZS )ro   z/PYHs chunk, contains the image dpi information.c                 ó‚   •— t          t          | ¦  «                             |¦  «         || _        || _        || _        d S r)   )r*   ro   r+   Ú_horz_px_per_unitÚ_vert_px_per_unitÚ_units_specifier)r   rb   r:   r>   r9   r.   s        €r   r+   z_pHYsChunk.__init__ä   s?   ø€ Ý�j˜$ÑÔ×(Ò(¨Ñ4Ô4Ð4Ø!1ˆÔØ!1ˆÔØ /ˆÔÐÐr   c                 ó    — |                      |¦  «        }|                      |d¦  «        }|                     |d¦  «        } | ||||¦  «        S )z{Return a _pHYsChunk instance containing the image resolution extracted from
        the pHYs chunk in `stream` at `offset`.rf   re   )rh   Ú	read_byte)r   rb   r]   rc   r:   r>   r9   s          r   rr   z_pHYsChunk.from_offsetê   s[   € ð &×/Ò/°Ñ7Ô7ÐØ%×/Ò/°¸Ñ:Ô:ÐØ$×.Ò.¨v°qÑ9Ô9ˆØˆs�:Ð/Ð1AÀ?ÑSÔSÐSr   c                 ó   — | j         S r)   )rƒ   r   s    r   r:   z_pHYsChunk.horz_px_per_unitó   ó   € àÔ%Ð%r   c                 ó   — | j         S r)   )r„   r   s    r   r>   z_pHYsChunk.vert_px_per_unit÷   r‰   r   c                 ó   — | j         S r)   )r…   r   s    r   r9   z_pHYsChunk.units_specifierû   s   € àÔ$Ð$r   )r!   r"   r#   r$   r+   r&   rr   r%   r:   r>   r9   rD   rE   s   @r   ro   ro   á   s­   ø€ € € € € Ø9Ð9ð0ð 0ð 0ð 0ð 0ð ðTð Tñ „[ðTð ð&ð &ñ „Xð&ð ð&ð &ñ „Xð&ð ð%ð %ñ „Xð%ð %ð %ð %ð %r   ro   N)Ú	constantsr   r   Ú
exceptionsr   Úhelpersr   r   Úimager   r
   r   r0   rK   ra   rq   rn   ro   r   r   r   ú<module>r�      s–  ðØ 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ø /Ð /Ð /Ð /Ð /Ð /Ø -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ø "Ð "Ð "Ð "Ð "Ð "ð<ð <ð <ð <ð <ˆ/ñ <ô <ð <ð86ð 6ð 6ð 6ð 6ñ 6ô 6ð 6ðr"ð "ð "ð "ð "ñ "ô "ð "ðJ$7ð $7ð $7ð $7ð $7ñ $7ô $7ð $7ðNAð Að Að ð  ð  ð  ð  ñ  ô  ð  ð*ð ð ð ð �ñ ô ð ð2%ð %ð %ð %ð %�ñ %ô %ð %ð %ð %r   