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__/image.cpython-310.pyc
o

$wel�@s�dZddlmZddlZddlZddlZddlmZmZddl	m
Z
ddlmZddl
mZmZmZmZGdd	�d	�Zd
d�ZGdd
�d
�ZdS)z�Provides objects that can characterize image streams.

That characterization is as to content type and size, as a required step in including
them in a document.
�)�annotationsN)�IO�Tuple)�Self)�UnrecognizedImageError)�Emu�Inches�Length�lazypropertycs�eZdZdZd4�fdd	�Zed5dd
��Zedd��Zedd��Z	edd��Z
edd��Zedd��Z
ed6dd��Zed6dd��Zed6dd��Zed6dd ��Zed7d"d#��Zed7d$d%��Z	&d8d9d+d,�Zed-d.��Ze	&d:d;d2d3��Z�ZS)<�ImagezgGraphical image stream such as JPEG, PNG, or GIF with properties and methods
    required by ImagePart.�blob�bytes�filename�str�image_header�BaseImageHeadercs$tt|���||_||_||_dS�N)�superr�__init__�_blob�	_filename�
_image_header)�selfrrr��	__class__��I/home/arjun/projects/env/lib/python3.10/site-packages/docx/image/image.pyrs
zImage.__init__�returnrcCst�|�}|�||�S)z`Return a new |Image| subclass instance parsed from the image binary contained
        in `blob`.)�io�BytesIO�_from_stream)�clsr�streamrrr�	from_blobs
zImage.from_blobcCs�t|t�r,|}t|d��}|��}t�|�}Wd�n1s wYtj�|�}n
|}|�	d�|��}d}|�
|||�S)z�Return a new |Image| subclass instance loaded from the image file identified
        by `image_descriptor`, a path or file-like object.�rbNr)�
isinstancer�open�readrr�os�path�basename�seekr )r!�image_descriptorr)�frr"rrrr�	from_file%s
�
zImage.from_filecC�|jS)zThe bytes of the image 'file'.)r�rrrrr6�z
Image.blobcC�|jjS)zIMIME content type for this image, e.g. ``'image/jpeg'`` for a JPEG image.)r�content_typer0rrrr3;�zImage.content_typecCstj�|j�ddd�S)aThe file extension for the image.

        If an actual one is available from a load filename it is used. Otherwise a
        canonical extension is assigned based on the content type. Does not contain the
        leading period, e.g. 'jpg', not '.jpg'.
        �N)r(r)�splitextrr0rrr�ext@sz	Image.extcCr/)zpOriginal image file name, if loaded from disk, or a generic filename if
        loaded from an anonymous stream.)rr0rrrrJszImage.filename�intcCr2�z,The horizontal pixel dimension of the image.)r�px_widthr0rrrr:Pr4zImage.px_widthcCr2�z*The vertical pixel dimension of the image.)r�	px_heightr0rrrr<Ur4zImage.px_heightcCr2�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.
        )r�horz_dpir0rrrr>Z�zImage.horz_dpicCr2�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.
        )r�vert_dpir0rrrrAbr?zImage.vert_dpircC�t|j|j�S)z}A |Length| value representing the native width of the image, calculated from
        the values of `px_width` and `horz_dpi`.)rr:r>r0rrr�widthj�zImage.widthcCrB)zA |Length| value representing the native height of the image, calculated from
        the values of `px_height` and `vert_dpi`.)rr<rAr0rrr�heightprDzImage.heightNrC�
int | NonerE�Tuple[Length, Length]cCs�|dur|dur|j|jfS|dur(|dusJ�t|�t|j�}t|j|�}|dur<t|�t|j�}t|j|�}t|�t|�fS)a?(cx, cy) pair representing scaled dimensions of this image.

        The native dimensions of the image are scaled by applying the following rules to
        the `width` and `height` arguments.

        * If both `width` and `height` are specified, the return value is (`width`,
        `height`); no scaling is performed.
        * If only one is specified, it is used to compute a scaling factor that is then
        applied to the unspecified dimension, preserving the aspect ratio of the image.
        * If both `width` and `height` are |None|, the native dimensions are returned.

        The native dimensions are calculated using the dots-per-inch (dpi) value
        embedded in the image, defaulting to 72 dpi if no value is specified, as is
        often the case. The returned values are both |Length| objects.
        N)rCrE�float�roundr)rrCrE�scaling_factorrrr�scaled_dimensionsvszImage.scaled_dimensionscCst�|j���S)z#SHA1 hash digest of the image blob.)�hashlib�sha1r�	hexdigestr0rrrrM�sz
Image.sha1r"�	IO[bytes]�
str | NonecCs&t|�}|dur
d|j}||||�S)zhReturn an instance of the |Image| subclass corresponding to the format of the
        image in `stream`.Nzimage.%s)�_ImageHeaderFactory�default_ext)r!r"rrrrrrr �s	
zImage._from_stream)rr
rrrr)rr
rr)rr8)rr)NN)rCrFrErFrrGr)r"rOrr
rrPrr)�__name__�
__module__�__qualname__�__doc__r�classmethodr#r.�propertyrr3r
r7rr:r<r>rArCrErKrMr �
__classcell__rrrrrsD



	
� 
�rc	Cs^ddlm}dd�}||�}|D]\}}}|t|�}|||�}||kr,|�|�Sqt�)znReturn a |BaseImageHeader| subclass instance that knows how to parse the headers
    of the image in `stream`.r)�
SIGNATUREScSs|�d�|�d�S)Nr� )r+r')r"rrr�read_32�s

z$_ImageHeaderFactory.<locals>.read_32)�
docx.imagerZ�len�from_streamr)	r"rZr\�headerr!�offset�signature_bytes�end�found_bytesrrrrQ�s�rQc@s`eZdZdZdd�Zedd��Zedd��Zedd	��Zed
d��Z	edd
��Z
edd��ZdS)rz>Base class for image header subclasses like |Jpeg| and |Tiff|.cCs||_||_||_||_dSr)�	_px_width�
_px_height�	_horz_dpi�	_vert_dpi)rr:r<r>rArrrr�s
zBaseImageHeader.__init__cC�d}t|��)zDAbstract property definition, must be implemented by all subclasses.zNcontent_type property must be implemented by all subclasses of BaseImageHeader��NotImplementedError�r�msgrrrr3�s�zBaseImageHeader.content_typecCri)z�Default filename extension for images of this type.

        An abstract property definition, must be implemented by all subclasses.
        zMdefault_ext property must be implemented by all subclasses of BaseImageHeaderrjrlrrrrR�s�zBaseImageHeader.default_extcCr/r9)rer0rrrr:�r1zBaseImageHeader.px_widthcCr/r;)rfr0rrrr<�r1zBaseImageHeader.px_heightcCr/r=)rgr0rrrr>��zBaseImageHeader.horz_dpicCr/r@)rhr0rrrrA�rnzBaseImageHeader.vert_dpiN)rSrTrUrVrrXr3rRr:r<r>rArrrrr�s




r)rV�
__future__rrLrr(�typingrr�typing_extensionsr�docx.image.exceptionsr�docx.sharedrrr	r
rrQrrrrr�<module>s