Monday, August 10, 2009

How to overlay an image

The style example S10000_ImageOverlay shows how to overlay a simple image atop your whole muvee by modifying the definition of muvee-global-effect. The relevant part of the code is close to trivial and is reproduced here -

(define spider
(effect "PictureQuad" ()
(param "Path" (resource "spider.png"))))

(define muvee-global-effect
(layers (A)
A
spider))

With the muvee-global-effect defined as above, the muvees you create will have a giant spider spanning the whole screen ... just for kicks :P

Here are sample 4:3 and 16:9 videos of what you'll get with the above code -

4:3 version


16:9 version


Notice that the spider is presented in the correct aspect ratio in both cases even though we didn't say anything about the scaling to be performed in each case. This is because the coordinate system of the scene is setup to preserve the aspect ratio of entities placed in the scene. For a 4:3 muvee, the x coordinate spans [-4/3,4/3] and the y coordinate spans [-1,1]. Similarly for the 16:9 muvee, the x coordinate spans [-16/9,16/9] and the y coordinate spans [-1,1]. The spider image is 150x150 - i.e. it has 1:1 aspect ratio - which fits within the unit square.

Selecting different images based on output aspect ratio

Suppose you have two images frame-4by3.png and frame-16by9.png, you can select one of them based on the aspect ratio for which your muvee is being constructed ... like so -

(define ar-suffix
(if (< (fabs (- render-aspect-ratio 4/3)) 0.01)
"-4by3"
"-16by9"))

(define spider
(effect "PictureQuad" ()
(param "Path" (resource (format "frame" ar-suffix ".png")))))

The render-aspect-ratio symbol gives you the aspect ratio for which the muvee is being constructed. We use its value to pick the suffix string we need to use with "frame" in order to select the correct file. If you consistently use "-4by3" and "-16by9" as a convention, then the above suffix code can be reused to select more than one overlay image based on the render aspect ratio within your style.

Modifying an existing muvee-global-effect

If you're looking at a complex muvee-global-effect expression like
(define muvee-global-effect ....)
, you can mechanically add the overlay by first renaming the original definition to, say, muvee-global-effect-original and then adding the following new definition after the original one.

(define muvee-global-effect-original ....) ; Renamed definition.

(define muvee-global-effect
(effect-stack
(layers (A)
A
spider)
muvee-global-effect-original))

No comments:

Post a Comment