This filter uses the GUIserver
functions to display two color boxes. You can select a color from
either color boxes. When you're done the filter immediately goes to
work. Click OK to keep the final result or Cancel to return to the
image before entering the plugin.
This filter can also be used to simulate Sepia mode.
|
--Duotone.lua
function DoDuo (gr1,gr2)
local r,g,b,r2,g2,b2,r3,g3,b3
local x,y, y2,y3,av,av2
--basically map the image to a gradient created from the 2 colors.
r2,g2,b2 = decimal2rgb(gr1)
r3,g3,b3 = decimal2rgb(gr2)
for y = 0, height - 1 do
for x = 0, width - 1 do
r, g, b = get_rgb(x, y)
av=(r+g+b)/3
av2=1-av
r=(r2*av)+(r3*av2)
g=(g2*av)+(g3*av2)
b=(b2*av)+(b3*av2)
set_rgb(x, y, r, g, b)
end
progress(y2)
end
progress(0) -- reset the progress bar after usage.
Dog_Refresh()
end
-----------------------------------------------------------------
-- The main part of the program (GUI)
-----------------------------------------------------------------
-- in case we 'Cancel',...
Dog_SaveUndo()
GUI_SetCaption("Duotone filter")
-- create two colorboxes
dummy = GUI_AddControl("TextLabel", "Color 1")
h1 = GUI_AddControl("Colorbox", "", hex("44AAFF"), 0, 0)
dummy = GUI_AddControl("TextLabel", "Color 2")
h2 = GUI_AddControl("Colorbox", "", hex("224455") ,0, 0)
GUI_OpenPanel()
-- this is our main event loop. -------------------------
repeat
idx, retval, retstr = GUI_WaitOnEvent()
g1,dummy=GUI_GetSettings(h1)
g2,dummy=GUI_GetSettings(h2)
if idx >=0 then
DoDuo(g1,g2)
end
until idx < 0
-- end of main loop -------------------------------------
-- if we pressed 'Cancel' restore original and show it
if idx == -2 then
Dog_RestoreUndo()
Dog_GetBuffer()
Dog_Refresh()
end
GUI_ClosePanel()
|
|