-
Notifications
You must be signed in to change notification settings - Fork 1
/
PD-LogC-Exposure.dctl
104 lines (99 loc) · 3.74 KB
/
PD-LogC-Exposure.dctl
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
// Copyright 2022-present Contributors to the photographic-dctl project.
// SPDX-License-Identifier: BSD-3-Clause
// https://github.com/mikaelsundell/photographic-dctls
// clang-format off
DEFINE_UI_PARAMS(logc, LogC, DCTLUI_COMBO_BOX, 0, {LOGC3, LOGC4}, {LogC3, LogC4})
DEFINE_UI_PARAMS(ei, LogC3 EI, DCTLUI_COMBO_BOX, 7, {EI160, EI200, EI250, EI320, EI400, EI500, EI640, EI800, EI1000, EI1280, EI1600}, {EI 160, EI 200, EI 250, EI 320, EI 400, EI 500, EI 640, EI 800, EI 1000, EI 1280, EI 1600})
DEFINE_UI_PARAMS(exposure, Exposure, DCTLUI_SLIDER_FLOAT, 0.0, -8.0, 8.0, 0.1)
DEFINE_UI_PARAMS(ev, Exposure EV, DCTLUI_COMBO_BOX, 3, {EV_3, EV_2, EV_1, EV0, EV1, EV2, EV3}, {EV -3, EV -2, EV -1, EV 0, EV 1, EV 2, EV 3})
DEFINE_UI_PARAMS(adjustdisplay, Adjust for display, DCTLUI_CHECK_BOX, 0)
DEFINE_UI_PARAMS(showcolors, Show colors, DCTLUI_CHECK_BOX, 0)
DEFINE_UI_PARAMS(showlegend, Show legend, DCTLUI_CHECK_BOX, 0)
// headers
#include "PD-Common.h"
#include "PD-LogC.h"
// ev stops
__DEVICE__ float evstops(int ev) {
if (ev == EV_3) {
return -3.0f;
} else if (ev == EV_2) {
return -2.0f;
} else if (ev == EV_1) {
return -1.0f;
} else if (ev == EV0) {
return 0.0f;
} else if (ev == EV1) {
return 1.0f;
} else if (ev == EV2) {
return 2.0f;
} else if (ev == EV3) {
return 3.0f;
}
return 0.0;
}
// logc3 color
__DEVICE__ float3 logC_ev_color(float3 input_rgb, int ei, int ev, int logc) {
struct LogCColor colors[logC_stops];
if (logc == LOGC3) {
struct LogC3Curve cv = logC3_curve(ei);
float evs = evstops(ev);
for (unsigned long i = 0; i < logC_stops; i++) {
colors[i] = logC_colors[i];
float lin = pow_f(2.0f, colors[i].stop + evs + 0.5f) * 0.18f;
float log = min_f(LogC3Curve_lin_logC3(cv, lin), 1.0f);
colors[i].stop = log;
}
}
else {
struct LogC4Curve cv = logC4_curve();
float evs = evstops(ev);
for (unsigned long i = 0; i < logC_stops; i++) {
colors[i] = logC_colors[i];
float lin = pow_f(2.0f, colors[i].stop + evs + 0.5f) * 0.18f;
float log = min_f(LogC4Curve_lin_logC4(cv, lin), 1.0f);
colors[i].stop = log;
}
}
float3 result = make_float3(0.0f, 0.0f, 0.0f);
float lum = luma_rec709(input_rgb);
for (unsigned long i = 0; i < logC_stops; i++) {
if (lum <= colors[i].stop || i == (sizeof(logC_colors) / sizeof(struct LogCColor)) - 1) {
result = make_float3(colors[i].r, colors[i].g, colors[i].b);
break;
}
}
return result;
}
// transform
__DEVICE__ float3 transform(int p_Width, int p_Height, int p_X, int p_Y, float p_R, float p_G, float p_B)
{
float3 rgb = make_float3(p_R, p_G, p_B);
if (logc == LOGC3) {
rgb = lin_logC3(logC3_lin(rgb, ei) * pow_f(2.0, exposure), ei);
}
else {
rgb = lin_logC4(logC4_lin(rgb) * pow_f(2.0, exposure));
}
if (showcolors > 0) {
rgb = logC_ev_color(rgb, ei, ev, logc);
}
if (showlegend > 0) {
int legendwidth = p_Width * 0.8;
int offset = p_Height * 0.02;
int barheight = p_Height * 0.05;
int startY = p_Height - barheight - offset;
int startX = p_Width * 0.1;
int endX = startX + legendwidth;
if (p_Y >= startY && p_Y < startY + barheight && p_X >= startX && p_X < endX) {
int width = legendwidth / logC_stops;
int index = (p_X - startX) / width;
if (index >= 0 && index < logC_stops) {
return make_float3(logC_colors[index].r, logC_colors[index].g, logC_colors[index].b);
}
}
}
if (adjustdisplay) {
rgb = adjust_display(rgb);
}
return rgb;
}