U
    Å½„b�  ã                   @   sx   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 )é   )ÚImageÚ	ImageFileÚImagePalette)Úi16le)Úi32le©Úo8c                 C   s(   t | ƒdko&t| dƒdko&t| dƒdkS )Né   é   )é¯  i¯  é   )é    é   )ÚlenÚi16)Úprefix© r   ú6/tmp/pip-unpacked-wheel-_wxctax1/PIL/FliImagePlugin.pyÚ_accept   s
    ÿýr   c                   @   sH   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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�r6| j  d¡}t|dƒdk�r|  |d¡ nt|dƒdk�r6|  |d¡ 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>F   s     z&FliImageFile._open.<locals>.<listcomp>é   i ñ  iúñ  é   é   r   c                 S   s*   g | ]"\}}}t |ƒt |ƒ t |ƒ ‘qS r   r   )r   ÚrÚgÚbr   r   r   r!   Y   s     ZRGBó    éÿÿÿÿ)ÚfpÚreadr   ÚSyntaxErrorr   Zn_framesZis_animatedÚmodeÚ_sizeÚi32ÚinfoÚrangeÚ_FliImageFile__offsetÚ_paletter   ÚrawÚjoinÚpaletteÚ_FliImageFile__frameÚ_FliImageFile__fpÚtellÚ_FliImageFile__rewindÚseek)ÚselfÚsr   Úmagicr6   r   r   r   Ú_open/   s<    


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<   r6   ÚshiftÚiÚer=   Únr%   r&   r'   r   r   r   r3   b   s    zFliImageFile._palettec                 C   sJ   |   |¡sd S || jk r"|  d¡ t| jd |d ƒD ]}|  |¡ q6d S )Nr   r   )Z_seek_checkr7   Ú_seekr1   )r<   ÚframeÚfr   r   r   r;   t   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   )r7   r8   r;   r:   r2   ÚloadÚ
ValueErrorr*   r+   ÚEOFErrorr/   ZdecodermaxblockÚsizeZtile)r<   rE   r=   Z	framesizer   r   r   rD   }   s"    zFliImageFile._seekc                 C   s   | j S ©N)r7   ©r<   r   r   r   r9   ™   s    zFliImageFile.tellc                 C   sB   z4z| j | jkr| j  ¡  W n tk
r0   Y nX W 5 d | _ X d S rK   )r8   r*   ÚcloseÚAttributeErrorrL   r   r   r   Ú
_close__fpœ   s    
zFliImageFile._close__fpN)Ú__name__Ú
__module__Ú__qualname__ÚformatÚformat_descriptionZ!_close_exclusive_fp_after_loadingr?   r3   r;   rD   r9   rO   r   r   r   r   r   )   s   3	r   z.fliz.flcN)Ú r   r   r   Ú_binaryr   r   r   r/   r   r   r   Zregister_openrS   Zregister_extensionsr   r   r   r   Ú<module>   s    