Skip to content

Commit 0bbae67

Browse files
authored
Merge pull request #3 from nick-shaw/graph_overlay
Add the option to overlay curve plots.
2 parents 4d21667 + ccdb5c2 commit 0bbae67

File tree

7 files changed

+575
-96
lines changed

7 files changed

+575
-96
lines changed

model/GamutCompress.blink

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ kernel GamutCompression : public ImageComputationKernel<ePixelWise> {
99
float cyan;
1010
float magenta;
1111
float yellow;
12+
float p_Height;
1213
int method;
1314
bool hexagonal;
1415
bool invert;
16+
bool overlay;
1517

1618
local:
1719
float3 thr;
@@ -189,11 +191,14 @@ kernel GamutCompression : public ImageComputationKernel<ePixelWise> {
189191
}
190192

191193

192-
void process() {
194+
void process(int2 pos) {
193195
// source pixels
194196
SampleType(src) rgba = src();
195197
float3 rgb = float3(rgba.x, rgba.y, rgba.z);
196198

199+
// normalised pixel coordinates
200+
float2 fpos = float2((float)pos.x / dst.bounds.width(), (float)pos.y / p_Height);
201+
197202
// achromatic axis
198203
float ach = max(rgb.x, max(rgb.y, rgb.z));
199204

@@ -228,6 +233,21 @@ kernel GamutCompression : public ImageComputationKernel<ePixelWise> {
228233
// effectively this scales each color component relative to achromatic axis by the compressed distance
229234
float3 crgb = ach-cdist*ach_shd;
230235

236+
// Graph overlay method based on one by Paul Dore
237+
// https://github.com/baldavenger/DCTLs/tree/master/ACES%20TOOLS
238+
if (overlay) {
239+
float3 cramp = float3(
240+
compress(2.0f * fpos.x, lim.x, thr.x),
241+
compress(2.0f * fpos.x, lim.y, thr.y),
242+
compress(2.0f * fpos.x, lim.z, thr.z));
243+
bool overlay_r = fabs(2.0f * fpos.y - cramp.x) < 0.004f || fabs(fpos.y - 0.5f) < 0.0005f ? true : false;
244+
bool overlay_g = fabs(2.0f * fpos.y - cramp.y) < 0.004f || fabs(fpos.y - 0.5f) < 0.0005f ? true : false;
245+
bool overlay_b = fabs(2.0f * fpos.y - cramp.z) < 0.004f || fabs(fpos.y - 0.5f) < 0.0005f ? true : false;
246+
crgb.x = overlay_g || overlay_b ? 1.0f : crgb.x;
247+
crgb.y = overlay_b || overlay_r ? 1.0f : crgb.y;
248+
crgb.z = overlay_r || overlay_g ? 1.0f : crgb.z;
249+
}
250+
231251
// write to output
232252
dst() = float4(crgb.x, crgb.y, crgb.z, rgba.w);
233253
}

model/GamutCompress.dctl

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
DEFINE_UI_PARAMS(threshold_r, threshold r, DCTLUI_SLIDER_FLOAT, 0.8f, 0.4f, 1.0f, 0.0f);
2-
DEFINE_UI_PARAMS(threshold_g, threshold g, DCTLUI_SLIDER_FLOAT, 0.8f, 0.4f, 1.0f, 0.0f);
3-
DEFINE_UI_PARAMS(threshold_b, threshold b, DCTLUI_SLIDER_FLOAT, 0.8f, 0.4f, 1.0f, 0.0f);
1+
DEFINE_UI_PARAMS(threshold_r, threshold c, DCTLUI_SLIDER_FLOAT, 0.8f, 0.4f, 1.0f, 0.0f);
2+
DEFINE_UI_PARAMS(threshold_g, threshold m, DCTLUI_SLIDER_FLOAT, 0.8f, 0.4f, 1.0f, 0.0f);
3+
DEFINE_UI_PARAMS(threshold_b, threshold y, DCTLUI_SLIDER_FLOAT, 0.8f, 0.4f, 1.0f, 0.0f);
44
DEFINE_UI_PARAMS(power, power, DCTLUI_SLIDER_FLOAT, 1.2f, 1.0f, 3.0f, 1.0f);
55
DEFINE_UI_PARAMS(shd_rolloff, shd rolloff, DCTLUI_SLIDER_FLOAT, 0.0f, 0.0f, 0.1f, 0.0f);
66
DEFINE_UI_PARAMS(cyan, cyan, DCTLUI_SLIDER_FLOAT, 0.09f, 0.0f, 1.0f, 0.0f);
@@ -10,6 +10,7 @@ DEFINE_UI_PARAMS(cmethod, method, DCTLUI_COMBO_BOX, 2, {L, R, P, E, A, T}, {log,
1010
DEFINE_UI_PARAMS(working_colorspace, working space, DCTLUI_COMBO_BOX, 0, {acescct, acescc, acescg}, {acescct, acescc, acescg});
1111
DEFINE_UI_PARAMS(hexagonal, hexagonal, DCTLUI_CHECK_BOX, 0);
1212
DEFINE_UI_PARAMS(invert, invert, DCTLUI_CHECK_BOX, 0);
13+
DEFINE_UI_PARAMS(overlay, overlay graph, DCTLUI_CHECK_BOX, 0)
1314

1415
__CONSTANT__ float pi = 3.14159265359f;
1516

@@ -192,6 +193,9 @@ __DEVICE__ float3 transform(int p_Width, int p_Height, int p_X, int p_Y, float p
192193
{
193194
// ^-- this is necessary for the DCTL to work!
194195

196+
// normalised pixel coordinates
197+
float2 pos = make_float2((float)p_X / p_Width, (float)(p_Height - p_Y) / p_Height);
198+
195199
// source pixels
196200
float3 rgb = make_float3(p_R, p_G, p_B);
197201

@@ -287,6 +291,21 @@ __DEVICE__ float3 transform(int p_Width, int p_Height, int p_X, int p_Y, float p
287291
ach-cdist.y*ach_shd,
288292
ach-cdist.z*ach_shd);
289293

294+
// Graph overlay method based on one by Paul Dore
295+
// https://github.com/baldavenger/DCTLs/tree/master/ACES%20TOOLS
296+
if (overlay) {
297+
float3 cramp = make_float3(
298+
compress(2.0f * pos.x, lim.x, thr.x, invert, method, power),
299+
compress(2.0f * pos.x, lim.y, thr.y, invert, method, power),
300+
compress(2.0f * pos.x, lim.z, thr.z, invert, method, power));
301+
bool overlay_r = _fabs(2.0f * pos.y - cramp.x) < 0.004f || _fabs(pos.y - 0.5f) < 0.0005f ? true : false;
302+
bool overlay_g = _fabs(2.0f * pos.y - cramp.y) < 0.004f || _fabs(pos.y - 0.5f) < 0.0005f ? true : false;
303+
bool overlay_b = _fabs(2.0f * pos.y - cramp.z) < 0.004f || _fabs(pos.y - 0.5f) < 0.0005f ? true : false;
304+
crgb.x = overlay_g || overlay_b ? 1.0f : crgb.x;
305+
crgb.y = overlay_b || overlay_r ? 1.0f : crgb.y;
306+
crgb.z = overlay_r || overlay_g ? 1.0f : crgb.z;
307+
}
308+
290309
if (working_colorspace == acescct) {
291310
crgb.x = lin_to_acescct(crgb.x);
292311
crgb.y = lin_to_acescct(crgb.y);

model/GamutCompress.fuse

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,23 +107,23 @@ function Create()
107107
INP_Default = 0.0,
108108
})
109109

110-
InThresholdR = self:AddInput("threshold_r", "threshold_r", {
110+
InThresholdR = self:AddInput("threshold_c", "threshold_c", {
111111
LINKID_DataType = "Number",
112112
INPID_InputControl = "SliderControl",
113113
INP_Default = 0.8,
114114
INP_MinAllowed = 0.4,
115115
INP_MaxScale = 0.9999,
116116
})
117117

118-
InThresholdG = self:AddInput("threshold_g", "threshold_g", {
118+
InThresholdG = self:AddInput("threshold_m", "threshold_m", {
119119
LINKID_DataType = "Number",
120120
INPID_InputControl = "SliderControl",
121121
INP_Default = 0.8,
122122
INP_MinAllowed = 0.4,
123123
INP_MaxScale = 0.9999,
124124
})
125125

126-
InThresholdB = self:AddInput("threshold_b", "threshold_b", {
126+
InThresholdB = self:AddInput("threshold_y", "threshold_y", {
127127
LINKID_DataType = "Number",
128128
INPID_InputControl = "SliderControl",
129129
INP_Default = 0.8,
@@ -183,6 +183,14 @@ function Create()
183183
INP_Default = 0.0,
184184
})
185185

186+
InOverlay = self:AddInput("overlay graph", "overlay graph", {
187+
LINKID_DataType = "Number",
188+
INPID_InputControl = "CheckboxControl",
189+
INP_MinAllowed = 0.0,
190+
INP_MaxAllowed = 1.0,
191+
INP_Default = 0.0,
192+
})
193+
186194
InImage = self:AddInput("Input", "Input", {
187195
LINKID_DataType = "Image",
188196
LINK_Main = 1,
@@ -215,7 +223,9 @@ function Process(req)
215223
params.yellow = InYellow:GetValue(req).Value
216224
params.invert = InInvert:GetValue(req).Value
217225
params.srcCompOrder = src:IsMask() and 1 or 15
218-
226+
params.srcSize[0] = src.Width
227+
params.srcSize[1] = src.Height
228+
params.overlay = InOverlay:GetValue(req).Value
219229
node:SetParamBlock(params)
220230

221231
node:AddInput("src", src)
@@ -245,7 +255,9 @@ SolidParams = [[
245255
float magenta;
246256
float yellow;
247257
int invert;
258+
int overlay;
248259
int srcCompOrder;
260+
int srcSize[2];
249261
]]
250262

251263

@@ -393,6 +405,9 @@ SolidKernel = [[
393405
DEFINE_KERNEL_ITERATORS_XY(x, y);
394406
float4 rgb = _tex2DVecN(src, x, y, params->srcCompOrder);
395407

408+
// normalised pixel coordinates
409+
float2 pos = make_float2((float)x / params->srcSize[0], (float)y / params->srcSize[1]);
410+
396411
// set up method
397412
int method;
398413
if (params->method == 0) {
@@ -475,6 +490,21 @@ SolidKernel = [[
475490
ach-cdist.z*ach_shd,
476491
rgb.w);
477492

493+
// Graph overlay method based on one by Paul Dore
494+
// https://github.com/baldavenger/DCTLs/tree/master/ACES%20TOOLS
495+
if (params->overlay == 1) {
496+
float3 cramp = make_float3(
497+
compress(2.0f * pos.x, lim.x, thr.x, params->invert, method, params->power),
498+
compress(2.0f * pos.x, lim.y, thr.y, params->invert, method, params->power),
499+
compress(2.0f * pos.x, lim.z, thr.z, params->invert, method, params->power));
500+
bool overlay_r = _fabs(2.0f * pos.y - cramp.x) < 0.004f || _fabs(pos.y - 0.5f) < 0.0005f ? true : false;
501+
bool overlay_g = _fabs(2.0f * pos.y - cramp.y) < 0.004f || _fabs(pos.y - 0.5f) < 0.0005f ? true : false;
502+
bool overlay_b = _fabs(2.0f * pos.y - cramp.z) < 0.004f || _fabs(pos.y - 0.5f) < 0.0005f ? true : false;
503+
crgb.x = overlay_g || overlay_b ? 1.0f : crgb.x;
504+
crgb.y = overlay_b || overlay_r ? 1.0f : crgb.y;
505+
crgb.z = overlay_r || overlay_g ? 1.0f : crgb.z;
506+
}
507+
478508
_tex2DVec4Write(dst, x, y, crgb);
479509
}
480510
]]

model/GamutCompress.glsl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
uniform sampler2D frontTex, matteTex, selectiveTex;
22
uniform float power, cyan, magenta, yellow, shd_rolloff, adsk_result_w, adsk_result_h;
33
uniform int method, working_colorspace;
4-
uniform bool invert, hexagonal;
4+
uniform bool invert, hexagonal, overlay;
55
uniform vec3 threshold;
66

77
const float pi = 3.14159265359;
@@ -274,6 +274,21 @@ void main() {
274274
ach-cdist.y*ach_shd,
275275
ach-cdist.z*ach_shd);
276276

277+
// Graph overlay method based on one by Paul Dore
278+
// https://github.com/baldavenger/DCTLs/tree/master/ACES%20TOOLS
279+
if (overlay) {
280+
vec3 cramp = vec3(
281+
compress(2.0 * coords.x, lim.x, thr.x, invert, method, power),
282+
compress(2.0 * coords.x, lim.y, thr.y, invert, method, power),
283+
compress(2.0 * coords.x, lim.z, thr.z, invert, method, power));
284+
bool overlay_r = abs(2.0 * coords.y - cramp.x) < 0.004 || abs(coords.y - 0.5) < 0.0005 ? true : false;
285+
bool overlay_g = abs(2.0 * coords.y - cramp.y) < 0.004 || abs(coords.y - 0.5) < 0.0005 ? true : false;
286+
bool overlay_b = abs(2.0 * coords.y - cramp.z) < 0.004 || abs(coords.y - 0.5) < 0.0005 ? true : false;
287+
crgb.x = overlay_g || overlay_b ? 1.0 : crgb.x;
288+
crgb.y = overlay_b || overlay_r ? 1.0 : crgb.y;
289+
crgb.z = overlay_r || overlay_g ? 1.0 : crgb.z;
290+
}
291+
277292
if (working_colorspace == 1) {
278293
crgb.x = lin_to_acescct(crgb.x);
279294
crgb.y = lin_to_acescct(crgb.y);

0 commit comments

Comments
 (0)