< Previous | Contents | Next >

Example

The following example implements a very simple Gain using MultiProcessPixels. Note that this is not the recommended way to perform a Gain - see the Image:Gain function for a much faster approach.


FuRegisterClass("MultiPxl", CT_Tool, { REGS_Category = "Fuses\\Examples", REGS_OpIconString = "MltP",

REGS_OpDescription = "Multi threaded pixel operations Fuse",

})


function Create()

InGain = self:AddInput("Gain", "Gain", { LINKID_DataType = "Number", INPID_InputControl = "SliderControl", INP_Default = 2.0,

image

})


InImage1 = self:AddInput("Input 1", "Input1", { LINKID_DataType = "Image",

LINK_Main = 1,

})


InImage2 = self:AddInput("Input 2", "Input2", { LINKID_DataType = "Image",

LINK_Main = 2,

})



end

OutImage = self:AddOutput("Output", "Output", { LINKID_DataType = "Image",

LINK_Main = 1,

})


-- pixel function

local func = function (x, y, p1, p2) p1.R = gain * (p1.R - p2.R) p1.G = p1.G - p2.G - bright p1.B = var_C * (p1.B - p2.B) p1.A = p1.A - p2.A

return p1

end


function Process(req)

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


local ingain = InGain:GetValue(req).Value local out = Image({IMG_Like = img1})


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

if func and (img1.Width == img2.Width) and (img1.Height == img2.

Height) then


out:MultiProcessPixels(nil, {gain = ingain , bright=-0.3, var_C=1.5},

0,0, img1.Width, img1.Height, img1, img2, func)


end

end

OutImage:Set(req, out)