the
Gamma Filter.......
This Lua script uses the GUI server.
Use gamma for correcting images for different display devices.
|
--Gamma_GUI.lua
function DoGamma(gamma,a,b2)
local x,y,r,g,b
for y = 0, height - 1 do
for x = 0, width - 1 do
r, g, b = get_rgb(x, y)
r = a*(r^gamma)+b2
g= a*(g^gamma)+b2
b = a*(b^gamma)+b2
if r>1 then r=1 elseif r<0 then r=0 end
if g>1 then g=1 elseif g<0 then g=0 end
if b>1 then b=1 elseif b<0 then b=0 end
set_rgb(x, y, r, g, b)
end
progress(y / height)
end
progress(0) --reset
end
-- the main program.
Dog_SaveUndo()
local a,b,gamma
a=1.0
b=0.0
gamma=1.0
GUI_SetCaption("Gamma")
GUI_SetSpacing(18)
GUI_AddControl("Textlabel","Use gamma for correcting images for")
GUI_SetSpacing(22)
GUI_AddControl("Textlabel","different display devices.")
about = GUI_AddControl("button", "More...")
GUI_SetSpacing(30)
GUI_AddControl("Line")
h1 = GUI_AddControl("text", "Gamma")
GUI_SetSettings(h1,0,gamma)
h2 = GUI_AddControl("text", "A")
GUI_SetSettings(h2,0,a)
h3 = GUI_AddControl("text", "B")
GUI_SetSettings(h3,0,b)
h4 = GUI_AddControl("button", "Preview")
h5 = GUI_AddControl("check", "Apply to anim")
GUI_OpenPanel()
--event loop. Repeat until ok or cancel pressed (index of -1 or
-2)
repeat
idx, retval, retstr = GUI_WaitOnEvent()
dummy,gamma = GUI_GetSettings(h1)
dummy,a = GUI_GetSettings(h2)
dummy,b = GUI_GetSettings(h3)
if (idx==h4) then
DoGamma (gamma,a,b)
Dog_Refresh()
end
if (idx==about) then
Dog_MessageBox("Colors are between 0-1",
"gamma is generally between 0-2.",
"Formula: A*(channel^Gamma)+B")
end
until idx < 0 --repeat until
animate=GUI_GetSettings(h5)
GUI_ClosePanel()
--OK
if (idx==-1) then
if animate==0 then
DoGamma (gamma,a,b)
Dog_Refresh()
end
--apply to frames
if animate==1 then
Dog_RestoreUndo()
Dog_GetBuffer()
frames=Dog_GetTotalFrames()
currentframe=Dog_GetCurrentFrame()
for n=0,frames-1 do
Dog_GotoFrame(n)
DoGamma (gamma,a,b)
Dog_Refresh()
end
Dog_GotoFrame(currentframe)
end
end -- end ok
--Cancel
if idx == -2 then
--Restore the image
Dog_RestoreUndo()
Dog_GetBuffer()
end
|
|