-
Notifications
You must be signed in to change notification settings - Fork 13
/
GamutCompress_blink.nk
56 lines (56 loc) · 4.75 KB
/
GamutCompress_blink.nk
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
set cut_paste_input [stack 0]
push $cut_paste_input
Group {
name GamutCompress_blink
addUserKnob {20 GamutCompress}
addUserKnob {6 use_gpu l "use gpu" t "use gpu for blinkscript node" -STARTLINE}
use_gpu true
addUserKnob {26 ""}
addUserKnob {18 threshold t "Percentage of the outer gamut boundary to affect. A value of 0.2 means 20% of the outer gamut will be utilized for gamut compression." R 0 0.2}
threshold 0.15
addUserKnob {6 threshold_panelDropped l "panel dropped state" -STARTLINE +HIDDEN}
addUserKnob {35 distance_presets l distance t "choose distance presets for common digital cinema camera source gamuts" M {"presets/ACEScg from Filmlight E-Gamut" "knobs this \{cyan 0.122 magenta 0.201 yellow 0.139\}" "presets/ACEScg from Alexa Wide Gamut" "knobs this \{cyan 0.078 magenta 0.22 yellow 0.056\}" "presets/ACEScg from RedWideGamutRGB" "knobs this \{cyan 0.143 magenta 0.239 yellow 0.316\}" "presets/ACEScg from Sony S-Gamut3.Cine" "knobs this \{cyan 0.074 magenta 0.264 yellow 0.049\}" "presets/ACEScg from Sony S-Gamut3" "knobs this \{cyan 0.089 magenta 0.182 yellow 0.004\}" "presets/ACEScg from Panasonic V-Gamut" "knobs this \{cyan 0.06 magenta 0.148 yellow 0.012\}"}}
addUserKnob {7 cyan t "Maximum distance beyond the green-blue gamut boundary to compress to the gamut boundary." R 0 0.4}
cyan 0.1
addUserKnob {7 magenta t "Maximum distance beyond the blue-red gamut boundary to compress to the gamut boundary." R 0 0.4}
magenta 0.2
addUserKnob {7 yellow t "Maximum distance beyond the red-green gamut boundary to compress to the gamut boundary." R 0 0.4}
yellow 0.1
addUserKnob {4 direction M {forward inverse}}
addUserKnob {20 info_tab l Info}
addUserKnob {26 info_label l " " T "<style> a:link \{ color: #ccc \}</style>\n<font color=#ccc>\n<b>GamutCompress v0.7</b><br>\nmaps out of gamut colors back into gamut.\n<br><br><a href=https://github.com/jedypod/gamut-compress>Documentation</a>"}
addUserKnob {26 about_label l " " T "<style> a:link \{ color: #ccc \}</style>\n<font color=#ccc><br>\n<b>About</b><br>\nWritten by <a href=https://github.com/jedypod color=red>Jed Smith</a> <br> with <a href=https://community.acescentral.com/t/rgb-saturation-gamut-mapping-approach-and-a-comp-vfx-perspective>help</a> from the <a href=https://community.acescentral.com/c/aces-development-acesnext/vwg-aces-gamut-mapping-working-group>ACES Gamut Mapping VWG</a>"}
}
Input {
inputs 0
name Input
xpos -40
ypos -10
}
AddChannels {
name AddChannels
xpos -40
ypos 44
}
BlinkScript {
recompileCount 1
ProgramGroup 1
KernelDescription "2 \"GamutCompression\" iterate pixelWise c0d43fd0eba9efe2ea0c3fb1b173b0116570ea6ec879ba3765d9333e4c27883a 2 \"src\" Read Point \"dst\" Write Point 3 \"th\" Float 3 AAAAAAAAAAAAAAAAAAAAAA== \"dl\" Float 3 AAAAAAAAAAAAAAAAAAAAAA== \"invert\" Bool 1 AA== 3 \"th\" 3 1 \"dl\" 3 1 \"invert\" 1 1 1 \"s\" Float 3 1 AAAAAAAAAAAAAAAAAAAAAA=="
kernelSource "kernel GamutCompression : public ImageComputationKernel<ePixelWise> \{\n Image<eRead, eAccessPoint, eEdgeClamped> src;\n Image<eWrite> dst;\n\n param:\n float3 th;\n float3 dl;\n bool invert;\n\n local:\n float3 s;\n\n void init() \{\n // Pre-calculate scale so compression function passes through distance limit: (x=dl, y=1)\n s = ((float3)(1.0f)-th)/sqrt(max((float3)(1.001f),dl)-(float3)(1.0f));\n \}\n\n void process() \{\n float3 rgb = float3(src().x, src().y, src().z);\n\n float ac = max(rgb.x, max(rgb.y, rgb.z)); // Achromatic axis\n // Inverse RGB Ratios: distance from achromatic axis\n float3 d = ac == 0.0f ? (float3)(0.0f) : (ac-rgb)/fabs(ac);\n\n float3 cd; // Compressed distance\n // Parabolic compression function: https://www.desmos.com/calculator/nvhp63hmtj\n if (!invert) \{\n cd.x = d.x<th.x?d.x:s.x*sqrt(d.x-th.x+s.x*s.x/4.0f)-s.x*sqrt(s.x*s.x/4.0f)+th.x;\n cd.y = d.y<th.y?d.y:s.y*sqrt(d.y-th.y+s.y*s.y/4.0f)-s.y*sqrt(s.y*s.y/4.0f)+th.y;\n cd.z = d.z<th.z?d.z:s.z*sqrt(d.z-th.z+s.z*s.z/4.0f)-s.z*sqrt(s.z*s.z/4.0f)+th.z;\n \} else \{\n cd.x = d.x<th.x?d.x:pow(d.x-th.x+s.x*sqrt(s.x*s.x/4.0f),2.0f)/(s.x*s.x)-s.x*s.x/4.0f+th.x;\n cd.y = d.y<th.y?d.y:pow(d.y-th.y+s.y*sqrt(s.y*s.y/4.0f),2.0f)/(s.y*s.y)-s.y*s.y/4.0f+th.y;\n cd.z = d.z<th.z?d.z:pow(d.z-th.z+s.z*sqrt(s.z*s.z/4.0f),2.0f)/(s.z*s.z)-s.z*s.z/4.0f+th.z;\n \}\n\n rgb = ac-cd*fabs(ac);\n dst() = float4(rgb.x, rgb.y, rgb.z, src().w);\n \}\n\};"
useGPUIfAvailable {{parent.use_gpu}}
rebuild ""
GamutCompression_th {{1-parent.threshold.r} {1-parent.threshold.g} {1-parent.threshold.b}}
GamutCompression_dl {{1+parent.cyan} {1+parent.magenta} {1+parent.yellow}}
GamutCompression_invert {{parent.direction}}
rebuild_finalise ""
name GamutCompress
selected true
xpos -40
ypos 104
}
Output {
name Output
xpos -40
ypos 170
}
end_group