-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhsv.lua
87 lines (77 loc) · 1.75 KB
/
hsv.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
-- by Ningow
function init()
setName("HSV")
setDesc("Adjust HSV values")
setSize(120,18+18+18+24+64+8+8+7+4)
addOutput(24+32)
addInput("Texture",24+64+8+8)
addInputParameter("H","Hue",18+24+64+8+8,0,0,255)
addInputParameter("S","Saturation",18+18+24+64+8+8,127,0,255)
addInputParameter("V","Value",18+18+18+24+64+8+8,127,0,255)
end
-- Ugly way to use channels
function getChroma(R, G, B)
m = math.min(math.min(R, G), B)
M = math.max(math.max(R, G), B)
return (M-m)
end
function rgbM(n, H, S, V)
k = math.fmod((n + (H*6)), 6)
out = V - (V*S*math.max(math.min(k,4-k,1),0))
return out
end
function getHue(R, G, B)
m = math.min(math.min(R, G), B)
M = math.max(math.max(R, G), B)
if (m == M) then
return 0
end
if (M == R) then
hue = (G-B)/(M-m)
end
if (M == G) then
hue = 2+(B-R)/(M-m)
end
if (M == B) then
hue = 4+(R-G)/(M-m)
end
hue = hue / 6
if (hue < 0) then
hue = hue + 1
end
if (hue > 1) then
hue = hue - 1
end
return hue
end
function apply()
x = 0
y = 0
tileSize = getTileSize()
for i=0, tileSize*tileSize-1 do
x = i%tileSize
y = math.floor(i/tileSize)
R, G, B = getValue(0,x,y,1) -- Scan Texture
hmod = getValue(1,x,y,255)
hnew = getHue(R, G, B) + hmod
if (hnew > 1) then
hnew = hnew - 1
end
if (hnew < 0) then
hnew = hnew + 1
end
vmod = (getValue(3,x,y,255)*2) - 1
vnew = math.min((math.max((math.max( (math.max(R, G)) , B) + vmod), 0)), 1)
smod = (getValue(2,x,y,255)*2) - 1
if(vnew == 0) then
snew = (getChroma(R, G, B)) + smod
else
snew = (getChroma(R, G, B) / vnew) + smod
end
--convert to rgb
outr = rgbM(5, hnew, snew, vnew)
outg = rgbM(3, hnew, snew, vnew)
outb = rgbM(1, hnew, snew, vnew)
setPixel(0,x,y,outr,outg,outb)
end
end