-
Notifications
You must be signed in to change notification settings - Fork 1
/
PD-Cineon-Exposure.dctl
85 lines (80 loc) · 2.93 KB
/
PD-Cineon-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
// 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(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-Cineon.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;
}
// cineon color
__DEVICE__ float3 cineon_color(float3 input_rgb, int ev) {
struct CineonCurve cv = cineon_curve();
float evs = evstops(ev);
struct CineonColor colors[cineon_stops];
for (unsigned long i = 0; i < cineon_stops; i++) {
colors[i] = cineon_colors[i];
float lin = pow_f(2.0f, colors[i].stop + evs + 0.5f) * 0.18f;
float3 log = min_f3(CineonCurve_lin_cineon(cv, make_float3(lin, lin, lin)), 1.0f);
colors[i].stop = log.x;
}
float3 result = make_float3(0.0f, 0.0f, 0.0f);
float lum = luma_rec709(input_rgb);
for (unsigned long i = 0; i < cineon_stops; i++) {
if (lum <= colors[i].stop || i == (sizeof(cineon_colors) / sizeof(struct CineonColor)) - 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);
rgb = max_f3(lin_cineon(cineon_lin(rgb) * pow_f(2.0f, exposure)), 0.0f);
if (showcolors > 0) {
rgb = cineon_color(rgb, ev);
}
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 / cineon_stops;
int index = (p_X - startX) / width;
if (index >= 0 && index < cineon_stops) {
return make_float3(cineon_colors[index].r, cineon_colors[index].g, cineon_colors[index].b);
}
}
}
if (adjustdisplay) {
rgb = adjust_display(rgb);
}
return rgb;
}