forked from calvinsilly/Tetrahedral-Interpolation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TetraInterp_02.blink
103 lines (85 loc) · 2.65 KB
/
TetraInterp_02.blink
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
kernel Tetra : ImageComputationKernel<ePixelWise>
{
Image<eRead, eAccessPoint, eEdgeClamped> src; // the input image
Image<eWrite> dst; // the output image
param:
float3 blk;
float3 wht;
float3 red;
float3 grn;
float3 blu;
float3 cyn;
float3 mag;
float3 yel;
void define(){
defineParam(blk, "blk", float3(0.f,0.f,0.f));
defineParam(wht, "wht", float3(1.f,1.f,1.f));
defineParam(red, "red", float3(1.f,0.f,0.f));
defineParam(grn, "grn", float3(0.f,1.f,0.f));
defineParam(blu, "blu", float3(0.f,0.f,1.f));
defineParam(cyn, "cyn", float3(0.f,1.f,1.f));
defineParam(mag, "mag", float3(1.f,0.f,1.f));
defineParam(yel, "yel", float3(1.f,1.f,0.f));
}
float3 tetra( float3 triplet , float3 corners[8]){
float r = triplet.x;
float g = triplet.y;
float b = triplet.z;
float3 red = corners[0];
float3 yel = corners[1];
float3 grn = corners[2];
float3 cyn = corners[3];
float3 blu = corners[4];
float3 mag = corners[5];
float3 wht = corners[6];
float3 blk = corners[7];
if (r>g) {
//r>g>b
if (g>b){
return r*(red-blk)+blk + g*(yel-red) + b*(wht-yel);
}
//r>b>g
else if (r>b){
return r*(red-blk)+blk + g*(wht-mag) + b*(mag-red);
}
//b>r>g
else{
return r*(mag-blu) + g*(wht-mag) + b*(blu-blk)+blk;
}
}
else {
//b>g>r
if (b>g){
return r*(wht-cyn) + g*(cyn-blu) + b*(blu-blk)+blk;
}
//g>b>r
else if (b>r){
return r*(wht-cyn) + g*(grn-blk)+blk + b*(cyn-grn);
}
//g>r>b
else{
return r*(yel-grn) + g*(grn-blk)+blk + b*(wht-yel);
}
}
}
void process() {
// Read the input image
SampleType(src) input = src();
float3 rgb;
rgb.x = input.x;
rgb.y = input.y;
rgb.z = input.z;
float3 corners[8];
corners[0] = red;
corners[1] = yel;
corners[2] = grn;
corners[3] = cyn;
corners[4] = blu;
corners[5] = mag;
corners[6] = wht;
corners[7] = blk;
float3 output = tetra( rgb , corners);
// Write the result to the output image
dst() = float4 ( output.x, output.y , output.z , input.w);
}
};