
    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    @/var/www/html/env/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     ||  <yy--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    gt%'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       eoo1D1D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    lD*,%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!*.>.>GE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)zGenerate 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EN))221lAFJ&*K))V#EN2Q66L 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5I  @@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    fd$&%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%//:$..vq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 $7NA   * 2% %r   