Skip to content

Commit

Permalink
Merge pull request #3 from nick-shaw/graph_overlay
Browse files Browse the repository at this point in the history
Add the option to overlay curve plots.
  • Loading branch information
KelSolaar authored Aug 4, 2020
2 parents 4d21667 + ccdb5c2 commit 0bbae67
Show file tree
Hide file tree
Showing 7 changed files with 575 additions and 96 deletions.
22 changes: 21 additions & 1 deletion model/GamutCompress.blink
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ kernel GamutCompression : public ImageComputationKernel<ePixelWise> {
float cyan;
float magenta;
float yellow;
float p_Height;
int method;
bool hexagonal;
bool invert;
bool overlay;

local:
float3 thr;
Expand Down Expand Up @@ -189,11 +191,14 @@ kernel GamutCompression : public ImageComputationKernel<ePixelWise> {
}


void process() {
void process(int2 pos) {
// source pixels
SampleType(src) rgba = src();
float3 rgb = float3(rgba.x, rgba.y, rgba.z);

// normalised pixel coordinates
float2 fpos = float2((float)pos.x / dst.bounds.width(), (float)pos.y / p_Height);

// achromatic axis
float ach = max(rgb.x, max(rgb.y, rgb.z));

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

// Graph overlay method based on one by Paul Dore
// https://github.com/baldavenger/DCTLs/tree/master/ACES%20TOOLS
if (overlay) {
float3 cramp = float3(
compress(2.0f * fpos.x, lim.x, thr.x),
compress(2.0f * fpos.x, lim.y, thr.y),
compress(2.0f * fpos.x, lim.z, thr.z));
bool overlay_r = fabs(2.0f * fpos.y - cramp.x) < 0.004f || fabs(fpos.y - 0.5f) < 0.0005f ? true : false;
bool overlay_g = fabs(2.0f * fpos.y - cramp.y) < 0.004f || fabs(fpos.y - 0.5f) < 0.0005f ? true : false;
bool overlay_b = fabs(2.0f * fpos.y - cramp.z) < 0.004f || fabs(fpos.y - 0.5f) < 0.0005f ? true : false;
crgb.x = overlay_g || overlay_b ? 1.0f : crgb.x;
crgb.y = overlay_b || overlay_r ? 1.0f : crgb.y;
crgb.z = overlay_r || overlay_g ? 1.0f : crgb.z;
}

// write to output
dst() = float4(crgb.x, crgb.y, crgb.z, rgba.w);
}
Expand Down
25 changes: 22 additions & 3 deletions model/GamutCompress.dctl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
DEFINE_UI_PARAMS(threshold_r, threshold r, DCTLUI_SLIDER_FLOAT, 0.8f, 0.4f, 1.0f, 0.0f);
DEFINE_UI_PARAMS(threshold_g, threshold g, DCTLUI_SLIDER_FLOAT, 0.8f, 0.4f, 1.0f, 0.0f);
DEFINE_UI_PARAMS(threshold_b, threshold b, DCTLUI_SLIDER_FLOAT, 0.8f, 0.4f, 1.0f, 0.0f);
DEFINE_UI_PARAMS(threshold_r, threshold c, DCTLUI_SLIDER_FLOAT, 0.8f, 0.4f, 1.0f, 0.0f);
DEFINE_UI_PARAMS(threshold_g, threshold m, DCTLUI_SLIDER_FLOAT, 0.8f, 0.4f, 1.0f, 0.0f);
DEFINE_UI_PARAMS(threshold_b, threshold y, DCTLUI_SLIDER_FLOAT, 0.8f, 0.4f, 1.0f, 0.0f);
DEFINE_UI_PARAMS(power, power, DCTLUI_SLIDER_FLOAT, 1.2f, 1.0f, 3.0f, 1.0f);
DEFINE_UI_PARAMS(shd_rolloff, shd rolloff, DCTLUI_SLIDER_FLOAT, 0.0f, 0.0f, 0.1f, 0.0f);
DEFINE_UI_PARAMS(cyan, cyan, DCTLUI_SLIDER_FLOAT, 0.09f, 0.0f, 1.0f, 0.0f);
Expand All @@ -10,6 +10,7 @@ DEFINE_UI_PARAMS(cmethod, method, DCTLUI_COMBO_BOX, 2, {L, R, P, E, A, T}, {log,
DEFINE_UI_PARAMS(working_colorspace, working space, DCTLUI_COMBO_BOX, 0, {acescct, acescc, acescg}, {acescct, acescc, acescg});
DEFINE_UI_PARAMS(hexagonal, hexagonal, DCTLUI_CHECK_BOX, 0);
DEFINE_UI_PARAMS(invert, invert, DCTLUI_CHECK_BOX, 0);
DEFINE_UI_PARAMS(overlay, overlay graph, DCTLUI_CHECK_BOX, 0)

__CONSTANT__ float pi = 3.14159265359f;

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

// normalised pixel coordinates
float2 pos = make_float2((float)p_X / p_Width, (float)(p_Height - p_Y) / p_Height);

// source pixels
float3 rgb = make_float3(p_R, p_G, p_B);

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

// Graph overlay method based on one by Paul Dore
// https://github.com/baldavenger/DCTLs/tree/master/ACES%20TOOLS
if (overlay) {
float3 cramp = make_float3(
compress(2.0f * pos.x, lim.x, thr.x, invert, method, power),
compress(2.0f * pos.x, lim.y, thr.y, invert, method, power),
compress(2.0f * pos.x, lim.z, thr.z, invert, method, power));
bool overlay_r = _fabs(2.0f * pos.y - cramp.x) < 0.004f || _fabs(pos.y - 0.5f) < 0.0005f ? true : false;
bool overlay_g = _fabs(2.0f * pos.y - cramp.y) < 0.004f || _fabs(pos.y - 0.5f) < 0.0005f ? true : false;
bool overlay_b = _fabs(2.0f * pos.y - cramp.z) < 0.004f || _fabs(pos.y - 0.5f) < 0.0005f ? true : false;
crgb.x = overlay_g || overlay_b ? 1.0f : crgb.x;
crgb.y = overlay_b || overlay_r ? 1.0f : crgb.y;
crgb.z = overlay_r || overlay_g ? 1.0f : crgb.z;
}

if (working_colorspace == acescct) {
crgb.x = lin_to_acescct(crgb.x);
crgb.y = lin_to_acescct(crgb.y);
Expand Down
38 changes: 34 additions & 4 deletions model/GamutCompress.fuse
Original file line number Diff line number Diff line change
Expand Up @@ -107,23 +107,23 @@ function Create()
INP_Default = 0.0,
})

InThresholdR = self:AddInput("threshold_r", "threshold_r", {
InThresholdR = self:AddInput("threshold_c", "threshold_c", {
LINKID_DataType = "Number",
INPID_InputControl = "SliderControl",
INP_Default = 0.8,
INP_MinAllowed = 0.4,
INP_MaxScale = 0.9999,
})

InThresholdG = self:AddInput("threshold_g", "threshold_g", {
InThresholdG = self:AddInput("threshold_m", "threshold_m", {
LINKID_DataType = "Number",
INPID_InputControl = "SliderControl",
INP_Default = 0.8,
INP_MinAllowed = 0.4,
INP_MaxScale = 0.9999,
})

InThresholdB = self:AddInput("threshold_b", "threshold_b", {
InThresholdB = self:AddInput("threshold_y", "threshold_y", {
LINKID_DataType = "Number",
INPID_InputControl = "SliderControl",
INP_Default = 0.8,
Expand Down Expand Up @@ -183,6 +183,14 @@ function Create()
INP_Default = 0.0,
})

InOverlay = self:AddInput("overlay graph", "overlay graph", {
LINKID_DataType = "Number",
INPID_InputControl = "CheckboxControl",
INP_MinAllowed = 0.0,
INP_MaxAllowed = 1.0,
INP_Default = 0.0,
})

InImage = self:AddInput("Input", "Input", {
LINKID_DataType = "Image",
LINK_Main = 1,
Expand Down Expand Up @@ -215,7 +223,9 @@ function Process(req)
params.yellow = InYellow:GetValue(req).Value
params.invert = InInvert:GetValue(req).Value
params.srcCompOrder = src:IsMask() and 1 or 15

params.srcSize[0] = src.Width
params.srcSize[1] = src.Height
params.overlay = InOverlay:GetValue(req).Value
node:SetParamBlock(params)

node:AddInput("src", src)
Expand Down Expand Up @@ -245,7 +255,9 @@ SolidParams = [[
float magenta;
float yellow;
int invert;
int overlay;
int srcCompOrder;
int srcSize[2];
]]


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

// normalised pixel coordinates
float2 pos = make_float2((float)x / params->srcSize[0], (float)y / params->srcSize[1]);

// set up method
int method;
if (params->method == 0) {
Expand Down Expand Up @@ -475,6 +490,21 @@ SolidKernel = [[
ach-cdist.z*ach_shd,
rgb.w);

// Graph overlay method based on one by Paul Dore
// https://github.com/baldavenger/DCTLs/tree/master/ACES%20TOOLS
if (params->overlay == 1) {
float3 cramp = make_float3(
compress(2.0f * pos.x, lim.x, thr.x, params->invert, method, params->power),
compress(2.0f * pos.x, lim.y, thr.y, params->invert, method, params->power),
compress(2.0f * pos.x, lim.z, thr.z, params->invert, method, params->power));
bool overlay_r = _fabs(2.0f * pos.y - cramp.x) < 0.004f || _fabs(pos.y - 0.5f) < 0.0005f ? true : false;
bool overlay_g = _fabs(2.0f * pos.y - cramp.y) < 0.004f || _fabs(pos.y - 0.5f) < 0.0005f ? true : false;
bool overlay_b = _fabs(2.0f * pos.y - cramp.z) < 0.004f || _fabs(pos.y - 0.5f) < 0.0005f ? true : false;
crgb.x = overlay_g || overlay_b ? 1.0f : crgb.x;
crgb.y = overlay_b || overlay_r ? 1.0f : crgb.y;
crgb.z = overlay_r || overlay_g ? 1.0f : crgb.z;
}

_tex2DVec4Write(dst, x, y, crgb);
}
]]
17 changes: 16 additions & 1 deletion model/GamutCompress.glsl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
uniform sampler2D frontTex, matteTex, selectiveTex;
uniform float power, cyan, magenta, yellow, shd_rolloff, adsk_result_w, adsk_result_h;
uniform int method, working_colorspace;
uniform bool invert, hexagonal;
uniform bool invert, hexagonal, overlay;
uniform vec3 threshold;

const float pi = 3.14159265359;
Expand Down Expand Up @@ -274,6 +274,21 @@ void main() {
ach-cdist.y*ach_shd,
ach-cdist.z*ach_shd);

// Graph overlay method based on one by Paul Dore
// https://github.com/baldavenger/DCTLs/tree/master/ACES%20TOOLS
if (overlay) {
vec3 cramp = vec3(
compress(2.0 * coords.x, lim.x, thr.x, invert, method, power),
compress(2.0 * coords.x, lim.y, thr.y, invert, method, power),
compress(2.0 * coords.x, lim.z, thr.z, invert, method, power));
bool overlay_r = abs(2.0 * coords.y - cramp.x) < 0.004 || abs(coords.y - 0.5) < 0.0005 ? true : false;
bool overlay_g = abs(2.0 * coords.y - cramp.y) < 0.004 || abs(coords.y - 0.5) < 0.0005 ? true : false;
bool overlay_b = abs(2.0 * coords.y - cramp.z) < 0.004 || abs(coords.y - 0.5) < 0.0005 ? true : false;
crgb.x = overlay_g || overlay_b ? 1.0 : crgb.x;
crgb.y = overlay_b || overlay_r ? 1.0 : crgb.y;
crgb.z = overlay_r || overlay_g ? 1.0 : crgb.z;
}

if (working_colorspace == 1) {
crgb.x = lin_to_acescct(crgb.x);
crgb.y = lin_to_acescct(crgb.y);
Expand Down
Loading

0 comments on commit 0bbae67

Please sign in to comment.