grafX2/share/grafx2/scripts/bru_db_GrayscaleDesat.lua
Yves Rizoud 3ca5322379 Reorganized source code and directory tree.
git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1375 416bcca6-2ee7-4201-b75f-2eb2f807beb1
2010-03-05 02:53:19 +00:00

30 lines
812 B
Lua

--BRUSH Remap: Grayscale (desaturate)
--by Richard Fhager
--http://hem.fyristorg.com/dawnbringer/
-- This script was adopted from Evalion, a Javascript codecrafting/imageprocessing project
--http://goto.glocalnet.net/richard_fhager/evalion/evalion.html
percent = 100
--
function desaturate(percent,r,g,b) -- V1.0 by Richard Fhager
p = percent / 100
a = (math.min(math.max(r,g,b),255) + math.max(math.min(r,g,b),0)) * 0.5 * p
r = math.min(math.max(r + (a-r*p),0),255) -- Capping may not be needed if mathcolor/setcolor is updated
g = math.min(math.max(g + (a-g*p),0),255)
b = math.min(math.max(b + (a-b*p),0),255)
return r,g,b
end
--
w, h = getbrushsize()
for x = 0, w - 1, 1 do
for y = 0, h - 1, 1 do
putbrushpixel(x, y, matchcolor(desaturate(percent,getcolor(getbrushpixel(x,y)))));
end
end