o
    Z#a                     @   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v S )N      )  i  )leni16)prefix r   4/usr/lib/python3/dist-packages/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 )FliImageFileFLIzAutodesk FLI/FLC AnimationFc                 C   s  | j d}t|rt|ddv 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rK|d d }|| j
d< dd tdD }| j d}d| _t|ddkrw| jt	| | _| j d}t|ddkr| j d}t|ddkr| |d nt|ddkr| |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   * RGB    )fpreadr   r   SyntaxErrorn_framesis_animatedmode_sizei32inforange_FliImageFile__offset_paletter   rawjoinpalette_FliImageFile__frame_FliImageFile__fptell_FliImageFile__rewindseek)selfsr   magicr:   r   r   r   _open+   sB   


zFliImageFile._openc           
      C   s   d}t t| jdD ]L}| jd}||d  }|d }|dkr$d}| j|d }t dt|dD ]#}|| |> }||d  |> }||d  |> }	|||	f||< |d7 }q4qd S )Nr   r%   r   r#   r   )r5   r   r,   r-   r   )
r@   r:   shiftierA   nr&   r'   r(   r   r   r   r7   b   s    
zFliImageFile._palettec                 C   sJ   |  |sd S || jk r| d t| jd |d D ]}| | qd S )Nr   r   )_seek_checkr;   _seekr5   )r@   framefr   r   r   r?   t   s   


zFliImageFile.seekc                 C   s   |dkrd| _ | j| j d| _n|   || j d kr$td| || _ | 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
   fli)r   r   )r;   r<   r?   r>   r6   load
ValueErrorr,   r-   EOFErrorr3   decodermaxblocksizetile)r@   rJ   rA   	framesizer   r   r   rI   }   s"   zFliImageFile._seekc                 C   s   | j S N)r;   r@   r   r   r   r=      s   zFliImageFile.tellc                 C   sP   z#z| j | jkr| j   W n	 ty   Y nw W d | _ d S W d | _ d S d | _ w rT   )r<   r,   closeAttributeErrorrU   r   r   r   
_close__fp   s   

zFliImageFile._close__fpN)__name__
__module____qualname__formatformat_description!_close_exclusive_fp_after_loadingrC   r7   r?   rI   r=   rX   r   r   r   r   r   %   s    7	r   z.fliz.flcN) r   r   r   _binaryr   r   r   r3   r   r   r   register_openr\   register_extensionsr   r   r   r   <module>   s   	 