B
    6d[                 @   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ko&t| ddkS )N      )i  i     )r      )leni16)prefix r   6/tmp/pip-unpacked-wheel-lxgm_btu/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s0d}t|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rt|d}d }x|t|D ]p}|d k	r.| j |d tj | j d}t|d}	|	dkrj| ||	dkrbdnd P t	|}|sP qW dd |D }tdd|| _d| _| j | _| j  | _| d d S )N         s     znot an FLI/FLC filer	   r   P   
      r
   i  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
      r!      r   c             S   s*   g | ]"\}}}t |t | t | qS r   )r   )r   rgbr   r   r   r   a   s    ZRGB    )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smsgr   magicr7   Znumber_of_subchunks
chunk_size_Z
chunk_typer   r   r   _open/   sN    






zFliImageFile._openc       
      C   s   d}xt t| jdD ]}| jd}||d  }|d }|dkrJd}| j|d }xZt dt|dD ]F}|| |> }||d  |> }||d  |> }	|||	f||< |d7 }qlW qW d S )Nr   r"   r   r    r   )r/   r   r(   r)   r   )
r<   r7   shiftier=   nr#   r$   r%   r   r   r   r4   j   s    zFliImageFile._palettec             C   sN   |  |sd S || jk r"| d x&t| jd |d D ]}| | q8W d S )Nr   r   )Z_seek_checkr8   _seekr/   )r<   framefr   r   r   r1   |   s    


zFliImageFile.seekc             C   s   |dkr$d| _ | j| j d| _n|   || j d krLd| }t||| _ | j| _| j| j | jd}|s|t	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   )r8   r9   r1   r;   r0   load
ValueErrorr(   r)   EOFErrorr-   ZdecodermaxblocksizeZtile)r<   rH   r>   r=   Z	framesizer   r   r   rG      s$    
zFliImageFile._seekc             C   s   | j S )N)r8   )r<   r   r   r   r:      s    zFliImageFile.tellN)__name__
__module____qualname__formatformat_descriptionZ!_close_exclusive_fp_after_loadingrB   r4   r1   rG   r:   r   r   r   r   r   *   s   ;	r   z.fliz.flc)r2    r   r   r   _binaryr   r   r   r-   r   r   r   Zregister_openrQ   Zregister_extensionsr   r   r   r   <module>   s   