
    }f                    0   d dl mZ d dlZd dlZd dlZddlmZmZmZm	Z	 ddl
mZ d Zd Z G d d	ej                  Z ej        ej        e            ej        ej        e            ej        ej        d
            ej        ej        d           dS )    )annotationsN   )ImageImageSequenceJpegImagePluginTiffImagePlugin)o32lec                2    t          j        | ||           d S N)r   _save)imfpfilenames      K/var/www/rtfcompare/venv/lib/python3.11/site-packages/PIL/MpoImagePlugin.pyr   r   #   s    "b(+++++    c           
        | j                             dg           }|s0	 | j        }n# t          $ r d}Y nw xY w|st	          | ||           d S d}g }t          j        | g|          D ]1}t          j        |          D ]}|sdt          j
        dd          z   dz   dz   |j         d	<   |j                             d
          }	t          |	t          j                  r|	                                }	|	|j         d
<   |	r|dt          |	          z   z  }t!          j        |||           |                    |                                           |                    |d           |                    |                                |d         z
             3t)          j                    }
d|
d<   t          |          |
d<   d}d}t-          |          D ]<\  }}|dk    rd}nd}|t          j
        d|||dd          z  }|dk    r||z  }||z  }=||
d<   |                    |           |                    dt3          d          z   |
                    d          z              |                    dt4          j                   d S )Nappend_imagesF   s   z>HX   s   MPF sR                                                                                     extraexif   JPEGs   0100i     r   r   i   z<LLLHH  s   II*    )encoderinfogetis_animatedAttributeErrorr   	itertoolschainr   Iteratorstructpack
isinstancer   Exiftobyteslenr   appendtellsaver   ImageFileDirectory_v2	enumerateseekwriter	   osSEEK_END)r   r   r   r   animated
mpf_offsetoffsets
imSequenceim_framer   ifd	mpentriesdata_offsetisizemptypes                   r   	_save_allr?   '   s   N&&;;M 	~HH 	 	 	HHH	 	"b(###FJGordM:: 8 8
%.z:: 	8 	8H 8  &+dF";";;hFR $W-  +//77dEJ// 8<<>>D37H(0 0!c$ii-/J%hH===rwwyy))))b&)))rwwyy72;67777#	8& 
/
1
1CCKg,,CKIKW%%  466FFFV[64aKKK	66:%KtCKGGJHH]U1XX%A6777GGAr{s   ' 66c                  R    e Zd ZdZdZdZd ZddZd Zd Z	d	 Z
edd
            ZdS )MpoImageFileMPOzMPO (CIPA DC-007)Fc                    | j                             d           t          j                            |            |                                  d S )Nr   )r   r0   r   JpegImageFile_open_after_jpeg_openselfs    r   rE   zMpoImageFile._openg   sB    Q%++D111r   Nc                    ||n                                   _         j        d          _         fd j        d         D              _        d j        d<    j        t	           j                  k    sJ  j        d=  j        dk     _         j         _         j        	                     j        d                    d _
        d _        d _        d S )Nr   c                <    g | ]}|d          j         d         z   S )
DataOffsetmpoffset)info).0mpentrH   s     r   
<listcomp>z1MpoImageFile._after_jpeg_open.<locals>.<listcomp>o   s7     
 
 
<AE,$)J"77
 
 
r   r   r   rL   r   )_getmpmpinfon_frames_MpoImageFile__mpoffsetsr*   rM   r    r   _fpr0   _MpoImageFile__frameoffsetreadonly)rH   mpheaders   ` r   rF   zMpoImageFile._after_jpeg_openl   s    "*"6hhDKKMMF+
 
 
 
EI[QWEX
 
 
   }D$4 5 55555Ij!=1,7d&q)***r   c                :    | j                             |           d S r   )rU   r0   )rH   poss     r   	load_seekzMpoImageFile.load_seek   s    cr   c                   |                      |          sd S | j        | _        | j        |         | _        | j                            d          }d| j        v r| j        d= | j                            | j        dz              | j                            d          sd}t          |          | j                            | j                   t          j                            |            | j                            d          |k    r|                                  dd| j        z   | j        | j        d         d         fg| _        || _        d S )Nr      zNo data found for framejpeg)r   r   r   r   )_seek_checkrU   r   rT   rW   rM   r   r0   read
ValueErrorr   rD   rE   _reload_exifr=   tilerV   )rH   frameoriginal_exifmsgs       r   r0   zMpoImageFile.seek   s(   && 	F(&u-	f--TY	&!T[1_%%%w||A 	"+CS//!T[!!!%++D1119==  M11fty0$+ty|B?OPQ	r   c                    | j         S r   )rV   rG   s    r   r,   zMpoImageFile.tell   s
    |r   c                H    t           | _        |                     |           | S )aC  
        Transform the instance of JpegImageFile into
        an instance of MpoImageFile.
        After the call, the JpegImageFile is extended
        to be an MpoImageFile.

        This is essentially useful when opening a JPEG
        file that reveals itself as an MPO, to avoid
        double call to _open.
        )rA   	__class__rF   )jpeg_instancerY   s     r   adoptzMpoImageFile.adopt   s&     #/&&x000r   r   )__name__
__module____qualname__formatformat_description!_close_exclusive_fp_after_loadingrE   rF   r\   r0   r,   staticmethodrl    r   r   rA   rA   b   s        F,(-%     
   &    ,      \  r   rA   z.mpoz	image/mpo)
__future__r   r"   r2   r%    r   r   r   r   _binaryr	   r   r?   rD   rA   register_saverp   register_save_allregister_extensionregister_mimert   r   r   <module>r|      sD  ( # " " " " "     				                  , , ,4 4 4vG G G G G?0 G G Gb  L' / / /  +Y 7 7 7  ,f 5 5 5  L' 5 5 5 5 5r   