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

;;

;;  FILTER EXAMPLE

;;

;;  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 shows how real time effects can be applied

;;  to images using gfx:filter-image, even when these images are from a movie.

;;

;;  A complete list of filters and filter parameters can

;;  be found in apples "Core Image Programming Guide".

;;

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


(define canvas (gfx:make-canvas))

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

(define torus-params '(("inputIntensity" . 5)))

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

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


(define loop

   (lambda (time movie-time)

      (let* ((image (gfx:get-movie-frame movie movie-time *gfx:ciimage*))

             (filtered-image (gfx:filter-image image "CIEdges" torus-params)))

         (gfx:draw-image time canvas filtered-image 1.0 '(75 150))

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

         (if (> movie-time lgth)

             (callback (- time 4000) 'loop time 0.0)

             (callback (- time 4000) 'loop time (+ movie-time 0.1))))))


(loop (now) 0.0)