Ë
    \Rði   ã                   óÔ   — 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y)é   )Ú	MIME_TYPEÚPNG_CHUNK_TYPE)ÚInvalidImageStreamError)Ú
BIG_ENDIANÚStreamReader)ÚBaseImageHeaderc                   ó@   — e Zd ZdZed„ «       Zed„ «       Zed„ «       Zy)Ú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    úI/var/www/html/Extract/venv/lib/python3.12/site-packages/docx/image/png.pyÚcontent_typezPng.content_type
   s   € ô �}‰}Ðó    c                  ó   — y)z8Default filename extension, always 'png' for PNG images.Úpng© r   s    r   Údefault_extzPng.default_ext   s   € ð r   c                 ó¢   — t         j                  |«      }|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   sK   € ô ×!Ñ! &Ó)ˆà—?‘?ˆØ×$Ñ$ˆ	Ø—?‘?ˆØ—?‘?ˆá�8˜Y¨°(Ó;Ð;r   N)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úpropertyr   r   Úclassmethodr    r   r   r   r
   r
      s?   „ Ù-àñó ðð
 ñó ðð ñ
<ó ñ
<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                 ó8   •— t         t        | �  «        || _        y ©N)Úsuperr   Ú__init__Ú_chunks)r   ÚchunksÚ	__class__s     €r   r+   z_PngParser.__init__&   s   ø€ ÜŒj˜$Ñ(Ô*Øˆ�r   c                 ó<   — t         j                  |«      } | |«      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Ó,ˆÙ�6‹{Ðr   c                 óF   — | 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                 óF   — | 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                 ó€   — | j                   j                  }|€y| j                  |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.
        éH   )r,   ÚpHYsÚ_dpiÚunits_specifierÚhorz_px_per_unit©r   r7   s     r   r   z_PngParser.horz_dpi=   ó8   € ð �|‰|× Ñ ˆØˆ<ØØ�y‰y˜×-Ñ-¨t×/DÑ/DÓEÐEr   c                 ó€   — | j                   j                  }|€y| j                  |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.
        r6   )r,   r7   r8   r9   Úvert_px_per_unitr;   s     r   r   z_PngParser.vert_dpiH   r<   r   c                 ó@   — | dk(  r|rt        t        |dz  «      «      S y)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   s&   € ð ˜aÒ¡KÜ”u˜[¨6Ñ1Ó2Ó3Ð3Ør   )r!   r"   r#   r$   r+   r&   r   r%   r   r   r   r   Ústaticmethodr8   Ú__classcell__©r.   s   @r   r   r   #   s‡   ø„ ÙXôð ñó ðð ñó ðð
 ñó ðð
 ñFó ðFð ñFó ðFð ñó ôr   r   c                   óX   ‡ — 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                 óJ   •— t         t        | �  «        t        |«      | _        y r)   )r*   r0   r+   Úlistr,   )r   Úchunk_iterabler.   s     €r   r+   z_Chunks.__init___   s   ø€ ÜŒg�tÑ%Ô'Ü˜NÓ+ˆ�r   c                 ón   — t         j                  |«      }t        |j                  «       «      } | |«      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   s1   € ô $×/Ñ/°Ó7ˆÜ�l×.Ñ.Ó0Ó1ˆÙ�6‹{Ðr   c                 óH   — d„ }| j                  |«      }|€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™o´×1DÑ1DÑD€ r   zno IHDR chunk in PNG image)Ú_find_firstr   )r   Úmatchr2   s      r   r2   z_Chunks.IHDRj   s0   € ñ EˆØ×Ñ Ó&ˆØˆ<Ü)Ð*FÓGÐGØˆr   c                 ó*   — d„ }| j                  |«      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ˆØ×Ñ Ó&Ð&r   c                 ó>   — | j                   D ]  } ||«      sŒ|c S  y)zGReturn first chunk in stream order returning True for function `match`.N)r,   )r   rV   rR   s      r   rU   z_Chunks._find_firsty   s&   € à—\‘\ò 	ˆEÙ�U�|Ø’ð	ð r   )r!   r"   r#   r$   r+   r&   r    r%   r2   r7   rU   rD   rE   s   @r   r0   r0   \   sL   ø„ ÙBô,ð ñó ðð ñó ðð ñ'ó ð'ö
r   r0   c                   ó>   ‡ — 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                 ó8   •— t         t        | �  «        || _        y r)   )r*   rK   r+   Ú_stream_rdr)r   Ú
stream_rdrr.   s     €r   r+   z_ChunkParser.__init__„   s   ø€ ÜŒl˜DÑ*Ô,Ø%ˆÕr   c                 ó2   — 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ˆ
Ù�:‹Ðr   c              #   ór   K  — | j                  «       D ]   \  }}t        || j                  |«      }|–— Œ" y­w)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�   s>   è ø€ ð #'×":Ñ":Ó"<ò 	ÑˆJ˜Ü! *¨d×.>Ñ.>ÀÓGˆEØ‹Kñ	ùs   ‚57c              #   óº   K  — d}	 | j                   j                  |«      }| j                   j                  d|d«      }|dz   }||f–— |dk(  ry|d|z   dz   z  }ŒU­w)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.
        é   é   ÚIENDN)r\   Ú	read_longÚread_str)r   Úchunk_offsetÚchunk_data_lenrb   Údata_offsets        r   r`   z _ChunkParser._iter_chunk_offsets–   sy   è ø€ ð ˆØØ!×-Ñ-×7Ñ7¸ÓEˆNØ×)Ñ)×2Ñ2°1°lÀAÓFˆJØ&¨Ñ*ˆKØ˜kÐ)Ò)Ø˜VÒ#Øà˜E NÑ2°QÑ6Ñ6ˆLð ùs   ‚AA)
r!   r"   r#   r$   r+   r&   r    rL   r`   rD   rE   s   @r   rK   rK   �   s)   ø„ Ù2ô&ð ñó ðòö7r   rK   c                 ó¨   — t         j                  t        t         j                  t        i}|j                  | t        «      }|j                  | ||«      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€IØ× Ñ  ¨Z¸Ó@Ð@r   c                   óB   ‡ — 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                 ó8   •— t         t        | �  «        || _        y 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   € ñ �:‹Ð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   ³   s5   ø„ ñô
&ð ñó ðð ñ ó ô r   rq   c                   óR   ‡ — 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                 óH   •— t         t        | �  |«       || _        || _        y r)   )r*   rn   r+   Ú	_px_widthÚ
_px_height)r   rb   r   r   r.   s       €r   r+   z_IHDRChunk.__init__Ë   s    ø€ ÜŒj˜$Ñ(¨Ô4Ø!ˆŒØ#ˆ�r   c                 ó\   — |j                  |«      }|j                  |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Ð   s5   € ð ×'Ñ'¨Ó/ˆØ×(Ñ(¨°Ó3ˆ	Ù�:˜x¨Ó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   È   sG   ø„ Ù4ô$ð
 ñ4ó ð4ð ñó ðð ñó ôr   rn   c                   ób   ‡ — 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                 óV   •— t         t        | �  |«       || _        || _        || _        y 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Ø!1ˆÔØ!1ˆÔØ /ˆÕr   c                 ó‚   — |j                  |«      }|j                  |d«      }|j                  |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ê   sM   € ð &×/Ñ/°Ó7ÐØ%×/Ñ/°¸Ó:ÐØ$×.Ñ.¨v°qÓ9ˆÙ�:Ð/Ð1AÀ?Ó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ô0ð ñTó ðTð ñ&ó ð&ð ñ&ó ð&ð ñ%ó ô%r   ro   N)Ú	constantsr   r   Ú
exceptionsr   Úhelpersr   r   Úimager   r
   r   r0   rK   ra   rq   rn   ro   r   r   r   ú<module>r�      sf   ðß 0Ý /ß -Ý "ô<ˆ/ô <÷86ñ 6÷r"ñ "÷J$7ñ $7òNA÷ ñ  ô*�ô ô2%�õ %r   