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

$we><�@s�dZddlZddlmZmZddlmZmZddlm	Z	ddl
mZGdd�de	�ZGd	d
�d
e�Z
Gdd�de�ZGd
d�d�ZGdd�d�ZGdd�d�Zdd�ZGdd�d�ZGdd�de�ZGdd�de�ZGdd�de�ZdS)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@s(eZdZdZedd��Zedd��ZdS)�Jpegz(Base class for JFIF and EXIF subclasses.cCstjS)zWMIME content type for this image, unconditionally `image/jpeg` for JPEG
        images.)r�JPEG��self�r�H/home/arjun/projects/env/lib/python3.10/site-packages/docx/image/jpeg.py�content_type�zJpeg.content_typecCsdS)z8Default filename extension, always 'jpg' for JPG images.�jpgrr
rrr
�default_extszJpeg.default_extN)�__name__�
__module__�__qualname__�__doc__�propertyrrrrrr
rs
rc@�eZdZdZedd��ZdS)�Exifz*Image header parser for Exif image format.cC�8t�|�}|jj}|jj}|jj}|jj}|||||�S)z[Return |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�markersrrr r!rrr
r s
zExif.from_streamN�rrrr�classmethodrrrrr
r�rc@r)�Jfifz*Image header parser for JFIF image format.cCr)zXReturn a |Jfif| instance having header properties parsed from image in
        `stream`.)rrrrr�app0r r!r"rrr
r2s
zJfif.from_streamNr&rrrr
r)/r(r)csXeZdZdZ�fdd�Zdd�Zedd��Zedd	��Z	ed
d��Z
edd
��Z�ZS)rzfSequence of markers in a JPEG file, perhaps truncated at first SOS marker for
    performance reasons.cstt|���t|�|_dS�N)�superr�__init__�list�_markers)rr%��	__class__rr
r-Dsz_JfifMarkers.__init__cCsNd}d}g}|jD]}|�||j|jt|j�|jf�q	|g|}d�|�S)z{Returns 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�linesrrr
�__str__Hs
���
	
z_JfifMarkers.__str__cCsDt�|�}g}|��D]}|�|�|jtjkr||�Sq||�S)zrReturn a |_JfifMarkers| instance containing a |_JfifMarker| subclass instance
        for each marker in `stream`.)�
_MarkerParserr�iter_markersr3r7r�SOS)r#r$�
marker_parserr%r=rrr
r

�z_JfifMarkers.from_streamcC�(|jD]}|jtjkr|Sqtd��)z#First APP0 marker in image markers.zno APP0 marker in image)r/r7r�APP0�KeyError�r�mrrr
r*g�

�z_JfifMarkers.app0cCrD)z#First APP1 marker in image markers.zno APP1 marker in image)r/r7r�APP1rFrGrrr
rorIz_JfifMarkers.app1cCs(|jD]}|jtjvr|Sqtd��)z4First start of frame (SOFn) marker in this sequence.z(no start of frame (SOFn) marker in image)r/r7r�SOF_MARKER_CODESrFrGrrr
rwrIz_JfifMarkers.sof)
rrrrr-r?r'rrr*rr�
__classcell__rrr0r
r@s


rcs4eZdZdZ�fdd�Zedd��Zdd�Z�ZS)r@zUService class that knows how to parse a JFIF stream and iterate over its
    markers.c�tt|���||_dSr+)r,r@r-�_stream)r�
stream_readerr0rr
r-��
z_MarkerParser.__init__cCst|t�}||�S)zFReturn a |_MarkerParser| instance to parse JFIF markers from `stream`.)rr)r#r$rOrrr
r�s
z_MarkerParser.from_streamccs^�t�|j�}d}d}|tjkr-|�|�\}}t||j|�}|V||j}|tjksdSdS)z�Generate a (marker_code, segment_offset) 2-tuple for each marker in the JPEG
        `stream`, in the order they occur in the stream.rN)�
_MarkerFinderrrNr�EOI�next�_MarkerFactoryr5)r�
marker_finder�startr7�segment_offsetr=rrr
rA�s�

�z_MarkerParser.iter_markers)	rrrrr-r'rrArLrrr0r
r@�s
r@csLeZdZdZ�fdd�Zedd��Zdd�Zdd	�Zd
d�Z	dd
�Z
�ZS)rQzFService class that knows how to find the next JFIF marker in a stream.crMr+)r,rQr-rN)rr$r0rr
r-�rPz_MarkerFinder.__init__cCs||�S)zCReturn a |_MarkerFinder| instance to find JFIF markers in `stream`.r)r#r$rrr
r�sz_MarkerFinder.from_streamcCsH|}	|j|d�}|j|dd�\}}|dkrq||d}}	||fS)aXReturn 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.
        T)rV��)�_offset_of_next_ff_byte�_next_non_ff_byte)rrV�position�byte_r7rWrrr
rS�sz_MarkerFinder.nextcCsB|j�|�|��}|dkr|��}|dks|j��d}||fS)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.
        ��rX�rN�seek�
_read_byte�tell)rrVr]�offset_of_non_ff_byterrr
r[�s�z_MarkerFinder._next_non_ff_bytecCs>|j�|�|��}|dkr|��}|dks|j��d}|S)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^rXr_)rrVr]�offset_of_ff_byterrr
rZ�s�z%_MarkerFinder._offset_of_next_ff_bytecCs|j�d�}|std��|S)zeReturn the next byte read from stream.

        Raise Exception if stream is at end of file.
        rXzunexpected end of file)rN�read�	Exception)rr]rrr
ra�sz_MarkerFinder._read_byte)rrrrr-r'rrSr[rZrarLrrr0r
rQ�s
rQcCsB|tjkrt}n|tjkrt}n
|tjvrt}nt}|�|||�S)znReturn |_Marker| or subclass instance appropriate for marker at `offset` in
    `stream` having `marker_code`.)	rrE�_App0MarkerrJ�_App1MarkerrK�
_SofMarker�_Markerr)r7r$r4�
marker_clsrrr
rT�s


rTcs\eZdZdZ�fdd�Zedd��Zedd��Zedd	��Z	ed
d��Z
edd
��Z�ZS)rjzqBase class for JFIF marker classes.

    Represents a marker and its segment occuring in a JPEG byte stream.
    cs$tt|���||_||_||_dSr+)r,rjr-�_marker_code�_offset�_segment_length)rr7r4r5r0rr
r-�s
z_Marker.__init__cCs&t�|�rd}n|�|�}||||�S)zhReturn a generic |_Marker| instance for the marker at `offset` in `stream`
        having `marker_code`.r)r�
is_standalone�
read_short)r#r$r7r4r5rrr
r�s

z_Marker.from_streamcC�|jS)umThe single-byte code that identifies the type of this marker, e.g. ``'à'``
        for start of image (SOI).)rlr
rrr
r7rz_Marker.marker_codecCstj|jSr+)r�marker_namesrlr
rrr
r8sz_Marker.namecCrqr+)rmr
rrr
r4sz_Marker.offsetcCrq)z-The length in bytes of this marker's segment.)rnr
rrr
r5�z_Marker.segment_length)
rrrrr-r'rrr7r8r4r5rLrrr0r
rj�s
	


rjcsLeZdZdZ�fdd�Zedd��Zedd��Zdd	�Ze	d
d��Z
�ZS)rgz&Represents a JFIF APP0 marker segment.cs*tt|��|||�||_||_||_dSr+)r,rgr-�_density_units�
_x_density�
_y_density)rr7r4�length�
density_units�	x_density�	y_densityr0rr
r-s
z_App0Marker.__init__cC�|�|j�S�z[Horizontal dots per inch specified in this marker, defaults to 72 if not
        specified.)�_dpirur
rrr
r '�z_App0Marker.horz_dpicCr{�zYVertical dots per inch specified in this marker, defaults to 72 if not
        specified.)r}rvr
rrr
r!-r~z_App0Marker.vert_dpicCs8|jdkr	|}|S|jdkrtt|d��}|Sd}|S)z6Return dots per inch corresponding to `density` value.rX�gR���Q@�H)rt�int�round)r�density�dpirrr
r}3s

��z_App0Marker._dpicCs@|�|�}|�|d�}|�|d�}|�|d�}|||||||�S)zUReturn an |_App0Marker| instance for the APP0 marker at `offset` in
        `stream`.�	�
�)rp�	read_byte)r#r$r7r4r5rxryrzrrr
r=s
�z_App0Marker.from_stream)rrrrr-rr r!r}r'rrLrrr0r
rgs


rgcs\eZdZdZ�fdd�Zedd��Zedd��Zedd	��Z	ed
d��Z
edd
��Z�ZS)rhz-Represents a JFIF APP1 (Exif) marker segment.c�$tt|��|||�||_||_dSr+)r,rhr-�	_horz_dpi�	_vert_dpi)rr7r4rwr r!r0rr
r-W�
z_App1Marker.__init__cCsH|�|�}|�||�r||||dd�S|�|||�}|||||j|j�S)zmExtract the horizontal and vertical dots-per-inch value from the APP1 header
        at `offset` in `stream`.r�)rp�_is_non_Exif_APP1_segment�_tiff_from_exif_segmentr r!)r#r$r7r4r5�tiffrrr
r\s

z_App1Marker.from_streamcCrqr|)r�r
rrr
r nrz_App1Marker.horz_dpicCrqr)r�r
rrr
r!trz_App1Marker.vert_dpicCs |�|d�|�d�}|dkS)z�Return 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.r��sExif)r`re)r#r$r4�exif_signaturerrr
r�zs
z%_App1Marker._is_non_Exif_APP1_segmentcCs0|�|d�|�|d�}t�|�}t�|�S)zoReturn a |Tiff| instance parsed from the Exif APP1 segment of
        `segment_length` at `offset` in `stream`.�)r`re�io�BytesIOrr)r#r$r4r5�
segment_bytes�	substreamrrr
r��s

z#_App1Marker._tiff_from_exif_segment)
rrrrr-r'rrr r!r�r�rLrrr0r
rhTs



rhcsDeZdZdZ�fdd�Zedd��Zedd��Zedd	��Z	�Z
S)
riz7Represents a JFIF start of frame (SOFx) marker segment.cr�r+)r,rir-�	_px_width�
_px_height)rr7r4r5rrr0rr
r-�r�z_SofMarker.__init__cCs2|�|�}|�|d�}|�|d�}||||||�S)zJReturn an |_SofMarker| instance for the SOFn marker at `offset` in stream.��)rp)r#r$r7r4r5rrrrr
r�s

z_SofMarker.from_streamcCrq)zImage height in pixels.)r�r
rrr
r�rsz_SofMarker.px_heightcCrq)zImage width in pixels.)r�r
rrr
r�rsz_SofMarker.px_width)rrrrr-r'rrrrrLrrr0r
ri�s

ri)rr��docx.image.constantsrr�docx.image.helpersrr�docx.image.imager�docx.image.tiffrrrr)rr@rQrTrjrgrhrirrrr
�<module>s"@I*8: