-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathTetrahedral Interpolation HSV.fuse
471 lines (406 loc) · 13.8 KB
/
Tetrahedral Interpolation HSV.fuse
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
--[[--
----------------------------------------------------------------------
MIT License
Copyright (c) 2020 calvinsilly
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
----------------------------------------------------------------------
--]]--
FuRegisterClass("TetrahedralInterpolationHSV", CT_Tool, {
REGS_Name = "Tetrahedral Interpolation HSV",
REGS_Category = "Color",
REGS_OpIconStrinS = "TIH",
REGS_OpDescription = "",
REGS_Company = "Ember Light",
REG_Fuse_NoEdit = false,
REG_Fuse_NoReload = false,
REG_SupportsDoD = false,
})
function Create()
Info = self:AddInput("Red = Hue\nGreen = Saturation\nBlue = Value", "Info", {
LINKID_DataType = "Text",
INPID_InputControl = "LabelControl",
INP_External = false,
INP_Passive = true,
LBLC_MultiLine = true,
})
InfoText = self:AddInput(" ", "BlackPoint", {
INP_MinScale = -1,
INP_MaxScale = 1,
INP_Default = 0,
INPID_InputControl = "ColorControl",
CLRC_ColorSpace = 0,
LINKID_DataType = "Number",
IC_ControlID = 3,
IC_ControlGroup = 9,
})
--BLACK
self:BeginControlNest("Black Point", "BLACK", true, {})
InBl = self:AddInput(" ", "BlackPoint", {
INP_MinScale = -1,
INP_MaxScale = 1,
INP_Default = 0,
INPID_InputControl = "ColorControl",
CLRC_ColorSpace = 0,
LINKID_DataType = "Number",
IC_ControlID = 3,
IC_ControlGroup = 9,
})
self:EndControlNest()
--WHITE
self:BeginControlNest("White Point", "WHITE", true, {})
InW = self:AddInput(" ", "WhitePoint", {
INP_MinScale = -1,
INP_MaxScale = 1,
INP_Default = 1,
INPID_InputControl = "ColorControl",
CLRC_ColorSpace = 0,
LINKID_DataType = "Number",
IC_ControlID = 3,
IC_ControlGroup = 8,
})
self:EndControlNest()
--RED
self:BeginControlNest("Red", "RED", true, {})
InRH = self:AddInput(" ", "RH", {
INP_MinScale = -1,
INP_MaxScale = 1,
INP_Default = 0,
INPID_InputControl = "ColorControl",
CLRC_ColorSpace = 0,
LINKID_DataType = "Number",
IC_ControlID = 0,
IC_ControlGroup = 2,
})
InRS = self:AddInput("RS", "RS", {
INP_MinScale = -1,
INP_MaxScale = 1,
INP_Default = 0,
INPID_InputControl = "ColorControl",
CLRC_ColorSpace = 0,
LINKID_DataType = "Number",
IC_ControlID = 1,
IC_ControlGroup = 2,
})
InRV = self:AddInput("RV", "RV", {
INP_MinScale = -1,
INP_MaxScale = 1,
INP_Default = 0,
INPID_InputControl = "ColorControl",
CLRC_ColorSpace = 0,
LINKID_DataType = "Number",
IC_ControlID = 2,
IC_ControlGroup = 2,
})
self:EndControlNest()
--Green
self:BeginControlNest("Green", "GREEN", true, {})
InGH = self:AddInput(" ", "GH", {
INP_MinScale = -1,
INP_MaxScale = 1,
INP_Default = 0,
INPID_InputControl = "ColorControl",
CLRC_ColorSpace = 0,
LINKID_DataType = "Number",
IC_ControlID = 0,
IC_ControlGroup = 3,
})
InGS = self:AddInput("GS", "GS", {
INP_MinScale = -1,
INP_MaxScale = 1,
INP_Default = 0,
INPID_InputControl = "ColorControl",
CLRC_ColorSpace = 0,
LINKID_DataType = "Number",
IC_ControlID = 1,
IC_ControlGroup = 3,
})
InGV = self:AddInput("GV", "GV", {
INP_MinScale = -1,
INP_MaxScale = 1,
INP_Default = 0,
INPID_InputControl = "ColorControl",
CLRC_ColorSpace = 0,
LINKID_DataType = "Number",
IC_ControlID = 2,
IC_ControlGroup = 3,
})
self:EndControlNest()
--Blue
self:BeginControlNest("Blue", "BLUE", true, {})
InBH = self:AddInput(" ", "BH", {
INP_MinScale = -1,
INP_MaxScale = 1,
INP_Default = 0,
INPID_InputControl = "ColorControl",
CLRC_ColorSpace = 0,
LINKID_DataType = "Number",
IC_ControlID = 0,
IC_ControlGroup = 4,
})
InBS = self:AddInput("BS", "BS", {
INP_MinScale = -1,
INP_MaxScale = 1,
INP_Default = 0,
INPID_InputControl = "ColorControl",
CLRC_ColorSpace = 0,
LINKID_DataType = "Number",
IC_ControlID = 1,
IC_ControlGroup = 4,
})
InBV = self:AddInput("BV", "BV", {
INP_MinScale = -1,
INP_MaxScale = 1,
INP_Default = 0,
INPID_InputControl = "ColorControl",
CLRC_ColorSpace = 0,
LINKID_DataType = "Number",
IC_ControlID = 2,
IC_ControlGroup = 4,
})
self:EndControlNest()
--Cyan
self:BeginControlNest("Cyan", "CYAN", true, {})
InCH = self:AddInput(" ", "CH", {
INP_MinScale = -1,
INP_MaxScale = 1,
INP_Default = 0,
INPID_InputControl = "ColorControl",
CLRC_ColorSpace = 0,
LINKID_DataType = "Number",
IC_ControlID = 0,
IC_ControlGroup = 5,
})
InCS = self:AddInput("CS", "CS", {
INP_MinScale = -1,
INP_MaxScale = 1,
INP_Default = 0,
INPID_InputControl = "ColorControl",
CLRC_ColorSpace = 0,
LINKID_DataType = "Number",
IC_ControlID = 1,
IC_ControlGroup = 5,
})
InCV = self:AddInput("CV", "CV", {
INP_MinScale = -1,
INP_MaxScale = 1,
INP_Default = 0,
INPID_InputControl = "ColorControl",
CLRC_ColorSpace = 0,
LINKID_DataType = "Number",
IC_ControlID = 2,
IC_ControlGroup = 5,
})
self:EndControlNest()
--Magenta
self:BeginControlNest("Magenta", "MAGENTA", true, {})
InMH = self:AddInput(" ", "MH", {
INP_MinScale = -1,
INP_MaxScale = 1,
INP_Default = 0,
INPID_InputControl = "ColorControl",
CLRC_ColorSpace = 0,
LINKID_DataType = "Number",
IC_ControlID = 0,
IC_ControlGroup = 6,
})
InMS = self:AddInput("MS", "MS", {
INP_MinScale = -1,
INP_MaxScale = 1,
INP_Default = 0,
INPID_InputControl = "ColorControl",
CLRC_ColorSpace = 0,
LINKID_DataType = "Number",
IC_ControlID = 1,
IC_ControlGroup = 6,
})
InMV = self:AddInput("MV", "MV", {
INP_MinScale = -1,
INP_MaxScale = 1,
INP_Default = 0,
INPID_InputControl = "ColorControl",
CLRC_ColorSpace = 0,
LINKID_DataType = "Number",
IC_ControlID = 2,
IC_ControlGroup = 6,
})
self:EndControlNest()
--Yellow
self:BeginControlNest("Yellow", "YELLOW", true, {})
InYH = self:AddInput(" ", "YH", {
INP_MinScale = -1,
INP_MaxScale = 1,
INP_Default = 0,
INPID_InputControl = "ColorControl",
CLRC_ColorSpace = 0,
LINKID_DataType = "Number",
IC_ControlID = 0,
IC_ControlGroup = 7,
})
InYS = self:AddInput("YS", "YS", {
INP_MinScale = -1,
INP_MaxScale = 1,
INP_Default = 0,
INPID_InputControl = "ColorControl",
CLRC_ColorSpace = 0,
LINKID_DataType = "Number",
IC_ControlID = 1,
IC_ControlGroup = 7,
})
InYV = self:AddInput("YV", "YV", {
INP_MinScale = -1,
INP_MaxScale = 1,
INP_Default = 0,
INPID_InputControl = "ColorControl",
CLRC_ColorSpace = 0,
LINKID_DataType = "Number",
IC_ControlID = 2,
IC_ControlGroup = 7,
})
self:EndControlNest()
InImage = self:AddInput("Input", "Input", {
LINKID_DataType = "Image",
LINK_Main = 1,
})
OutImage = self:AddOutput("Output", "Output", {
LINKID_DataType = "Image",
LINK_Main = 1,
})
end
function Process(req)
local src = InImage:GetValue(req)
--local dst = Image({IMG_Like = src})
local dst = Image{ IMG_Like = src, IMG_DeferAlloc = true }
if not req:IsPreCalc() then
---==== PIXEL PROCESS ===---
--This calls on our kernel to process the image we created.
local node = DVIPComputeNode(req, "SolidTIHSVKernel", SolidTIHSVKernel, "SolidTIHSVParams", SolidTIHSVParams)
local params = node:GetParamBlock(SolidTIHSVParams)
--This gets the values of our sliders from the control panel.
params.blk = InBl:GetValue(req).Value
params.wht = InW:GetValue(req).Value
params.red[0] = InRH:GetValue(req).Value
params.red[1] = InRS:GetValue(req).Value
params.red[2] = InRV:GetValue(req).Value
params.grn[0] = InGH:GetValue(req).Value
params.grn[1] = InGS:GetValue(req).Value
params.grn[2] = InGV:GetValue(req).Value
params.blu[0] = InBH:GetValue(req).Value
params.blu[1] = InBS:GetValue(req).Value
params.blu[2] = InBV:GetValue(req).Value
params.cyn[0] = InCH:GetValue(req).Value
params.cyn[1] = InCS:GetValue(req).Value
params.cyn[2] = InCV:GetValue(req).Value
params.mag[0] = InMH:GetValue(req).Value
params.mag[1] = InMS:GetValue(req).Value
params.mag[2] = InMV:GetValue(req).Value
params.yel[0] = InYH:GetValue(req).Value
params.yel[1] = InYS:GetValue(req).Value
params.yel[2] = InYV:GetValue(req).Value
params.srcCompOrder = src:IsMask() and 1 or 15
node:SetParamBlock(params)
node:AddInput("src", src)
node:AddOutput("dst", dst)
local ok = node:RunSession(req)
if not ok then
dst = nil
end
end
OutImage:Set(req, dst)
end
--These are the parameters that we need access to in our kernel.
SolidTIHSVParams = [[
int srcCompOrder;
float blk;
float wht;
float red[3];
float grn[3];
float blu[3];
float cyn[3];
float mag[3];
float yel[3];
]]
--This is the GPU kernel, all of the image algorithms happen here.
SolidTIHSVKernel = [[
#define blk params->blk
#define wht params->wht
#define r_Hue params->red[0]
#define r_Sat params->red[1]
#define r_Val params->red[2]
#define g_Hue params->grn[0]
#define g_Sat params->grn[1]
#define g_Val params->grn[2]
#define b_Hue params->blu[0]
#define b_Sat params->blu[1]
#define b_Val params->blu[2]
#define c_Hue params->cyn[0]
#define c_Sat params->cyn[1]
#define c_Val params->cyn[2]
#define m_Hue params->mag[0]
#define m_Sat params->mag[1]
#define m_Val params->mag[2]
#define y_Hue params->yel[0]
#define y_Sat params->yel[1]
#define y_Val params->yel[2]
#define make_float3 to_float3
__KERNEL__ void SolidTIHSVKernel(
__CONSTANTREF__ SolidTIHSVParams *params,
__TEXTURE2D__ src,
__TEXTURE2D_WRITE__ dst
)
{
DEFINE_KERNEL_ITERATORS_XY(x, y);
float4 In = _tex2DVecN(src, x, y, params->srcCompOrder);
float3 rgb;
const float r = In.x;
const float g = In.y;
const float b = In.z;
float3 red = make_float3(r_Val + 1.0f, r_Val - r_Sat, r_Val + r_Hue - r_Sat);
float3 grn = make_float3(g_Val - g_Sat, g_Val + 1.0f, g_Val + g_Hue - g_Sat);
float3 blu = make_float3(b_Val + b_Hue - b_Sat, b_Val - b_Sat, b_Val + 1.0f);
float3 cyn = make_float3(c_Val - c_Sat, c_Val + 1.0f + c_Hue, c_Val + 1.0f);
float3 mag = make_float3(m_Val + 1.0f, m_Val - m_Sat, m_Val + 1.0f + m_Hue);
float3 yel = make_float3(y_Val + 1.0f + y_Hue, y_Val + 1.0f, y_Val - y_Sat);
if (r>g) {
// r>g>b
if (g>b) {
rgb = r*(red-blk)+blk + g*(yel-red) + b*(wht-yel);
}
// r>b>g
else if (r>b) {
rgb = r*(red-blk)+blk + g*(wht-mag) + b*(mag-red);
}
// b>r>g
else {
rgb = r*(mag-blu) + g*(wht-mag) + b*(blu-blk)+blk;
}
} else {
// b>g>r
if (b>g) {
rgb = r*(wht-cyn) + g*(cyn-blu) + b*(blu-blk)+blk;
}
// g>b>r
else if (b>r) {
rgb = r*(wht-cyn) + g*(grn-blk)+blk + b*(cyn-grn);
}
// g>r>b
else {
rgb = r*(yel-grn) + g*(grn-blk)+blk + b*(wht-yel);
}
}
_tex2DVec4Write(dst, x, y, to_float4(rgb.x, rgb.y, rgb.z, In.w));
}
]]