
    e                        d dl mZ 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 Z G d	 d
ej
                        Z ej                  ej                   ee        ej"                  ej                   ddg       y)    )annotationsN   )Image	ImageFileImagePalette)i16le)i32le)o8c                ^    t        |       dk\  xr t        | d      dv xr t        | d      dv S )N      )  i     )r      )leni16)prefixs    4/usr/lib/python3/dist-packages/PIL/FliImagePlugin.py_acceptr      s:    Fq 	&N..	&Ov%    c                  6    e Zd ZdZdZdZd Zd Zd Zd Z	d Z
y	)
FliImageFileFLIzAutodesk FLI/FLC AnimationFc           	     J   | j                   j                  d      }t        |      r|dd dk(  sd}t        |      t	        |d      | _        | j
                  dkD  | _        d| _        t	        |d	      t	        |d
      f| _        t        |d      }t	        |d      }|dk(  r|dz  dz  }|| j                  d<   t        d      D cg c]  }|||f	 }}| j                   j                  d      }d| _        t	        |d      dk(  r8| j                  t        |      z   | _        | j                   j                  d      }t	        |d      dk(  rt	        |d      }d }t        |      D ]  }	|-| j                   j                  |dz
  t        j                         | j                   j                  d      }t	        |d      }
|
dv r| j!                  ||
dk(  rdnd        nt        |      }|r n |D cg c])  \  }}}t#        |      t#        |      z   t#        |      z   + }}}}t%        j&                  ddj)                  |            | _        d| _        | j                   | _        | j                   j1                         | _        | j                  d       y c c}w c c}}}w )N         s     znot an FLI/FLC filer   r   P   
      r   r   i  F   duration   i   i  )r      r%      r   RGBr   )fpreadr   SyntaxErrorr   n_framesis_animated_mode_sizei32inforange_FliImageFile__offsetseekosSEEK_CUR_paletter
   r   rawjoinpalette_FliImageFile__frame_fptell_FliImageFile__rewind)selfsmsgr#   magicar:   number_of_subchunks
chunk_size_
chunk_typergbs                 r   _openzFliImageFile._open0   sN   GGLL
qBx;6'Cc"" Aq	==1, 
AYAr
*
 q":Aq	F? 4B.H (		* ',Cj1Aq!911GGLLq!9 MMCF2DMR Aq!9"%a)J./ 
)GGLLa=GGLLO AY
(MM'
b0@1aH V
!
 ;BBBYaA2a52a5=2a5(BB#''sxx/@A 77		!E 26 Cs   J4.Jc                   d}t        t        | j                  j                  d                  D ]  }| j                  j                  d      }||d   z   }|d   }|dk(  rd}| j                  j                  |dz        }t        dt	        |      d      D ]-  }||   |z  }||dz      |z  }||dz      |z  }	|||	f||<   |dz  }/  y )Nr   r&   r   r$   r   )r2   r   r)   r*   r   )
r?   r:   shiftier@   nrH   rI   rJ   s
             r   r7   zFliImageFile._palettek   s     s477<<?+, 	AQAAaDA!AAvQU#A1c!fa( aDEMa!eH%a!eH%AY
Q	r   c                    | j                  |      sy || j                  k  r| j                  d       t        | j                  dz   |dz         D ]  }| j                  |        y )Nr   r   )_seek_checkr;   _seekr2   )r?   framefs      r   r4   zFliImageFile.seek}   sX    &4<<JJqMt||a'3 	AJJqM	r   c                <   |dk(  r4d| _         | j                  j                  | j                         d| _        n| j                          || j                   dz   k7  rd| }t        |      || _         | j                  | _        | j                  j                  | j                         | j                  j                  d      }|sd}t        |      t        |      }|| _        dd	| j                  z   | j                  d fg| _        | xj                  |z  c_        y )
Nr   r(   r   r   zcannot seek to frame r   zmissing frame sizefli)r   r   )r;   r<   r4   r>   r3   load
ValueErrorr)   r*   EOFErrorr0   decodermaxblocksizetile)r?   rT   rA   r@   	framesizes        r   rS   zFliImageFile._seek   s    A:DLHHMM$--(DM IIKDLL1$$)%1CS/! ((T]]#GGLLO&C3-F	(Vdii/EF	"r   c                    | j                   S )N)r;   )r?   s    r   r=   zFliImageFile.tell   s    ||r   N)__name__
__module____qualname__formatformat_description!_close_exclusive_fp_after_loadingrK   r7   r4   rS   r=    r   r   r   r   +   s-    F5(-%9v$#<r   r   z.fliz.flc)
__future__r   r5    r   r   r   _binaryr   r   r	   r0   r
   r   r   register_openrc   register_extensionsrf   r   r   <module>rl      so   " # 	 , , ! ! z9&& z@   L''w ?   ,--/? @r   