< Previous | Contents | Next >

Example

The following example Fuse takes two image inputs, creates a new image with exactly the same attributes as the first Image input, then adds the two together.


function Process(req)

local img1 = InImage1:GetValue(req) local img2 = InImage2:GetValue(req)


local out = nil -- fail if we don’t meet below conditions


-- Must have a valid operation function, and images must be same dimensions

if (img1.Width == img2.Width) and (img1.Height == img2.Height) then out = Image({IMG_Like = img1})

out:ProcessPixels(0,0, img1.Width, img1.Height, img1, img2,

func)

end

OutImage:Set(req, out)

end


The following example creates an image from scratch using the full range of attributes for an Image object.


function Process(req)

local realwidth = Width; local realheight = Height;


-- We’ll handle proxy ourselves Width = Width / Scale

Height = Height / Scale Scale = 1


local imgattrs = {

IMG_Document = self.Comp,

{ IMG_Channel = "Red", },

{ IMG_Channel = "Green", },

{ IMG_Channel = "Blue", },

{ IMG_Channel = "Alpha", }, IMG_Width = Width, IMG_Height = Height, IMG_XScale = XAspect, IMG_YScale = YAspect,

IMAT_OriginalWidth = realwidth, IMAT_OriginalHeight = realheight, IMG_Quality = not req:IsQuick(),

IMG_MotionBlurQuality = not req:IsNoMotionBlur(),

}

if not req:IsStampOnly() then imgattrs.IMG_ProxyScale = 1

end


if SourceDepth ~= 0 then imgattrs.IMG_Depth = SourceDepth

end

local img = Image(imgattrs) --Image Creation based on Attributes local random = math.random

local p = Pixel({A=1})


for y=0,Height-1 do

if self.Status ~= "OK" then break end


for x=0,Width-1 do

p.R = random()

p.G = random()

p.B = random() img:SetPixel(x,y, p)

end

end

OutImage:Set(req, img)

end