
    h(                         S SK JrJrJr  S SKJr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 " S S\5      r " S S\5      rg)   )	MIME_TYPETIFF_FLDTIFF_TAG)
BIG_ENDIANLITTLE_ENDIANStreamReader)BaseImageHeaderc                   H    \ rS rSrSr\S 5       r\S 5       r\S 5       r	Sr
g)Tiff   zXImage header parser for TIFF images.

Handles both big and little endian byte ordering.
c                 "    [         R                  $ )zSReturn the MIME type of this TIFF image, unconditionally the string
``image/tiff``.)r   TIFFselfs    A/var/www/html/env/lib/python3.13/site-packages/docx/image/tiff.pycontent_typeTiff.content_type   s     ~~    c                     g)z:Default filename extension, always 'tiff' for TIFF images.tiff r   s    r   default_extTiff.default_ext   s     r   c                     [         R                  U5      nUR                  nUR                  nUR                  nUR
                  nU " X4XV5      $ )zQReturn a |Tiff| instance containing the properties of the TIFF image in
`stream`.)_TiffParserparsepx_width	px_heighthorz_dpivert_dpi)clsstreamparserr   r   r   r    s          r   from_streamTiff.from_stream   sG     ""6*??$$	????8;;r   r   N)__name__
__module____qualname____firstlineno____doc__propertyr   r   classmethodr$   __static_attributes__r   r   r   r   r      sC    
  
   
< 
<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\S 5       rSrU =r$ )r   %   zgParses a TIFF image stream to extract the image properties found in its main
image file directory (IFD)c                 6   > [         [        U ]  5         Xl        g N)superr   __init___ifd_entries)r   ifd_entries	__class__s     r   r3   _TiffParser.__init__)   s    k4)+'r   c                     U R                  U5      nUR                  S5      n[        R                  X#5      nU " U5      $ )zeReturn an instance of |_TiffParser| containing the properties parsed from the
TIFF image in `stream`.   )_make_stream_reader	read_long_IfdEntriesr$   )r!   r"   
stream_rdrifd0_offsetr5   s        r   r   _TiffParser.parse-   s?     ,,V4
 **1-!--jF;r   c                 @    U R                  [        R                  5      $ )zThe 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_RESOLUTIONr   s    r   r   _TiffParser.horz_dpi6        yy..//r   c                 @    U R                  [        R                  5      $ )zThe vertical dots per inch value calculated from the XResolution and
ResolutionUnit tags of the IFD; defaults to 72 if those tags are not present.)rA   r   Y_RESOLUTIONr   s    r   r    _TiffParser.vert_dpi<   rD   r   c                 T    U R                   R                  [        R                  5      $ )zThe 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.)r4   getr   IMAGE_LENGTHr   s    r   r   _TiffParser.px_heightB   s!    
   $$X%:%:;;r   c                 T    U R                   R                  [        R                  5      $ )zThe 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.)r4   rI   r   IMAGE_WIDTHr   s    r   r   _TiffParser.px_widthI   s!    
   $$X%9%9::r   c                 j    UR                  S5        UR                  S5      nUS:X  a  [        $ [        $ )zReturn either BIG_ENDIAN or LITTLE_ENDIAN depending on the endian indicator
found in the TIFF `stream` header, either 'MM' or 'II'.       s   MM)seekreadr   r   )r!   r"   
endian_strs      r   _detect_endian_TiffParser._detect_endianP   s.     	A[[^
'50zCmCr   c                     U R                   nX;  a  gUR                  [        R                  S5      nUS:X  a  gUS:X  a  SOSnX!   n[	        [        XT-  5      5      $ )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.
H   rQ   r   gRQ@)r4   rI   r   RESOLUTION_UNITintround)r   resolution_tagr5   resolution_unitunits_per_inchdots_per_units         r   rA   _TiffParser._dpiX   sd     '', &//(*B*BAFa-2#357899r   c                 :    U R                  U5      n[        X5      $ )zReturn a |StreamReader| instance with wrapping `stream` and having "endian-
ness" determined by the 'MM' or 'II' indicator in the TIFF stream header.)rU   r   )r!   r"   endians      r   r:   _TiffParser._make_stream_readern   s     ##F+F++r   )r4   )r&   r'   r(   r)   r*   r3   r,   r   r+   r   r    r   r   rU   rA   r:   r-   __classcell__r6   s   @r   r   r   %   s    "(     0 0
 0 0
 < < ; ; D D:, , ,r   r   c                   R   ^  \ rS rSrSrU 4S jrS rS r\S 5       r	S	S jr
SrU =r$ )
r<   v   zyImage File Directory for a TIFF image, having mapping (dict) semantics allowing
"tag" values to be retrieved by tag code.c                 6   > [         [        U ]  5         Xl        g r1   )r2   r<   r3   _entries)r   entriesr6   s     r   r3   _IfdEntries.__init__z   s    k4)+r   c                 8    U R                   R                  U5      $ )z5Provides ``in`` operator, e.g. ``tag in ifd_entries``)ri   __contains__r   keys     r   rm   _IfdEntries.__contains__~   s    }}))#..r   c                 8    U R                   R                  U5      $ )zCProvides indexed access, e.g. ``tag_value = ifd_entries[tag_code]``)ri   __getitem__rn   s     r   rr   _IfdEntries.__getitem__   s    }}((--r   c                     [        X5      nUR                  5        Vs0 s H  oDR                  UR                  _M     nnU " U5      $ s  snf )zNReturn a new |_IfdEntries| instance parsed from `stream` starting at
`offset`.)
_IfdParseriter_entriestagvalue)r!   r"   offset
ifd_parsererj   s         r   r$   _IfdEntries.from_stream   sG      /
+5+B+B+DE+Da55!''>+DE7| Fs    Ac                 8    U R                   R                  X5      $ )z`Return value of IFD entry having tag matching `tag_code`, or `default` if no
matching tag found.)ri   rI   )r   tag_codedefaults      r   rI   _IfdEntries.get   s     }}  33r   )ri   r1   )r&   r'   r(   r)   r*   r3   rm   rr   r,   r$   rI   r-   rd   re   s   @r   r<   r<   v   s5    1 /.  4 4r   r<   c                   B   ^  \ rS rSrSrU 4S jrS r\S 5       rSr	U =r
$ )ru      z]Service object that knows how to extract directory entries from an Image File
Directory (IFD)c                 B   > [         [        U ]  5         Xl        X l        g r1   )r2   ru   r3   _stream_rdr_offset)r   r=   ry   r6   s      r   r3   _IfdParser.__init__   s    j$(*%r   c              #      #    [        U R                  5       H2  nU R                  S-   US-  -   n[        U R                  U5      nUv   M4     g7f)zNGenerate an |_IfdEntry| instance corresponding to each entry in the
directory.rQ      N)range_entry_countr   _IfdEntryFactoryr   )r   idxdir_entry_offset	ifd_entrys       r   rv   _IfdParser.iter_entries   sL      **+C#||a/38<()9)9;KLIO ,s   AAc                 L    U R                   R                  U R                  5      $ )zDThe count of directory entries, read from the top of the IFD header.)r   
read_shortr   r   s    r   r   _IfdParser._entry_count   s     **4<<88r   )r   r   )r&   r'   r(   r)   r*   r3   rv   r+   r   r-   rd   re   s   @r   ru   ru      s&    
 9 9r   ru   c                    [         R                  [        [         R                  [        [         R
                  [        [         R                  [        0nU R                  US5      nUR                  U[        5      nUR                  X5      $ )zpReturn an |_IfdEntry| subclass instance containing the value of the directory
entry at `offset` in `stream_rdr`.rQ   )r   ASCII_AsciiIfdEntrySHORT_ShortIfdEntryLONG_LongIfdEntryRATIONAL_RationalIfdEntryr   rI   	_IfdEntryr$   )r=   ry   ifd_entry_classes
field_typeEntryClss        r   r   r      sj     	},	 &&vq1J $$Z;H
33r   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      zkBase class for IFD entry classes.

Subclasses are differentiated by value type, e.g. ASCII, long int, etc.
c                 B   > [         [        U ]  5         Xl        X l        g r1   )r2   r   r3   	_tag_code_value)r   r~   rx   r6   s      r   r3   _IfdEntry.__init__   s    i')!r   c                     UR                  US5      nUR                  US5      nUR                  US5      nU R                  XXE5      nU " X65      $ )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.
rP   r9      )r   r;   _parse_value)r!   r=   ry   r~   value_countvalue_offsetrx   s          r   r$   _IfdEntry.from_stream   sW     ((3 **615!++FA6  [O8##r   c                     g)zoReturn the value of this field parsed from `stream_rdr` at `offset`.

Intended to be overridden by subclasses.
zUNIMPLEMENTED FIELD TYPEr   r!   r=   ry   r   r   s        r   r   _IfdEntry._parse_value   s     *r   c                     U R                   $ )z.Short int code that identifies this IFD entry.)r   r   s    r   rw   _IfdEntry.tag   s     ~~r   c                     U R                   $ )z7Value of this tag, its type being dependent on the tag.)r   r   s    r   rx   _IfdEntry.value   s     {{r   )r   r   )r&   r'   r(   r)   r*   r3   r,   r$   r   r+   rw   rx   r-   rd   re   s   @r   r   r      s]    

 $ $ * *    r   r   c                   (    \ rS rSrSr\S 5       rSrg)r      z<IFD entry having the form of a NULL-terminated ASCII string.c                 ,    UR                  US-
  U5      $ )zReturn 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   s        r   r   _AsciiIfdEntry._parse_value   s     "";?LAAr   r   Nr&   r'   r(   r)   r*   r,   r   r-   r   r   r   r   r      s    FB Br   r   c                   (    \ rS rSrSr\S 5       rSrg)r      z0IFD entry expressed as a short (2-byte) integer.c                 4    US:X  a  UR                  US5      $ g)zyReturn the short int value contained in the `value_offset` field of this
entry.

Only supports single values at present.
r   r   z)Multi-value short integer NOT IMPLEMENTED)r   r   s        r   r   _ShortIfdEntry._parse_value   s"     !((33>r   r   Nr   r   r   r   r   r      s    :	? 	?r   r   c                   (    \ rS rSrSr\S 5       rSrg)r   i  z/IFD entry expressed as a long (4-byte) integer.c                 4    US:X  a  UR                  US5      $ g)zxReturn the long int value contained in the `value_offset` field of this
entry.

Only supports single values at present.
r   r   z(Multi-value long integer NOT IMPLEMENTEDr;   r   s        r   r   _LongIfdEntry._parse_value  s"     !''22=r   r   Nr   r   r   r   r   r     s    9	> 	>r   r   c                   (    \ rS rSrSr\S 5       rSrg)r   i  z5IFD entry expressed as a numerator, denominator pair.c                 ^    US:X  a'  UR                  U5      nUR                  US5      nXV-  $ g)zReturn the rational (numerator / denominator) value at `value_offset` in
`stream_rdr` as a floating-point number.

Only supports single values at present.
r   r9   z$Multi-value Rational NOT IMPLEMENTEDr   )r!   r=   ry   r   r   	numeratordenominators          r   r   _RationalIfdEntry._parse_value  s:     !",,\:I$..|Q?K**9r   r   Nr   r   r   r   r   r     s    ?: :r   r   N)	constantsr   r   r   helpersr   r   r   imager	   r   r   r<   ru   r   r   r   r   r   r   r   r   r   <module>r      s    4 4 < < "<? <>N, N,b4 4<9 9.4) )X
BY 
B?Y ? >I > :	 :r   