Ë
    \RðiE  ã                  ó�   — d Z ddlmZ ddlZddlZddlZddlmZmZ ddl	m
Z
 ddlmZmZmZmZ  G d„ d«      Zdd	„Z G d
„ d«      Zy)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)ÚUnrecognizedImageError)ÚEmuÚInchesÚLengthÚlazypropertyc                  ó@  ‡ — e Zd ZdZdˆ fd„Zedd„«       Zedd„«       Zed„ «       Z	edd„«       Z
ed„ «       Zed„ «       Zedd	„«       Zedd
„«       Zedd„«       Zedd„«       Zedd„«       Zedd„«       Z	 d	 	 	 	 	 dd„Zed„ «       Ze	 d	 	 	 	 	 	 	 dd„«       Zˆ xZS )ÚImagezgGraphical image stream such as JPEG, PNG, or GIF with properties and methods
    required by ImagePart.c                óT   •— t         t        | �  «        || _        || _        || _        y ©N)Úsuperr   Ú__init__Ú_blobÚ	_filenameÚ_image_header)ÚselfÚblobÚfilenameÚimage_headerÚ	__class__s       €úK/var/www/html/Extract/venv/lib/python3.12/site-packages/docx/image/image.pyr   zImage.__init__   s&   ø€ ÜŒe�TÑ#Ô%ØˆŒ
Ø!ˆŒØ)ˆÕó    c                óP   — t        j                  |«      }| j                  ||«      S )z`Return a new |Image| subclass instance parsed from the image binary contained
        in `blob`.)ÚioÚBytesIOÚ_from_stream)Úclsr   Ústreams      r   Ú	from_blobzImage.from_blob   s%   € ô —‘˜DÓ!ˆØ×Ñ ¨Ó-Ð-r   c                ób  — t        |t        «      r\|}t        |d«      5 }|j                  «       }t	        j
                  |«      }ddd«       t        j                  j                  |«      }n%|}|j                  d«       |j                  «       }d}| j                  |«      S # 1 sw Y   ŒaxY w)z‡Return a new |Image| subclass instance loaded from the image file identified
        by `image_descriptor`, a path or file-like object.ÚrbNr   )Ú
isinstanceÚstrÚopenÚreadr   r   ÚosÚpathÚbasenameÚseekr   )r   Úimage_descriptorr)   Úfr   r    r   s          r   Ú	from_filezImage.from_file#   s™   € ô Ð&¬Ô,Ø#ˆDÜ�d˜DÓ!ð * QØ—v‘v“x�ÜŸ™ DÓ)�÷*ô —w‘w×'Ñ'¨Ó-‰Hà%ˆFØ�K‰K˜ŒNØ—;‘;“=ˆDØˆHØ×Ñ ¨¨hÓ7Ð7÷*ð *ús   Ÿ&B%Â%B.c                ó   — | j                   S )zThe bytes of the image 'file'.)r   ©r   s    r   r   z
Image.blob4   s   € ð �z‰zÐr   c                ó.   — | j                   j                  S )zIMIME content type for this image, e.g. ``'image/jpeg'`` for a JPEG image.)r   Úcontent_typer0   s    r   r2   zImage.content_type9   s   € ð ×!Ñ!×.Ñ.Ð.r   c                ó`   — t         j                  j                  | j                  «      d   dd S )a  The 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)   Úsplitextr   r0   s    r   Úextz	Image.ext>   s)   € ô �w‰w×Ñ §¡Ó/°Ñ2°1°2Ð6Ð6r   c                ó   — | j                   S )zpOriginal image file name, if loaded from disk, or a generic filename if
        loaded from an anonymous stream.)r   r0   s    r   r   zImage.filenameH   s   € ð �~‰~Ðr   c                ó.   — | j                   j                  S ©z,The horizontal pixel dimension of the image.)r   Úpx_widthr0   s    r   r:   zImage.px_widthN   s   € ð ×!Ñ!×*Ñ*Ð*r   c                ó.   — | j                   j                  S ©z*The vertical pixel dimension of the image.)r   Ú	px_heightr0   s    r   r=   zImage.px_heightS   s   € ð ×!Ñ!×+Ñ+Ð+r   c                ó.   — | 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.
        )r   Úhorz_dpir0   s    r   r@   zImage.horz_dpiX   ó   € ð ×!Ñ!×*Ñ*Ð*r   c                ó.   — | 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.
        )r   Úvert_dpir0   s    r   rD   zImage.vert_dpi`   rA   r   c                óF   — t        | j                  | j                  z  «      S )z}A |Length| value representing the native width of the image, calculated from
        the values of `px_width` and `horz_dpi`.)r   r:   r@   r0   s    r   ÚwidthzImage.widthh   s   € ô �d—m‘m d§m¡mÑ3Ó4Ð4r   c                óF   — t        | j                  | j                  z  «      S )zA |Length| value representing the native height of the image, calculated from
        the values of `px_height` and `vert_dpi`.)r   r=   rD   r0   s    r   ÚheightzImage.heightn   s   € ô �d—n‘n t§}¡}Ñ4Ó5Ð5r   c                óZ  — |€|€| j                   | j                  fS |€=|€J ‚t        |«      t        | j                  «      z  }t        | j                   |z  «      }|€9t        |«      t        | j                   «      z  }t        | j                  |z  «      }t	        |«      t	        |«      fS )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.
        )rF   rH   ÚfloatÚroundr   )r   rF   rH   Úscaling_factors       r   Úscaled_dimensionszImage.scaled_dimensionst   s�   € ð$ ˆ=˜V˜^Ø—:‘:˜tŸ{™{Ð*Ð*àˆ=ØÐ%Ð%Ð%Ü" 6›]¬U°4·;±;Ó-?Ñ?ˆNÜ˜$Ÿ*™* ~Ñ5Ó6ˆEàˆ>Ü" 5›\¬E°$·*±*Ó,=Ñ=ˆNÜ˜4Ÿ;™;¨Ñ7Ó8ˆFä�5‹zœ3˜v›;Ð&Ð&r   c                ó\   — t        j                  | j                  «      j                  «       S )z#SHA1 hash digest of the image blob.)ÚhashlibÚsha1r   Ú	hexdigestr0   s    r   rP   z
Image.sha1”   s    € ô �|‰|˜DŸJ™JÓ'×1Ñ1Ó3Ð3r   c                óN   — t        |«      }|€d|j                  z  } | |||«      S )zhReturn an instance of the |Image| subclass corresponding to the format of the
        image in `stream`.zimage.%s)Ú_ImageHeaderFactoryÚdefault_ext)r   r    r   r   r   s        r   r   zImage._from_stream™   s3   € ô +¨6Ó2ˆØÐØ! L×$<Ñ$<Ñ<ˆHÙ�4˜ <Ó0Ð0r   )r   Úbytesr   r%   r   ÚBaseImageHeader)r   rU   Úreturnr   )r,   zstr | IO[bytes]©rW   r%   )rW   Úint)rW   r   )NN)rF   úint | Length | NonerH   rZ   rW   zTuple[Length, Length]r   )r    ú	IO[bytes]r   rU   r   z
str | NonerW   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úclassmethodr!   r.   Úpropertyr   r2   r
   r6   r   r:   r=   r@   rD   rF   rH   rM   rP   r   Ú__classcell__)r   s   @r   r   r      su  ø„ ñõ*ð ò.ó ð.ð ò8ó ð8ð  ñó ðð ò/ó ð/ð ñ7ó ð7ð ñó ðð
 ò+ó ð+ð ò,ó ð,ð ò+ó ð+ð ò+ó ð+ð ò5ó ð5ð
 ò6ó ð6ð PTð'Ø(ð'Ø9Lð'à	ó'ð@ ñ4ó ð4ð ð
  $ð	1àð1ð ð1ð ð	1ð
 
ò1ó ô1r   r   c                óž   — ddl m} dd„} || «      }|D ]1  \  }}}|t        |«      z   }||| }||k(  sŒ |j                  | «      c S  t        ‚)zRA |BaseImageHeader| subclass instance that can parse headers of image in `stream`.r   )Ú
SIGNATURESc                óF   — | j                  d«       | j                  d«      S )Nr   é    )r+   r'   )r    s    r   Úread_32z$_ImageHeaderFactory.<locals>.read_32¬   s   € Ø�‰�AŒØ�{‰{˜2‹Ðr   ©r    r[   )Ú
docx.imagerd   ÚlenÚfrom_streamr   )	r    rd   rg   Úheaderr   ÚoffsetÚsignature_bytesÚendÚfound_bytess	            r   rS   rS   ¨   se   € å%óñ �V‹_€FØ(2ò +Ñ$ˆˆV�_Ø”s˜?Ó+Ñ+ˆØ˜V CÐ(ˆØ˜/Ó)Ø—?‘? 6Ó*Ò*ð	+ô
 !Ð r   c                  ó|   — e Zd ZdZd
d„Zedd„«       Zedd„«       Zed„ «       Zed„ «       Z	ed„ «       Z
ed„ «       Zy	)rV   z>Base class for image header subclasses like |Jpeg| and |Tiff|.c                ó<   — || _         || _        || _        || _        y r   )Ú	_px_widthÚ
_px_heightÚ	_horz_dpiÚ	_vert_dpi)r   r:   r=   r@   rD   s        r   r   zBaseImageHeader.__init__¼   s   € Ø!ˆŒØ#ˆŒØ!ˆŒØ!ˆ�r   c                ó   — d}t        |«      ‚)zDAbstract property definition, must be implemented by all subclasses.zNcontent_type property must be implemented by all subclasses of BaseImageHeader©ÚNotImplementedError)r   Úmsgs     r   r2   zBaseImageHeader.content_typeÂ   s   € ð _ˆÜ! #Ó&Ð&r   c                ó   — t        d«      ‚)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 BaseImageHeaderrx   r0   s    r   rT   zBaseImageHeader.default_extÈ   s   € ô "Ø[ó
ð 	
r   c                ó   — | j                   S r9   )rs   r0   s    r   r:   zBaseImageHeader.px_widthÒ   s   € ð �~‰~Ðr   c                ó   — | j                   S r<   )rt   r0   s    r   r=   zBaseImageHeader.px_height×   s   € ð �‰Ðr   c                ó   — | j                   S r?   )ru   r0   s    r   r@   zBaseImageHeader.horz_dpiÜ   ó   € ð �~‰~Ðr   c                ó   — | j                   S rC   )rv   r0   s    r   rD   zBaseImageHeader.vert_dpiä   r   r   N)r:   rY   r=   rY   r@   rY   rD   rY   rX   )r\   r]   r^   r_   r   ra   r2   rT   r:   r=   r@   rD   © r   r   rV   rV   ¹   s‚   „ ÙHó"ð ò'ó ð'ð
 ò
ó ð
ð ñó ðð ñó ðð ñó ðð ñó ñr   rV   rh   )r_   Ú
__future__r   rO   r   r(   Útypingr   r   Údocx.image.exceptionsr   Údocx.sharedr   r   r	   r
   r   rS   rV   r�   r   r   ú<module>r†      s@   ðñõ #ã Û 	Û 	ß å 8ß 9Ó 9÷S1ñ S1ól!÷"1ò 1r   