
    0-Phd                        d Z ddlZddlZddlZddlZddlZ ej        e          Z	 G d d          Z
d Zd Zd Zd-dZd.d
Zd Zd-dZd Zd Z G d d          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d d e          Z G d! d"e          Zd# Zd$ Z	 d/d(Z d0d+Z!d, Z"e!Z#e"Z$dS )1aL  
Provides a function (write_swf) to store a series of numpy arrays in an
SWF movie, that can be played on a wide range of OS's.

In desperation of wanting to share animated images, and then lacking a good
writer for animated gif or .avi, I decided to look into SWF. This format
is very well documented.

This is a pure python module to create an SWF file that shows a series
of images. The images are stored using the DEFLATE algorithm (same as
PNG and ZIP and which is included in the standard Python distribution).
As this compression algorithm is much more effective than that used in
GIF images, we obtain better quality (24 bit colors + alpha channel)
while still producesing smaller files (a test showed ~75%). Although
SWF also allows for JPEG compression, doing so would probably require
a third party library for the JPEG encoding/decoding, we could
perhaps do this via Pillow or freeimage.

sources and tools:

- SWF on wikipedia
- Adobes "SWF File Format Specification" version 10
  (http://www.adobe.com/devnet/swf/pdf/swf_file_format_spec_v10.pdf)
- swftools (swfdump in specific) for debugging
- iwisoft swf2avi can be used to convert swf to avi/mpg/flv with really
  good quality, while file size is reduced with factors 20-100.
  A good program in my opinion. The free version has the limitation
  of a watermark in the upper left corner.

    Nc                   D    e Zd ZdZddZd Zd Zd Zd Zd Z	d	 Z
d
 ZdS )BitArrayzDynamic array of bits that automatically resizes
    with factors of two.
    Append bits using .append() or +=
    You can reverse bits using .reverse()
    Nc                     t          j        dt           j                  | _        d| _        ||                     |           d S d S )N)   dtyper   )npzerosuint8data_lenappend)self	initvalues     T/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/imageio/plugins/_swf.py__init__zBitArray.__init__=   sG    HU"(333		 KK	""""" !     c                     | j         S N)r   r   s    r   __len__zBitArray.__len__C   s
    yr   c                 t    | j         d | j                                                                     d          S )Nascii)r   r   tobytesdecoder   s    r   __repr__zBitArray.__repr__F   s/    y49%--//66w???r   c                     | j         j        d         }| j        |k    rKt          j        |dz  ft          j                  }| j         d | j                 |d | j        <   || _         d S d S )Nr      r   )r   shaper   r	   r
   r   )r   arraylentmps      r   
_checkSizezBitArray._checkSizeI   si    9?1%9  (HqL?"(;;;C#y495C$)DIII ! r   c                 0    |                      |           | S r   )r   )r   values     r   __add__zBitArray.__add__Q   s    Er   c                 h   t          |t                    rt          |          }t          |t                    rt          |          }t          |t                    st	          d          |D ]B}t          |          | j        | j        <   | xj        dz  c_        |                                  Cd S )Nz#Append bits as strings or integers!   )	
isinstancer   strint
ValueErrorordr   r   r"   )r   bitsbits      r   r   zBitArray.appendU   s    dH%% 	t99DdC   	t99D$$$ 	DBCCC  	 	C#&s88DIdi IINIIOO	 	r   c                     | j         d| j                                                 }|ddd         | j         d| j        <   dS )zIn-place reverse.N)r   r   copy)r   r!   s     r   reversezBitArray.reversed   sB    i$)$))++!$TTrT	+DI+r   c                 b   t          |           }d}|dz  t          |          k     r|dz  }|dz  t          |          k     |                    |dz  d          }t                      }t	          |          D ]5}t          ||dz  |dz   dz           d          }|t          |          z  }6|S )zZConvert to bytes. If necessary,
        zeros are padded to the end (right side).
        r      r'   0r   )r)   lenljustbytesranger*   	int2uint8)r   r-   nbytesbbir!   s         r   r   zBitArray.tobytesi   s     4yy qj3t99$$aKF qj3t99$$ zz&1*c** WWv 	! 	!Ad1q5AEQ;./33C)C.. BB 	r   r   )__name__
__module____qualname____doc__r   r   r   r"   r%   r   r2   r    r   r   r   r   6   s         # # # #  @ @ @      + + +
    r   r   c                 H    t          |                               dd          S )N   littler*   to_bytesr=   s    r   
int2uint32rI          q66??1h'''r   c                 H    t          |                               dd          S )Nr   rE   rF   rH   s    r   
int2uint16rL      rJ   r   c                 H    t          |                               dd          S )Nr'   rE   rF   rH   s    r   r:   r:      rJ   r   c                 B   | }t                      }|dk    r |t          |dz            z  }|dz	  }|dk     |                                 |Et          |          |k    rt	          d          t          |                              |d          }t          |          S )zoconvert int to a string of bits (0's and 1's in a string),
    pad to n elements. Convert back using int(ss,2).r   r   r'   Nz)int2bits fail: len larger than padlength.r5   )r   r)   r2   r6   r+   rjustr=   niir<   s       r   int2bitsrS      s     
B 
B
q&&
c"q&kk1W q&& JJLLL 	}r77Q;;HIIIWW]]1c"" B<<r   r4   c                    d}t          t          |                     D ]L}| ||dz            }t          t          |                    dd          }|                    dd          |z   }Mt          |d |         d          S )N r'   r   r4   r5   )r9   r6   binr,   rO   r*   )r<   rQ   r$   r=   br!   s         r   bits2intrX      s    E 3r77^^ * *q1q5yM#a&&kk!""o		!S!!E) uRaRy!r   c                 &   d}t          d          D ]L}| ||dz            }t          t          |                    dd         }|                    dd          |z   }Mt	          |dd         d          }t	          |dd         d          }|dz   }|dk    rtd}t          dd	          D ]L}| ||dz            }t          t          |                    dd         }|                    dd          |z   }Mt	          |d          }|d	z   }|||fS )
zPbb should be 6 bytes at least
    Return (type, length, length_of_full_tag)
    rU   r   r'   Nr4   r5   
   ?      )r9   rV   r,   rO   r*   )r<   r$   r=   rW   r!   typeLL2s           r   get_type_and_lenr`      s,   
 E 1XX * *q1q5yM#a&&kk!""o		!S!!E) uSbSz1DE"##JA	
QB 	Bwwq! 	. 	.A1q1u9Ac!ff++abb/CIIa%%-EEqMMU B;r   c                    | }| dk     rt          |          dz
  }t                      }|dk    r |t          |dz            z  }|dz	  }|dk     |                                 dt          |          z   }|8t	          |          |k    rt          d          |                    |d          }| dk     r>|                    dd                              dd                              dd          }t          |          S )	zconvert signed int to a string of bits (0's and 1's in a string),
    pad to n elements. Negative numbers are stored in 2's complement bit
    patterns, thus positive numbers always start with a 0.
    r   r'   r   r5   Nz/signedint2bits fail: len larger than padlength.x1)absr   r)   r2   r6   r+   rO   replacerP   s       r   signedint2bitsrf      s     
B1uuWWq[ 
B
q&&
c"q&kk1W q&& JJLLL 
s2wwB}r77Q;;NOOOXXa 	1uuZZS!!))#s33;;CEE B<<r   c                     d}| D ])}t          t          |dz                      }||k    r|}*t          |d          }| D ]}|t          |dz  |          z  }|S )zGiven a few (signed) numbers, store them
    as compactly as possible in the wat specifief by the swf format.
    The numbers are multiplied by 20, assuming they
    are twits.
    Can be used to make the RECT record.
    r'         )r6   rf   rS   )arrmaxlenr=   r!   r-   s        r   
twits2bitsrl      s     F  .R(())<<F FAD / /q2vv...Kr   c                     t          dd          }| D ]T}|dk     rt          d          t          |          }||z
  }|t          |d          z  }|t          |dz  d          z  }U|S )zGiven a few (signed) numbers, convert them to bits,
    stored as FB (float bit values). We always use 16.16.
    Negative numbers are not (yet) possible, because I don't
    know how the're implemented (ambiguity).
       ri   r   z"Dit not implement negative floats!   i   r   )rS   r+   r*   )rj   r-   r=   i1i2s        r   floats2bitsrr     s     B??D ) )q55ABBBVVVR   eR(((Kr   c                   .    e Zd Zd Zd Zd Zd ZddZdS )Tagc                 :    t                      | _         d| _        d S )Nr0   )r8   tagtyper   s    r   r   zTag.__init__!  s    WW
r   c                     t                      )z!Implement this to create the tag.)NotImplementedErrorr   s    r   process_tagzTag.process_tag%  s    !###r   c                    |                                   t          | j        d          }|dz  }t          t	          t          |          d                    }|t          t          | j                            z  }|| j        z  }|S )z)Calls processTag and attaches the header.rZ   111111r   )	ry   rS   rv   rL   r*   r)   rI   r6   r8   )r   r-   r<   s      r   get_tagzTag.get_tag)  s~     b)) 	CIIq))** 	jTZ))) 	dj	r   c                 (    t          ||||g          S )z>Simply uses makeCompactArray to produce
        a RECT Record.)rl   )r   xminxmaxyminymaxs        r   make_rect_recordzTag.make_rect_record<  s     4tT2333r   Nc                 T   |||dS t                      }|r&|dz  }|t          |d         |d         g          z  }n|dz  }|r&|dz  }|t          |d         |d         g          z  }n|dz  }|r!|t          |d         |d         g          z  }n|t          ddg          z  }|S )N00000000rc   r   r'   r5   )r   rr   rl   )r   scale_xyrot_xytrans_xyr-   s        r   make_matrix_recordzTag.make_matrix_recordA  s    83C7 zz  	CKDK!hqk :;;;DDCKD  	CKDKF1I 6777DDCKD  	'JXa[9:::DDJ1v&&&D r   NNN)r>   r?   r@   r   ry   r|   r   r   rB   r   r   rt   rt      sd          $ $ $  &4 4 4
     r   rt   c                       e Zd Zd ZdS )
ControlTagc                 :    t                               |            d S r   )rt   r   r   s    r   r   zControlTag.__init__e  s    Tr   N)r>   r?   r@   r   rB   r   r   r   r   d  s#            r   r   c                       e Zd Zd Zd ZdS )FileAttributesTagc                 H    t                               |            d| _        d S )NE   r   r   rv   r   s    r   r   zFileAttributesTag.__init__j  s!    D!!!r   c                 @    d                     d          dz  | _        d S )N r   rD   )encoder8   r   s    r   ry   zFileAttributesTag.process_tagn  s    ]]7++u5


r   Nr>   r?   r@   r   ry   rB   r   r   r   r   i  s2          6 6 6 6 6r   r   c                       e Zd Zd Zd ZdS )ShowFrameTagc                 H    t                               |            d| _        d S Nr'   r   r   s    r   r   zShowFrameTag.__init__s  s!    D!!!r   c                 ,    t                      | _         d S r   )r8   r   s    r   ry   zShowFrameTag.process_tagw  s    WW


r   Nr   rB   r   r   r   r   r  s2              r   r   c                       e Zd ZdZd Zd ZdS )SetBackgroundTagz1Set the color in 0-255, or 0-1 (if floats given).c                 X    d| _         t          |          dk    r|d         }|| _        d S )N	   r'   r   )rv   r6   rgb)r   r   s     r   r   zSetBackgroundTag.__init__~  s,    s88q==a&Cr   c                     t                      }t          d          D ];}| j        |         }t          |t                    r|dz  }|t          |          z  }<|| _         d S )N      )r8   r9   r   r(   floatr:   )r   r<   r=   clrs       r   ry   zSetBackgroundTag.process_tag  sc    WWq 	! 	!A(1+C#u%%  Ci)C.. BB


r   N)r>   r?   r@   rA   r   ry   rB   r   r   r   r   {  s8        ;;      r   r   c                   "    e Zd ZddZd Zd ZdS )DoActionTagstopc                 X    t                               |            d| _        |g| _        d S )N   )rt   r   rv   actionsr   actions     r   r   zDoActionTag.__init__  s(    Txr   c                 :    | j                             |           d S r   )r   r   r   s     r   r   zDoActionTag.append  s    F#####r   c                 F   t                      }| j        D ]q}|                                }|dk    r|d                    d          z  }5|dk    r|d                    d          z  }Tt                              d|z             r|t          d          z  }|| _         d S )Nr   r   playzunknown action: %sr   )r8   r   lowerr   loggerwarningr:   )r   r<   r   s      r   ry   zDoActionTag.process_tag  s    WWl 	> 	>F\\^^FfmmG,,,6!!fmmG,,,3f<====
ill


r   N)r   )r>   r?   r@   r   r   ry   rB   r   r   r   r     sF               
$ $ $    r   r   c                       e Zd ZdZd ZdS )DefinitionTagr   c                     t                               |            t          xj        dz  c_        t          j        | _        d S r   )rt   r   r   counteridr   s    r   r   zDefinitionTag.__init__  s6    T"'r   N)r>   r?   r@   r   r   rB   r   r   r   r     s(        G( ( ( ( (r   r   c                       e Zd Zd Zd ZdS )	BitmapTagc                    t                               |            d| _        t          |j                  dk    r|j        d         dv rt          j        |j        d         |j        d         dft
          j                  d	z  }t          d          D ]}|d d d d |f         |d d d d |dz   f<   |j        d         dk    r|d d d d df         |d d d d df<   nt          d
          t          |j                  dk    rjt          j        |j        d         |j        d         dft
          j                  d	z  }t          d          D ]}|d d d d f         |d d d d |dz   f<   nt          d
          t          j        |                                t          j                  | _        |j        | _        d S )N$   r   r   r   rD   r   r'   rD   r   r   zInvalid shape to be an image.)r   r   rv   r6   r   r	   onesr   r9   r+   zlibcompressr   DEFLATED_dataimshape)r   imr!   r=   s       r   r   zBitmapTag.__init__  s   t$$$ rx==Ax{f$$grx{BHQK;28LLLsRq 3 3A')!!!QQQ'{C111a!e$$8A;!###%aaaAg;C111aL !@AAA]]a'28A;Q7rxHHH3NC1XX , ,#%aaad8AAAqqq!a%K  , <=== ]3;;==$-@@
xr   c                 
   t                      }|t          | j                  z  }|t          d          z  }|t          | j        d                   z  }|t          | j        d                   z  }|| j        z  }|| _         d S )Nri   r'   r   )r8   rL   r   r:   r   r   )r   r<   s     r   ry   zBitmapTag.process_tag  sv    WW
j!!!
ill
ja)))
ja)))
dj


r   Nr   rB   r   r   r   r     s3             @	 	 	 	 	r   r   c                       e Zd ZddZd ZdS )PlaceObjectTagNr   r   Fc                     t                               |            d| _        || _        || _        || _        || _        d S )N   )r   r   rv   depth	idToPlacexymove)r   r   r   r   r   s        r   r   zPlaceObjectTag.__init__  s=    D!!!
"			r   c                 h   | j         }| j        }| j        }t                      }| j        r|d                    d          z  }n|d                    d          z  }|t          |          z  }|t          |          z  }||                     |                                          z  }|| _        d S )Nr   r   r   )r   )	r   r   r   r8   r   r   rL   r   r   )r   r   r   r   r<   s        r   ry   zPlaceObjectTag.process_tag  s    
W^ WW9 	)&--(((BB &--(((B
j
jnn
d%%r%22::<<<


r   )Nr   Fr   rB   r   r   r   r     s7               r   r   c                   .    e Zd Zd Zd ZddZd Zd ZdS )ShapeTagc                 r    t                               |            d| _        || _        || _        || _        d S )Nr   )r   r   rv   bitmapIdr   wh)r   r   r   r   s       r   r   zShapeTag.__init__  s6    t$$$ r   c                 L   t                      }|t          | j                  z  }| j        | j        }}|                     |d         |d         |d         |d                   }||                                z  }|t          d          z  }|d                    d          z  }|t          | j	                  z  }|| 
                    d                                          z  }|t          d          z  }|d                    d          z  }|| _         t                      }||                     dd| j        d         | j        d         f          z  }||                     | j        d          d          z  }||                     d| j        d                    z  }||                     | j        d         d          z  }||                     d| j        d                   z  }||                                 z  }| xj         |                                z  c_         d	S )
z-Returns a defineshape tag. with a bitmap fillr   r'   Ar   )rh   rh   )r   D)moveToN)r8   rL   r   r   r   r   r   r:   r   r   r   r   make_style_change_recordmake_straight_edge_recordmake_end_shape_record)r   r<   r   r   r!   r-   s         r   ry   zShapeTag.process_tag  s    WW
j!!!$'B##BqE2a5"Q%A??
ckkmm
 	ill
fmmG$$$
j'''
d%%x%88@@BBB 	ill 	fmmG$$$
 zz--aDGAJPQ
;S-TTT..
{A>>>..q471:+>>>..twqz1===..q$'!*=== 	**,,,

dllnn$



r   Nc                 &   t                      }|dz  }|dz  }|r|dz  }n|dz  }|r|dz  }n|dz  }|dz  }|r|dz  }n|dz  }|r |t          |d         |d         g          z  }|r|t          |d          z  }|r|t          |d          z  }|S )Nr5   rc   r   r'   rD   )r   rl   rS   )r   	lineStyle	fillStyler   r-   s        r   r   z!ShapeTag.make_style_change_record6  s    
 zz 	CKDDCKD 	CKDDCKD 	CKDDCKD
  	7Jq	6!95666D 	+HY***D 	+HY***Dr   c                    t          |          dk    r|d         }t          |d         dz            }t          |d         dz            }t          t          |          t          |          g          }t                      }|dz  }|t	          |dz
  d          z  }|dz  }|t          |d         dz  |          z  }|t          |d         dz  |          z  }|S )Nr'   r   rh   11r   rD   rc   )r6   rf   maxr   rS   )r   dxdyxbitsybitsnbitsr-   s         r   r   z"ShapeTag.make_straight_edge_recordX  s    t99>>7D tAw|,,tAw|,,SZZU,--zzA&&&tAw|U333tAw|U333 r   c                 6    t                      }|dz  }|dz  }|S )Nr5   00000)r   )r   r-   s     r   r   zShapeTag.make_end_shape_recordl  s"    zzr   r   )r>   r?   r@   r   ry   r   r   r   rB   r   r   r   r     sf          /% /% /%h       D  (    r   r   c                 D   | ||dz            }|dz  }t          | ||dz                      }|dz  }t          | ||dz            d          }|dz  }t          | ||dz            d          }|dz  }|dk    rt                              d           dS d}| ||||z
  z            }	t	          j        |	          }
t          j        |
t          j                  }|dk    r6	 ||d	f|_	        n*# t          $ r t                              d
           Y nw xY w|dk    r||df|_	        |}t          j        |          }|dddddf         |dddddf<   |dddddf         |dddddf<   |ddddd	f         |dddddf<   |dddddf         |ddddd	f<   |S )z;With pf's seed after the recordheader, reads the pixeldata.r   r'   r   ri   z4Can only read 24bit or 32bit RGB(A) lossless images.   r   rh   r   z'Cannot read image due to byte alignmentr   rD   Nr   )r,   rX   r   r   r   
decompressr	   
frombufferr   r   	Exception
zeros_like)r<   r=   tagTypeL1charIdformatwidthheightoffsetbb2r   arW   s                r   read_pixelsr   s  s!    AE	]FFAAAIFFARAE	]B''EFAbQUmR((FFA {{MNNNNN Q"v+&&' s##M$bh/// b==J %* J J JHIIIIIJ b==eQ&AGAa  A111aaa7AaaaAgJ111aaa7AaaaAgJ111aaa7AaaaAgJ111aaa7AaaaAgJs   !
C, ,$DDc           	      2   g }| D ]}t          |t          j                  rH|j        t          j        k    r|                    |           n|j        t          j        t          j        fv r|                                }d|cxk     rdk     rn nn+|	                                }d||dk     <   d||dk    <   |dz  }|                    |
                    t          j                             n4|
                    t          j                  }|                    |           |j        dk    r,|j        dk    r |j        d         dvrt          d	          Wt          d	          t          d
t          t          |                    z             |S )ztcheckImages(images)
    Check numpy images and correct intensity range etc.
    The same for all movie formats.
       i,  r   r'   r   r   r   r   z&This array can not represent an image.zInvalid image type: )r(   r	   ndarrayr   r   r   float32float64r   r1   astypendimr   r+   r)   r]   )imagesimages2r   theMaxs       r   checkImagesr    s    G E Eb"*%% 	Ex28##r""""bj"*555%%%%#%%%%%B!"BrAvJ!"BrAvJ#IBryy223333YYrx((r"""w!||A8A;f,,$%MNNN - !!IJJJ3c$r((mmCDDD Nr   r'     r  rZ   c                 0   t                      }|d                    d          z  }|d                    d          z  }|t          |          z  }|d                    d          z  }|t                                          d|d         d|d                                                   z  }|t          d          t          |          z   z  }|t          |          z  }|                     |           |D ])}|                     |                                           *|                     d                    d                     | 	                                }| 
                    d           |                     t          |                     d	S )
z(Give the given file (as bytes) a header.Fr   WS0000r   r'   z  rD   N)r8   r   r:   rt   r   r   rL   writer|   tellseekrI   )	fptaglistnframes	framesizefpsversionr<   tagszes	            r   
build_filer    s_    
B#**W

B$++g

B)G

B&--
 
  B#%%
 
 IaL!Yq\
B
B
J
J
L
LLB)A,,3
''B*W

BHHRLLL     
 HHZw''((( ''))CGGAJJJHHZ__r   皙?Tc                    t          |          }t                      t          ddd          g}t          d          r<t	                    t	          |          k    rd D             nt          d          fd|D             t          t                              fdD             }d |D             }dz  }d}|D ]}	t          |	          }
|	j	        d	         |	j	        d         f}t          |
j        d
|          }t          d	|j        |dk              }|                    |
||g           t          ||                   D ]#}|                    t!                                 $|d	z  }|s"|                    t#          d                     t%          | d          }	 t'          |||||           n# t(          $ r  w xY w	 |                                 dS # |                                 w xY w)a  Write an swf-file from the specified images. If repeat is False,
    the movie is finished with a stop action. Duration may also
    be a list with durations for each frame (note that the duration
    for each frame is always an integer amount of the minimum duration.)

    Images should be a list consisting numpy arrays with values between
    0 and 255 for integer types, and between 0 and 1 for float types.

    r   r   c                     g | ]}|S rB   rB   .0ds     r   
<listcomp>zwrite_swf.<locals>.<listcomp>  s    ,,,a,,,r   z-len(duration) doesn't match amount of images.c                     g | ]}S rB   rB   )r  r   durations     r   r  zwrite_swf.<locals>.<listcomp>  s    ///H///r   c                 4    g | ]}t          |z            S rB   )round)r  r  minDurations     r   r  zwrite_swf.<locals>.<listcomp>  s%    777eAO$$777r   c                 H    g | ]}t          d t          |                     S )r'   )r   r*   r  s     r   r  zwrite_swf.<locals>.<listcomp>  s&    ---c!SVVnn---r   g      ?r'   r   )r   r   wb)r  r  r  N)r  r   r   hasattrr6   r+   r   minr   r   r   r   r   extendr9   r   r   r   openr  r   close)filenamer   r  repeatr  r  delaysr  r  r   bmr   shpor=   r  r!  s     `             @r   	write_swfr/    s?    &!!G !""$4Q1$=$=>G x## 0x==CLL((,,8,,,HHLMMM////w/// H&&K7777h777F--f---F 
C G  r]]hqk28A;'beVR((Aru7Q;777B|$$$vg'' 	+ 	+ANN<>>****1 ,{6**+++ 
h		B2w23GGGGG    	H 	








s   2G G- GG- -Hc                 :   t           j                            |           st          dt	          |           z             g }t          | d          }|                                }	 |dd                             dd          }|                                dk    rn_|                                dk    r(|d	d
         t          j
        |d
d	                   z   }nt          dt	          |           z             d
}t          |||dz            d          }d|dz  z   }|dz  }|dz  r|dz  }t          |          }||dz   z  }d}	 |dz  }|||dz            }	|	snt          |	          \  }
}}|st                              d           n^|
dv r-t!          ||dz   |
|          }||                    |           n |
dv rt                              d           n	 |
dk    rn||z  }|                                 n# |                                 w xY w|S )zRead all images from an SWF (shockwave flash) file. Returns a list
    of numpy arrays.

    Limitation: only read the PNG encoded images (not the JPG encoded ones).
    zFile not found: rbr   r   r   ignoreFWSCWSNr4   zNot a valid SWF file: r'   ri   rD   g       @Tr\   z%Invalid tag length, could not proceed)rh   r   )r\      #   Z   z&Ignoring JPEG image: cannot read JPEG.)ospathisfileIOErrorr)   r'  readr   upperr   r   rX   r*   r`   r   r   r   r   r(  )r)  r   r  r<   r!   r=   r   Lrectr   headTr   r_   r   s                 r   read_swfrA  /  sT    7>>(## :(3x==8999 F 
h		B	B81gnnWh//99;;%YY[[E!!BQB$/"QRR&111BB2S]]BCCC AAI**EAI19 	QJEE

	UQY 	qLG a!a%i=D  )..IAr2 FGGG H}} QUAr22>MM"%%%o%%GHHHH Avv GA=	B 	







 Ms   &FH Hr   )r4   )r'   r  rZ   r4   )r  T)%rA   r8  r   timeloggingnumpyr	   	getLoggerr>   r   r   rI   rL   r:   rS   rX   r`   rf   rl   rr   rt   r   r   r   r   r   r   r   r   r   r   r  r  r/  rA  writeSwfreadSwfrB   r   r   <module>rH     s>   > 
			        
	8	$	$G G G G G G G GT( ( (( ( (( ( (   ,     D   D  .  (> > > > > > > >H       
6 6 6 6 6
 6 6 6    :       z   &    #   4( ( ( ( (C ( ( (* * * * * * * *Z    Z   8v v v v v} v v vr, , ,l& & &T CD   :: : : :@M M Mb 
r   