o
    ÓWf™  ã                   @  s¦   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d„ Zdd	„ ZG d
d„ dejƒZe eje¡ e eje¡ e ejd¡ e ejd¡ dS )é    )ÚannotationsNé   )ÚImageÚImageSequenceÚJpegImagePluginÚTiffImagePlugin)Úo32lec                 C  s   t  | ||¡ d S ©N)r   Ú_save)ÚimÚfpÚfilename© r   úz/media/darth/New Volume E/PROJECTS/DRIVERZZ/DRIVERZZ_CUSTOMER_APIS/venv/lib/python3.10/site-packages/PIL/MpoImagePlugin.pyr
   #   s   r
   c              
   C  sÌ  | j  dg ¡}|s$z| j}W n ty   d}Y nw |s$t| ||ƒ d S d}g }t | g|¡D ]Z}t |¡D ]R}|swdt	 
dd¡ d d |j d	< |j  d
¡}	t|	tjƒr^|	 ¡ }	|	|j d
< |	rh|dt|	ƒ 7 }t |||¡ | | ¡ ¡ q6| |d¡ | | ¡ |d  ¡ q6q/t ¡ }
d|
d< t|ƒ|
d< d}d}t|ƒD ]%\}}|dkr«d}nd}|t	 
d|||dd¡7 }|dkrÁ||8 }||7 }q ||
d< | |¡ | dtdƒ |
 d¡ ¡ | dtj¡ d S )NÚappend_imagesFé   s   ÿâz>HéX   s   MPF sR                                                                                     ÚextraÚexifé   ÚJPEGéÿÿÿÿs   0100i °  é°  ó    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Úmptyper   r   r   Ú	_save_all'   sZ   
ÿÿ
ï

r=   c                   @  sP   e Zd ZdZdZdZdd„ Zddd„Zd	d
„ Zdd„ Z	dd„ Z
eddd„ƒZdS )ÚMpoImageFileÚMPOzMPO (CIPA DC-007)Fc                 C  s$   | j  d¡ tj | ¡ |  ¡  d S )Nr   )r   r.   r   ÚJpegImageFileÚ_openÚ_after_jpeg_open©Úselfr   r   r   rA   g   s   zMpoImageFile._openNc                   sž   |d ur|nˆ   ¡ ˆ _ˆ jd ˆ _‡ fd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                   s   g | ]}|d  ˆ j d  ‘qS )Ú
DataOffsetÚmpoffset)Úinfo)Ú.0ÚmpentrC   r   r   Ú
<listcomp>o   s    ÿz1MpoImageFile._after_jpeg_open.<locals>.<listcomp>r   r   rF   r   )Ú_getmpÚmpinfoÚn_framesÚ_MpoImageFile__mpoffsetsr(   rG   r   r   Ú_fpr.   Ú_MpoImageFile__frameÚoffsetÚreadonly)rD   Úmpheaderr   rC   r   rB   l   s   
ÿ

zMpoImageFile._after_jpeg_openc                 C  s   | j  |¡ d S r	   )rO   r.   )rD   Úposr   r   r   Ú	load_seek   s   zMpoImageFile.load_seekc                 C  sÈ   |   |¡sd S | j| _| j| | _| j d¡}d| jv r | jd= | j | jd ¡ | j d¡s5d}t	|ƒ‚| j | j¡ t
j | ¡ | j d¡|krN|  ¡  dd| j | j| jd d fg| _|| _d S )Nr   é   zNo data found for frameÚjpeg)r   r   r   r   )Ú_seek_checkrO   r   rN   rQ   rG   r   r.   ÚreadÚ
ValueErrorr   r@   rA   Ú_reload_exifr;   ÚtilerP   )rD   ÚframeÚoriginal_exifÚmsgr   r   r   r.   ‚   s"   

"
zMpoImageFile.seekc                 C  s   | j S r	   )rP   rC   r   r   r   r*   ˜   s   zMpoImageFile.tellc                 C  s   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.
        )r>   Ú	__class__rB   )Újpeg_instancerS   r   r   r   Úadopt›   s   
zMpoImageFile.adoptr	   )Ú__name__Ú
__module__Ú__qualname__ÚformatÚformat_descriptionÚ!_close_exclusive_fp_after_loadingrA   rB   rU   r.   r*   Ústaticmethodrb   r   r   r   r   r>   b   s    
r>   z.mpoz	image/mpo)Ú
__future__r   r    r0   r#   Ú r   r   r   r   Ú_binaryr   r
   r=   r@   r>   Úregister_saverf   Úregister_save_allÚregister_extensionÚregister_mimer   r   r   r   Ú<module>   s   ;Q