DogLua - Lua filters for Project Dogwaffle:
 

Shift RGB

back

more Lua Scripts

 DogLua:   Overview - Downloading - Reference Guide - Sample Scripts - Lua Browser
  see also:  GUI Server - more SDK Info

 
the Shift_RGB filter.......

This Lua script uses the GUI server for user-selectable parameters.

You cam find the code shown to the right.

It is also available in a .lua file here:   shiftRGB.lua 

 

You can simply save this file to the folder where Dogwaffle's Lua script files are located on your system.















-- Shift RGB gui
-- This script lets you enter a value for each channel
-- R, G and B, and it will apply a horizontal shift
-- of the respective channels by the indicated number of pixels.
-- this can be useful to restore a bad image that shows a
-- red or blue shift or similar channel offset on all pixels
-- It can also create some cool ghosting effects
--
-- Note: each time you enter a value, it goes and applies the
-- new shift transform. Be sure to wait for its completion
-- before entering the next digit if you're entering an offset
-- of 2 or 3 digits or more, as it may otherwise miss the
-- input after the first if busy.

function shift_rgb(sr,sg,sb)

local x, y, r, g, b
for y = 0, height - 1 do
  for x = 0, width - 1 do
    r, n, n = get_rgb(x-sr, y)
    n, g, n = get_rgb(x-sg, y)
    n, n, b = get_rgb(x-sb, y)

    set_rgb(x, y, r, g, b)
  end
  progress(y / height)
end

end


-- ------------
--  Simple GUI
-- ------------

Dog_SaveUndo()

GUI_SetCaption("Shift r,g,b independantly")

h1 = GUI_AddControl("Number", "Red", 0)
h2 = GUI_AddControl("Number", "Green", 0)
h3 = GUI_AddControl("Number", "Blue", 0)

GUI_OpenPanel()


repeat
idx, retval, retstr = GUI_WaitOnEvent()


if (idx>-1) then

     sr =  GUI_GetSettings(h1)
     sg =  GUI_GetSettings(h2)
     sb =  GUI_GetSettings(h3)
     shift_rgb(sr,sg,sb)
     Dog_Refresh()
end

until idx < 0 --repeat until


GUI_ClosePanel()


if idx == -2 then
--Restore the image
Dog_RestoreUndo()
Dog_GetBuffer()
end