
    &Th                     r   d dl Z d dlZd dlZddlmZmZmZmZmZm	Z	 ddl
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       y)    N   )ExifTagsImage	ImageFileImageSequenceJpegImagePluginTiffImagePlugin)i16be)o32lec                 2    t        j                  | ||       y N)r   _save)imfpfilenames      Z/home/stella.sw7ft.com/public_html/venv/lib/python3.12/site-packages/PIL/MpoImagePlugin.pyr   r   (   s    "b(+    c           
         | j                   j                  dg       }|s	 | j                  }|st	        | ||       y d}g }t        j                  | g|      D ]"  }t        j                  |      D ]  }|sdt        j                  dd      z   dz   dz   |j                   d	<   |j                   j                  d
      }	t        |	t        j                        r|	j                         }	|	|j                   d
<   |	r|dt        |	      z   z  }t!        j                  |||       |j#                  |j%                                |j'                  |d       |j#                  |j%                         |d   z
         	 % t)        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<   |j/                  |       |j1                  dt3        d      z   |
j                  d      z          |j/                  dt4        j6                         y # t        $ r d}Y 9w xY w)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_allrA   ,   sE   NN&&;M	~~H "b(#JGoordM: 8
%..z: 	8H  &++dF";;hFR $$W-  ++//7dEJJ/<<>D37H((0!c$i-/J%%hH=rwwy)b&)rwwy72;67#	88( 
/
/
1CCKg,CKIKW% 46FFV[[64aKK	6:%Kt CKGGJHH]U1X%A67GGAr{{_  	H	s   I I&%I&c                   J    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y)MpoImageFileMPOzMPO (CIPA DC-007)Fc                     | j                   j                  d       t        j                  j	                  |        | j                          y )Nr   )r   r2   r   JpegImageFile_open_after_jpeg_openselfs    r   rG   zMpoImageFile._openl   s1    Q%%++D1r   Nc                 8   | j                   | _        ||n| j                         | _        | j                  d   | _        | j                  d   D cg c]  }|d   | j
                  d   z    c}| _        d| j                  d<   | j                  t        | j                        k(  sJ | j
                  d= | j                  dkD  | _        | j                  | _
        | j                  j                  | j                  d          d| _        d| _        d| _        y c c}w )Nr   r   
DataOffsetmpoffsetr   r   )r?   _initial_size_getmpmpinfon_framesinfo_MpoImageFile__mpoffsetsr,   r"   r   _fpr2   _MpoImageFile__frameoffsetreadonly)rJ   mpheadermpents      r   rH   zMpoImageFile._after_jpeg_openq   s    !YY"*"6hDKKMF+EI[[QWEX
<AE,$))J"77
   }}D$4$4 5555IIj!==1,77d&&q)*
s   Dc                 :    | j                   j                  |       y r   )rT   r2   )rJ   poss     r   	load_seekzMpoImageFile.load_seek   s    cr   c                    | j                  |      sy | j                  | _        | j                  |   | _        | j                  j                  | j                  dz          | j                  j                  d      }|sd}t        |      | j                  | _	        t        |      dk(  rt        | j                  j                  d            dz
  }t        j                  | j                  |      | j                  d<   | j                          | j                  d   |   d   d   }|j!                  d      rz| j#                         j%                  t&        j(                  j*                        }d	|v r?d
|v r;|d	   |d
   f| _	        n+d| j                  v r| j                  d= | j                          dd| j,                  z   | j                  | j.                  dffg| _        || _        y )N   zNo data found for framei  r   r   	AttributeMPTypezLarge Thumbnaili  i  jpeg)r   r    )_seek_checkrT   r   rS   rV   r2   read
ValueErrorrN   _sizei16r   
_safe_readrR   _reload_exifrP   
startswithgetexifget_ifdr   IFDr*   r?   modetilerU   )rJ   framesegmentmsgnr@   r   s          r   r2   zMpoImageFile.seek   s   &((&&u-T[[1_%'',,q/+CS/!''
w<6!DGGLLO$q(A ) 4 4TWWa @DIIf[[(/<XFF  !23||~--hll.?.?@D=Ud]"&u+tE{!;DJtyy 		&!ftyy0$++		2OP	r   c                     | j                   S r   )rU   rI   s    r   r.   zMpoImageFile.tell   s    ||r   c                 >    t         | _        | j                  |       | 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.
        )rC   	__class__rH   )jpeg_instancerX   s     r   adoptzMpoImageFile.adopt   s      #/&&x0r   r   )__name__
__module____qualname__formatformat_description!_close_exclusive_fp_after_loadingrG   rH   r\   r2   r.   staticmethodrx    r   r   rC   rC   g   s@    F,(-% 
(:  r   rC   z.mpoz	image/mpo)r$   r4   r'   rb   r   r   r   r   r   r	   _binaryr
   rg   r   r   rA   rF   rC   register_saver|   register_save_allregister_extensionregister_mimer   r   r   <module>r      s   *  	   " ,4vO?00 Or   L'' /   ++Y 7   ,,f 5   L'' 5r   