File: //opt/resolve/Developer/Fusion Fuse/Example 1 Bright Contrast.fuse
--[[--
Example Fuse 1
This uses internal Fusion Color and Corlor Matrix operations to change the color of images.
Copyright (c) 1988-2020, BMD, by Steve Roberts
This Fuse Demos built in image processing functions in Fusion.
This Uses Fusion internal image processing operations:
Color Matrix is similar to 3D matrix operation and applied to the color of an image.
This will apply Brightness, Contrast and Saturation to images
--]]--
--******************************************************************************************************
-- This Registers the Fuse into Fusion, gives its Name, and Menu location. Location of Help. Can Fuse be edited.
FuRegisterClass("ExampleBrightContrast", CT_Tool, {
REGS_Name = "Ex1 Bright Contrast",
REGS_Category = "Fuses\\Examples",
REGS_OpIconString = "E1BC",
REGS_OpDescription = "Example using internal Color Matrix image processing functions ",
REGS_HelpTopic = "Example Location of Help", --This can be a URL
REGS_URL = "www.blackmagicdesign.com",
--REGS_IconID = "Icons.Tools.Icons.Example",-- This can be Inline as an array of Values
REG_OpNoMask = false,
REG_NoBlendCtrls = false,
REG_NoObjMatCtrls = false,
REG_NoMotionBlurCtrls = true,
REG_Fuse_NoEdit = false,
REG_Fuse_NoReload = false,
REG_Version = 1,
}) -- End of RegisterClass
--****************************************************************************************************
--Create will define all the controls, like sliders, check boxes, onscreen crosshairs etc, that will show in Inspector Tool control area
function Create()
InBright = self:AddInput("Brightness", "Brightness", {
LINKID_DataType = "Number",
INPID_InputControl = "SliderControl",
INP_MaxScale = 1.0,
INP_MinScale = -1.0,
INP_Default = 0.0,
})
InContrast = self:AddInput("Contrast", "Contrast", {
LINKID_DataType = "Number",
INPID_InputControl = "SliderControl",
INP_MaxScale = 1.0,
INP_MinScale = -1.0,
INP_Default = 0.0,
})
InSaturation = self:AddInput("Saturation", "Saturation", {
LINKID_DataType = "Number",
INPID_InputControl = "SliderControl",
INP_MaxScale = 5.0,
INP_MinScale = 0.0,
INP_Default = 1.0,
ICD_Center = 1,
})
InImage = self:AddInput("Input", "Input", {
LINKID_DataType = "Image",
LINK_Main = 1,
})
OutImage = self:AddOutput("Output", "Output", {
LINKID_DataType = "Image",
LINK_Main = 1,
})
end -- end of Create()
--*************************************************************************************************************
-- The Process section is the main section where the image processing rendering occurs
function Process(req)
local img = InImage:GetValue(req)
local bright = InBright:GetValue(req).Value
local contrast = InContrast:GetValue(req).Value + 1
local sat = InSaturation:GetValue(req).Value
local r = 0
local g = 0
local b = 0
local a = 0
if bright == 0 and sat == 1.0 and contrast == 1.0 then
-- no change, go ahead and bypass this tool
OutImage:Set(req, img)
else
-- create a color matrix
local m = ColorMatrixFull()
--Apply Brightness to the matrix via Offset function
r = bright
g = bright
b = bright
m:Offset(r, g, b, a)
--Apply Contrast by offsetting the 0.5 color midpoint to 0.0, scaling around that, and offsetting back again
r = contrast
g = contrast
b = contrast
a = 1
m:Offset(-0.5, -0.5, -0.5, -0.5)
m:Scale(r, g, b, a)
m:Offset(0.5, 0.5, 0.5, 0.5)
--Apply Saturation by converting the Color Matrix to YUV and Scaling the Chroma UV channels
m:RGBtoYUV()
m:Scale(1, sat, sat, 1) -- scale U and V chroma channels, leave Y luma channel alone
m:YUVtoRGB()
--Apply the Color Matrix to the image img into the output image out
out = img:ApplyMatrixOf(m, {})
--Output the image
OutImage:Set(req, out)
end
end