ó
    ‰*£h   ã                   óÔ   • S SK JrJr  S SKJr  S SKJrJr  S SKJ	r	   " S S\	5      r
 " S S5      r " S	 S
5      r " S S5      rS r " S S5      r " S S\5      r " S S\5      rg)é   )Ú	MIME_TYPEÚPNG_CHUNK_TYPE)ÚInvalidImageStreamError)Ú
BIG_ENDIANÚStreamReader)ÚBaseImageHeaderc                   óH   • \ rS rSrSr\S 5       r\S 5       r\S 5       r	Sr
g)ÚPngé   z#Image header parser for PNG images.c                 ó"   • [         R                  $ )zMMIME content type for this image, unconditionally `image/png` for PNG
images.)r   ÚPNG©Úselfs    ÚK/home/mande/repo/quber/.venv/lib/python3.13/site-packages/docx/image/png.pyÚcontent_typeÚPng.content_type
   s   € ô �}‰}Ðó    c                 ó   • g)z8Default filename extension, always 'png' for PNG images.Úpng© r   s    r   Údefault_extÚPng.default_ext   s   € ð r   c                 óž   • [         R                  U5      nUR                  nUR                  nUR                  nUR
                  nU " X4XV5      $ )zOReturn 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_streamÚPng.from_stream   sG   € ô ×!Ñ! &Ó)ˆà—?‘?ˆØ×$Ñ$ˆ	Ø—?‘?ˆØ—?‘?ˆá�8¨Ó;Ð;r   r   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Úpropertyr   r   Úclassmethodr#   Ú__static_attributes__r   r   r   r
   r
      s?   † Ù-àñó ðð
 ñó ðð ñ
<ó ó
<r   r
   c                   óŒ   ^ • \ rS rSrSrU 4S jr\S 5       r\S 5       r	\S 5       r
\S 5       r\S 5       r\S	 5       rS
rU =r$ )r   é#   zNParses a PNG image stream to extract the image properties found in its chunks.c                 ó6   >• [         [        U ]  5         Xl        g ©N)Úsuperr   Ú__init__Ú_chunks)r   ÚchunksÚ	__class__s     €r   r2   Ú_PngParser.__init__&   s   ø€ ÜŒj˜$Ñ(Ô*Ø�r   c                 ó<   • [         R                  U5      nU " U5      $ )zfReturn a |_PngParser| instance containing the header properties parsed from
the PNG image in `stream`.)Ú_Chunksr#   )r    r!   r4   s      r   r   Ú_PngParser.parse*   s   € ô ×$Ñ$ VÓ,ˆÙ�6‹{Ðr   c                 óF   • U R                   R                  nUR                  $ )z.The number of pixels in each row of the image.)r3   ÚIHDRr   ©r   r;   s     r   r   Ú_PngParser.px_width1   s   € ð �|‰|× Ñ ˆØ�}‰}Ðr   c                 óF   • U R                   R                  nUR                  $ )z2The number of stacked rows of pixels in the image.)r3   r;   r   r<   s     r   r   Ú_PngParser.px_height7   s   € ð �|‰|× Ñ ˆØ�~‰~Ðr   c                 ó‚   • U R                   R                  nUc  gU R                  UR                  UR                  5      $ )zwInteger dots per inch for the width of this image.

Defaults to 72 when not present in the file, as is often the case.
éH   )r3   ÚpHYsÚ_dpiÚunits_specifierÚhorz_px_per_unit©r   rB   s     r   r   Ú_PngParser.horz_dpi=   ó8   € ð �|‰|× Ñ ˆØ‰<ØØ�y‰y˜×-Ñ-¨t×/DÑ/DÓEÐEr   c                 ó‚   • U R                   R                  nUc  gU R                  UR                  UR                  5      $ )zxInteger dots per inch for the height of this image.

Defaults to 72 when not present in the file, as is often the case.
rA   )r3   rB   rC   rD   Úvert_px_per_unitrF   s     r   r   Ú_PngParser.vert_dpiH   rH   r   c                 óL   • U S:X  a  U(       a  [        [        US-  5      5      $ g)zOReturn dots per inch value calculated from `units_specifier` and
`px_per_unit`.r   g¦
F%uš?rA   )ÚintÚround)rD   Úpx_per_units     r   rC   Ú_PngParser._dpiS   s&   € ð ˜aÓ¦KÜ”u˜[¨6Ñ1Ó2Ó3Ð3Ør   ©r3   )r%   r&   r'   r(   r)   r2   r+   r   r*   r   r   r   r   ÚstaticmethodrC   r,   Ú__classcell__©r5   s   @r   r   r   #   s‡   ø† ÙXõð ñó ðð ñó ðð
 ñó ðð
 ñFó ðFð ñFó ðFð ñó ör   r   c                   ób   ^ • \ rS rSrSrU 4S jr\S 5       r\S 5       r	\S 5       r
S rSrU =r$ )	r8   é\   z8Collection of the chunks parsed from a PNG image stream.c                 óJ   >• [         [        U ]  5         [        U5      U l        g r0   )r1   r8   r2   Úlistr3   )r   Úchunk_iterabler5   s     €r   r2   Ú_Chunks.__init___   s   ø€ ÜŒg�tÑ%Ô'Ü˜NÓ+ˆ�r   c                 ón   • [         R                  U5      n[        UR                  5       5      nU " U5      $ )zBReturn a |_Chunks| instance containing the PNG chunks in `stream`.)Ú_ChunkParserr#   rX   Úiter_chunks)r    r!   Úchunk_parserr4   s       r   r#   Ú_Chunks.from_streamc   s1   € ô $×/Ñ/°Ó7ˆÜ�l×.Ñ.Ó0Ó1ˆÙ�6‹{Ðr   c                 óJ   • S nU R                  U5      nUc  [        S5      eU$ )zIHDR chunk in PNG image.c                 ó<   • U R                   [        R                  :H  $ r0   )Ú	type_namer   r;   ©Úchunks    r   Ú<lambda>Ú_Chunks.IHDR.<locals>.<lambda>m   ó   € ˜eŸo™o´×1DÑ1DÒDr   zno IHDR chunk in PNG image)Ú_find_firstr   )r   Úmatchr;   s      r   r;   Ú_Chunks.IHDRj   s0   € ñ EˆØ×Ñ Ó&ˆØ‰<Ü)Ð*FÓGÐGØˆr   c                 ó*   • S nU R                  U5      $ )z2PHYs chunk in PNG image, or |None| if not present.c                 ó<   • U R                   [        R                  :H  $ r0   )rb   r   rB   rc   s    r   re   Ú_Chunks.pHYs.<locals>.<lambda>v   rg   r   )rh   )r   ri   s     r   rB   Ú_Chunks.pHYss   s   € ñ EˆØ×Ñ Ó&Ð&r   c                 óL   • U R                    H  nU" U5      (       d  M  Us  $    g)zGReturn first chunk in stream order returning True for function `match`.NrQ   )r   ri   rd   s      r   rh   Ú_Chunks._find_firsty   s#   € à—\”\ˆEÙ�U�|‹|Ø’ñ "ð r   rQ   )r%   r&   r'   r(   r)   r2   r+   r#   r*   r;   rB   rh   r,   rS   rT   s   @r   r8   r8   \   sQ   ø† ÙBõ,ð ñó ðð ñó ðð ñ'ó ð'÷
ð r   r8   c                   óH   ^ • \ rS rSrSrU 4S jr\S 5       rS rS r	Sr
U =r$ )r\   é�   z(Extracts chunks from a PNG image stream.c                 ó6   >• [         [        U ]  5         Xl        g r0   )r1   r\   r2   Ú_stream_rdr)r   Ú
stream_rdrr5   s     €r   r2   Ú_ChunkParser.__init__„   s   ø€ ÜŒl˜DÑ*Ô,Ø%Õr   c                 ó2   • [        U[        5      nU " U5      $ )z\Return a |_ChunkParser| instance that can extract the chunks from the PNG
image in `stream`.)r   r   )r    r!   ru   s      r   r#   Ú_ChunkParser.from_streamˆ   s   € ô " &¬*Ó5ˆ
Ù�:‹Ðr   c              #   ór   #   • U R                  5        H  u  p[        XR                  U5      nUv •  M!     g7f)zyGenerate a |_Chunk| subclass instance for each chunk in this parser's PNG
stream, in the order encountered in the stream.N)Ú_iter_chunk_offsetsÚ_ChunkFactoryrt   )r   Ú
chunk_typeÚoffsetrd   s       r   r]   Ú_ChunkParser.iter_chunks�   s4   é € ð #'×":Ñ":Ö"<ÑˆJÜ! *×.>Ñ.>ÀÓGˆEØŒKò #=ùs   ‚57c              #   ó¼   #   • Sn U R                   R                  U5      nU R                   R                  SUS5      nUS-   nX44v •  US:X  a  gUSU-   S-   -  nMV  7f)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)rt   Ú	read_longÚread_str)r   Úchunk_offsetÚchunk_data_lenr|   Údata_offsets        r   rz   Ú _ChunkParser._iter_chunk_offsets–   sv   é € ð ˆØØ!×-Ñ-×7Ñ7¸ÓEˆNØ×)Ñ)×2Ñ2°1°lÀAÓFˆJØ&¨Ñ*ˆKØÐ)Ò)Ø˜VÓ#Øà˜E NÑ2°QÑ6Ñ6ˆLñ ùs   ‚AA)rt   )r%   r&   r'   r(   r)   r2   r+   r#   r]   rz   r,   rS   rT   s   @r   r\   r\   �   s.   ø† Ù2õ&ð ñó ðò÷7ð 7r   r\   c                 ó¦   • [         R                  [        [         R                  [        0nUR                  U [        5      nUR                  XU5      $ )zeReturn a |_Chunk| subclass instance appropriate to `chunk_type` parsed from
`stream_rdr` at `offset`.)r   r;   Ú
_IHDRChunkrB   Ú
_pHYsChunkÚgetÚ_ChunkÚfrom_offset)r|   ru   r}   Úchunk_cls_mapÚ	chunk_clss        r   r{   r{   ¨   sH   € ô 	×ÑœZÜ×ÑœZð€Mð ×!Ñ! *¬fÓ5€IØ× Ñ  ¸Ó@Ð@r   c                   óL   ^ • \ rS rSrSrU 4S jr\S 5       r\S 5       r	Sr
U =r$ )r�   é³   zMBase class for specific chunk types.

Also serves as the default chunk type.
c                 ó6   >• [         [        U ]  5         Xl        g r0   )r1   r�   r2   Ú_chunk_type)r   r|   r5   s     €r   r2   Ú_Chunk.__init__¹   s   ø€ ÜŒf�dÑ$Ô&Ø%Õr   c                 ó   • U " U5      $ )z@Return a default _Chunk instance that only knows its chunk type.r   )r    r|   ru   r}   s       r   rŽ   Ú_Chunk.from_offset½   s   € ñ �:‹Ðr   c                 ó   • U R                   $ )z.The chunk type name, e.g. 'IHDR', 'pHYs', etc.©r”   r   s    r   rb   Ú_Chunk.type_nameÂ   s   € ð ×ÑÐr   r™   )r%   r&   r'   r(   r)   r2   r+   rŽ   r*   rb   r,   rS   rT   s   @r   r�   r�   ³   s5   ø† ñõ
&ð ñó ðð ñ ó ö r   r�   c                   ó\   ^ • \ rS rSrSrU 4S jr\S 5       r\S 5       r	\S 5       r
SrU =r$ )rŠ   éÈ   z*IHDR chunk, contains the image dimensions.c                 óD   >• [         [        U ]  U5        X l        X0l        g r0   )r1   rŠ   r2   Ú	_px_widthÚ
_px_height)r   r|   r   r   r5   s       €r   r2   Ú_IHDRChunk.__init__Ë   s   ø€ ÜŒj˜$Ñ(¨Ô4Ø!ŒØ#�r   c                 óZ   • UR                  U5      nUR                  US5      nU " XU5      $ )ztReturn an _IHDRChunk instance containing the image dimensions extracted from
the IHDR chunk in `stream` at `offset`.r�   )rƒ   )r    r|   ru   r}   r   r   s         r   rŽ   Ú_IHDRChunk.from_offsetÐ   s3   € ð ×'Ñ'¨Ó/ˆØ×(Ñ(¨°Ó3ˆ	Ù�:¨Ó3Ð3r   c                 ó   • U R                   $ r0   )rž   r   s    r   r   Ú_IHDRChunk.px_widthØ   s   € à�~‰~Ðr   c                 ó   • U R                   $ r0   )rŸ   r   s    r   r   Ú_IHDRChunk.px_heightÜ   s   € à�‰Ðr   )rŸ   rž   )r%   r&   r'   r(   r)   r2   r+   rŽ   r*   r   r   r,   rS   rT   s   @r   rŠ   rŠ   È   sG   ø† Ù4õ$ð
 ñ4ó ð4ð ñó ðð ñó ör   rŠ   c                   ól   ^ • \ rS rSrSrU 4S jr\S 5       r\S 5       r	\S 5       r
\S 5       rSrU =r$ )	r‹   éá   z/PYHs chunk, contains the image dpi information.c                 óP   >• [         [        U ]  U5        X l        X0l        X@l        g r0   )r1   r‹   r2   Ú_horz_px_per_unitÚ_vert_px_per_unitÚ_units_specifier)r   r|   rE   rJ   rD   r5   s        €r   r2   Ú_pHYsChunk.__init__ä   s$   ø€ ÜŒj˜$Ñ(¨Ô4Ø!1ÔØ!1ÔØ /Õr   c                 ó~   • UR                  U5      nUR                  US5      nUR                  US5      nU " XXV5      $ )zsReturn a _pHYsChunk instance containing the image resolution extracted from
the pHYs chunk in `stream` at `offset`.r�   r€   )rƒ   Ú	read_byte)r    r|   ru   r}   rE   rJ   rD   s          r   rŽ   Ú_pHYsChunk.from_offsetê   sH   € ð &×/Ñ/°Ó7ÐØ%×/Ñ/°¸Ó:ÐØ$×.Ñ.¨v°qÓ9ˆÙ�:Ð1AÓSÐSr   c                 ó   • U R                   $ r0   )rª   r   s    r   rE   Ú_pHYsChunk.horz_px_per_unitó   ó   € à×%Ñ%Ð%r   c                 ó   • U R                   $ r0   )r«   r   s    r   rJ   Ú_pHYsChunk.vert_px_per_unit÷   r³   r   c                 ó   • U R                   $ r0   )r¬   r   s    r   rD   Ú_pHYsChunk.units_specifierû   s   € à×$Ñ$Ð$r   )rª   r¬   r«   )r%   r&   r'   r(   r)   r2   r+   rŽ   r*   rE   rJ   rD   r,   rS   rT   s   @r   r‹   r‹   á   s]   ø† Ù9õ0ð ñTó ðTð ñ&ó ð&ð ñ&ó ð&ð ñ%ó ö%r   r‹   N)Ú	constantsr   r   Ú
exceptionsr   Úhelpersr   r   Úimager   r
   r   r8   r\   r{   r�   rŠ   r‹   r   r   r   Ú<module>r¼      sf   ðß 0Ý /ß -Ý "ô<ˆ/ô <÷86ñ 6÷r"ñ "÷J$7ñ $7òNA÷ ñ  ô*�ô ô2%�õ %r   