-- Convert a Big-Endian hexadecimal value into a Little-Endian one
local function reverseBytes(number)
local hexValue = string.format('%X', number) -- Convert integer to hexadecimal string
if #hexValue % 2 ~= 0 then hexValue = '0' .. hexValue end -- Ensure the length is even
if #hexValue <3 then hexValue = '00' .. hexValue end -- Ensure correct # of bytes
if #hexValue <5 then hexValue = '00' .. hexValue end
local reversedHex = ''
for i = #hexValue, 1, -2 do
reversedHex = reversedHex .. string.sub(hexValue, i-1, i)
end
return tonumber("0x"..reversedHex)
end
-- Update the colours of a 1-step gradiant source
-- Example: updateGradiantColours("My Gradiant", 0xFDCC00, 0xEF0031)
local function updateGradiantColours(sourceName, fromColour, toColour)
local newFromColour = 0xFF000000 + reverseBytes(fromColour)
local newToColour = 0xFF000000 + reverseBytes(toColour)
local gradientSource = obs.obs_get_source_by_name(sourceName)
local settings = obs.obs_data_create()
-- '_1' is incremented for each gradiant step; Eg. 2-step gradiant has to_color_1 and to_color_2
obs.obs_data_set_int(settings, "from_color", tonumber(newFromColour))
obs.obs_data_set_int(settings, "to_color_1", tonumber(newToColour))
obs.obs_source_update(gradientSource, settings)
obs.obs_data_release(settings)
obs.obs_source_release(gradientSource)
end