+
    i<                     $   R t ^ RIt^ RIHtHt ^ RIHtHt ^ RIH	t	 ^ RI
Ht  ! R R]	4      t ! R R	]4      t ! R
 R]4      t ! R R4      t ! R R4      t ! R R4      tR t ! R R4      t ! R R]4      t ! R R]4      t ! R R]4      tR# )zdObjects related to parsing headers of JPEG image streams.

Includes both JFIF and Exif sub-formats.
N)JPEG_MARKER_CODE	MIME_TYPE)
BIG_ENDIANStreamReader)BaseImageHeader)Tiffc                   D   a  ] tR t^t o Rt]R 4       t]R 4       tRtV t	R# )Jpegz(Base class for JFIF and EXIF subclasses.c                "    \         P                  # )zOMIME content type for this image, unconditionally `image/jpeg` for JPEG
images.)r   JPEGselfs   &V/Users/agent/.openclaw/workspace/.venv/lib/python3.14/site-packages/docx/image/jpeg.pycontent_typeJpeg.content_type   s     ~~    c                    R# )z8Default filename extension, always 'jpg' for JPG images.jpg r   s   &r   default_extJpeg.default_ext   s     r   r   N)
__name__
__module____qualname____firstlineno____doc__propertyr   r   __static_attributes____classdictcell____classdict__s   @r   r	   r	      s.     2 
  r   r	   c                   4   a  ] tR t^t o Rt]R 4       tRtV tR# )Exifz*Image header parser for Exif image format.c                    \         P                  V4      pVP                  P                  pVP                  P                  pVP
                  P                  pVP
                  P                  pV ! W4WV4      # )zSReturn |Exif| instance having header properties parsed from Exif image in
`stream`.)_JfifMarkersfrom_streamsofpx_width	px_heightapp1horz_dpivert_dpiclsstreammarkersr'   r(   r*   r+   s   &&     r   r%   Exif.from_stream    s_     **62 ;;''KK))	<<((<<((8;;r   r   N	r   r   r   r   r   classmethodr%   r   r   r   s   @r   r"   r"      s     4< <r   r"   c                   4   a  ] tR t^/t o Rt]R 4       tRtV tR# )Jfifz*Image header parser for JFIF image format.c                    \         P                  V4      pVP                  P                  pVP                  P                  pVP
                  P                  pVP
                  P                  pV ! W4WV4      # )zPReturn a |Jfif| instance having header properties parsed from image in
`stream`.)r$   r%   r&   r'   r(   app0r*   r+   r,   s   &&     r   r%   Jfif.from_stream2   s]     **62;;''KK))	<<((<<((8;;r   r   Nr1   r   s   @r   r4   r4   /   s     4
< 
<r   r4   c                   |   a a ] tR t^@t oRtV 3R ltR t]R 4       t]	R 4       t
]	R 4       t]	R 4       tRtVtV ;t# )	r$   zbSequence of markers in a JPEG file, perhaps truncated at first SOS marker for
performance reasons.c                L   < \         \        V `  4        \        V4      V n        R # N)superr$   __init__list_markers)r   r/   	__class__s   &&r   r<   _JfifMarkers.__init__D   s    lD*,Wr   c           	        RpRp. pV P                    FP  pVP                  VVP                  VP                  \	        VP
                  4      VP                  3,          4       KR  	  V.V,           pRP                  V4      # )zsReturns a tabular listing of the markers in this instance, which can be handy
for debugging and perhaps other uses.z4 offset  seglen  mc  name
=======  ======  ==  =====z%7d  %6d  %02X  %s
)r>   appendoffsetsegment_lengthordmarker_codenamejoin)r   headertmplrowsmarkerliness   &     r   __str___JfifMarkers.__str__H   s|     I#mmFKKMM))**+KK	 $ 4yyr   c                    \         P                  V4      p. pVP                  4        F5  pVP                  V4       VP                  \
        P                  8X  g   K5   M	  V ! V4      # )zjReturn a |_JfifMarkers| instance containing a |_JfifMarker| subclass instance
for each marker in `stream`.)_MarkerParserr%   iter_markersrC   rG   r   SOS)r-   r.   marker_parserr/   rM   s   &&   r   r%   _JfifMarkers.from_stream[   s\     &11&9#002FNN6"!!%5%9%99 3 7|r   c                    V P                    F&  pVP                  \        P                  8X  g   K$  Vu # 	  \	        R4      h)z#First APP0 marker in image markers.zno APP0 marker in image)r>   rG   r   APP0KeyErrorr   ms   & r   r6   _JfifMarkers.app0g   8     A}} 0 5 55  011r   c                    V P                    F&  pVP                  \        P                  8X  g   K$  Vu # 	  \	        R4      h)z#First APP1 marker in image markers.zno APP1 marker in image)r>   rG   r   APP1rY   rZ   s   & r   r)   _JfifMarkers.app1o   r]   r   c                    V P                    F&  pVP                  \        P                  9   g   K$  Vu # 	  \	        R4      h)z4First start of frame (SOFn) marker in this sequence.z(no start of frame (SOFn) marker in image)r>   rG   r   SOF_MARKER_CODESrY   rZ   s   & r   r&   _JfifMarkers.sofw   s8     A}} 0 A AA  ABBr   )r>   )r   r   r   r   r   r<   rO   r2   r%   r   r6   r)   r&   r   r   __classcell__r?   r    s   @@r   r$   r$   @   sl     & & 	 	 2 2 2 2 C C Cr   r$   c                   L   a a ] tR t^t oRtV 3R lt]R 4       tR tRt	Vt
V ;t# )rR   zQService class that knows how to parse a JFIF stream and iterate over its
markers.c                8   < \         \        V `  4        Wn        R # r:   )r;   rR   r<   _stream)r   stream_readerr?   s   &&r   r<   _MarkerParser.__init__   s    mT+-$r   c                2    \        V\        4      pV ! V4      # )zFReturn a |_MarkerParser| instance to parse JFIF markers from `stream`.)r   r   )r-   r.   ri   s   && r   r%   _MarkerParser.from_stream   s     %VZ8=!!r   c              #     "   \         P                  V P                  4      p^ pRpV\        P                  8w  dB   VP                  V4      w  r4\        W0P                  V4      pVx  WEP                  ,           pKV  R# 5i)z}Generate a (marker_code, segment_offset) 2-tuple for each marker in the JPEG
`stream`, in the order they occur in the stream.N)_MarkerFinderr%   rh   r   EOInext_MarkerFactoryrE   )r   marker_finderstartrG   segment_offsetrM   s   &     r   rS   _MarkerParser.iter_markers   so      &11$,,?-111*7*<*<U*C'K#K~NFL"%:%::E	 2s   A<A>rh   )r   r   r   r   r   r<   r2   r%   rS   r   r   rd   re   s   @@r   rR   rR      s-     % " "

; 
;r   rR   c                   ^   a a ] tR t^t oRtV 3R lt]R 4       tR tR t	R t
R tRtVtV ;t# )	rn   zFService class that knows how to find the next JFIF marker in a stream.c                8   < \         \        V `  4        Wn        R # r:   )r;   rn   r<   rh   )r   r.   r?   s   &&r   r<   _MarkerFinder.__init__   s    mT+-r   c                    V ! V4      # )zCReturn a |_MarkerFinder| instance to find JFIF markers in `stream`.r   )r-   r.   s   &&r   r%   _MarkerFinder.from_stream   s     6{r   c                    Tp V P                  VR7      pV P                  V^,           R7      w  r#VR8X  d   K7  Y2^,           rT WE3# )a0  Return a (marker_code, segment_offset) 2-tuple identifying and locating the
first marker in `stream` occuring after offset `start`.

The returned `segment_offset` points to the position immediately following the
2-byte marker code, the start of the marker segment, for those markers that have
a segment.
)rs       )_offset_of_next_ff_byte_next_non_ff_byte)r   rs   positionbyte_rG   rt   s   &&    r   rp   _MarkerFinder.next   sX     33(3CH"448a<4HOH*/A**r   c                    V P                   P                  V4       V P                  4       pVR8X  d   V P                  4       pK  V P                   P                  4       ^,
          pW23# )u   Return an offset, byte 2-tuple for the next byte in `stream` that is not
'ÿ', starting with the byte at offset `start`.

If the byte at offset `start` is not 'ÿ', `start` and the returned `offset`
will be the same.
   rh   seek
_read_bytetell)r   rs   r   offset_of_non_ff_bytes   &&  r   r   _MarkerFinder._next_non_ff_byte   sW     	% !wOO%E $ 1 1 3a 7$++r   c                    V P                   P                  V4       V P                  4       pVR8w  d   V P                  4       pK  V P                   P                  4       ^,
          pV# )u   Return the offset of the next 'ÿ' byte in `stream` starting with the byte
at offset `start`.

Returns `start` if the byte at that offset is a hex 255; it does not necessarily
advance in the stream.
r   r   )r   rs   r   offset_of_ff_bytes   &&  r   r~   %_MarkerFinder._offset_of_next_ff_byte   sT     	% !wOO%E LL--/!3  r   c                b    V P                   P                  ^4      pV'       g   \        R4      hV# )zUReturn the next byte read from stream.

Raise Exception if stream is at end of file.
zunexpected end of file)rh   read	Exception)r   r   s   & r   r   _MarkerFinder._read_byte   s,    
 !!!$455r   rv   )r   r   r   r   r   r<   r2   r%   rp   r   r~   r   r   r   rd   re   s   @@r   rn   rn      s:     P  +,,! r   rn   c                    V \         P                  8X  d   \        pM>V \         P                  8X  d   \        pM"V \         P
                  9   d   \        pM\        pVP                  WV4      # )zjReturn |_Marker| or subclass instance appropriate for marker at `offset` in
`stream` having `marker_code`.)	r   rX   _App0Markerr_   _App1Markerrb   
_SofMarker_Markerr%   )rG   r.   rD   
marker_clss   &&& r   rq   rq      sX     &+++ 
	(--	- 
	(99	9

!!&v>>r   c                      a a ] tR t^t oRtV 3R lt]R 4       t]R 4       t	]R 4       t
]R 4       t]R 4       tRtVtV ;t# )	r   ziBase class for JFIF marker classes.

Represents a marker and its segment occuring in a JPEG byte stream.
c                P   < \         \        V `  4        Wn        W n        W0n        R # r:   )r;   r   r<   _marker_code_offset_segment_length)r   rG   rD   rE   r?   s   &&&&r   r<   _Marker.__init__   s!    gt%''-r   c                t    \         P                  ! V4      '       d   ^ pMVP                  V4      pV ! W#V4      # )z`Return a generic |_Marker| instance for the marker at `offset` in `stream`
having `marker_code`.)r   is_standalone
read_short)r-   r.   rG   rD   rE   s   &&&& r   r%   _Marker.from_stream   s7     ))+66N#..v6N;77r   c                    V P                   # )ue   The single-byte code that identifies the type of this marker, e.g. ``'à'``
for start of image (SOI).)r   r   s   &r   rG   _Marker.marker_code  s        r   c                D    \         P                  V P                  ,          # r:   )r   marker_namesr   r   s   &r   rH   _Marker.name  s    ,,T->->??r   c                    V P                   # r:   )r   r   s   &r   rD   _Marker.offset  s    ||r   c                    V P                   # )z-The length in bytes of this marker's segment.)r   r   s   &r   rE   _Marker.segment_length  s     ###r   )r   r   r   )r   r   r   r   r   r<   r2   r%   r   rG   rH   rD   rE   r   r   rd   re   s   @@r   r   r      sz     
. 8 8 ! !
 @ @   $ $ $r   r   c                   l   a a ] tR tRt oRtV 3R lt]R 4       t]R 4       tR t	]
R 4       tRtVtV ;t# )	r   i  z&Represents a JFIF APP0 marker segment.c                T   < \         \        V `  WV4       W@n        WPn        W`n        R # r:   )r;   r   r<   _density_units
_x_density
_y_density)r   rG   rD   lengthdensity_units	x_density	y_densityr?   s   &&&&&&&r   r<   _App0Marker.__init__  s$    k4)+vF+##r   c                8    V P                  V P                  4      # zSHorizontal dots per inch specified in this marker, defaults to 72 if not
specified.)_dpir   r   s   &r   r*   _App0Marker.horz_dpi%       yy))r   c                8    V P                  V P                  4      # zQVertical dots per inch specified in this marker, defaults to 72 if not
specified.)r   r   r   s   &r   r+   _App0Marker.vert_dpi+  r   r   c                    V P                   ^8X  d   TpV# V P                   ^8X  d   \        \        VR,          4      4      pV# ^HpV# )z6Return dots per inch corresponding to `density` value.gRQ@)r   intround)r   densitydpis   && r   r   _App0Marker._dpi1  sR    !#C
 
	   A%eGdN+,C 
 C
r   c                    VP                  V4      pVP                  V^	4      pVP                  V^
4      pVP                  V^4      pV ! W#WEWg4      # )zMReturn an |_App0Marker| instance for the APP0 marker at `offset` in
`stream`.)r   	read_byte)r-   r.   rG   rD   rE   r   r   r   s   &&&&    r   r%   _App0Marker.from_stream;  sY      **62((3%%fb1	%%fb1	;y\\r   )r   r   r   )r   r   r   r   r   r<   r   r*   r+   r   r2   r%   r   r   rd   re   s   @@r   r   r     sV     0$ * *
 * *
 ] ] ]r   r   c                      a a ] tR tRt oRtV 3R lt]R 4       t]R 4       t	]R 4       t
]R 4       t]R 4       tR	tVtV ;t# )
r   iP  z-Represents a JFIF APP1 (Exif) marker segment.c                H   < \         \        V `  WV4       W@n        WPn        R # r:   )r;   r   r<   	_horz_dpi	_vert_dpi)r   rG   rD   r   r*   r+   r?   s   &&&&&&r   r<   _App1Marker.__init__S  s    k4)+vF!!r   c                    VP                  V4      pV P                  W4      '       d   V ! W#V^H^H4      # V P                  WV4      pV ! W#WEP                  VP                  4      # )zeExtract the horizontal and vertical dots-per-inch value from the APP1 header
at `offset` in `stream`.)r   _is_non_Exif_APP1_segment_tiff_from_exif_segmentr*   r+   )r-   r.   rG   rD   rE   tiffs   &&&&  r   r%   _App1Marker.from_streamX  s_      **62((88{NBCC**6>J;t}}UUr   c                    V P                   # r   )r   r   s   &r   r*   _App1Marker.horz_dpij       ~~r   c                    V P                   # r   )r   r   s   &r   r+   _App1Marker.vert_dpip  r   r   c                ^    VP                  V^,           4       VP                  ^4      pVR8g  # )zReturn True if the APP1 segment at `offset` in `stream` is NOT an Exif
segment, as determined by the ``'Exif  '`` signature at offset 2 in the
segment.s   Exif  )r   r   )r-   r.   rD   exif_signatures   &&& r   r   %_App1Marker._is_non_Exif_APP1_segmentv  s,    
 	FQJQ00r   c                    VP                  V^,           4       VP                  V^,
          4      p\        P                  ! V4      p\        P
                  ! V4      # )zgReturn a |Tiff| instance parsed from the Exif APP1 segment of
`segment_length` at `offset` in `stream`.)r   r   ioBytesIOr   r%   )r-   r.   rD   rE   segment_bytes	substreams   &&&&  r   r   #_App1Marker._tiff_from_exif_segment  sF    
 	FQJNQ$67JJ}-		**r   )r   r   )r   r   r   r   r   r<   r2   r%   r   r*   r+   r   r   r   r   rd   re   s   @@r   r   r   P  sx     7"
 V V"  
  
 1 1 + + +r   r   c                   f   a a ] tR tRt oRtV 3R lt]R 4       t]R 4       t	]R 4       t
RtVtV ;t# )r   i  z7Represents a JFIF start of frame (SOFx) marker segment.c                H   < \         \        V `  WV4       W@n        WPn        R # r:   )r;   r   r<   	_px_width
_px_height)r   rG   rD   rE   r'   r(   r?   s   &&&&&&r   r<   _SofMarker.__init__  s    j$(nM!#r   c                    VP                  V4      pVP                  V^4      pVP                  V^4      pV ! W#WFV4      # )zJReturn an |_SofMarker| instance for the SOFn marker at `offset` in stream.)r   )r-   r.   rG   rD   rE   r(   r'   s   &&&&   r   r%   _SofMarker.from_stream  sG      **62%%fa0	$$VQ/;)LLr   c                    V P                   # )zImage height in pixels.)r   r   s   &r   r(   _SofMarker.px_height  s     r   c                    V P                   # )zImage width in pixels.)r   r   s   &r   r'   _SofMarker.px_width  s     ~~r   )r   r   )r   r   r   r   r   r<   r2   r%   r   r(   r'   r   r   rd   re   s   @@r   r   r     sP     A$
 M M     r   r   )r   r   docx.image.constantsr   r   docx.image.helpersr   r   docx.image.imager   docx.image.tiffr   r	   r"   r4   r$   rR   rn   rq   r   r   r   r   r   r   r   <module>r      s   
 
 < 7 ,  ? <4 <$<4 <"=C =C@; ;6F FR?'$ '$T1]' 1]h7+' 7+t r   