a
    Lˆc1  ã                   @   s€   d dl Z ddlmZmZmZ ddlmZ ddlmZ	 ddlm
Z
 dd„ ZG d	d
„ d
ejƒZe ejee¡ e ejddg¡ dS )é    Né   )ÚImageÚ	ImageFileÚImagePalette)Úi16le)Úi32le©Úo8c                 C   s(   t | ƒdko&t| dƒdv o&t| dƒdv S )Né   é   )é¯  i¯  é   )r   é   )ÚlenÚi16)Úprefix© r   úU/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/PIL/FliImagePlugin.pyÚ_accept   s
    ÿýr   c                   @   s@   e Zd ZdZdZdZdd„ Zdd„ Zdd	„ Zd
d„ Z	dd„ Z
dS )ÚFliImageFileZFLIzAutodesk FLI/FLC AnimationFc           	      C   sÊ  | j  d¡}t|ƒr$|dd… dks,tdƒ‚t|dƒ| _| jdk| _d| _t|d	ƒt|d
ƒf| _t	|dƒ}t|dƒ}|dkrˆ|d d }|| j
d< dd„ tdƒD ƒ}| j  d¡}d| _t|dƒdkrà| jt	|ƒ | _| j  d¡}t|dƒdk�r€t|dƒ}d }t|ƒD ]x}|d u�r(| j  |d tj¡ | j  d¡}t|dƒ}|dv �rh|  ||dk�r\dnd¡  �q€t	|ƒ}|�s �q€�qdd„ |D ƒ}t dd |¡¡| _d| _| j | _| j  ¡ | _|  d¡ d S )Né€   é   é   s     znot an FLI/FLC filer
   r   ÚPé   é
   é   r   r   iè  éF   Údurationc                 S   s   g | ]}|||f‘qS r   r   )Ú.0Úar   r   r   Ú
<listcomp>G   ó    z&FliImageFile._open.<locals>.<listcomp>é   i ñ  iúñ  )r   é   r$   é   r   c                 S   s*   g | ]"\}}}t |ƒt |ƒ t |ƒ ‘qS r   r   )r   ÚrÚgÚbr   r   r   r!   b   r"   ZRGBr"   éÿÿÿÿ)ÚfpÚreadr   ÚSyntaxErrorr   Zn_framesZis_animatedÚmodeÚ_sizeÚi32ÚinfoÚrangeÚ_FliImageFile__offsetÚseekÚosÚSEEK_CURÚ_paletter   ÚrawÚjoinÚpaletteÚ_FliImageFile__frameÚ_fpÚtellÚ_FliImageFile__rewind)	ÚselfÚsr   Úmagicr9   Znumber_of_subchunksÚ
chunk_sizeÚ_Z
chunk_typer   r   r   Ú_open0   sL    







zFliImageFile._openc           
      C   s¶   d}t t| j d¡ƒƒD ]˜}| j d¡}||d  }|d }|dkrHd}| j |d ¡}t dt|ƒdƒD ]F}|| |> }||d  |> }||d  |> }	|||	f||< |d7 }qhqd S )Nr   r%   r   r#   r   )r1   r   r*   r+   r   )
r>   r9   ÚshiftÚiÚer?   Únr&   r'   r(   r   r   r   r6   k   s    zFliImageFile._palettec                 C   sJ   |   |¡sd S || jk r"|  d¡ t| jd |d ƒD ]}|  |¡ q6d S )Nr   r   )Z_seek_checkr:   Ú_seekr1   )r>   ÚframeÚfr   r   r   r3   }   s    


zFliImageFile.seekc                 C   s°   |dkr$d| _ | j | j¡ d| _n|  ¡  || j d krHtd|› �ƒ‚|| _ | j| _| j | j¡ | j d¡}|sxt	‚t
|ƒ}|| _dd| j | jd fg| _|  j|7  _d S )	Nr   r)   r   r   zcannot seek to frame r   Zfli)r   r   )r:   r;   r3   r=   r2   ÚloadÚ
ValueErrorr*   r+   ÚEOFErrorr/   ZdecodermaxblockÚsizeZtile)r>   rI   r?   Z	framesizer   r   r   rH   †   s"    zFliImageFile._seekc                 C   s   | j S )N)r:   )r>   r   r   r   r<   ¢   s    zFliImageFile.tellN)Ú__name__Ú
__module__Ú__qualname__ÚformatÚformat_descriptionZ!_close_exclusive_fp_after_loadingrC   r6   r3   rH   r<   r   r   r   r   r   *   s   ;	r   z.fliz.flc)r4   Ú r   r   r   Ú_binaryr   r   r   r/   r	   r   r   Zregister_openrR   Zregister_extensionsr   r   r   r   Ú<module>   s   