o
    g[                     @   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v ot| ddv S )N      )  i     )r      )leni16)prefix r   P/home/ubuntu/cloudmapper/venv/lib/python3.10/site-packages/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 )FliImageFileFLIzAutodesk FLI/FLC AnimationFc           
      C   s  | j d}t|r|dd dksd}t|t|d| _| jdk| _d| _t|d	t|d
f| _t	|d}t|d}|dkrF|d d }|| j
d< dd tdD }| j d}d| _t|ddkrr| jt	| | _| j d}t|ddkrt|d}d }t|D ]5}|d ur| j |d tj | j d}t|d}	|	dv r| ||	dkrdnd  n	t	|}|s nqd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      r$      r   c                 S   s*   g | ]\}}}t |t | t | qS r   r   )r    rgbr   r   r   r"   a   s   * RGB    )fpreadr   SyntaxErrorr   n_frames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   magicr=   number_of_subchunks
chunk_size_
chunk_typer   r   r   _open/   sP   




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   )
rB   r=   shiftierC   nr&   r'   r(   r   r   r   r:   j   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   )rB   framefr   r   r   r7   |   s   


zFliImageFile.seekc                 C   s   |dkrd| _ | j| j d| _n|   || j d kr&d| }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   fli)r   r   )r>   r?   r7   rA   r6   load
ValueErrorr,   r-   EOFErrorr3   decodermaxblocksizetile)rB   rQ   rD   rC   	framesizer   r   r   rP      s$   
zFliImageFile._seekc                 C   s   | j S )N)r>   )rB   r   r   r   r@      s   zFliImageFile.tellN)__name__
__module____qualname__formatformat_description!_close_exclusive_fp_after_loadingrJ   r:   r7   rP   r@   r   r   r   r   r   *   s    ;	r   z.fliz.flc)r8    r   r   r   _binaryr   r   r   r3   r	   r   r   register_openr^   register_extensionsr   r   r   r   <module>   s   