;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;

;;  MOVIE PLAYS BACK AND FORTH

;;

;;  Download a medium sized quicktime trailer from apple

;;  Load it into quicktime-pro and export it at its current

;;  size but in TIFF format.  Use that file in gfx:load-movie.

;; 

;;  Impromptu does not currently support any format

;;  other than TIFF

;;

;;  This example plays a movie forwards and backwards

;;  at the same time. frames from the head and tail of the

;;  movie are composited on each other using gfx:image2image

;;  with a 50% transperency and then displayed.

;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



(define canvas (gfx:make-canvas))


(define movie (gfx:load-movie "/tmp/myfilm.mov"))

(define mlgth (- (gfx:get-movie-duration movie) 1.0))

(define frame-length (* *second* 0.1))


(define loop

   (lambda (time mtime)

      (let ((pic1 (gfx:get-movie-frame movie mtime))

            (pic2 (gfx:get-movie-frame movie (- mlgth mtime))))

         ; composit pic2 on pict1 with a 50% transparency

         (gfx:image2image pic2 pic1 0.5 '(0 0))

         (gfx:draw-image time canvas pic1 1.0 '(75 175))

         (set! time (+ time frame-length))

         (if (< mtime mlgth)

             (callback (- time 1000) 'loop time (+ mtime 0.1))))))


(loop (now) 0.0)