Eyeon:Script/Reference/Applications/Fusion Expressions/Examples/Example 1

From VFXPedia

Jump to: navigation, search

Lesson 1 -- Resizing

With some major revisions having been made to eyeonScript since version 4, new functions previously only available to the internal mechanisms of Fusion have been exposed to the user. One of the more interesting features is the ability to resize a tool's input image. I had a problem the other day where I was masking one image by another image. Image 1 was a 640 X 480 targa, and Image 2 was a 2048X1556 anamorphic Cineon. I wanted to use the targa's luminance values as a mask for a brightness contrast tool, however the mask would be smaller than the full frame.

I could correct this by having a Resize tool in the composition right before the Brightness Contrast, but that's not very dynamic. What if, for example, I wanted to replace the loader with a temporary proxy file that was at a lower resolution? Alternatively, if it was needed in a macro of some sort? We can instead put this in the FrameRenderScript area of the tool.

-- first, check to see if the Resize function has been initialized.
-- will only be initialized if there's an associated mask image.
-- the way InTool scripts work is that any of the tool's inputs can be referred to
-- without the 
-- use of a tool object beforehand.
-- so for example, we check to see if the EffectMask has the resize function by simply 
-- typing this:
 
if EffectMask.Resize then
 
        -- If there's an input, we use that to determine the size to which we will 
        -- resize the effect mask.
 
        if Input then
               -- set up the rszWidth and rszHeight variables to equal that of the
               -- input's width and height, syntax below:
 
               rszHeight = Input.Height
               rszWidth = Input.Width
        else
               -- if there's no input, it's a creator, meaning that we need to 
               -- base this on the size of the Width or Height slider.
               -- if it has such an input...
 
               if Width then
                     rszWidth = Width
                     rszHeight = Height
               else
                     -- if it doesn't, then it's likely a loader
                     -- you could mask a loader with this method if you connected it 
                     -- to the GarbageMatte input of a matte control after the 
                     -- loader,and made the adjustment accordingly
                     -- to the script.
 
                     print("Cannot Auto Resize Effect Mask")
               end
        end
 
        -- if the variable was initialized...
 
        if rszWidth then
               -- Set the EffectMask according to the rszWidth/rszHeight variables
               -- using the Resize function..
 
               EffectMask = EffectMask:Resize(nil, { RSZ_Width = rszWidth, RSZ_Height = rszHeight, RSZ_Filter = "CatmulRom"})
        end
end


As you can see in the Resize function, we're passing an image as the first argument (set to nil for all InTool script purposes), and then a table of properties for the Resize operation. RSZ_WIDTH and RSZ_Height referring to the width and height to resize the image to, and RSZ_Filter being the desired filter method passed as a string.

Getting a user to input this much code into a tool isn't user friendly, so what we'll do is write a tool script.

-- turn the function into a string literal so we can easily pass it into the FrameRenderScript input (a string value)
 
functionToPass = [[
 
-- first, check to see if the Resize function has been initialized.
-- will only be initialized if there's an associated mask image.
 
-- the way intool scripts work is that any of the tool's inputs can be referred to without the 
-- use of a tool object beforehand.
-- so for example, we check to see if the EffectMask has the resize function by simply typing this:
 
if EffectMask.Resize then
        -- If there's an input, we use that to determine the size to which we will resize the effect mask.
 
        if Input then
               -- set up the rszWidth and rszHeight variables to equal that of the
               -- input's width and height, syntax below:
 
               rszHeight = Input.Height
               rszWidth = Input.Width
        else
               -- if there's no input, it's a creator, meaning that we need to 
               -- base this on the size of the Width or Height slider.
               -- if it has such an input...
 
               if Width then
                     rszWidth = Width
                     rszHeight= Height
               else
                     -- if it doesn't, then it's likely a loader
                     -- you could mask a loader with this method if you connected it 
                     -- to the GarbageMatte input, and made the adjustment accordingly.
 
                     print("Cannot Auto Resize Effect Mask")
               end
        end
 
        -- if the variable was initialized...
 
        if rszWidth then
               -- Set the EffectMask according to the rszWidth/rszHeight variables
               -- using the Resize function..
 
               EffectMask = EffectMask:Resize(nil, { RSZ_Width = rszWidth, RSZ_Height = rszHeight, RSZ_Filter = "CatmulRom"})
        end
end
]]
 
if tool then
        tool.FrameRenderScript = tool.FrameRenderScript.."\n\n\n -- FUNCTION GENERATED BY AUTO RESIZE EFFECT MASK SCRIPT \n\n"..functionToPass
else
        print("ERROR: This script is a tool script.")
end


And there we go. We could do things like add options for the various inputs they could run this script on (Garbage Mattes, Glow Masks, etc.) and for the filter type, but the script is complete for now.


Tips for Example 1 (edit)

EyeonTips:Script/Reference/Applications/Fusion Expressions/Examples/Example 1