HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib/python3.10/site-packages/docx/image/__pycache__/png.cpython-310.pyc
o

$we �@s�ddlmZmZddlmZddlmZmZddlm	Z	Gdd�de	�Z
Gdd�d�ZGd	d
�d
�ZGdd�d�Z
d
d�ZGdd�d�ZGdd�de�ZGdd�de�ZdS)�)�	MIME_TYPE�PNG_CHUNK_TYPE)�InvalidImageStreamError)�
BIG_ENDIAN�StreamReader)�BaseImageHeaderc@s4eZdZdZedd��Zedd��Zedd��ZdS)	�Pngz#Image header parser for PNG images.cCstjS)zUMIME content type for this image, unconditionally `image/png` for PNG
        images.)r�PNG��self�r�G/home/arjun/projects/env/lib/python3.10/site-packages/docx/image/png.py�content_type
szPng.content_typecCsdS)z8Default filename extension, always 'png' for PNG images.�pngrr
rrr
�default_extszPng.default_extcCs0t�|�}|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�parserrrrrrrr
�from_streams
zPng.from_streamN)	�__name__�
__module__�__qualname__�__doc__�propertyrr�classmethodrrrrr
rs

rcsheZdZdZ�fdd�Zedd��Zedd��Zedd	��Z	ed
d��Z
edd
��Zedd��Z
�ZS)rzNParses a PNG image stream to extract the image properties found in its chunks.c�tt|���||_dS�N)�superr�__init__�_chunks)r�chunks��	__class__rr
r$&�
z_PngParser.__init__cCst�|�}||�S)znReturn a |_PngParser| instance containing the header properties parsed from
        the PNG image in `stream`.)�_Chunksr)rrr&rrr
r*�
z_PngParser.parsecC�|jj}|jS)z.The number of pixels in each row of the image.)r%�IHDRr�rr-rrr
r1�z_PngParser.px_widthcCr,)z2The number of stacked rows of pixels in the image.)r%r-rr.rrr
r7r/z_PngParser.px_heightcC�$|jj}|dur
dS|�|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�rr2rrr
r=�z_PngParser.horz_dpicCr0)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.
        Nr1)r%r2r3r4�vert_px_per_unitr6rrr
rHr7z_PngParser.vert_dpicCs |dkr|rtt|d��SdS)zWReturn dots per inch value calculated from `units_specifier` and
        `px_per_unit`.rg�
F%u�?r1)�int�round)r4�px_per_unitrrr
r3Ssz_PngParser._dpi)rrrrr$r rrrrrr�staticmethodr3�
__classcell__rrr'r
r#s






rcsLeZdZdZ�fdd�Zedd��Zedd��Zedd	��Z	d
d�Z
�ZS)r*z8Collection of the chunks parsed from a PNG image stream.cstt|���t|�|_dSr")r#r*r$�listr%)r�chunk_iterabler'rr
r$_sz_Chunks.__init__cCst�|�}t|���}||�S)zBReturn a |_Chunks| instance containing the PNG chunks in `stream`.)�_ChunkParserrr>�iter_chunks)rr�chunk_parserr&rrr
rcs
z_Chunks.from_streamcCs&dd�}|�|�}|durtd��|S)zIHDR chunk in PNG image.cS�|jtjkSr")�	type_namerr-��chunkrrr
�<lambda>m�z_Chunks.IHDR.<locals>.<lambda>Nzno IHDR chunk in PNG image)�_find_firstr)r�matchr-rrr
r-js

z_Chunks.IHDRcCsdd�}|�|�S)z2PHYs chunk in PNG image, or |None| if not present.cSrCr")rDrr2rErrr
rGvrHz_Chunks.pHYs.<locals>.<lambda>)rI)rrJrrr
r2ss
z_Chunks.pHYscCs |jD]
}||�r
|SqdS)zGReturn first chunk in stream order returning True for function `match`.N)r%)rrJrFrrr
rIys

�z_Chunks._find_first)rrrrr$r rrr-r2rIr=rrr'r
r*\s


r*cs<eZdZdZ�fdd�Zedd��Zdd�Zdd	�Z�Z	S)
r@z(Extracts chunks from a PNG image stream.cr!r")r#r@r$�_stream_rdr)r�
stream_rdrr'rr
r$�r)z_ChunkParser.__init__cCst|t�}||�S)zdReturn a |_ChunkParser| instance that can extract the chunks from the PNG
        image in `stream`.)rr)rrrLrrr
r�r+z_ChunkParser.from_streamccs,�|��D]\}}t||j|�}|VqdS)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�
_ChunkFactoryrK)r�
chunk_type�offsetrFrrr
rA�s
��z_ChunkParser.iter_chunksccsT�d}	|j�|�}|j�d|d�}|d}||fV|dkr!dS|d|d7}q)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)rK�	read_long�read_str)r�chunk_offset�chunk_data_lenrO�data_offsetrrr
rM�s�
�z _ChunkParser._iter_chunk_offsets)
rrrrr$r rrArMr=rrr'r
r@�s
r@cCs*tjttjti}|�|t�}|�|||�S)ziReturn a |_Chunk| subclass instance appropriate to `chunk_type` parsed from
    `stream_rdr` at `offset`.)rr-�
_IHDRChunkr2�
_pHYsChunk�get�_Chunk�from_offset)rOrLrP�
chunk_cls_map�	chunk_clsrrr
rN�s
�rNcs8eZdZdZ�fdd�Zedd��Zedd��Z�Z	S)r\zUBase class for specific chunk types.

    Also serves as the default chunk type.
    cr!r")r#r\r$�_chunk_type)rrOr'rr
r$�r)z_Chunk.__init__cCs||�S)z@Return a default _Chunk instance that only knows its chunk type.r)rrOrLrPrrr
r]�sz_Chunk.from_offsetcC�|jS)z.The chunk type name, e.g. 'IHDR', 'pHYs', etc.)r`r
rrr
rD�sz_Chunk.type_name)
rrrrr$r r]rrDr=rrr'r
r\�s
r\csDeZdZdZ�fdd�Zedd��Zedd��Zedd	��Z	�Z
S)
rYz*IHDR chunk, contains the image dimensions.cs tt|��|�||_||_dSr")r#rYr$�	_px_width�
_px_height)rrOrrr'rr
r$�s
z_IHDRChunk.__init__cCs"|�|�}|�|d�}||||�S)z|Return an _IHDRChunk instance containing the image dimensions extracted from
        the IHDR chunk in `stream` at `offset`.rR)rT)rrOrLrPrrrrr
r]�s
z_IHDRChunk.from_offsetcCrar")rbr
rrr
r��z_IHDRChunk.px_widthcCrar")rcr
rrr
r�rdz_IHDRChunk.px_height)rrrrr$r r]rrrr=rrr'r
rY�s

rYcsPeZdZdZ�fdd�Zedd��Zedd��Zedd	��Z	ed
d��Z
�ZS)rZz/PYHs chunk, contains the image dpi information.cs&tt|��|�||_||_||_dSr")r#rZr$�_horz_px_per_unit�_vert_px_per_unit�_units_specifier)rrOr5r8r4r'rr
r$�s
z_pHYsChunk.__init__cCs0|�|�}|�|d�}|�|d�}|||||�S)z{Return a _pHYsChunk instance containing the image resolution extracted from
        the pHYs chunk in `stream` at `offset`.rRrQ)rT�	read_byte)rrOrLrPr5r8r4rrr
r]�s
z_pHYsChunk.from_offsetcCrar")rer
rrr
r5�rdz_pHYsChunk.horz_px_per_unitcCrar")rfr
rrr
r8�rdz_pHYsChunk.vert_px_per_unitcCrar")rgr
rrr
r4�rdz_pHYsChunk.units_specifier)rrrrr$r r]rr5r8r4r=rrr'r
rZ�s


rZN)�	constantsrr�
exceptionsr�helpersrr�imagerrrr*r@rNr\rYrZrrrr
�<module>s9%'