3
V^-  ã               @   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jejeeƒ ej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é   é   é¯  é¯  )r   r   )ÚlenÚi16)Úprefix© r   ú4/tmp/pip-build-zn8x4q5s/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 jdƒ}t|dd… ƒ}|d koFt|dd… ƒd!koF|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 jdƒ}d| _
t|dd… ƒdk�r| j
t|ƒ | _
| j jdƒ}t|dd… ƒdk�rv| j jdƒ}t|dd… ƒdk�rT| j|dƒ n"t|dd… ƒdk�rv| j|dƒ dd„ |D ƒ}tjddj|ƒƒ| _d"| _| j | _| j jƒ | _| jdƒ d S )#Né€   r
   r	   é¯  é¯  é   é   é    é   é   é   s     znot an FLI/FLC fileé   ÚPé
   é   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úñ  é   é   c             S   s*   g | ]"\}}}t |ƒt |ƒ t |ƒ ‘qS r   )r   )r#   ÚrÚgÚbr   r   r   r%   V   s    ZRGBó    r   )r   r   )r   r   éÿÿÿÿ)Ú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"   r;   r   r   r   Ú_open)   s>    "
zFliImageFile._openc       
      C   sÒ   d}xÈt t| jjdƒƒƒD ]°}| jjdƒ}|t|d ƒ }t|d ƒ}|dkrRd}| jj|d ƒ}xft dt|ƒdƒD ]R}t|| ƒ|> }t||d  ƒ|> }t||d  ƒ|> }	|||	f||< |d7 }qtW qW d S )Nr   r(   r   r&   r   )r6   r   r.   r/   r   r   )
rA   r;   ÚshiftÚiÚerB   Únr)   r*   r+   r   r   r   r8   _   s    zFliImageFile._palettec             C   s   | j S )N)r1   )rA   r   r   r   Ún_framesq   s    zFliImageFile.n_framesc             C   s
   | j dkS )Nr   )r1   )rA   r   r   r   Úis_animatedu   s    zFliImageFile.is_animatedc             C   sN   | j |ƒsd S || jk r"| jdƒ x&t| jd |d ƒD ]}| j|ƒ q8W d S )Nr   r   )Z_seek_checkr<   Ú_seekr6   )rA   ÚframeÚfr   r   r   r@   y   s    


zFliImageFile.seekc             C   s®   |dkr$d| _ | jj| jƒ d| _n| jƒ  || j d krFtd| ƒ‚|| _ | j| _| jj| jƒ | jjdƒ}|svt	‚t
|ƒ}|| _dd| j | jd fg| _|  j|7  _d S )	Nr   r   r   zcannot seek to frame %dr
   Zflir-   )r   r   )r<   r=   r@   r?   r7   ÚloadÚ
ValueErrorr.   r/   ÚEOFErrorr4   ZdecodermaxblockÚsizeZtile)rA   rL   rB   Z	framesizer   r   r   rK   ‚   s"    zFliImageFile._seekc             C   s   | j S )N)r<   )rA   r   r   r   r>   ž   s    zFliImageFile.tellc             C   sB   z4y| j | jkr| j jƒ  W n tk
r0   Y nX W d d | _ X d S )N)r=   r.   ÚcloseÚAttributeError)rA   r   r   r   Ú
_close__fp¡   s    
zFliImageFile._close__fpN)Ú__name__Ú
__module__Ú__qualname__ÚformatÚformat_descriptionZ!_close_exclusive_fp_after_loadingrD   r8   ÚpropertyrI   rJ   r@   rK   r>   rT   r   r   r   r   r   #   s   6	r   z.fliz.flcN)Ú r   r   r   Ú_binaryr   r   r   r   r4   r   r   r   Zregister_openrX   Zregister_extensionsr   r   r   r   Ú<module>   s   	 