#NEWLINE# def decode_animation( self , file , filename ) : #NEWLINE# #INDENT# quicktime . EnterMovies ( ) #NEWLINE# data_ref = self . _get_data_ref ( file , filename ) #NEWLINE# if ( not data_ref ) : #NEWLINE# #INDENT# raise ImageDecodeException ( ( filename or file ) ) #NEWLINE# #UNINDENT# movie = c_void_p ( ) #NEWLINE# id = c_short ( ) #NEWLINE# result = quicktime . NewMovieFromDataRef ( byref ( movie ) , newMovieActive , 0 , data_ref , PointerDataHandlerSubType ) #NEWLINE# if ( not movie ) : #NEWLINE# #INDENT# raise ImageDecodeException ( ( filename or file ) ) #NEWLINE# #UNINDENT# quicktime . GoToBeginningOfMovie ( movie ) #NEWLINE# time_scale = float ( quicktime . GetMovieTimeScale ( movie ) ) #NEWLINE# ( format , qtformat ) = self . _get_formats ( ) #NEWLINE# rect = Rect ( ) #NEWLINE# quicktime . GetMovieBox ( time , byref ( rect ) ) #NEWLINE# width = rect . right #NEWLINE# height = rect . bottom #NEWLINE# pitch = ( len ( format ) * width ) #NEWLINE# buffer = ( c_byte * ( ( width * height ) * len ( format ) ) ) ( ) #NEWLINE# world = GWorldPtr ( ) #NEWLINE# quicktime . QTNewGWorldFromPtr ( byref ( world ) , qtformat , byref ( rect ) , c_void_p ( ) , c_void_p ( ) , 0 , buffer , ( len ( format ) * width ) ) #NEWLINE# quicktime . SetGWorld ( world , 0 ) #NEWLINE# quicktime . SetMovieGWorld ( movie , world , 0 ) #NEWLINE# visual = quicktime . GetMovieIndTrackType ( movie , 1 , VisualMediaCharacteristic , movieTrackCharacteristic ) #NEWLINE# if ( not visual ) : #NEWLINE# #INDENT# raise ImageDecodeException ( 'No video track' ) #NEWLINE# #UNINDENT# time = 0 #NEWLINE# interesting_time = c_int ( ) #NEWLINE# quicktime . GetTrackNextInterestingTime ( visual , nextTimeMediaSample , time , 1 , byref ( interesting_time ) , None ) #NEWLINE# duration = ( interesting_time . value / time_scale ) #NEWLINE# frames = [ ] #NEWLINE# while ( time >= 0 ) : #NEWLINE# #INDENT# result = quicktime . GetMoviesError ( ) #NEWLINE# if ( result == noErr ) : #NEWLINE# #INDENT# result = quicktime . UpdateMovie ( movie ) #NEWLINE# #UNINDENT# if ( result == noErr ) : #NEWLINE# #INDENT# quicktime . MoviesTask ( movie , 0 ) #NEWLINE# result = quicktime . GetMoviesError ( ) #NEWLINE# #UNINDENT# _oscheck ( result ) #NEWLINE# buffer_copy = ( c_byte * len ( buffer ) ) ( ) #NEWLINE# memmove ( buffer_copy , buffer , len ( buffer ) ) #NEWLINE# image = ImageData ( width , height , format , buffer_copy , ( - pitch ) ) #NEWLINE# frames . append ( AnimationFrame ( image , duration ) ) #NEWLINE# interesting_time = c_int ( ) #NEWLINE# duration = c_int ( ) #NEWLINE# quicktime . GetTrackNextInterestingTime ( visual , nextTimeMediaSample , time , 1 , byref ( interesting_time ) , byref ( duration ) ) #NEWLINE# quicktime . SetMovieTimeValue ( movie , interesting_time ) #NEWLINE# time = interesting_time . value #NEWLINE# duration = ( duration . value / time_scale ) #NEWLINE# if ( duration <= 0.01 ) : #NEWLINE# #INDENT# duration = 0.1 #NEWLINE# #UNINDENT# #UNINDENT# quicktime . DisposeMovie ( movie ) #NEWLINE# carbon . DisposeHandle ( data_ref ) #NEWLINE# quicktime . ExitMovies ( ) #NEWLINE# return Animation ( frames )