U
    &^-                     @   sl   d dl mZmZmZ d dlmZmZmZ	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)i8i16lei32leo8c                 C   s    t | dkot| dd dkS )N        i  )leni16)prefix r   6/tmp/pip-install-a1j0c_p1/Pillow/PIL/FliImagePlugin.py_accept   s    r   c                   @   s`   e Zd ZdZdZdZdd Zdd Zedd	 Z	e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|dd }|dkrHt|dd dkrH|dd	 d
ksPtdt|dd | _d| _t|dd t|dd f| _t|dd }|dkr|d d }|| jd< dd t	dD }| j d}d| _
t|dd dkr| j
t| | _
| j d}t|dd dkrv| j d}t|dd dkrT| |d n"t|dd dkrv| |d dd |D }tdd|| _d| _| j | _| j  | _| d d S ) N   r
   r	   r         )             s     znot an FLI/FLC file   P
      r   i  F   durationc                 S   s   g | ]}|||fqS r   r   ).0ar   r   r   
<listcomp>C   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#   V   s     ZRGB    )fpreadr   SyntaxError_FliImageFile__framecountmode_sizei32inforange_FliImageFile__offset_paletter   rawjoinpalette_FliImageFile__frame_FliImageFile__fptell_FliImageFile__rewindseek)selfsmagicr    r9   r   r   r   _open)   sD    "
zFliImageFile._openc           
      C   s   d}t t| jdD ]}| jd}|t|d  }t|d }|dkrPd}| j|d }t dt|dD ]R}t|| |> }t||d  |> }t||d  |> }	|||	f||< |d7 }qpqd S )Nr   r&   r   r$   r   )r4   r   r,   r-   r   r   )
r?   r9   shiftier@   nr'   r(   r)   r   r   r   r6   _   s    zFliImageFile._palettec                 C   s   | j S Nr/   r?   r   r   r   n_framesq   s    zFliImageFile.n_framesc                 C   s
   | j dkS )Nr   rH   rI   r   r   r   is_animatedu   s    zFliImageFile.is_animatedc                 C   sJ   |  |sd S || jk r"| d t| jd |d D ]}| | q6d S )Nr   r   )Z_seek_checkr:   _seekr4   )r?   framefr   r   r   r>   y   s    


zFliImageFile.seekc                 C   s   |dkr$d| _ | j| j d| _n|   || j d krFtd| || _ | j| _| j| j | jd}|svt	t
|}|| _dd| j | jd fg| _|  j|7  _d S )	Nr   r+   r   r   zcannot seek to frame %dr
   Zfli)r   r   )r:   r;   r>   r=   r5   load
ValueErrorr,   r-   EOFErrorr2   ZdecodermaxblocksizeZtile)r?   rM   r@   Z	framesizer   r   r   rL      s"    zFliImageFile._seekc                 C   s   | j S rG   )r:   rI   r   r   r   r<      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 rG   )r;   r,   closeAttributeErrorrI   r   r   r   
_close__fp   s    
zFliImageFile._close__fpN)__name__
__module____qualname__formatformat_descriptionZ!_close_exclusive_fp_after_loadingrB   r6   propertyrJ   rK   r>   rL   r<   rU   r   r   r   r   r   #   s   6

	r   z.fliz.flcN) r   r   r   _binaryr   r   r   r   r2   r   r   r   Zregister_openrY   Zregister_extensionsr   r   r   r   <module>   s   	 