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

$we�(�@s�ddlmZmZmZddlmZmZmZddlm	Z	Gdd�de	�Z
Gdd�d�ZGdd	�d	�ZGd
d�d�Z
dd
�ZGdd�d�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZdS)�)�	MIME_TYPE�TIFF_FLD�TIFF_TAG)�
BIG_ENDIAN�
LITTLE_ENDIAN�StreamReader)�BaseImageHeaderc@s4eZdZdZedd��Zedd��Zedd��ZdS)	�Tiffz`Image header parser for TIFF images.

    Handles both big and little endian byte ordering.
    cCstjS)z[Return the MIME type of this TIFF image, unconditionally the string
        ``image/tiff``.)r�TIFF��self�r
�H/home/arjun/projects/env/lib/python3.10/site-packages/docx/image/tiff.py�content_typeszTiff.content_typecC�dS)z:Default filename extension, always 'tiff' for TIFF images.�tiffr
rr
r
r�default_extszTiff.default_extcCs0t�|�}|j}|j}|j}|j}|||||�S)zYReturn a |Tiff| instance containing the properties of the TIFF image in
        `stream`.)�_TiffParser�parse�px_width�	px_height�horz_dpi�vert_dpi)�cls�stream�parserrrrrr
r
r�from_streams
zTiff.from_streamN)	�__name__�
__module__�__qualname__�__doc__�propertyrr�classmethodrr
r
r
rr	s

r	cs|eZdZdZ�fdd�Zedd��Zedd��Zedd	��Z	ed
d��Z
edd
��Zedd��Zdd�Z
edd��Z�ZS)rzkParses a TIFF image stream to extract the image properties found in its main
    image file directory (IFD)c�tt|���||_dS�N)�superr�__init__�_ifd_entries)r�ifd_entries��	__class__r
rr&)�
z_TiffParser.__init__cCs(|�|�}|�d�}t�||�}||�S)zmReturn an instance of |_TiffParser| containing the properties parsed from the
        TIFF image in `stream`.�)�_make_stream_reader�	read_long�_IfdEntriesr)rr�
stream_rdr�ifd0_offsetr(r
r
rr-s

z_TiffParser.parsecC�|�tj�S)z�The horizontal dots per inch value calculated from the XResolution and
        ResolutionUnit tags of the IFD; defaults to 72 if those tags are not present.)�_dpir�X_RESOLUTIONrr
r
rr6�z_TiffParser.horz_dpicCr2)z�The vertical dots per inch value calculated from the XResolution and
        ResolutionUnit tags of the IFD; defaults to 72 if those tags are not present.)r3r�Y_RESOLUTIONrr
r
rr<r5z_TiffParser.vert_dpicC�|j�tj�S)z�The number of stacked rows of pixels in the image, |None| if the IFD contains
        no ``ImageLength`` tag, the expected case when the TIFF is embeded in an Exif
        image.)r'�getr�IMAGE_LENGTHrr
r
rrB�z_TiffParser.px_heightcCr7)z�The number of pixels in each row in the image, |None| if the IFD contains no
        ``ImageWidth`` tag, the expected case when the TIFF is embeded in an Exif
        image.)r'r8r�IMAGE_WIDTHrr
r
rrIr:z_TiffParser.px_widthcCs$|�d�|�d�}|dkrtStS)z�Return either BIG_ENDIAN or LITTLE_ENDIAN depending on the endian indicator
        found in the TIFF `stream` header, either 'MM' or 'II'.��sMM)�seek�readrr)rr�
endian_strr
r
r�_detect_endianPs

z_TiffParser._detect_endiancCs^|j}||vr	dStj|vr|tjnd}|dkrdS|dkr!dnd}||}tt||��S)a!Return the dpi value calculated for `resolution_tag`, which can be either
        TIFF_TAG.X_RESOLUTION or TIFF_TAG.Y_RESOLUTION.

        The calculation is based on the values of both that tag and the
        TIFF_TAG.RESOLUTION_UNIT tag in this parser's |_IfdEntries| instance.
        �Hr=rgR���Q@)r'r�RESOLUTION_UNIT�int�round)r�resolution_tagr(�resolution_unit�units_per_inch�
dots_per_unitr
r
rr3Xs

��z_TiffParser._dpicCs|�|�}t||�S)z�Return a |StreamReader| instance with wrapping `stream` and having "endian-
        ness" determined by the 'MM' or 'II' indicator in the TIFF stream header.)rAr)rr�endianr
r
rr-rs

z_TiffParser._make_stream_reader)rrrr r&r"rr!rrrrrAr3r-�
__classcell__r
r
r)rr%s$





rcsFeZdZdZ�fdd�Zdd�Zdd�Zedd	��Zd
dd�Z	�Z
S)r/z}Image File Directory for a TIFF image, having mapping (dict) semantics allowing
    "tag" values to be retrieved by tag code.cr#r$)r%r/r&�_entries)r�entriesr)r
rr&~r+z_IfdEntries.__init__cC�|j�|�S)z5Provides ``in`` operator, e.g. ``tag in ifd_entries``)rL�__contains__�r�keyr
r
rrO��z_IfdEntries.__contains__cCrN)zCProvides indexed access, e.g. ``tag_value = ifd_entries[tag_code]``)rL�__getitem__rPr
r
rrS�rRz_IfdEntries.__getitem__cCs$t||�}dd�|��D�}||�S)zVReturn a new |_IfdEntries| instance parsed from `stream` starting at
        `offset`.cSsi|]}|j|j�qSr
)�tag�value)�.0�er
r
r�
<dictcomp>�sz+_IfdEntries.from_stream.<locals>.<dictcomp>)�
_IfdParser�iter_entries)rr�offset�
ifd_parserrMr
r
rr�s
z_IfdEntries.from_streamNcCs|j�||�S)zhReturn value of IFD entry having tag matching `tag_code`, or `default` if no
        matching tag found.)rLr8)r�tag_code�defaultr
r
rr8��z_IfdEntries.getr$)rrrr r&rOrSr"rr8rKr
r
r)rr/zs
r/cs4eZdZdZ�fdd�Zdd�Zedd��Z�ZS)rYzaService object that knows how to extract directory entries from an Image File
    Directory (IFD)c�tt|���||_||_dSr$)r%rYr&�_stream_rdr�_offset)rr0r[r)r
rr&��
z_IfdParser.__init__ccs:�t|j�D]}|jd|d}t|j|�}|VqdS)zVGenerate an |_IfdEntry| instance corresponding to each entry in the
        directory.r=�N)�range�_entry_countrb�_IfdEntryFactoryra)r�idx�dir_entry_offset�	ifd_entryr
r
rrZ�s��z_IfdParser.iter_entriescCs|j�|j�S)zDThe count of directory entries, read from the top of the IFD header.)ra�
read_shortrbrr
r
rrf�r_z_IfdParser._entry_count)	rrrr r&rZr!rfrKr
r
r)rrY�srYcCs@tjttjttjttjti}|�	|d�}|�
|t�}|�||�S)ztReturn an |_IfdEntry| subclass instance containing the value of the directory
    entry at `offset` in `stream_rdr`.r=)
r�ASCII�_AsciiIfdEntry�SHORT�_ShortIfdEntry�LONG�
_LongIfdEntry�RATIONAL�_RationalIfdEntryrkr8�	_IfdEntryr)r0r[�ifd_entry_classes�
field_type�EntryClsr
r
rrg�s�rgcsPeZdZdZ�fdd�Zedd��Zedd��Zedd	��Z	ed
d��Z
�ZS)rtzsBase class for IFD entry classes.

    Subclasses are differentiated by value type, e.g. ASCII, long int, etc.
    cr`r$)r%rtr&�	_tag_code�_value)rr]rUr)r
rr&�rcz_IfdEntry.__init__cCs>|�|d�}|�|d�}|�|d�}|�||||�}|||�S)a!Return an |_IfdEntry| subclass instance containing the tag and value of the
        tag parsed from `stream_rdr` at `offset`.

        Note this method is common to all subclasses. Override the ``_parse_value()``
        method to provide distinctive behavior based on field type.
        r<r,�)rkr.�_parse_value)rr0r[r]�value_count�value_offsetrUr
r
rr�s

z_IfdEntry.from_streamcCr)zReturn the value of this field parsed from `stream_rdr` at `offset`.

        Intended to be overridden by subclasses.
        zUNIMPLEMENTED FIELD TYPEr
�rr0r[r|r}r
r
rr{�sz_IfdEntry._parse_valuecC�|jS)z.Short int code that identifies this IFD entry.)rxrr
r
rrT��z
_IfdEntry.tagcCr)z7Value of this tag, its type being dependent on the tag.)ryrr
r
rrU�r�z_IfdEntry.value)rrrr r&r"rr{r!rTrUrKr
r
r)rrt�s


rtc@�eZdZdZedd��ZdS)rmz<IFD entry having the form of a NULL-terminated ASCII string.cCs|�|d|�S)z�Return the ASCII string parsed from `stream_rdr` at `value_offset`.

        The length of the string, including a terminating '' (NUL) character, is in
        `value_count`.
        r)�read_strr~r
r
rr{�sz_AsciiIfdEntry._parse_valueN�rrrr r"r{r
r
r
rrm��rmc@r�)roz0IFD entry expressed as a short (2-byte) integer.cC�|dkr
|�|d�SdS)z�Return the short int value contained in the `value_offset` field of this
        entry.

        Only supports single values at present.
        rrzz)Multi-value short integer NOT IMPLEMENTED)rkr~r
r
rr{��z_ShortIfdEntry._parse_valueNr�r
r
r
rro�r�roc@r�)rqz/IFD entry expressed as a long (4-byte) integer.cCr�)z�Return the long int value contained in the `value_offset` field of this
        entry.

        Only supports single values at present.
        rrzz(Multi-value long integer NOT IMPLEMENTED�r.r~r
r
rr{	r�z_LongIfdEntry._parse_valueNr�r
r
r
rrqr�rqc@r�)rsz5IFD entry expressed as a numerator, denominator pair.cCs*|dkr|�|�}|�|d�}||SdS)z�Return the rational (numerator / denominator) value at `value_offset` in
        `stream_rdr` as a floating-point number.

        Only supports single values at present.
        rr,z$Multi-value Rational NOT IMPLEMENTEDr�)rr0r[r|r}�	numerator�denominatorr
r
rr{s

z_RationalIfdEntry._parse_valueNr�r
r
r
rrsr�rsN)�	constantsrrr�helpersrrr�imagerr	rr/rYrgrtrmrorqrsr
r
r
r�<module>sU,