87#define INVERSE_SQRT_3 0.5773502691896258f
88#define SAFETY_MARGIN 0.01f
90#define DT_GUI_CURVE_EDITOR_INSET DT_PIXEL_APPLY_DPI(1)
361 return _(
"tone mapping|curve|view transform|contrast|saturation|highlights");
367 "for display on SDR screens and paper prints\n"
368 "while preventing clipping in non-destructive ways"),
369 _(
"corrective and creative"),
370 _(
"linear or non-linear, RGB, scene-referred"),
371 _(
"non-linear, RGB"),
372 _(
"non-linear, RGB, display-referred"));
435 geometry->
grey_display = powf(CLAMP(
p->grey_point_target,
p->black_point_target,
p->white_point_target) / 100.0f,
436 1.0f /
p->output_power);
438 geometry->
grey_display = powf(0.1845f, 1.0f /
p->output_power);
440 const float dynamic_range =
p->white_point_source -
p->black_point_source;
441 geometry->
grey_log = fabsf(
p->black_point_source) / dynamic_range;
442 geometry->
black_display = powf(CLAMP(
p->black_point_target, 0.0f,
p->grey_point_target) / 100.0f,
443 1.0f /
p->output_power);
444 geometry->
white_display = powf(fmaxf(
p->white_point_target,
p->grey_point_target) / 100.0f,
445 1.0f /
p->output_power);
447 const float slope =
p->contrast * dynamic_range / 8.0f;
448 float min_contrast = 1.0f;
449 min_contrast = fmaxf(min_contrast,
451 min_contrast = fmaxf(min_contrast,
456 const float clamped_contrast = CLAMP(geometry->
contrast, min_contrast, 100.0f);
458 geometry->
contrast = clamped_contrast;
480 const float latitude = CLAMP(
p->latitude, 0.0f, 100.0f) / 100.0f;
481 const float balance = CLAMP(
p->balance, -50.0f, 50.0f) / 100.0f;
490 const float balance_correction = (balance > 0.0f)
493 nodes->
toe_log -= balance_correction;
504 float *
const toe,
float *
const shoulder)
510 *toe = CLAMP(
p->latitude, 0.0f, 100.0f);
511 *shoulder = CLAMP(
p->latitude, 0.0f, 100.0f);
515 const float toe_span = fmaxf(geometry.
grey_log - geometry.
xmin, 1e-6f);
516 const float shoulder_span = fmaxf(geometry.
xmax - geometry.
grey_log, 1e-6f);
517 *toe = CLAMP((geometry.
grey_log - nodes.
toe_log) / toe_span, 0.0f, 1.0f) * 100.0f;
518 *shoulder = CLAMP((nodes.
shoulder_log - geometry.
grey_log) / shoulder_span, 0.0f, 1.0f) * 100.0f;
522 const float toe,
const float shoulder,
523 float *
const latitude,
float *
const balance)
528 *latitude =
p->latitude;
529 *balance =
p->balance;
533 const float toe_value = CLAMP(toe, 0.0f, 100.0f) / 100.0f;
534 const float shoulder_value = CLAMP(shoulder, 0.0f, 100.0f) / 100.0f;
535 const float toe_span = fmaxf(geometry.
grey_log - geometry.
xmin, 1e-6f);
536 const float shoulder_span = fmaxf(geometry.
xmax - geometry.
grey_log, 1e-6f);
537 const float latitude_value = CLAMP((toe_span * toe_value + shoulder_span * shoulder_value)
538 / (toe_span + shoulder_span),
541 float balance_value = 0.0f;
542 if(latitude_value > 1e-6f)
544 if(toe_value > shoulder_value)
545 balance_value = 0.5f * (1.0f - shoulder_value / latitude_value);
546 else if(shoulder_value > toe_value)
547 balance_value = 0.5f * (toe_value / latitude_value - 1.0f);
550 *latitude = latitude_value * 100.0f;
551 *balance = CLAMP(balance_value, -0.5f, 0.5f) * 100.0f;
564 float grey_log = spline.
x[2];
565 float toe_log = fminf(spline.
x[1], grey_log);
566 float shoulder_log = fmaxf(spline.
x[3], grey_log);
567 float black_display = spline.
y[0];
568 float grey_display = spline.
y[2];
569 float white_display = spline.
y[4];
570 const float scaled_safety_margin =
SAFETY_MARGIN * (white_display - black_display);
571 float toe_display = fminf(spline.
y[1], grey_display);
572 float shoulder_display = fmaxf(spline.
y[3], grey_display);
574 float hardness =
n->output_power;
575 float contrast = (shoulder_display - toe_display) / (shoulder_log - toe_log);
577 float linear_intercept = grey_display - (contrast * grey_log);
578 if(toe_display < black_display + scaled_safety_margin)
580 toe_display = black_display + scaled_safety_margin;
582 toe_log = (toe_display - linear_intercept) / contrast;
584 if(shoulder_display > white_display - scaled_safety_margin)
586 shoulder_display = white_display - scaled_safety_margin;
588 shoulder_log = (shoulder_display - linear_intercept) / contrast;
591 contrast *= 8.0f / (
n->white_point_source -
n->black_point_source);
592 contrast *= hardness * powf(grey_display, hardness-1.0f);
594 const float latitude = CLAMP((shoulder_display - toe_display) / ((white_display - black_display) - 2.0f * scaled_safety_margin), 0.0f, 0.99f);
596 float toe_display_ref = latitude * (black_display + scaled_safety_margin) + (1.0f - latitude) * grey_display;
597 float shoulder_display_ref = latitude * (white_display - scaled_safety_margin) + (1.0f - latitude) * grey_display;
599 if(shoulder_display < shoulder_display_ref)
600 balance = 0.5f * (1.0f - fmaxf(shoulder_display - grey_display, 0.0f) / fmaxf(shoulder_display_ref - grey_display, 1E-5f));
602 balance = -0.5f * (1.0f - fmaxf(grey_display - toe_display, 0.0f) / fmaxf(grey_display - toe_display_ref, 1E-5f));
609 n->black_point_target = powf(black_display, hardness) * 100.0f;
610 n->white_point_target = powf(white_display, hardness) * 100.0f;
612 n->latitude = latitude * 100.0f;
613 n->contrast = contrast;
614 n->balance = balance * 100.0f;
619 const int new_version)
621 if(old_version == 1 && new_version == 5)
623 typedef struct dt_iop_filmicrgb_params_v1_t
625 float grey_point_source;
626 float black_point_source;
627 float white_point_source;
628 float security_factor;
629 float grey_point_target;
630 float black_point_target;
631 float white_point_target;
638 } dt_iop_filmicrgb_params_v1_t;
640 dt_iop_filmicrgb_params_v1_t *o = (dt_iop_filmicrgb_params_v1_t *)old_params;
646 n->grey_point_source = o->grey_point_source;
647 n->white_point_source = o->white_point_source;
648 n->black_point_source = o->black_point_source;
649 n->security_factor = o->security_factor;
650 n->grey_point_target = o->grey_point_target;
651 n->black_point_target = o->black_point_target;
652 n->white_point_target = o->white_point_target;
653 n->output_power = o->output_power;
654 n->latitude = o->latitude;
655 n->contrast = o->contrast;
656 n->saturation = o->saturation;
657 n->balance = o->balance;
658 n->preserve_color = o->preserve_color;
661 n->reconstruct_threshold
663 n->reconstruct_bloom_vs_details =
d->reconstruct_bloom_vs_details;
664 n->reconstruct_grey_vs_color =
d->reconstruct_grey_vs_color;
665 n->reconstruct_structure_vs_texture =
d->reconstruct_structure_vs_texture;
666 n->reconstruct_feather = 3.0f;
668 n->auto_hardness =
TRUE;
669 n->custom_grey =
TRUE;
670 n->high_quality_reconstruction = 0;
671 n->noise_distribution =
d->noise_distribution;
672 n->noise_level = 0.f;
674 n->compensate_icc_black =
FALSE;
678 if(old_version == 2 && new_version == 5)
680 typedef struct dt_iop_filmicrgb_params_v2_t
682 float grey_point_source;
683 float black_point_source;
684 float white_point_source;
685 float reconstruct_threshold;
686 float reconstruct_feather;
687 float reconstruct_bloom_vs_details;
688 float reconstruct_grey_vs_color;
689 float reconstruct_structure_vs_texture;
690 float security_factor;
691 float grey_point_target;
692 float black_point_target;
693 float white_point_target;
703 int high_quality_reconstruction;
706 } dt_iop_filmicrgb_params_v2_t;
708 dt_iop_filmicrgb_params_v2_t *o = (dt_iop_filmicrgb_params_v2_t *)old_params;
714 n->grey_point_source = o->grey_point_source;
715 n->white_point_source = o->white_point_source;
716 n->black_point_source = o->black_point_source;
717 n->security_factor = o->security_factor;
718 n->grey_point_target = o->grey_point_target;
719 n->black_point_target = o->black_point_target;
720 n->white_point_target = o->white_point_target;
721 n->output_power = o->output_power;
722 n->latitude = o->latitude;
723 n->contrast = o->contrast;
724 n->saturation = o->saturation;
725 n->balance = o->balance;
726 n->preserve_color = o->preserve_color;
727 n->shadows = o->shadows;
728 n->highlights = o->highlights;
729 n->reconstruct_threshold = o->reconstruct_threshold;
730 n->reconstruct_bloom_vs_details = o->reconstruct_bloom_vs_details;
731 n->reconstruct_grey_vs_color = o->reconstruct_grey_vs_color;
732 n->reconstruct_structure_vs_texture = o->reconstruct_structure_vs_texture;
733 n->reconstruct_feather = o->reconstruct_feather;
734 n->version = o->version;
735 n->auto_hardness = o->auto_hardness;
736 n->custom_grey = o->custom_grey;
737 n->high_quality_reconstruction = o->high_quality_reconstruction;
738 n->noise_level =
d->noise_level;
739 n->noise_distribution =
d->noise_distribution;
740 n->noise_level = 0.f;
742 n->compensate_icc_black =
FALSE;
746 if(old_version == 3 && new_version == 5)
748 typedef struct dt_iop_filmicrgb_params_v3_t
750 float grey_point_source;
751 float black_point_source;
752 float white_point_source;
753 float reconstruct_threshold;
754 float reconstruct_feather;
755 float reconstruct_bloom_vs_details;
757 float reconstruct_grey_vs_color;
759 float reconstruct_structure_vs_texture;
761 float security_factor;
762 float grey_point_target;
763 float black_point_target;
764 float white_point_target;
775 gboolean auto_hardness;
776 gboolean custom_grey;
777 int high_quality_reconstruction;
779 int noise_distribution;
783 } dt_iop_filmicrgb_params_v3_t;
785 dt_iop_filmicrgb_params_v3_t *o = (dt_iop_filmicrgb_params_v3_t *)old_params;
791 n->grey_point_source = o->grey_point_source;
792 n->white_point_source = o->white_point_source;
793 n->black_point_source = o->black_point_source;
794 n->security_factor = o->security_factor;
795 n->grey_point_target = o->grey_point_target;
796 n->black_point_target = o->black_point_target;
797 n->white_point_target = o->white_point_target;
798 n->output_power = o->output_power;
799 n->latitude = o->latitude;
800 n->contrast = o->contrast;
801 n->saturation = o->saturation;
802 n->balance = o->balance;
803 n->preserve_color = o->preserve_color;
804 n->shadows = o->shadows;
805 n->highlights = o->highlights;
806 n->reconstruct_threshold = o->reconstruct_threshold;
807 n->reconstruct_bloom_vs_details = o->reconstruct_bloom_vs_details;
808 n->reconstruct_grey_vs_color = o->reconstruct_grey_vs_color;
809 n->reconstruct_structure_vs_texture = o->reconstruct_structure_vs_texture;
810 n->reconstruct_feather = o->reconstruct_feather;
811 n->version = o->version;
812 n->auto_hardness = o->auto_hardness;
813 n->custom_grey = o->custom_grey;
814 n->high_quality_reconstruction = o->high_quality_reconstruction;
815 n->noise_level =
d->noise_level;
816 n->noise_distribution =
d->noise_distribution;
817 n->noise_level =
d->noise_level;
819 n->compensate_icc_black =
FALSE;
823 if(old_version == 4 && new_version == 5)
825 typedef struct dt_iop_filmicrgb_params_v4_t
827 float grey_point_source;
828 float black_point_source;
829 float white_point_source;
830 float reconstruct_threshold;
831 float reconstruct_feather;
832 float reconstruct_bloom_vs_details;
833 float reconstruct_grey_vs_color;
834 float reconstruct_structure_vs_texture;
835 float security_factor;
836 float grey_point_target;
837 float black_point_target;
838 float white_point_target;
847 gboolean auto_hardness;
848 gboolean custom_grey;
849 int high_quality_reconstruction;
853 gboolean compensate_icc_black;
854 gint internal_version;
855 } dt_iop_filmicrgb_params_v4_t;
857 dt_iop_filmicrgb_params_v4_t *o = (dt_iop_filmicrgb_params_v4_t *)old_params;
861 switch(o->internal_version)
881static inline __attribute__((always_inline))
float pixel_rgb_norm_power_simd(
const dt_aligned_pixel_simd_t pixel)
886 float numerator = 0.0f;
887 float denominator = 0.0f;
889 for(
int c = 0; c < 3; c++)
891 const float value = fabsf(pixel[c]);
893 const float RGB_cubic = RGB_square *
value;
894 numerator += RGB_cubic;
895 denominator += RGB_square;
898 return numerator / fmaxf(denominator, 1e-12f);
904 return pixel_rgb_norm_power_simd(dt_load_simd_aligned(pixel));
921 return fmaxf(fmaxf(pixel[0], pixel[1]), pixel[2]);
930 return dt_ioppr_get_rgb_matrix_luminance(
rgb, work_profile->
matrix_in, work_profile->
lut_in,
931 work_profile->unbounded_coeffs_in, work_profile->
lutsize,
935 return work_profile->
matrix_in[1][0] * pixel[0] + work_profile->
matrix_in[1][1] * pixel[1]
936 + work_profile->
matrix_in[1][2] * pixel[2];
939 return pixel[0] * 0.2225045f + pixel[1] * 0.7168786f + pixel[2] * 0.0606169f;
942 return pixel_rgb_norm_power_simd(pixel);
945 return sqrtf(sqf(pixel[0]) + sqf(pixel[1]) + sqf(pixel[2]));
948 return sqrtf(sqf(pixel[0]) + sqf(pixel[1]) + sqf(pixel[2])) *
INVERSE_SQRT_3;
957 return dt_ioppr_get_rgb_matrix_luminance(
rgb, work_profile->
matrix_in, work_profile->
lut_in,
958 work_profile->unbounded_coeffs_in, work_profile->
lutsize,
962 return work_profile->
matrix_in[1][0] * pixel[0] + work_profile->
matrix_in[1][1] * pixel[1]
963 + work_profile->
matrix_in[1][2] * pixel[2];
966 return pixel[0] * 0.2225045f + pixel[1] * 0.7168786f + pixel[2] * 0.0606169f;
975 return get_pixel_norm_simd(dt_load_simd_aligned(pixel), variant, work_profile);
980 const
float dynamic_range)
982 return clamp_simd((log2f(
x / grey) - black) / dynamic_range);
987 const
float dynamic_range)
990 return grey * exp2f(dynamic_range *
x + black);
1009 if(
x < latitude_min)
1015 result = M1[0] +
x * (M2[0] +
x * (M3[0] +
x * (M4[0] +
x * M5[0])));
1020 result = M1[0] +
x * (M2[0] +
x * (M3[0] +
x * M4[0]));
1025 const float xi = latitude_min -
x;
1026 const float rat = xi * (xi * M2[0] + 1.f);
1027 result = M4[0] - M1[0] * rat / (rat + M3[0]);
1030 else if(
x > latitude_max)
1036 result = M1[1] +
x * (M2[1] +
x * (M3[1] +
x * (M4[1] +
x * M5[1])));
1041 result = M1[1] +
x * (M2[1] +
x * (M3[1] +
x * M4[1]));
1046 const float xi =
x - latitude_max;
1047 const float rat = xi * (xi * M2[1] + 1.f);
1048 result = M4[1] + M1[1] * rat / (rat + M3[1]);
1054 result = M1[2] +
x * M2[2];
1062filmic_desaturate_v1(
const float x,
const float sigma_toe,
const float sigma_shoulder,
1063 const float saturation)
1065 const float radius_toe =
x;
1066 const float radius_shoulder = 1.0f -
x;
1068 const float key_toe = expf(-0.5f * radius_toe * radius_toe / sigma_toe);
1069 const float key_shoulder = expf(-0.5f * radius_shoulder * radius_shoulder / sigma_shoulder);
1071 return 1.0f -
clamp_simd((key_toe + key_shoulder) / saturation);
1077filmic_desaturate_v2(
const float x,
const float sigma_toe,
const float sigma_shoulder,
1078 const float saturation)
1080 const float radius_toe =
x;
1081 const float radius_shoulder = 1.0f -
x;
1082 const float sat2 = 0.5f / sqrtf(saturation);
1083 const float key_toe = expf(-radius_toe * radius_toe / sigma_toe * sat2);
1084 const float key_shoulder = expf(-radius_shoulder * radius_shoulder / sigma_shoulder * sat2);
1086 return (saturation - (key_toe + key_shoulder) * (saturation));
1097#define MAX_NUM_SCALES 10
1100 const float normalize,
const float feathering,
const size_t width,
1101 const size_t height,
const size_t ch)
1113 const float pix_max = fmaxf(sqrtf(sqf(in[
k]) + sqf(in[
k + 1]) + sqf(in[
k + 2])), 0.f);
1114 const float argument = -pix_max *
normalize + feathering;
1122 clipped += (4.f > argument);
1126 return (clipped > 9);
1129 float *
const inpainted,
const float noise_level,
const float threshold,
1138 for(
size_t j = 0; j <
width; j++)
1148 const size_t idx =
i *
width + j;
1149 const size_t index = idx * 4;
1150 const float weight = mask[idx];
1151 const float *
const restrict pix_in = __builtin_assume_aligned(in + index, 16);
1163 float *
const restrict pix_out = __builtin_assume_aligned(inpainted + index, 16);
1171 const float *
const restrict texture,
const float *
const restrict mask,
1172 float *
const restrict reconstructed,
const size_t width,
1173 const size_t height,
const size_t ch,
const float gamma,
1174 const float gamma_comp,
const float beta,
const float beta_comp,
1175 const float delta,
const size_t s,
const size_t scales)
1180 const float alpha = mask[
k /
ch];
1183 const float *
const restrict HF_c = __builtin_assume_aligned(HF +
k, 16);
1184 const float *
const restrict LF_c = __builtin_assume_aligned(LF +
k, 16);
1185 const float *
const restrict TT_c = __builtin_assume_aligned(texture +
k, 16);
1194 const float grey_details = (HF_c[0] + HF_c[1] + HF_c[2]) / 3.f;
1199 const float grey_HF = beta_comp * (gamma_comp * grey_details + gamma * grey_texture);
1203 const float grey_residual = beta_comp * (LF_c[0] + LF_c[1] + LF_c[2]) / 3.f;
1204 __OMP_SIMD__(aligned(reconstructed:64) aligned(HF_c, LF_c, TT_c:16))
1205 for(
size_t c = 0; c < 4; c++)
1212 const float details = (gamma_comp * HF_c[c] + gamma * TT_c[c]) * beta + grey_HF;
1215 const float residual = (s == scales - 1) ? (grey_residual + LF_c[c] * beta) : 0.f;
1216 reconstructed[
k + c] += alpha * (
delta * details + residual);
1223 const float *
const restrict texture,
1224 const float *
const restrict mask,
1225 float *
const restrict reconstructed,
const size_t width,
1226 const size_t height,
const size_t ch,
const float gamma,
1227 const float gamma_comp,
const float beta,
const float beta_comp,
1228 const float delta,
const size_t s,
const size_t scales)
1246 const float alpha = mask[
k /
ch];
1249 const float *
const restrict HF_c = __builtin_assume_aligned(HF +
k, 16);
1250 const float *
const restrict LF_c = __builtin_assume_aligned(LF +
k, 16);
1251 const float *
const restrict TT_c = __builtin_assume_aligned(texture +
k, 16);
1260 const float grey_details = (HF_c[0] + HF_c[1] + HF_c[2]) / 3.f;
1265 const float grey_HF = (gamma_comp * grey_details + gamma * grey_texture);
1267 for(
size_t c = 0; c < 4; c++)
1271 const float details = 0.5f * ((gamma_comp * HF_c[c] + gamma * TT_c[c]) + grey_HF);
1274 const float residual = (s == scales - 1) ? LF_c[c] : 0.f;
1275 reconstructed[
k + c] += alpha * (
delta * details + residual);
1282static inline void init_reconstruct(
const float *
const restrict in,
const float *
const restrict mask,
1283 float *
const restrict reconstructed,
const size_t width,
1292 reconstructed[4*
k + c] = fmaxf(in[4*
k + c] * (1.f - mask[
k]), 0.f);
1299 float *
const restrict HF,
float *
const restrict texture,
1304 for(
size_t c = 0; c < 4; ++c) HF[4*
k + c] = texture[4*
k + c] = detail[4*
k + c] - LF[4*
k + c];
1329 const float *
const restrict in,
const float *
const restrict mask,
1330 float *
const restrict reconstructed,
1338 const int scales =
get_scales(pipe, roi_in, piece);
1374 for(
int s = 0; s < scales; ++s)
1376 const float *restrict detail;
1378 float *restrict HF_RGB_temp;
1385 HF_RGB_temp = LF_even;
1391 HF_RGB_temp = LF_odd;
1397 HF_RGB_temp = LF_even;
1400 const int mult = 1 << s;
1415 gamma, gamma_comp, beta, beta_comp,
delta, s, scales);
1418 gamma, gamma_comp, beta, beta_comp,
delta, s, scales);
1441 const float *
const restrict pix_in = in +
k;
1442 float *
const restrict pix_out =
out +
k;
1446 for(
int c = 0; c < 3; c++)
1451 const float lum = (work_profile)
1452 ? dt_ioppr_get_rgb_matrix_luminance(temp, work_profile->
matrix_in, work_profile->
lut_in,
1453 work_profile->unbounded_coeffs_in,
1461 for(
int c = 0; c < 3; c++)
1464 spline.
M1, spline.
M2, spline.
M3, spline.
M4, spline.
M5,
1466 spline.
y[0], spline.
y[4]),
1482 const float *
const restrict pix_in = in +
k;
1483 float *
const restrict pix_out =
out +
k;
1487 for(
int c = 0; c < 3; c++)
1492 const float lum = (work_profile)
1493 ? dt_ioppr_get_rgb_matrix_luminance(temp, work_profile->
matrix_in, work_profile->
lut_in,
1494 work_profile->unbounded_coeffs_in,
1502 for(
int c = 0; c < 3; c++)
1505 spline.
M1, spline.
M2, spline.
M3, spline.
M4, spline.
M5,
1507 spline.
y[0], spline.
y[4]),
1523 const float *
const restrict pix_in = in +
k;
1524 float *
const restrict pix_out =
out +
k;
1527 float norm = fmaxf(get_pixel_norm(pix_in, variant, work_profile),
NORM_MIN);
1531 ratios[c] = pix_in[c] / norm;
1534 const float min_ratios = fminf(fminf(ratios[0], ratios[1]), ratios[2]);
1535 if(min_ratios < 0.0f)
1546 const float lum = (work_profile) ? dt_ioppr_get_rgb_matrix_luminance(
1547 ratios, work_profile->
matrix_in, work_profile->
lut_in, work_profile->unbounded_coeffs_in,
1552 for(
int c = 0; c < 3; c++) ratios[c] =
linear_saturation(ratios[c], lum, desaturation) / norm;
1556 norm = powf(
CLAMPF(filmic_spline(norm, spline.
M1, spline.
M2, spline.
M3, spline.
M4, spline.
M5,
1558 spline.
y[0], spline.
y[4]),
1578 const float *
const restrict pix_in = in +
k;
1579 float *
const restrict pix_out =
out +
k;
1581 float norm = fmaxf(get_pixel_norm(pix_in, variant, work_profile),
NORM_MIN);
1587 ratios[c] = pix_in[c] / norm;
1590 const float min_ratios = fminf(fminf(ratios[0], ratios[1]), ratios[2]);
1591 const int sanitize = (min_ratios < 0.0f);
1595 ratios[c] -= min_ratios;
1605 norm = powf(
CLAMPF(filmic_spline(norm, spline.
M1, spline.
M2, spline.
M3, spline.
M4, spline.
M5,
1607 spline.
y[0], spline.
y[4]),
1611 for(
int c = 0; c < 3; c++) ratios[c] = fmaxf(ratios[c] + (1.0f - ratios[c]) * (1.0f - desaturation), 0.0f);
1616 norm /= fmaxf(get_pixel_norm(ratios, variant, work_profile),
NORM_MIN);
1619 pix_out[c] = ratios[c] * norm;
1622 const float max_pix = fmaxf(fmaxf(pix_out[0], pix_out[1]), pix_out[2]);
1623 const int penalize = (max_pix > 1.0f);
1630 ratios[c] = fmaxf(ratios[c] + (1.0f - max_pix), 0.0f);
1631 pix_out[c] = ratios[c] * norm;
1638static inline __attribute__((always_inline)) dt_aligned_pixel_simd_t
1639pipe_RGB_to_Ych_simd(
const dt_aligned_pixel_simd_t in,
const dt_aligned_pixel_simd_t matrix0,
1640 const dt_aligned_pixel_simd_t matrix1,
const dt_aligned_pixel_simd_t matrix2)
1651 const dt_aligned_pixel_simd_t
Yrg = LMS_to_Yrg_simd(dt_mat3x4_mul_vec4(in, matrix0, matrix1, matrix2));
1652 const float r =
Yrg[1] - 0.21902143f;
1653 const float g =
Yrg[2] - 0.54371398f;
1654 const float c = dt_fast_hypotf(
g,
r);
1655 const float cos_h =
c != 0.f ?
r /
c : 1.f;
1656 const float sin_h =
c != 0.f ?
g /
c : 0.f;
1657 return (dt_aligned_pixel_simd_t){
Yrg[0],
c, cos_h, sin_h };
1661static inline __attribute__((always_inline)) dt_aligned_pixel_simd_t
1662Ych_to_pipe_RGB_simd(
const dt_aligned_pixel_simd_t in,
const dt_aligned_pixel_simd_t matrix0,
1663 const dt_aligned_pixel_simd_t matrix1,
const dt_aligned_pixel_simd_t matrix2)
1668 const dt_aligned_pixel_simd_t
Yrg = {
1670 in[1] * in[2] + 0.21902143f,
1671 in[1] * in[3] + 0.54371398f,
1674 return dt_mat3x4_mul_vec4(Yrg_to_LMS_simd(Yrg), matrix0, matrix1, matrix2);
1677static inline __attribute__((always_inline)) dt_aligned_pixel_simd_t
1678filmic_desaturate_v4(
const dt_aligned_pixel_simd_t Ych_original, dt_aligned_pixel_simd_t Ych_final,
1679 const float saturation)
1687 const float chroma_original = Ych_original[1] * Ych_original[0];
1688 float chroma_final = Ych_final[1] * Ych_final[0];
1697 const float delta_chroma = saturation * (chroma_original - chroma_final);
1699 const int filmic_brightens = (Ych_final[0] > Ych_original[0]);
1700 const int filmic_resat = (chroma_original < chroma_final);
1701 const int filmic_desat = (chroma_original > chroma_final);
1702 const int user_resat = (saturation > 0.f);
1703 const int user_desat = (saturation < 0.f);
1705 chroma_final = (filmic_brightens && filmic_resat)
1706 ? (chroma_original + chroma_final) / 2.f
1707 : ((user_resat && filmic_desat) || user_desat)
1708 ? chroma_final + delta_chroma
1711 Ych_final[1] = fmaxf(chroma_final / Ych_final[0], 0.f);
1721#define CIE_Y_1931_to_CIE_Y_2006(x) (1.05785528f * (x))
1725clip_chroma_white_raw(
const float coeffs[3],
const float target_white,
const float Y,
1726 const float cos_h,
const float sin_h)
1728 const float denominator_Y_coeff = coeffs[0] * (0.979381443298969f * cos_h + 0.391752577319588f * sin_h)
1729 + coeffs[1] * (0.0206185567010309f * cos_h + 0.608247422680412f * sin_h)
1730 - coeffs[2] * (cos_h + sin_h);
1731 const float denominator_target_term = target_white * (0.68285981628866f * cos_h + 0.482137060515464f * sin_h);
1734 if(denominator_Y_coeff == 0.f)
return FLT_MAX;
1739 const float Y_asymptote = denominator_target_term / denominator_Y_coeff;
1740 if(Y <= Y_asymptote)
return FLT_MAX;
1746 const float denominator = Y * denominator_Y_coeff - denominator_target_term;
1747 const float numerator = -0.427506877216495f
1748 * (Y * (coeffs[0] + 0.856492345150334f * coeffs[1] + 0.554995960637719f * coeffs[2])
1749 - 0.988237752433297f * target_white);
1751 return numerator / denominator;
1756clip_chroma_white(
const float coeffs[3],
const float target_white,
const float Y,
1757 const float cos_h,
const float sin_h)
1763 const float eps = 1e-3f;
1765 const float delta_Y =
MAX(max_Y - Y, 0.f);
1769 max_chroma = delta_Y / (
eps * max_Y) * clip_chroma_white_raw(coeffs, target_white, (1.f -
eps) * max_Y, cos_h, sin_h);
1773 max_chroma = clip_chroma_white_raw(coeffs, target_white, Y, cos_h, sin_h);
1775 return max_chroma >= 0.f ? max_chroma : FLT_MAX;
1780clip_chroma_black(
const float coeffs[3],
const float cos_h,
const float sin_h)
1789 const float denominator = coeffs[0] * (0.979381443298969f * cos_h + 0.391752577319588f * sin_h)
1790 + coeffs[1] * (0.0206185567010309f * cos_h + 0.608247422680412f * sin_h)
1791 - coeffs[2] * (cos_h + sin_h);
1794 if(denominator == 0.f)
return FLT_MAX;
1796 const float numerator = -0.427506877216495f * (coeffs[0] + 0.856492345150334f * coeffs[1] + 0.554995960637719f * coeffs[2]);
1797 const float max_chroma = numerator / denominator;
1798 return max_chroma >= 0.f ? max_chroma : FLT_MAX;
1803clip_chroma(
const dt_colormatrix_t matrix_out,
const float target_white,
const float Y,
1804 const float cos_h,
const float sin_h,
const float chroma)
1812 const float chroma_R_white = clip_chroma_white(matrix_out[0], target_white, Y, cos_h, sin_h);
1813 const float chroma_G_white = clip_chroma_white(matrix_out[1], target_white, Y, cos_h, sin_h);
1814 const float chroma_B_white = clip_chroma_white(matrix_out[2], target_white, Y, cos_h, sin_h);
1815 const float max_chroma_white =
MIN(
MIN(chroma_R_white, chroma_G_white), chroma_B_white);
1817 const float chroma_R_black = clip_chroma_black(matrix_out[0], cos_h, sin_h);
1818 const float chroma_G_black = clip_chroma_black(matrix_out[1], cos_h, sin_h);
1819 const float chroma_B_black = clip_chroma_black(matrix_out[2], cos_h, sin_h);
1820 const float max_chroma_black =
MIN(
MIN(chroma_R_black, chroma_G_black), chroma_B_black);
1822 return MIN(
MIN(chroma, max_chroma_black), max_chroma_white);
1826static inline __attribute__((always_inline)) dt_aligned_pixel_simd_t
1827gamut_check_Yrg_filmic_simd(
const dt_aligned_pixel_simd_t Ych)
1831 const dt_aligned_pixel_simd_t
Yrg = {
1833 Ych[1] * Ych[2] + 0.21902143f,
1834 Ych[1] * Ych[3] + 0.54371398f,
1837 float max_c = Ych[1];
1839 if(Yrg[1] < 0.f) max_c = fminf(-0.21902143f / Ych[2], max_c);
1840 if(Yrg[2] < 0.f) max_c = fminf(-0.54371398f / Ych[3], max_c);
1841 if(Yrg[1] + Yrg[2] > 1.f) max_c = fminf((1.f - 0.21902143f - 0.54371398f) / (Ych[2] + Ych[3]), max_c);
1843 return (dt_aligned_pixel_simd_t){ Ych[0], max_c, Ych[2], Ych[3] };
1847static inline __attribute__((always_inline)) dt_aligned_pixel_simd_t
1848gamut_check_RGB_simd(
const dt_colormatrix_t matrix_out,
const dt_aligned_pixel_simd_t matrix_in0,
1849 const dt_aligned_pixel_simd_t matrix_in1,
const dt_aligned_pixel_simd_t matrix_in2,
1850 const dt_aligned_pixel_simd_t matrix_out0,
const dt_aligned_pixel_simd_t matrix_out1,
1851 const dt_aligned_pixel_simd_t matrix_out2,
const float display_black,
1852 const float display_white,
const dt_aligned_pixel_simd_t Ych_in)
1856 dt_aligned_pixel_simd_t RGB_brightened = Ych_to_pipe_RGB_simd(Ych_in, matrix_out0, matrix_out1, matrix_out2);
1857 const float min_pix =
MIN(
MIN(RGB_brightened[0], RGB_brightened[1]), RGB_brightened[2]);
1858 const float black_offset =
MAX(-min_pix, 0.f);
1861 const dt_aligned_pixel_simd_t Ych_brightened
1862 = pipe_RGB_to_Ych_simd(RGB_brightened, matrix_in0, matrix_in1, matrix_in2);
1868 const float Y = CLAMP((Ych_in[0] + Ych_brightened[0]) / 2.f,
1871 const float new_chroma = clip_chroma(matrix_out, display_white, Y, Ych_in[2], Ych_in[3], Ych_in[1]);
1874 dt_aligned_pixel_simd_t RGB_out
1875 = Ych_to_pipe_RGB_simd((dt_aligned_pixel_simd_t){
Y, new_chroma, Ych_in[2], Ych_in[3] },
1876 matrix_out0, matrix_out1, matrix_out2);
1884static inline __attribute__((always_inline)) dt_aligned_pixel_simd_t
1885gamut_mapping_simd(dt_aligned_pixel_simd_t Ych_final,
const dt_aligned_pixel_simd_t Ych_original,
1886 const dt_colormatrix_t output_matrix,
const dt_aligned_pixel_simd_t input_matrix0,
1887 const dt_aligned_pixel_simd_t input_matrix1,
const dt_aligned_pixel_simd_t input_matrix2,
1888 const dt_aligned_pixel_simd_t output_matrix0,
const dt_aligned_pixel_simd_t output_matrix1,
1889 const dt_aligned_pixel_simd_t output_matrix2,
1890 const dt_colormatrix_t export_output_matrix,
const dt_aligned_pixel_simd_t export_input_matrix0,
1891 const dt_aligned_pixel_simd_t export_input_matrix1,
const dt_aligned_pixel_simd_t export_input_matrix2,
1892 const dt_aligned_pixel_simd_t export_output_matrix0,
const dt_aligned_pixel_simd_t export_output_matrix1,
1893 const dt_aligned_pixel_simd_t export_output_matrix2,
const float display_black,
1894 const float display_white,
const float saturation,
const int use_output_profile)
1897 Ych_final[2] = Ych_original[2];
1898 Ych_final[3] = Ych_original[3];
1904 Ych_final = filmic_desaturate_v4(Ych_original, Ych_final, saturation);
1905 Ych_final = gamut_check_Yrg_filmic_simd(Ych_final);
1907 if(!use_output_profile)
1911 return gamut_check_RGB_simd(output_matrix, input_matrix0, input_matrix1, input_matrix2,
1912 output_matrix0, output_matrix1, output_matrix2,
1913 display_black, display_white, Ych_final);
1918 dt_aligned_pixel_simd_t pix_out
1919 = gamut_check_RGB_simd(export_output_matrix, export_input_matrix0, export_input_matrix1, export_input_matrix2,
1920 export_output_matrix0, export_output_matrix1, export_output_matrix2,
1921 display_black, display_white, Ych_final);
1924 const dt_aligned_pixel_simd_t
LMS
1925 = dt_mat3x4_mul_vec4(pix_out, export_input_matrix0, export_input_matrix1, export_input_matrix2);
1927 return dt_mat3x4_mul_vec4(
LMS, output_matrix0, output_matrix1, output_matrix2);
1948 const int use_output_profile = (!
IS_NULL_PTR(export_profile));
1949 if(use_output_profile)
1960 return use_output_profile;
1997 simd_matrices->
input[
row] = dt_colormatrix_row_to_simd(input_matrix_t,
row);
1998 simd_matrices->
output[
row] = dt_colormatrix_row_to_simd(output_matrix_t,
row);
1999 simd_matrices->
export_input[
row] = dt_colormatrix_row_to_simd(export_input_matrix_t,
row);
2000 simd_matrices->
export_output[
row] = dt_colormatrix_row_to_simd(export_output_matrix_t,
row);
2004static inline __attribute__((always_inline)) dt_aligned_pixel_simd_t
2005norm_tone_mapping_v4_simd(
const dt_aligned_pixel_simd_t pix_in,
2010 const float norm_min,
const float norm_max)
2014 float norm =
CLAMPF(get_pixel_norm_simd(pix_in,
type, work_profile), norm_min, norm_max);
2016 const dt_aligned_pixel_simd_t ratios = pix_in /
dt_simd_set1(norm);
2022 norm = powf(
CLAMPF(filmic_spline(norm, spline.
M1, spline.
M2, spline.
M3, spline.
M4, spline.
M5,
2024 spline.
y[0], spline.
y[4]),
2031static inline __attribute__((always_inline)) dt_aligned_pixel_simd_t
2037 dt_aligned_pixel_simd_t pix_out = pix_in;
2038 for(
size_t c = 0;
c < 3;
c++)
2041 pix_out[
c] = powf(
CLAMPF(filmic_spline(mapped, spline.
M1, spline.
M2, spline.
M3, spline.
M4, spline.
M5,
2058 const float display_black,
const float display_white)
2066 const int use_output_profile = filmic_v4_prepare_matrices(input_matrix, output_matrix, export_input_matrix,
2067 export_output_matrix, work_profile, export_profile);
2076 const dt_aligned_pixel_simd_t pix_in = dt_load_simd_aligned(in +
k);
2077 const dt_aligned_pixel_simd_t pix_out
2078 = norm_tone_mapping_v4_simd(pix_in, variant, work_profile, data, spline, norm_min, norm_max);
2081 const dt_aligned_pixel_simd_t Ych_original = pipe_RGB_to_Ych_simd(pix_in, simd_matrices.
input[0],
2082 simd_matrices.
input[1], simd_matrices.
input[2]);
2083 const dt_aligned_pixel_simd_t Ych_final = pipe_RGB_to_Ych_simd(pix_out, simd_matrices.
input[0],
2084 simd_matrices.
input[1], simd_matrices.
input[2]);
2086 dt_store_simd_nontemporal(
out +
k,
2087 gamut_mapping_simd(Ych_final, Ych_original, output_matrix,
2088 simd_matrices.
input[0], simd_matrices.
input[1], simd_matrices.
input[2],
2090 export_output_matrix,
2093 display_black, display_white, data->
saturation, use_output_profile));
2106 const float display_black,
const float display_white)
2115 const int use_output_profile = filmic_v4_prepare_matrices(input_matrix, output_matrix, export_input_matrix,
2116 export_output_matrix, work_profile, export_profile);
2122 const dt_aligned_pixel_simd_t pix_in = dt_load_simd_aligned(in +
k);
2123 const dt_aligned_pixel_simd_t pix_out = RGB_tone_mapping_v4_simd(pix_in, data, spline);
2124 const dt_aligned_pixel_simd_t Ych_original = pipe_RGB_to_Ych_simd(pix_in, simd_matrices.
input[0],
2125 simd_matrices.
input[1], simd_matrices.
input[2]);
2126 dt_aligned_pixel_simd_t Ych_final = pipe_RGB_to_Ych_simd(pix_out, simd_matrices.
input[0],
2127 simd_matrices.
input[1], simd_matrices.
input[2]);
2129 Ych_final[1] = fminf(Ych_original[1], Ych_final[1]);
2131 dt_store_simd_nontemporal(
out +
k,
2132 gamut_mapping_simd(Ych_final, Ych_original, output_matrix,
2133 simd_matrices.
input[0], simd_matrices.
input[1], simd_matrices.
input[2],
2135 export_output_matrix,
2138 display_black, display_white, data->
saturation, use_output_profile));
2145static inline void filmic_v5(
const float *
const restrict in,
float *
const restrict
out,
2150 const size_t height,
const size_t ch,
const float display_black,
2151 const float display_white)
2160 const int use_output_profile = filmic_v4_prepare_matrices(input_matrix, output_matrix, export_input_matrix,
2161 export_output_matrix, work_profile, export_profile);
2170 const dt_aligned_pixel_simd_t pix_in = dt_load_simd_aligned(in +
k);
2171 const dt_aligned_pixel_simd_t naive_rgb = RGB_tone_mapping_v4_simd(pix_in, data, spline);
2172 const dt_aligned_pixel_simd_t max_rgb
2179 const dt_aligned_pixel_simd_t Ych_original = pipe_RGB_to_Ych_simd(pix_in, simd_matrices.
input[0],
2180 simd_matrices.
input[1], simd_matrices.
input[2]);
2182 dt_aligned_pixel_simd_t Ych_final = pipe_RGB_to_Ych_simd(pix_out, simd_matrices.
input[0],
2183 simd_matrices.
input[1], simd_matrices.
input[2]);
2185 Ych_final[1] = fminf(Ych_original[1], Ych_final[1]);
2187 dt_store_simd_nontemporal(
out +
k,
2188 gamut_mapping_simd(Ych_final, Ych_original, output_matrix,
2189 simd_matrices.
input[0], simd_matrices.
input[1], simd_matrices.
input[2],
2191 export_output_matrix,
2194 display_black, display_white, 0.f, use_output_profile));
2201static inline void display_mask(
const float *
const restrict mask,
float *
const restrict
out,
2214static inline void compute_ratios(
const float *
const restrict in,
float *
const restrict norms,
2215 float *
const restrict ratios,
2217 const int variant,
const size_t width,
const size_t height)
2222 const dt_aligned_pixel_simd_t pix_in = dt_load_simd_aligned(in +
k);
2223 const float norm = fmaxf(get_pixel_norm_simd(pix_in, variant, work_profile),
NORM_MIN);
2224 norms[
k / 4] = norm;
2225 dt_store_simd_nontemporal(ratios +
k, pix_in /
dt_simd_set1(norm));
2232static inline void restore_ratios(
float *
const restrict ratios,
const float *
const restrict norms,
2238 dt_aligned_pixel_simd_t ratio = dt_load_simd_aligned(ratios + 4 *
k);
2239 const float norm = norms[
k];
2244 dt_store_simd_nontemporal(ratios + 4 *
k, ratio);
2252 const int scales =
get_scales(pipe, roi_in, piece);
2253 const int max_filter_radius = (1 << scales);
2257 tiling->factor_cl = 9.0f;
2260 tiling->maxbuf_cl = 1.0f;
2262 tiling->overlap = max_filter_radius;
2270 const void *
const restrict ivoid,
2271 void *
const restrict
ovoid)
2279 const size_t ch = 4;
2290 float *restrict in = (
float *)ivoid;
2291 float *
const restrict
out = (
float *)
ovoid;
2315 if(recover_highlights &&
IS_NULL_PTR(reconstructed))
2370 data, piece, roi_in, roi_out))
2395 const float white_display = powf(data->spline.y[4], data->
output_power);
2396 const float black_display = powf(data->spline.y[0], data->
output_power);
2400 filmic_v5(in,
out, work_profile, export_profile, data, data->spline, roi_out->
width,
2401 roi_out->
height,
ch, black_display, white_display);
2445 const int devid = pipe->
devid;
2451 const int scales =
get_scales(pipe, roi_in, piece);
2464 err = CL_MEM_OBJECT_ALLOCATION_FAILURE;
2475 if(err != CL_SUCCESS)
goto error;
2493 for(
int s = 0; s < scales; ++s)
2515 const int mult = 1 << s;
2518 const int clamp_lf = 1;
2521 .yoffset = 0, .yfactor = 1,
2522 .cellsize = 4 *
sizeof(float), .overhead = 0,
2523 .sizex = 1 << 16, .sizey = 1 };
2525 hblocksize = hlocopt.
sizex;
2532 const size_t horizontal_local[3] = { hblocksize, 1, 1 };
2540 (hblocksize + 4 * mult) * 4 *
sizeof(
float), NULL);
2542 horizontal_sizes, horizontal_local);
2554 if(err != CL_SUCCESS)
goto error;
2558 .yoffset = 2 * mult, .yfactor = 1,
2559 .cellsize = 4 *
sizeof(float), .overhead = 0,
2560 .sizex = 1, .sizey = 1 << 16 };
2562 vblocksize = vlocopt.
sizey;
2569 const size_t vertical_local[3] = { 1, vblocksize, 1 };
2577 (vblocksize + 4 * mult) * 4 *
sizeof(
float), NULL);
2579 vertical_sizes, vertical_local);
2591 if(err != CL_SUCCESS)
goto error;
2601 if(err != CL_SUCCESS)
goto error;
2604 size_t origin[] = { 0, 0, 0 };
2606 if(err != CL_SUCCESS)
goto error;
2609 const int blur_size = 1;
2610 const int clamp_hf = 0;
2618 if(err != CL_SUCCESS)
goto error;
2627 if(err != CL_SUCCESS)
goto error;
2647 if(err != CL_SUCCESS)
goto error;
2668 const int devid = pipe->
devid;
2675 cl_mem inpainted = NULL;
2676 cl_mem reconstructed = NULL;
2678 cl_mem ratios = NULL;
2679 cl_mem norms = NULL;
2684 const int use_work_profile = (
IS_NULL_PTR(work_profile)) ? 0 : 1;
2692 const int use_output_profile = filmic_v4_prepare_matrices(input_matrix, output_matrix, export_input_matrix,
2693 export_output_matrix, work_profile, export_profile);
2698 float input_matrix_3x4[12];
2699 float output_matrix_3x4[12];
2705 cl_mem export_input_matrix_cl = NULL;
2706 cl_mem export_output_matrix_cl = NULL;
2708 cl_mem dev_profile_info = NULL;
2709 cl_mem dev_profile_lut = NULL;
2711 cl_float *profile_lut_cl = NULL;
2713 cl_mem clipped = NULL;
2716 &dev_profile_info, &dev_profile_lut);
2717 if(err != CL_SUCCESS)
goto error;
2719 if(use_output_profile)
2721 float export_input_matrix_3x4[12];
2722 float export_output_matrix_3x4[12];
2732 uint32_t is_clipped = 0;
2735 if(err != CL_SUCCESS)
goto error;
2747 if(err != CL_SUCCESS)
goto error;
2751 if(err != CL_SUCCESS)
goto error;
2776 const float noise_level =
d->noise_level / scale;
2787 if(err != CL_SUCCESS)
goto error;
2792 if(err != CL_SUCCESS)
goto error;
2796 if(
d->high_quality_reconstruction > 0)
2803 for(
int i = 0;
i <
d->high_quality_reconstruction;
i++)
2813 if(err != CL_SUCCESS)
goto error;
2817 if(err != CL_SUCCESS)
goto error;
2826 if(err != CL_SUCCESS)
goto error;
2844 const float white_display = powf(spline.
y[4],
d->output_power);
2845 const float black_display = powf(spline.
y[0],
d->output_power);
2884 if(err != CL_SUCCESS)
goto error;
2926 if(err != CL_SUCCESS)
goto error;
2962 const float grey = get_pixel_norm(self->
picked_color,
p->preserve_color, work_profile) / 2.0f;
2964 const float prev_grey =
p->grey_point_source;
2965 p->grey_point_source = CLAMP(100.f * grey, 0.001f, 100.0f);
2966 const float grey_var = log2f(prev_grey /
p->grey_point_source);
2967 p->black_point_source =
p->black_point_source - grey_var;
2968 p->white_point_source =
p->white_point_source + grey_var;
2969 p->output_power = logf(
p->grey_point_target / 100.0f)
2970 / logf(-
p->black_point_source / (
p->white_point_source -
p->black_point_source));
2979 gtk_widget_queue_draw(self->
widget);
2993 float EVmin = CLAMP(log2f(black / (
p->grey_point_source / 100.0f)), -16.0f, -1.0f);
2994 EVmin *= (1.0f +
p->security_factor / 100.0f);
2996 p->black_point_source = fmaxf(EVmin, -16.0f);
2997 p->output_power = logf(
p->grey_point_target / 100.0f)
2998 / logf(-
p->black_point_source / (
p->white_point_source -
p->black_point_source));
3005 gtk_widget_queue_draw(self->
widget);
3020 float EVmax = CLAMP(log2f(white / (
p->grey_point_source / 100.0f)), 1.0f, 16.0f);
3021 EVmax *= (1.0f +
p->security_factor / 100.0f);
3023 p->white_point_source = EVmax;
3024 p->output_power = logf(
p->grey_point_target / 100.0f)
3025 / logf(-
p->black_point_source / (
p->white_point_source -
p->black_point_source));
3032 gtk_widget_queue_draw(self->
widget);
3045 const float grey = get_pixel_norm(self->
picked_color,
p->preserve_color, work_profile) / 2.0f;
3046 p->grey_point_source = CLAMP(100.f * grey, 0.001f, 100.0f);
3051 float EVmax = CLAMP(log2f(white / (
p->grey_point_source / 100.0f)), 1.0f, 16.0f);
3052 EVmax *= (1.0f +
p->security_factor / 100.0f);
3056 float EVmin = CLAMP(log2f(black / (
p->grey_point_source / 100.0f)), -16.0f, -1.0f);
3057 EVmin *= (1.0f +
p->security_factor / 100.0f);
3059 p->black_point_source = fmaxf(EVmin, -16.0f);
3060 p->white_point_source = EVmax;
3061 p->output_power = logf(
p->grey_point_target / 100.0f)
3062 / logf(-
p->black_point_source / (
p->white_point_source -
p->black_point_source));
3071 gtk_widget_queue_draw(self->
widget);
3085 const float *
const restrict in = (
const float *)
i;
3087 float min_Y = INFINITY;
3088 float max_RGB = 0.0f;
3091 for(
size_t k = 0;
k < (size_t)roi_out->
width * roi_out->
height * 4;
k += 4)
3095 work_profile->unbounded_coeffs_in, work_profile->
lutsize,
3098 if(isfinite(
XYZ[1]))
3099 min_Y = fminf(min_Y,
XYZ[1]);
3101 const float pixel_max = fmaxf(in[
k], fmaxf(in[
k + 1], in[
k + 2]));
3102 if(isfinite(pixel_max))
3103 max_RGB = fmaxf(max_RGB, pixel_max);
3106 if(!isfinite(min_Y) || !isfinite(max_RGB))
return;
3108 const float grey =
p->grey_point_source / 100.0f;
3109 const float white = fmaxf(max_RGB,
NORM_MIN);
3110 const float black = fmaxf(min_Y,
NORM_MIN);
3112 float EVmax = CLAMP(log2f(white / grey), 1.0f, 16.0f);
3113 EVmax *= (1.0f +
p->security_factor / 100.0f);
3115 float EVmin = CLAMP(log2f(black / grey), -16.0f, -1.0f);
3116 EVmin *= (1.0f +
p->security_factor / 100.0f);
3118 p->black_point_source = fmaxf(EVmin, -16.0f);
3119 p->white_point_source = EVmax;
3120 p->output_power = logf(
p->grey_point_target / 100.0f)
3121 / logf(-
p->black_point_source / (
p->white_point_source -
p->black_point_source));
3128 (
void *)picker, (
void *)pipe,
3135 if(picker ==
g->grey_point_source)
3137 else if(picker ==
g->black_point_source)
3139 else if(picker ==
g->white_point_source)
3141 else if(picker ==
g->auto_button)
3149 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(self->
off),
TRUE);
3156 g->show_mask = !(
g->show_mask);
3161 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
g->show_highlight_mask),
g->show_mask);
3174 float grey_display = 0.4638f;
3175 gboolean clamping =
FALSE;
3180 grey_display = powf(CLAMP(
p->grey_point_target,
p->black_point_target,
p->white_point_target) / 100.0f,
3181 1.0f / (
p->output_power));
3186 grey_display = powf(0.1845f, 1.0f / (
p->output_power));
3189 const float white_source =
p->white_point_source;
3190 const float black_source =
p->black_point_source;
3191 const float dynamic_range = white_source - black_source;
3194 const float black_log = 0.0f;
3195 const float grey_log = fabsf(
p->black_point_source) / dynamic_range;
3196 const float white_log = 1.0f;
3199 float black_display, white_display;
3207 black_display = CLAMP(
p->black_point_target, 0.0f,
p->grey_point_target) / 100.0f;
3208 white_display = fmaxf(
p->white_point_target,
p->grey_point_target) / 100.0f;
3213 black_display = powf(CLAMP(
p->black_point_target, 0.0f,
p->grey_point_target) / 100.0f,
3214 1.0f / (
p->output_power));
3216 = powf(fmaxf(
p->white_point_target,
p->grey_point_target) / 100.0f, 1.0f / (
p->output_power));
3219 float toe_log, shoulder_log, toe_display, shoulder_display, contrast;
3220 float balance = CLAMP(
p->balance, -50.0f, 50.0f) / 100.0f;
3223 float latitude = CLAMP(
p->latitude, 0.0f, 100.0f) / 100.0f * dynamic_range;
3224 contrast = CLAMP(
p->contrast, 1.00001f, 6.0f);
3228 toe_log = grey_log - latitude / dynamic_range * fabsf(black_source / dynamic_range);
3229 shoulder_log = grey_log + latitude / dynamic_range * fabsf(white_source / dynamic_range);
3232 float linear_intercept = grey_display - (contrast * grey_log);
3235 toe_display = (toe_log * contrast + linear_intercept);
3236 shoulder_display = (shoulder_log * contrast + linear_intercept);
3239 const float norm = sqrtf(contrast * contrast + 1.0f);
3242 const float coeff = -((2.0f * latitude) / dynamic_range) * balance;
3244 toe_display +=
coeff * contrast / norm;
3245 shoulder_display +=
coeff * contrast / norm;
3246 toe_log +=
coeff / norm;
3247 shoulder_log +=
coeff / norm;
3273 spline->
x[0] = black_log;
3274 spline->
x[1] = toe_log;
3275 spline->
x[2] = grey_log;
3276 spline->
x[3] = shoulder_log;
3277 spline->
x[4] = white_log;
3279 spline->
y[0] = black_display;
3280 spline->
y[1] = toe_display;
3281 spline->
y[2] = grey_display;
3282 spline->
y[3] = shoulder_display;
3283 spline->
y[4] = white_display;
3288 spline->
type[0] =
p->shadows;
3289 spline->
type[1] =
p->highlights;
3296 const double Tl = spline->
x[1];
3297 const double Tl2 = Tl * Tl;
3298 const double Tl3 = Tl2 * Tl;
3299 const double Tl4 = Tl3 * Tl;
3301 const double Sl = spline->
x[3];
3302 const double Sl2 = Sl * Sl;
3303 const double Sl3 = Sl2 * Sl;
3304 const double Sl4 = Sl3 * Sl;
3314 spline->
M2[2] = contrast;
3315 spline->
M1[2] = spline->
y[1] - spline->
M2[2] * spline->
x[1];
3316 spline->
M3[2] = 0.f;
3317 spline->
M4[2] = 0.f;
3318 spline->
M5[2] = 0.f;
3326 Tl4, Tl3, Tl2, Tl, 1.,
3327 4. * Tl3, 3. * Tl2, 2. * Tl, 1., 0.,
3328 12. * Tl2, 6. * Tl, 2., 0., 0. };
3330 double b0[
ORDER_4] = { spline->
y[0], 0., spline->
y[1], spline->
M2[2], 0. };
3334 spline->
M5[0] = b0[0];
3335 spline->
M4[0] = b0[1];
3336 spline->
M3[0] = b0[2];
3337 spline->
M2[0] = b0[3];
3338 spline->
M1[0] = b0[4];
3345 3. * Tl2, 2. * Tl, 1., 0.,
3346 6. * Tl, 2., 0., 0. };
3348 double b0[
ORDER_3] = { spline->
y[0], spline->
y[1], spline->
M2[2], 0. };
3352 spline->
M5[0] = 0.0f;
3353 spline->
M4[0] = b0[0];
3354 spline->
M3[0] = b0[1];
3355 spline->
M2[0] = b0[2];
3356 spline->
M1[0] = b0[3];
3360 const float P1[2] = { black_log, black_display };
3361 const float P0[2] = { toe_log, toe_display };
3362 const float x = P0[0] - P1[0];
3363 const float y = P0[1] - P1[1];
3364 const float g = contrast;
3365 const float b =
g / (2.f * y) + (sqrtf(sqf(
x *
g / y + 1.f) - 4.f) - 1.f) / (2.f *
x);
3366 const float c = y /
g * (b * sqf(
x) +
x) / (b * sqf(
x) +
x - (y /
g));
3367 const float a = c *
g;
3371 spline->
M4[0] = toe_display;
3380 3. * Sl2, 2. * Sl, 1., 0.,
3381 6. * Sl, 2., 0., 0. };
3383 double b1[
ORDER_3] = { spline->
y[4], spline->
y[3], spline->
M2[2], 0. };
3387 spline->
M5[1] = 0.0f;
3388 spline->
M4[1] = b1[0];
3389 spline->
M3[1] = b1[1];
3390 spline->
M2[1] = b1[2];
3391 spline->
M1[1] = b1[3];
3398 Sl4, Sl3, Sl2, Sl, 1.,
3399 4. * Sl3, 3. * Sl2, 2. * Sl, 1., 0.,
3400 12. * Sl2, 6. * Sl, 2., 0., 0. };
3402 double b1[
ORDER_4] = { spline->
y[4], 0., spline->
y[3], spline->
M2[2], 0. };
3406 spline->
M5[1] = b1[0];
3407 spline->
M4[1] = b1[1];
3408 spline->
M3[1] = b1[2];
3409 spline->
M2[1] = b1[3];
3410 spline->
M1[1] = b1[4];
3414 const float P1[2] = { white_log, white_display };
3415 const float P0[2] = { shoulder_log, shoulder_display };
3416 const float x = P1[0] - P0[0];
3417 const float y = P1[1] - P0[1];
3418 const float g = contrast;
3419 const float b =
g / (2.f * y) + (sqrtf(sqf(
x *
g / y + 1.f) - 4.f) - 1.f) / (2.f *
x);
3420 const float c = y /
g * (b * sqf(
x) +
x) / (b * sqf(
x) +
x - (y /
g));
3421 const float a = c *
g;
3425 spline->
M4[1] = shoulder_display;
3437 float grey_source = 0.1845f, grey_display = 0.4638f;
3441 grey_source =
p->grey_point_source / 100.0f;
3442 grey_display = powf(
p->grey_point_target / 100.0f, 1.0f / (
p->output_power));
3447 grey_source = 0.1845f;
3448 grey_display = powf(0.1845f, 1.0f / (
p->output_power));
3452 const float white_source =
p->white_point_source;
3453 const float black_source =
p->black_point_source;
3454 const float dynamic_range = white_source - black_source;
3457 const float grey_log = fabsf(
p->black_point_source) / dynamic_range;
3460 float contrast =
p->contrast;
3465 contrast = 1.0001f * grey_display / grey_log;
3469 d->dynamic_range = dynamic_range;
3470 d->black_source = black_source;
3471 d->grey_source = grey_source;
3472 d->output_power =
p->output_power;
3473 d->contrast = contrast;
3474 d->version =
p->version;
3475 d->spline_version =
p->spline_version;
3476 d->preserve_color =
p->preserve_color;
3477 d->high_quality_reconstruction =
p->high_quality_reconstruction;
3478 d->noise_level =
p->noise_level;
3485 d->saturation =
p->saturation / 100.0f;
3487 d->saturation = (2.0f *
p->saturation / 100.0f + 1.0f);
3489 d->sigma_toe = powf(
d->spline.latitude_min / 3.0f, 2.0f);
3490 d->sigma_shoulder = powf((1.0f -
d->spline.latitude_max) / 3.0f, 2.0f);
3492 d->reconstruct_threshold = powf(2.0f, white_source +
p->reconstruct_threshold) * grey_source;
3493 d->reconstruct_feather = exp2f(12.f /
p->reconstruct_feather);
3496 d->normalize =
d->reconstruct_feather /
d->reconstruct_threshold;
3497 d->reconstruct_structure_vs_texture = (
p->reconstruct_structure_vs_texture / 100.0f + 1.f) / 2.f;
3498 d->reconstruct_bloom_vs_details = (
p->reconstruct_bloom_vs_details / 100.0f + 1.f) / 2.f;
3499 d->reconstruct_grey_vs_color = (
p->reconstruct_grey_vs_color / 100.0f + 1.f) / 2.f;
3509 gint mask_was_shown =
g->show_mask;
3511 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
g->show_highlight_mask),
FALSE);
3533 float shoulder = 0.0f;
3550 &
p->latitude, &
p->balance);
3564 g->gui_show_labels =
dt_conf_get_int(
"plugins/darkroom/filmicrgb/graph_show_labels");
3566 g->gui_sizes_inited =
FALSE;
3570 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
g->auto_hardness),
p->auto_hardness);
3571 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
g->custom_grey),
p->custom_grey);
3582 d->white_point_source =
module->so->get_f("white_point_source")->Float.Default;
3583 d->output_power =
module->so->get_f("output_power")->Float.Default;
3598 d->white_point_source = exposure + 2.45f;
3599 d->black_point_source =
d->white_point_source - 12.f;
3600 d->output_power = logf(
d->grey_point_target / 100.0f)
3601 / logf(-
d->black_point_source / (
d->white_point_source -
d->black_point_source));
3603 module->workflow_enabled = TRUE;
3605 dt_iop_fmt_log(module,
"reload_defaults: class=%s needs_rawprepare=%d -> workflow_enabled=%d white=%.3f black=%.3f",
3608 d->white_point_source,
d->black_point_source);
3614 const int program = 22;
3629 const int wavelets = 35;
3666 double destination_y, gboolean show_head)
3668 cairo_move_to(cr, origin_x, origin_y);
3669 cairo_line_to(cr, destination_x, destination_y);
3675 const float angle_arrow = 45.f / 360.f *
M_PI;
3676 const float angle_trunk = atan2f((destination_y - origin_y), (destination_x - origin_x));
3679 const float x_1 = destination_x + radius / sinf(angle_arrow + angle_trunk);
3680 const float y_1 = destination_y + radius / cosf(angle_arrow + angle_trunk);
3682 const float x_2 = destination_x - radius / sinf(-angle_arrow + angle_trunk);
3683 const float y_2 = destination_y - radius / cosf(-angle_arrow + angle_trunk);
3685 cairo_move_to(cr, x_1, y_1);
3686 cairo_line_to(cr, destination_x, destination_y);
3687 cairo_line_to(cr, x_2, y_2);
3695 if(!
g->gui_sizes_inited)
return;
3710 cairo_set_source_rgba(cr, color.red, color.green, color.blue, color.alpha);
3715 cairo_set_source_rgba(cr, color.red, color.green, color.blue, color.alpha * 0.5);
3725 const float scale = 0.85;
3726 cairo_scale(cr, scale, scale);
3727 button->
icon(cr, -scale * button->
w / 2., -scale * button->
h / 2., scale * button->
w, scale * button->
h, 0, NULL);
3740 gtk_widget_get_allocation(widget, &
g->allocation);
3742 cairo_surface_t *cst =
3744 PangoFontDescription *desc =
3746 cairo_t *cr = cairo_create(cst);
3747 PangoLayout *layout = pango_cairo_create_layout(cr);
3749 pango_layout_set_font_description(layout, desc);
3751 g->context = gtk_widget_get_style_context(widget);
3756 const gint font_size = pango_font_description_get_size(desc);
3757 pango_font_description_set_size(desc, 0.95 * font_size);
3758 pango_layout_set_font_description(layout, desc);
3761 g_strlcpy(text,
"X",
sizeof(text));
3762 pango_layout_set_text(layout, text, -1);
3763 pango_layout_get_pixel_extents(layout, &
g->ink, NULL);
3764 g->line_height =
g->ink.height;
3767 g_strlcpy(text,
"-",
sizeof(text));
3768 pango_layout_set_text(layout, text, -1);
3769 pango_layout_get_pixel_extents(layout, &
g->ink, NULL);
3770 g->sign_width =
g->ink.width / 2.0;
3773 g_strlcpy(text,
"0",
sizeof(text));
3774 pango_layout_set_text(layout, text, -1);
3775 pango_layout_get_pixel_extents(layout, &
g->ink, NULL);
3776 g->zero_width =
g->ink.width;
3782 float margin_bottom;
3783 if(
g->gui_show_labels)
3786 margin_left = 3. *
g->zero_width + 2. *
g->inset;
3787 margin_bottom = 2. *
g->line_height + 4. *
g->inset;
3791 margin_left =
g->inset;
3792 margin_bottom =
g->inset;
3795 const float margin_top = 2. *
g->line_height +
g->inset;
3798 g->graph_width =
g->allocation.width - margin_right - margin_left;
3799 g->graph_height =
g->allocation.height - margin_bottom - margin_top;
3801 gtk_render_background(
g->context, cr, 0, 0,
g->allocation.width,
g->allocation.height);
3807 g->buttons[
i].right =
g->allocation.width;
3811 g->buttons[
i].w =
g->buttons[
i].right -
g->buttons[
i].left;
3812 g->buttons[
i].h =
g->buttons[
i].bottom -
g->buttons[
i].top;
3813 g->buttons[
i].state = GTK_STATE_FLAG_NORMAL;
3816 g->gui_sizes_inited =
TRUE;
3826 const float grey =
p->grey_point_source / 100.f;
3827 const float DR =
p->white_point_source -
p->black_point_source;
3830 cairo_translate(cr, margin_left, margin_top);
3832 cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND);
3835 pango_font_description_set_size(desc, font_size);
3836 pango_layout_set_font_description(layout, desc);
3838 g_strlcpy(text, _(
"look only"),
sizeof(text));
3840 g_strlcpy(text, _(
"look + mapping (lin)"),
sizeof(text));
3842 g_strlcpy(text, _(
"look + mapping (log)"),
sizeof(text));
3844 g_strlcpy(text, _(
"dynamic range mapping"),
sizeof(text));
3846 pango_layout_set_text(layout, text, -1);
3847 pango_layout_get_pixel_extents(layout, &
g->ink, NULL);
3851 cairo_rectangle(cr,
g->allocation.width - margin_left -
g->ink.width -
g->ink.x - 2. *
g->inset,
3852 -
g->line_height -
g->inset - 0.5 *
g->ink.height -
g->ink.y -
g->inset,
3853 g->ink.width + 3. *
g->inset,
g->ink.height + 2. *
g->inset);
3858 cairo_move_to(cr,
g->allocation.width - margin_left -
g->ink.width -
g->ink.x -
g->inset,
3859 -
g->line_height -
g->inset - 0.5 *
g->ink.height -
g->ink.y);
3860 pango_cairo_show_layout(cr, layout);
3864 pango_font_description_set_size(desc, 0.95 * font_size);
3865 pango_layout_set_font_description(layout, desc);
3871 cairo_rectangle(cr, 0, 0,
g->graph_width,
g->graph_height);
3873 cairo_fill_preserve(cr);
3883 cairo_scale(cr, 1., -1.);
3884 cairo_translate(cr, 0., -
g->graph_height);
3895 cairo_move_to(cr, 0,
g->graph_height);
3896 cairo_line_to(cr,
g->graph_width, 0);
3902 const float saturation = (2.0f *
p->saturation / 100.0f + 1.0f);
3903 const float sigma_toe = powf(
g->spline.latitude_min / 3.0f, 2.0f);
3904 const float sigma_shoulder = powf((1.0f -
g->spline.latitude_max) / 3.0f, 2.0f);
3906 cairo_set_source_rgb(cr, .5, .5, .5);
3916 cairo_move_to(cr, 0,
3917 g->graph_height * (1.0 - filmic_desaturate_v1(0.0f, sigma_toe, sigma_shoulder, saturation)));
3918 for(
int k = 1;
k < 256;
k++)
3920 float x =
k / 255.0;
3921 const float y = filmic_desaturate_v1(
x, sigma_toe, sigma_shoulder, saturation);
3928 cairo_line_to(cr,
x *
g->graph_width,
g->graph_height * (1.0 - y));
3933 cairo_move_to(cr, 0,
3934 g->graph_height * (1.0 - filmic_desaturate_v2(0.0f, sigma_toe, sigma_shoulder, saturation)));
3935 for(
int k = 1;
k < 256;
k++)
3937 float x =
k / 255.0;
3938 const float y = filmic_desaturate_v2(
x, sigma_toe, sigma_shoulder, saturation);
3945 cairo_line_to(cr,
x *
g->graph_width,
g->graph_height * (1.0 - y));
3951 float x_start = 0.f;
3957 float y_start =
clamp_simd(filmic_spline(x_start,
g->spline.M1,
g->spline.M2,
g->spline.M3,
g->spline.M4,
3958 g->spline.M5,
g->spline.latitude_min,
g->spline.latitude_max,
g->spline.type));
3961 y_start = powf(y_start,
p->output_power);
3965 cairo_move_to(cr, 0,
g->graph_height * (1.0 - y_start));
3967 for(
int k = 1;
k < 256;
k++)
3971 float x = powf(
k / 255.0f, 2.4f);
3979 float y = filmic_spline(
value,
g->spline.M1,
g->spline.M2,
g->spline.M3,
g->spline.M4,
g->spline.M5,
3980 g->spline.latitude_min,
g->spline.latitude_max,
g->spline.type);
3988 const float margin = 1
E-5;
3989 if(y >
g->spline.y[4] + margin)
3992 cairo_set_source_rgb(cr, 0.75, .5, 0.);
3994 else if(y < g->spline.
y[0] - margin)
3997 cairo_set_source_rgb(cr, 0.75, .5, 0.);
4005 y = powf(y,
p->output_power);
4009 cairo_line_to(cr,
x *
g->graph_width,
g->graph_height * (1.0 - y));
4011 cairo_move_to(cr,
x *
g->graph_width,
g->graph_height * (1.0 - y));
4023 float x_grey =
g->spline.x[2];
4024 float y_grey =
g->spline.y[2];
4029 y_grey = powf(y_grey,
p->output_power);
4037 cairo_set_source_rgb(cr, 0.75, 0.5, 0.0);
4038 cairo_arc(cr, x_grey *
g->graph_width, (1.0 - y_grey) *
g->graph_height,
DT_PIXEL_APPLY_DPI(6), 0,
4044 float x_black = 0.f;
4045 float y_black = 0.f;
4047 float x_white = 1.f;
4048 float y_white = 1.f;
4050 const float central_slope = (
g->spline.y[3] -
g->spline.y[1]) *
g->graph_width / ((
g->spline.x[3] -
g->spline.x[1]) *
g->graph_height);
4051 const float central_slope_angle = atanf(central_slope) +
M_PI / 2.0f;
4053 for(
int k = 0;
k < 5;
k++)
4057 float x =
g->spline.x[
k];
4058 float y =
g->spline.y[
k];
4059 const float ymin =
g->spline.y[0];
4060 const float ymax =
g->spline.y[4];
4062 const float y_margin =
SAFETY_MARGIN * 1.1f * (ymax - ymin);
4063 gboolean red = (((
k == 1) && (y - ymin <= y_margin))
4064 || ((
k == 3) && (ymax - y <= y_margin)));
4065 float start_angle = 0.0f;
4066 float end_angle = 2.f *
M_PI;
4069 if(contrast_clamped)
4073 start_angle = central_slope_angle +
M_PI;
4074 end_angle = central_slope_angle;
4078 start_angle = central_slope_angle;
4079 end_angle = start_angle +
M_PI;
4086 y = powf(y,
p->output_power);
4106 if(red) cairo_set_source_rgb(cr, 0.8, 0.35, 0.35);
4109 cairo_arc(cr,
x *
g->graph_width, (1.0 - y) *
g->graph_height,
DT_PIXEL_APPLY_DPI(4), start_angle, end_angle);
4119 if(
g->gui_show_labels)
4122 const float x_legend_top =
g->graph_height + 0.5 *
g->line_height;
4126 snprintf(text,
sizeof(text),
"%.0f",
p->grey_point_target);
4127 pango_layout_set_text(layout, text, -1);
4128 pango_layout_get_pixel_extents(layout, &
g->ink, NULL);
4129 cairo_move_to(cr, -2. *
g->inset -
g->ink.width -
g->ink.x,
4130 (1.0 - y_grey) *
g->graph_height - 0.5 *
g->ink.height -
g->ink.y);
4131 pango_cairo_show_layout(cr, layout);
4137 snprintf(text,
sizeof(text),
"%+.1f", 0.f);
4139 snprintf(text,
sizeof(text),
"%.0f",
p->grey_point_source);
4141 pango_layout_set_text(layout, text, -1);
4142 pango_layout_get_pixel_extents(layout, &
g->ink, NULL);
4143 cairo_move_to(cr, x_grey *
g->graph_width - 0.5 *
g->ink.width -
g->ink.x, x_legend_top);
4144 pango_cairo_show_layout(cr, layout);
4149 snprintf(text,
sizeof(text),
"%.0f",
p->black_point_target);
4150 pango_layout_set_text(layout, text, -1);
4151 pango_layout_get_pixel_extents(layout, &
g->ink, NULL);
4152 cairo_move_to(cr, -2. *
g->inset -
g->ink.width -
g->ink.x,
4153 (1.0 - y_black) *
g->graph_height - 0.5 *
g->ink.height -
g->ink.y);
4154 pango_cairo_show_layout(cr, layout);
4159 snprintf(text,
sizeof(text),
"%.0f",
p->white_point_target);
4160 pango_layout_set_text(layout, text, -1);
4161 pango_layout_get_pixel_extents(layout, &
g->ink, NULL);
4162 cairo_move_to(cr, -2. *
g->inset -
g->ink.width -
g->ink.x,
4163 (1.0 - y_white) *
g->graph_height - 0.5 *
g->ink.height -
g->ink.y);
4164 pango_cairo_show_layout(cr, layout);
4170 snprintf(text,
sizeof(text),
"%+.1f",
p->black_point_source);
4172 snprintf(text,
sizeof(text),
"%.0f", exp2f(
p->black_point_source) *
p->grey_point_source);
4174 pango_layout_set_text(layout, text, -1);
4175 pango_layout_get_pixel_extents(layout, &
g->ink, NULL);
4176 cairo_move_to(cr, x_black *
g->graph_width - 0.5 *
g->ink.width -
g->ink.x, x_legend_top);
4177 pango_cairo_show_layout(cr, layout);
4183 snprintf(text,
sizeof(text),
"%+.1f",
p->white_point_source);
4187 snprintf(text,
sizeof(text),
"%.0f \342\206\222", 100.f);
4189 snprintf(text,
sizeof(text),
"%.0f", exp2f(
p->white_point_source) *
p->grey_point_source);
4192 pango_layout_set_text(layout, text, -1);
4193 pango_layout_get_pixel_extents(layout, &
g->ink, NULL);
4195 fminf(x_white, 1.f) *
g->graph_width - 0.5 *
g->ink.width -
g->ink.x
4196 + 2. * (x_white > 1.f) *
g->sign_width,
4198 pango_cairo_show_layout(cr, layout);
4207 PangoStyle backup = pango_font_description_get_style(desc);
4208 pango_font_description_set_style(desc, PANGO_STYLE_ITALIC);
4209 pango_layout_set_font_description(layout, desc);
4211 snprintf(text,
sizeof(text), _(
"(%.0f %%)"), exp2f(
p->white_point_source) *
p->grey_point_source);
4212 pango_layout_set_text(layout, text, -1);
4213 pango_layout_get_pixel_extents(layout, &
g->ink, NULL);
4214 cairo_move_to(cr,
g->allocation.width -
g->ink.width -
g->ink.x - margin_left,
4215 g->graph_height + 3. *
g->inset +
g->line_height -
g->ink.y);
4216 pango_cairo_show_layout(cr, layout);
4220 pango_font_description_set_style(desc, backup);
4221 pango_layout_set_font_description(layout, desc);
4227 g_strlcpy(text, _(
"% display"),
sizeof(text));
4228 pango_layout_set_text(layout, text, -1);
4229 pango_layout_get_pixel_extents(layout, &
g->ink, NULL);
4230 cairo_move_to(cr, -2. *
g->inset -
g->zero_width -
g->ink.x,
4231 -
g->line_height -
g->inset - 0.5 *
g->ink.height -
g->ink.y);
4232 pango_cairo_show_layout(cr, layout);
4239 g_strlcpy(text, _(
"EV scene"),
sizeof(text));
4243 g_strlcpy(text, _(
"% camera"),
sizeof(text));
4245 pango_layout_set_text(layout, text, -1);
4246 pango_layout_get_pixel_extents(layout, &
g->ink, NULL);
4247 cairo_move_to(cr, 0.5 *
g->graph_width - 0.5 *
g->ink.width -
g->ink.x,
4248 g->graph_height + 3. *
g->inset +
g->line_height -
g->ink.y);
4249 pango_cairo_show_layout(cr, layout);
4256 cairo_identity_matrix(cr);
4262 const float display_DR = 12.f + log2f(
p->white_point_target / 100.f);
4264 const float y_display =
g->allocation.height / 3.f +
g->line_height;
4265 const float y_scene = 2. *
g->allocation.height / 3.f +
g->line_height;
4267 const float display_top = y_display -
g->line_height / 2;
4268 const float display_bottom = display_top +
g->line_height;
4270 const float scene_top = y_scene -
g->line_height / 2;
4271 const float scene_bottom = scene_top +
g->line_height;
4275 if(
g->gui_show_labels)
4279 g_strlcpy(text, _(
"display"),
sizeof(text));
4280 pango_layout_set_text(layout, text, -1);
4281 pango_layout_get_pixel_extents(layout, &
g->ink, NULL);
4282 cairo_move_to(cr, 0., y_display - 0.5 *
g->ink.height -
g->ink.y);
4283 pango_cairo_show_layout(cr, layout);
4285 const float display_label_width =
g->ink.width;
4288 g_strlcpy(text, _(
"(%)"),
sizeof(text));
4289 pango_layout_set_text(layout, text, -1);
4290 pango_layout_get_pixel_extents(layout, &
g->ink, NULL);
4291 cairo_move_to(cr, 0.5 * display_label_width - 0.5 *
g->ink.width -
g->ink.x,
4292 display_top - 4. *
g->inset -
g->ink.height -
g->ink.y);
4293 pango_cairo_show_layout(cr, layout);
4297 g_strlcpy(text, _(
"scene"),
sizeof(text));
4298 pango_layout_set_text(layout, text, -1);
4299 pango_layout_get_pixel_extents(layout, &
g->ink, NULL);
4300 cairo_move_to(cr, 0., y_scene - 0.5 *
g->ink.height -
g->ink.y);
4301 pango_cairo_show_layout(cr, layout);
4303 const float scene_label_width =
g->ink.width;
4306 g_strlcpy(text, _(
"(EV)"),
sizeof(text));
4307 pango_layout_set_text(layout, text, -1);
4308 pango_layout_get_pixel_extents(layout, &
g->ink, NULL);
4309 cairo_move_to(cr, 0.5 * scene_label_width - 0.5 *
g->ink.width -
g->ink.x,
4310 scene_bottom + 2. *
g->inset + 0. *
g->ink.height +
g->ink.y);
4311 pango_cairo_show_layout(cr, layout);
4316 dt_cairo_draw_arrow(cr, fminf(scene_label_width, display_label_width) / 2.f, y_scene -
g->line_height,
4317 fminf(scene_label_width, display_label_width) / 2.f,
4318 y_display +
g->line_height +
g->inset,
TRUE);
4320 column_left = fmaxf(display_label_width, scene_label_width) +
g->inset;
4328 const float display_HL_EV = -log2f(
p->grey_point_target /
p->white_point_target);
4329 const float display_LL_EV = display_DR - display_HL_EV;
4330 const float display_real_black_EV
4331 = -fmaxf(log2f(
p->black_point_target /
p->grey_point_target),
4332 -11.685887601778058f + display_HL_EV - log2f(
p->white_point_target / 100.f));
4333 const float scene_HL_EV =
p->white_point_source;
4334 const float scene_LL_EV = -
p->black_point_source;
4337 const float max_DR = ceilf(fmaxf(display_HL_EV, scene_HL_EV)) + ceilf(fmaxf(display_LL_EV, scene_LL_EV));
4338 const float EV = (column_right) / max_DR;
4342 const float grey_EV = fmaxf(ceilf(display_HL_EV), ceilf(scene_HL_EV));
4346 const float display_black_x = grey_x - display_real_black_EV * EV;
4347 const float display_DR_start_x = grey_x - display_LL_EV * EV;
4348 const float display_white_x = grey_x + display_HL_EV * EV;
4350 const float scene_black_x = grey_x - scene_LL_EV * EV;
4351 const float scene_white_x = grey_x + scene_HL_EV * EV;
4352 const float scene_lat_bottom = grey_x + (
g->spline.x[1] -
g->spline.x[2]) * EV * DR;
4353 const float scene_lat_top = grey_x + (
g->spline.x[3] -
g->spline.x[2]) * EV * DR;
4361 float display_lat_bottom = filmic_spline(
g->spline.latitude_min,
g->spline.M1,
g->spline.M2,
g->spline.M3,
g->spline.M4,
4362 g->spline.M5,
g->spline.latitude_min,
g->spline.latitude_max,
g->spline.type);
4363 display_lat_bottom = powf(fmaxf(display_lat_bottom,
NORM_MIN),
p->output_power);
4366 display_lat_bottom = log2f(display_lat_bottom/ (
p->grey_point_target / 100.f));
4369 if(display_lat_bottom < 0.f)
4370 display_lat_bottom = fmaxf(display_lat_bottom, -display_real_black_EV);
4371 else if(display_lat_bottom > 0.f)
4372 display_lat_bottom = fminf(display_lat_bottom, display_HL_EV);
4375 display_lat_bottom = grey_x + display_lat_bottom * EV;
4378 float display_lat_top = filmic_spline(
g->spline.latitude_max,
g->spline.M1,
g->spline.M2,
g->spline.M3,
g->spline.M4,
4379 g->spline.M5,
g->spline.latitude_min,
g->spline.latitude_max,
g->spline.type);
4380 display_lat_top = powf(fmaxf(display_lat_top,
NORM_MIN),
p->output_power);
4383 display_lat_top = log2f(display_lat_top / (
p->grey_point_target / 100.f));
4386 if(display_lat_top < 0.f)
4387 display_lat_top = fmaxf(display_lat_top, -display_real_black_EV);
4388 else if(display_lat_top > 0.f)
4389 display_lat_top = fminf(display_lat_top, display_HL_EV);
4392 display_lat_top = grey_x + display_lat_top * EV;
4394 cairo_move_to(cr, scene_lat_bottom, scene_top);
4395 cairo_line_to(cr, scene_lat_top, scene_top);
4396 cairo_line_to(cr, display_lat_top, display_bottom);
4397 cairo_line_to(cr, display_lat_bottom, display_bottom);
4398 cairo_line_to(cr, scene_lat_bottom, scene_top);
4402 for(
int i = 0;
i < (int)ceilf(display_DR);
i++)
4405 const float shade = powf(exp2f(-11.f + (
float)
i), 1.f / 2.4f);
4406 cairo_set_source_rgb(cr, shade, shade, shade);
4407 cairo_rectangle(cr, display_DR_start_x +
i * EV, display_top, EV,
g->line_height);
4408 cairo_fill_preserve(cr);
4411 cairo_set_source_rgb(cr, 0.75, .5, 0.);
4417 cairo_move_to(cr, grey_x, display_bottom + 2. *
g->inset);
4418 cairo_line_to(cr, grey_x, display_top - 2. *
g->inset);
4423 for(
int i = floorf(
p->black_point_source);
i < ceilf(
p->white_point_source);
i++)
4427 const float shade = powf(0.1845f * exp2f((
float)
i), 1.f / 2.4f);
4428 const float x_temp = grey_x +
i * EV;
4429 cairo_set_source_rgb(cr, shade, shade, shade);
4430 cairo_rectangle(cr, x_temp, scene_top, EV,
g->line_height);
4431 cairo_fill_preserve(cr);
4434 cairo_set_source_rgb(cr, 0.75, .5, 0.);
4443 if((
float)
i >
p->black_point_source && (
float)i < p->white_point_source)
4446 const float normal_value = ((float)
i -
p->black_point_source) / DR;
4447 float y_temp = filmic_spline(normal_value,
g->spline.M1,
g->spline.M2,
g->spline.M3,
g->spline.M4,
4448 g->spline.M5,
g->spline.latitude_min,
g->spline.latitude_max,
g->spline.type);
4449 y_temp = powf(fmaxf(y_temp,
NORM_MIN),
p->output_power);
4452 y_temp = log2f(y_temp / (
p->grey_point_target / 100.f));
4456 y_temp = fmaxf(y_temp, -display_real_black_EV);
4457 else if(y_temp > 0.f)
4458 y_temp = fminf(y_temp, display_HL_EV);
4461 y_temp = grey_x + y_temp * EV;
4469 float x_temp = grey_x +
p->black_point_source * EV;
4470 float y_temp = grey_x - display_real_black_EV * EV;
4473 x_temp = grey_x +
p->white_point_source * EV;
4474 y_temp = grey_x + display_HL_EV * EV;
4480 cairo_move_to(cr, display_black_x, display_bottom);
4481 cairo_line_to(cr, display_black_x, display_top - 2. *
g->inset);
4485 cairo_move_to(cr, grey_x, display_bottom);
4486 cairo_line_to(cr, grey_x, display_top - 2. *
g->inset);
4490 cairo_move_to(cr, display_white_x, display_bottom);
4491 cairo_line_to(cr, display_white_x, display_top - 2. *
g->inset);
4495 cairo_move_to(cr, scene_black_x, scene_bottom + 2. *
g->inset);
4496 cairo_line_to(cr, scene_black_x, scene_top);
4500 cairo_move_to(cr, grey_x, scene_bottom + 2. *
g->inset);
4501 cairo_line_to(cr, grey_x, scene_top);
4505 cairo_move_to(cr, scene_white_x, scene_bottom + 2. *
g->inset);
4506 cairo_line_to(cr, scene_white_x, scene_top);
4513 snprintf(text,
sizeof(text),
"%+.1f",
p->black_point_source);
4514 pango_layout_set_text(layout, text, -1);
4515 pango_layout_get_pixel_extents(layout, &
g->ink, NULL);
4516 cairo_move_to(cr, scene_black_x - 0.5 *
g->ink.width -
g->ink.x,
4517 scene_bottom + 2. *
g->inset + 0. *
g->ink.height +
g->ink.y);
4518 pango_cairo_show_layout(cr, layout);
4522 snprintf(text,
sizeof(text),
"%+.1f", 0.f);
4523 pango_layout_set_text(layout, text, -1);
4524 pango_layout_get_pixel_extents(layout, &
g->ink, NULL);
4525 cairo_move_to(cr, grey_x - 0.5 *
g->ink.width -
g->ink.x,
4526 scene_bottom + 2. *
g->inset + 0. *
g->ink.height +
g->ink.y);
4527 pango_cairo_show_layout(cr, layout);
4531 snprintf(text,
sizeof(text),
"%+.1f",
p->white_point_source);
4532 pango_layout_set_text(layout, text, -1);
4533 pango_layout_get_pixel_extents(layout, &
g->ink, NULL);
4534 cairo_move_to(cr, scene_white_x - 0.5 *
g->ink.width -
g->ink.x,
4535 scene_bottom + 2. *
g->inset + 0. *
g->ink.height +
g->ink.y);
4536 pango_cairo_show_layout(cr, layout);
4540 snprintf(text,
sizeof(text),
"%.0f",
p->black_point_target);
4541 pango_layout_set_text(layout, text, -1);
4542 pango_layout_get_pixel_extents(layout, &
g->ink, NULL);
4543 cairo_move_to(cr, display_black_x - 0.5 *
g->ink.width -
g->ink.x,
4544 display_top - 4. *
g->inset -
g->ink.height -
g->ink.y);
4545 pango_cairo_show_layout(cr, layout);
4549 snprintf(text,
sizeof(text),
"%.0f",
p->grey_point_target);
4550 pango_layout_set_text(layout, text, -1);
4551 pango_layout_get_pixel_extents(layout, &
g->ink, NULL);
4552 cairo_move_to(cr, grey_x - 0.5 *
g->ink.width -
g->ink.x,
4553 display_top - 4. *
g->inset -
g->ink.height -
g->ink.y);
4554 pango_cairo_show_layout(cr, layout);
4558 snprintf(text,
sizeof(text),
"%.0f",
p->white_point_target);
4559 pango_layout_set_text(layout, text, -1);
4560 pango_layout_get_pixel_extents(layout, &
g->ink, NULL);
4561 cairo_move_to(cr, display_white_x - 0.5 *
g->ink.width -
g->ink.x,
4562 display_top - 4. *
g->inset -
g->ink.height -
g->ink.y);
4563 pango_cairo_show_layout(cr, layout);
4568 pango_font_description_set_size(desc, font_size);
4569 pango_layout_set_font_description(layout, desc);
4572 cairo_set_source_surface(crf, cst, 0, 0);
4574 cairo_surface_destroy(cst);
4575 g_object_unref(layout);
4576 pango_font_description_free(desc);
4592 if(event->button == 1 && event->type == GDK_2BUTTON_PRESS)
4598 gtk_widget_queue_draw(GTK_WIDGET(
g->area));
4607 else if(event->button == 1)
4618 gtk_widget_queue_draw(GTK_WIDGET(
g->area));
4624 g->gui_show_labels = !
g->gui_show_labels;
4625 gtk_widget_queue_draw(GTK_WIDGET(
g->area));
4626 dt_conf_set_int(
"plugins/darkroom/filmicrgb/graph_show_labels",
g->gui_show_labels);
4636 else if(event->button == 3)
4646 gtk_widget_queue_draw(GTK_WIDGET(
g->area));
4652 g->gui_show_labels = !
g->gui_show_labels;
4653 gtk_widget_queue_draw(GTK_WIDGET(
g->area));
4654 dt_conf_set_int(
"plugins/darkroom/filmicrgb/graph_show_labels",
g->gui_show_labels);
4674 g->gui_hover =
TRUE;
4675 gtk_widget_queue_draw(GTK_WIDGET(
g->area));
4688 gtk_widget_queue_draw(GTK_WIDGET(
g->area));
4698 if(!
g->gui_sizes_inited)
return FALSE;
4701 const float y =
event->y;
4702 const float x =
event->x;
4704 if(
x > 0. && x < g->allocation.width && y > 0. && y < g->allocation.height)
g->gui_hover =
TRUE;
4706 gint save_active_button =
g->active_button;
4711 gint found_something =
FALSE;
4715 if(
x >
g->buttons[
i].left && x < g->buttons[
i].right && y >
g->buttons[
i].top && y < g->buttons[
i].bottom)
4718 g->buttons[
i].mouse_hover =
TRUE;
4719 g->active_button =
i;
4720 found_something =
TRUE;
4725 g->buttons[
i].mouse_hover =
FALSE;
4735 gtk_widget_set_tooltip_text(GTK_WIDGET(
g->area), _(
"use the parameters below to set the nodes.\n"
4736 "the bright curve is the filmic tone mapping curve\n"
4737 "the dark curve is the desaturation curve."));
4741 gtk_widget_set_tooltip_text(GTK_WIDGET(
g->area), _(
"toggle axis labels and values display"));
4745 gtk_widget_set_tooltip_text(GTK_WIDGET(
g->area), _(
"cycle through graph views.\n"
4746 "left click: cycle forward.\n"
4747 "right click: cycle backward.\n"
4748 "double-click: reset to look view."));
4752 gtk_widget_set_tooltip_text(GTK_WIDGET(
g->area),
"");
4755 if(save_active_button !=
g->active_button) gtk_widget_queue_draw(GTK_WIDGET(
g->area));
4761 if(save_active_button !=
g->active_button) (GTK_WIDGET(
g->area));
4778 g->gui_show_labels =
TRUE;
4780 g->gui_sizes_inited =
FALSE;
4783 g->area = GTK_DRAWING_AREA(gtk_drawing_area_new());
4784 gtk_widget_set_hexpand(GTK_WIDGET(
g->area),
TRUE);
4785 g_object_set_data(G_OBJECT(
g->area),
"iop-instance", self);
4787 gtk_widget_set_can_focus(GTK_WIDGET(
g->area),
TRUE);
4788 gtk_widget_add_events(GTK_WIDGET(
g->area), GDK_BUTTON_PRESS_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK
4791 g_signal_connect(G_OBJECT(
g->area),
"button-press-event", G_CALLBACK(
area_button_press), self);
4792 g_signal_connect(G_OBJECT(
g->area),
"leave-notify-event", G_CALLBACK(
area_leave_notify), self);
4793 g_signal_connect(G_OBJECT(
g->area),
"enter-notify-event", G_CALLBACK(
area_enter_notify), self);
4794 g_signal_connect(G_OBJECT(
g->area),
"motion-notify-event", G_CALLBACK(
area_motion_notify), self);
4803 g->grey_point_source
4807 gtk_widget_set_tooltip_text(
g->grey_point_source,
4808 _(
"adjust to match the average luminance of the image's subject.\n"
4809 "the value entered here will then be remapped to 18.45%.\n"
4810 "decrease the value to increase the overall brightness."));
4813 g->white_point_source
4817 gtk_widget_set_tooltip_text(
g->white_point_source,
4818 _(
"number of stops between middle gray and pure white.\n"
4819 "this is a reading a lightmeter would give you on the scene.\n"
4820 "adjust so highlights clipping is avoided"));
4823 g->black_point_source
4827 gtk_widget_set_tooltip_text(
4828 g->black_point_source, _(
"number of stops between middle gray and pure black.\n"
4829 "this is a reading a lightmeter would give you on the scene.\n"
4830 "increase to get more contrast.\ndecrease to recover more details in low-lights."));
4836 gtk_widget_set_tooltip_text(
g->security_factor, _(
"symmetrically enlarge or shrink the computed dynamic range.\n"
4837 "useful to give a safety margin to extreme luminances."));
4843 gtk_box_pack_start(GTK_BOX(hbox),
g->auto_button,
FALSE,
FALSE, 0);
4845 gtk_widget_set_tooltip_text(
g->auto_button, _(
"try to optimize the settings with some statistical assumptions.\n"
4846 "this will fit the luminance range inside the histogram bounds.\n"
4847 "works better for landscapes and evenly-lit pictures\n"
4848 "but fails for high-keys, low-keys and high-ISO pictures.\n"
4849 "this is not an artificial intelligence, but a simple guess.\n"
4850 "ensure you understand its assumptions before using it."));
4857 gtk_widget_set_tooltip_text(
g->custom_grey, _(
"enable to input custom middle-gray values.\n"
4858 "this is not recommended in general.\n"
4859 "fix the global exposure in the exposure module instead.\n"
4860 "disable to use standard 18.45 %% middle gray."));
4870 gtk_widget_set_tooltip_text(
g->reconstruct_threshold,
4871 _(
"set the exposure threshold upon which\n"
4872 "clipped highlights get reconstructed.\n"
4873 "values are relative to the scene white point.\n"
4874 "0 EV means the threshold is the same as the scene white point.\n"
4875 "decrease to include more areas,\n"
4876 "increase to exclude more areas."));
4880 gtk_widget_set_tooltip_text(
g->reconstruct_feather,
4881 _(
"soften the transition between clipped highlights and valid pixels.\n"
4882 "decrease to make the transition harder and sharper,\n"
4883 "increase to make the transition softer and blurrier."));
4887 gtk_box_pack_start(GTK_BOX(hbox),
dt_ui_label_new(_(
"display highlight reconstruction mask")),
TRUE,
TRUE, 0);
4900 gtk_widget_set_tooltip_text(
g->reconstruct_structure_vs_texture,
4902 _(
"decide which reconstruction strategy to favor,\n"
4903 "between inpainting a smooth color gradient,\n"
4904 "or trying to recover the textured details.\n"
4905 "0% is an equal mix of both.\n"
4906 "increase if at least one RGB channel is not clipped.\n"
4907 "decrease if all RGB channels are clipped over large areas."));
4911 gtk_widget_set_tooltip_text(
g->reconstruct_bloom_vs_details,
4913 _(
"decide which reconstruction strategy to favor,\n"
4914 "between blooming highlights like film does,\n"
4915 "or trying to recover sharp details.\n"
4916 "0% is an equal mix of both.\n"
4917 "increase if you want more details.\n"
4918 "decrease if you want more blur."));
4923 gtk_widget_set_tooltip_text(
g->reconstruct_grey_vs_color,
4925 _(
"decide which reconstruction strategy to favor,\n"
4926 "between recovering monochromatic highlights,\n"
4927 "or trying to recover colorful highlights.\n"
4928 "0% is an equal mix of both.\n"
4929 "increase if you want more color.\n"
4930 "decrease if you see magenta or out-of-gamut highlights."));
4937 gtk_widget_set_tooltip_text(
g->high_quality_reconstruction,
4938 _(
"run extra passes of chromaticity reconstruction.\n"
4939 "more iterations means more color propagation from neighbourhood.\n"
4940 "this will be slower but will yield more neutral highlights.\n"
4941 "it also helps with difficult cases of magenta highlights."));
4945 gtk_widget_set_tooltip_text(
g->noise_level, _(
"add statistical noise in reconstructed highlights.\n"
4946 "this avoids highlights to look too smooth\n"
4947 "when the picture is noisy overall,\n"
4948 "so they blend with the rest of the picture."));
4952 gtk_widget_set_tooltip_text(
g->noise_distribution, _(
"choose the statistical distribution of noise.\n"
4953 "this is useful to match natural sensor noise pattern.\n"));
4964 gtk_widget_set_tooltip_text(
g->contrast, _(
"slope of the linear part of the curve\n"
4965 "affects mostly the mid-tones"));
4969 gtk_widget_set_tooltip_text(
g->output_power, _(
"equivalent to paper grade in analog.\n"
4970 "increase to make highlights brighter and less compressed.\n"
4971 "decrease to mute highlights."));
4978 gtk_widget_set_tooltip_text(
g->toe,
4979 _(
"distance between middle gray and the start of the shadows roll-off.\n"
4980 "0% keeps the toe at middle gray, 100% pushes it to the point where the\n"
4981 "current slope would hit the output black level."));
4989 gtk_widget_set_tooltip_text(
g->shoulder,
4990 _(
"distance between middle gray and the start of the highlights roll-off.\n"
4991 "0% keeps the shoulder at middle gray, 100% pushes it to the point where the\n"
4992 "current slope would hit the output white level."));
4997 gtk_widget_set_tooltip_text(
g->highlights, _(
"choose the desired curvature of the filmic spline in highlights.\n"
4998 "hard uses a high curvature resulting in more tonal compression.\n"
4999 "soft uses a low curvature resulting in less tonal compression."));
5002 gtk_widget_set_tooltip_text(
g->shadows, _(
"choose the desired curvature of the filmic spline in shadows.\n"
5003 "hard uses a high curvature resulting in more tonal compression.\n"
5004 "soft uses a low curvature resulting in less tonal compression."));
5012 gtk_widget_set_tooltip_text(
g->saturation, _(
"desaturates the output of the module\n"
5013 "specifically at extreme luminances.\n"
5014 "increase if shadows and/or highlights are under-saturated."));
5017 gtk_widget_set_tooltip_text(
g->preserve_color, _(
"ensure the original color are preserved.\n"
5018 "may reinforce chromatic aberrations and chroma noise,\n"
5019 "so ensure they are properly corrected elsewhere.\n"));
5026 gtk_widget_set_tooltip_text(
g->version,
5027 _(
"v3 is darktable 3.0 desaturation method, same as color balance.\n"
5028 "v4 is a newer desaturation method, based on spectral purity of light."));
5032 gtk_widget_set_tooltip_text(
5033 g->auto_hardness, _(
"enable to auto-set the look hardness depending on the scene white and black points.\n"
5034 "this keeps the middle gray on the identity line and improves fast tuning.\n"
5035 "disable if you want a manual control."));
5044 gtk_widget_set_tooltip_text(
g->black_point_target, _(
"luminance of output pure black, "
5045 "this should be 0%\nexcept if you want a faded look"));
5050 gtk_widget_set_tooltip_text(
g->grey_point_target,
5051 _(
"middle gray value of the target display or color space.\n"
5052 "you should never touch that unless you know what you are doing."));
5058 gtk_widget_set_tooltip_text(
g->white_point_target, _(
"luminance of output pure white, "
5059 "this should be 100%\nexcept if you want a faded look"));
5064 gtk_box_pack_start(GTK_BOX(self->
widget),
5066 "plugins/darkroom/filmicrgb/graphheight", 230, 100),
5068 gtk_box_pack_start(GTK_BOX(self->
widget), GTK_WIDGET(
g->notebook),
FALSE,
FALSE, 0);
5076 if(
IS_NULL_PTR(w) || w ==
g->auto_hardness || w ==
g->security_factor || w ==
g->grey_point_source
5077 || w ==
g->black_point_source || w ==
g->white_point_source)
5081 if(w ==
g->security_factor || w ==
g->grey_point_source)
5083 float prev = *(
float *)previous;
5084 if(w ==
g->security_factor)
5086 float ratio = (
p->security_factor - prev) / (prev + 100.0f);
5088 float EVmin =
p->black_point_source;
5089 EVmin = EVmin + ratio * EVmin;
5091 float EVmax =
p->white_point_source;
5092 EVmax = EVmax + ratio * EVmax;
5094 p->white_point_source = EVmax;
5095 p->black_point_source = EVmin;
5099 float grey_var = log2f(prev /
p->grey_point_source);
5100 p->black_point_source =
p->black_point_source - grey_var;
5101 p->white_point_source =
p->white_point_source + grey_var;
5108 if(
p->auto_hardness)
5109 p->output_power = logf(
p->grey_point_target / 100.0f)
5110 / logf(-
p->black_point_source / (
p->white_point_source -
p->black_point_source));
5112 gtk_widget_set_visible(GTK_WIDGET(
g->output_power), !
p->auto_hardness);
5123 gtk_widget_set_tooltip_text(
g->saturation, _(
"desaturates the output of the module\n"
5124 "specifically at extreme luminances.\n"
5125 "increase if shadows and/or highlights are under-saturated."));
5130 gtk_widget_set_tooltip_text(
g->saturation, _(
"desaturates the output of the module\n"
5131 "specifically at medium luminances.\n"
5132 "increase if midtones are under-saturated."));
5137 gtk_widget_set_tooltip_text(
g->saturation, _(
"Positive values ensure saturation is kept unchanged over the whole range.\n"
5138 "Negative values bleache highlights at constant hue and luminance.\n"
5139 "Zero is an equal mix of both strategies."));
5140 gtk_widget_set_visible(GTK_WIDGET(
g->preserve_color),
FALSE);
5144 gtk_widget_set_visible(GTK_WIDGET(
g->preserve_color),
TRUE);
5148 if(
IS_NULL_PTR(w) || w ==
g->reconstruct_bloom_vs_details)
5150 if(
p->reconstruct_bloom_vs_details == -100.f)
5155 gtk_widget_set_sensitive(
g->reconstruct_structure_vs_texture,
FALSE);
5159 gtk_widget_set_sensitive(
g->reconstruct_structure_vs_texture,
TRUE);
5165 gtk_widget_set_visible(
g->grey_point_source,
p->custom_grey);
5166 gtk_widget_set_visible(
g->grey_point_target,
p->custom_grey);
5170 gtk_widget_queue_draw(GTK_WIDGET(
g->area));
static void error(char *msg)
void dt_bauhaus_slider_set_soft_range(GtkWidget *widget, float soft_min, float soft_max)
void dt_bauhaus_slider_set_digits(GtkWidget *widget, int val)
float dt_bauhaus_slider_get(GtkWidget *widget)
void dt_bauhaus_slider_set_soft_max(GtkWidget *widget, float val)
void dt_bauhaus_slider_set(GtkWidget *widget, float pos)
void dt_bauhaus_widget_set_label(GtkWidget *widget, const char *label)
GtkWidget * dt_bauhaus_slider_new_with_range(dt_bauhaus_t *bh, dt_gui_module_t *self, float min, float max, float step, float defval, int digits)
void dt_bauhaus_slider_set_format(GtkWidget *widget, const char *format)
static void set_color(cairo_t *cr, GdkRGBA color)
static __DT_CLONE_TARGETS__ void normalize(float *const buffer, const size_t width, const size_t height, const float norm)
static void blur_2D_Bspline(const float *const restrict in, float *const restrict out, float *const restrict tempbuf, const size_t width, const size_t height, const int mult, const gboolean clip_negatives)
const dt_colormatrix_t XYZ_D65_to_D50_CAT16
static const dt_aligned_pixel_simd_t const dt_adaptation_t const float p
return vector dt_simd_set1(valid ?(scaling+NORM_MIN) :NORM_MIN)
static float dt_camera_rgb_luminance(const float4 rgb)
void dt_iop_color_picker_reset(dt_iop_module_t *module, gboolean keep)
GtkWidget * dt_color_picker_new(dt_iop_module_t *module, dt_iop_color_picker_kind_t kind, GtkWidget *w)
static dt_aligned_pixel_t rgb
static const float const float const float min
static dt_aligned_pixel_t XYZ
const dt_colormatrix_t dt_aligned_pixel_t out
dt_store_simd_aligned(out, dt_mat3x4_mul_vec4(vin, dt_colormatrix_row_to_simd(matrix, 0), dt_colormatrix_row_to_simd(matrix, 1), dt_colormatrix_row_to_simd(matrix, 2)))
typedef void((*dt_cache_allocate_t)(void *userdata, dt_cache_entry_t *entry))
dt_image_pipe_class_t dt_image_pipe_class(const dt_image_t *img)
const char * dt_image_pipe_class_name(const dt_image_pipe_class_t klass)
float dt_image_get_exposure_bias(const struct dt_image_t *image_storage)
gboolean dt_image_needs_rawprepare(const dt_image_t *img)
void dt_conf_set_int(const char *name, int val)
int dt_conf_get_int(const char *name)
void dt_print(dt_debug_thread_t thread, const char *msg,...)
#define dt_free_align(ptr)
static void * dt_calloc_align(size_t size)
#define __OMP_SIMD__(...)
#define for_each_channel(_var,...)
#define dt_pixelpipe_cache_alloc_align_float_cache(pixels, id)
float dt_aligned_pixel_simd_t __attribute__((vector_size(16), aligned(16)))
Enable aggressive floating-point arithmetic optimizations, in denormals handling. Set through user pr...
#define DT_MODULE_INTROSPECTION(MODVER, PARAMSTYPE)
#define __OMP_DECLARE_SIMD__(...)
#define dt_pixelpipe_cache_free_align(mem)
#define dt_pixelpipe_cache_alloc_align_float(pixels, pipe)
#define __DT_CLONE_TARGETS__
#define __OMP_PARALLEL_FOR__(...)
static const dt_aligned_pixel_simd_t value
#define __OMP_PARALLEL_FOR_SIMD__(...)
#define IS_NULL_PTR(p)
C is way too permissive with !=, == and if(var) checks, which can mean too many things depending on w...
static float4 dt_noise_generator_simd(const dt_noise_distribution_t distribution, const float4 mu, const float4 param, uint state[4])
static unsigned int splitmix32(const unsigned long seed)
static float xoshiro128plus(uint state[4])
#define dt_dev_add_history_item(dev, module, enable, redraw)
#define dt_dev_pixelpipe_update_history_main(dev)
@ DT_DEV_PIXELPIPE_DISPLAY_MASK
@ DT_DEV_PIXELPIPE_DISPLAY_PASSTHRU
@ DT_DEV_PIXELPIPE_DISPLAY_NONE
static float dt_log_scale_axis(const float x, const float base)
static void dt_draw_grid(cairo_t *cr, const int num, const int left, const int top, const int right, const int bottom)
static void dt_draw_loglog_grid(cairo_t *cr, const int num, const int left, const int top, const int right, const int bottom, const float base)
void dtgtk_cairo_paint_refresh(cairo_t *cr, gint x, gint y, gint w, gint h, gint flags, void *data)
void dtgtk_cairo_paint_showmask(cairo_t *cr, gint x, gint y, gint w, gint h, gint flags, void *data)
void dtgtk_cairo_paint_text_label(cairo_t *cr, gint x, gint y, gint w, gint h, gint flags, void *data)
void(* DTGTKCairoPaintIconFunc)(cairo_t *cr, gint x, gint y, gint w, gint h, gint flags, void *data)
static void weight(const float *c1, const float *c2, const float sharpen, dt_aligned_pixel_t weight)
static void toe_shoulder_callback(GtkWidget *slider, gpointer user_data)
static gboolean area_button_press(GtkWidget *widget, GdkEventButton *event, gpointer user_data)
static gboolean area_scroll_callback(GtkWidget *widget, GdkEventScroll *event, gpointer user_data)
const char ** description(struct dt_iop_module_t *self)
static gboolean area_leave_notify(GtkWidget *widget, GdkEventCrossing *event, gpointer user_data)
static __DT_CLONE_TARGETS__ void display_mask(const float *const restrict mask, float *const restrict out, const size_t width, const size_t height)
dt_iop_filmic_noise_distribution_t
@ DT_FILMIC_NOISE_UNIFORM
@ DT_FILMIC_NOISE_POISSONIAN
@ DT_FILMIC_NOISE_GAUSSIAN
dt_iop_filmicrgb_curve_type_t
@ DT_FILMIC_CURVE_RATIONAL
void gui_reset(dt_iop_module_t *self)
void filmic_gui_draw_icon(cairo_t *cr, struct dt_iop_filmicrgb_gui_button_data_t *button, struct dt_iop_filmicrgb_gui_data_t *g)
static gboolean dt_iop_tonecurve_draw(GtkWidget *widget, cairo_t *crf, gpointer user_data)
dt_iop_filmic_rgb_gui_mode_t
@ DT_FILMIC_GUI_BASECURVE
@ DT_FILMIC_GUI_BASECURVE_LOG
static __DT_CLONE_TARGETS__ void filmic_split_v1(const float *const restrict in, float *const restrict out, const dt_iop_order_iccprofile_info_t *const work_profile, const dt_iop_filmicrgb_data_t *const data, const dt_iop_filmic_rgb_spline_t spline, const size_t width, const size_t height)
void reload_defaults(dt_iop_module_t *module)
static __DT_CLONE_TARGETS__ void wavelets_reconstruct_RGB(const float *const restrict HF, const float *const restrict LF, const float *const restrict texture, const float *const restrict mask, float *const restrict reconstructed, const size_t width, const size_t height, const size_t ch, const float gamma, const float gamma_comp, const float beta, const float beta_comp, const float delta, const size_t s, const size_t scales)
dt_iop_filmicrgb_colorscience_type_t
@ DT_FILMIC_COLORSCIENCE_V1
@ DT_FILMIC_COLORSCIENCE_V2
@ DT_FILMIC_COLORSCIENCE_V5
@ DT_FILMIC_COLORSCIENCE_V4
@ DT_FILMIC_COLORSCIENCE_V3
__DT_CLONE_TARGETS__ int process(dt_iop_module_t *self, const dt_dev_pixelpipe_t *pipe, const dt_dev_pixelpipe_iop_t *piece, const void *const restrict ivoid, void *const restrict ovoid)
void gui_update(dt_iop_module_t *self)
Refresh GUI controls from current params and configuration.
static void dt_cairo_draw_arrow(cairo_t *cr, double origin_x, double origin_y, double destination_x, double destination_y, gboolean show_head)
static void apply_auto_grey(dt_iop_module_t *self, const dt_iop_order_iccprofile_info_t *const work_profile)
static __DT_CLONE_TARGETS__ void filmic_chroma_v2_v3(const float *const restrict in, float *const restrict out, const dt_iop_order_iccprofile_info_t *const work_profile, const dt_iop_filmicrgb_data_t *const data, const dt_iop_filmic_rgb_spline_t spline, const int variant, const size_t width, const size_t height, const size_t ch, const dt_iop_filmicrgb_colorscience_type_t colorscience_version)
static void apply_auto_black(dt_iop_module_t *self, const dt_iop_order_iccprofile_info_t *const work_profile)
static __DT_CLONE_TARGETS__ void wavelets_reconstruct_ratios(const float *const restrict HF, const float *const restrict LF, const float *const restrict texture, const float *const restrict mask, float *const restrict reconstructed, const size_t width, const size_t height, const size_t ch, const float gamma, const float gamma_comp, const float beta, const float beta_comp, const float delta, const size_t s, const size_t scales)
void gui_focus(struct dt_iop_module_t *self, gboolean in)
static cl_int reconstruct_highlights_cl(const dt_dev_pixelpipe_t *pipe, cl_mem in, cl_mem mask, cl_mem reconstructed, const dt_iop_filmicrgb_reconstruction_type_t variant, dt_iop_filmicrgb_global_data_t *const gd, const dt_iop_filmicrgb_data_t *const data, const dt_dev_pixelpipe_iop_t *piece, const dt_iop_roi_t *const roi_in)
#define CIE_Y_1931_to_CIE_Y_2006(x)
static __DT_CLONE_TARGETS__ void filmic_chroma_v4(const float *const restrict in, float *const restrict out, const dt_iop_order_iccprofile_info_t *const work_profile, const dt_iop_order_iccprofile_info_t *const export_profile, const dt_iop_filmicrgb_data_t *const data, const dt_iop_filmic_rgb_spline_t spline, const int variant, const size_t width, const size_t height, const size_t ch, const dt_iop_filmicrgb_colorscience_type_t colorscience_version, const float display_black, const float display_white)
static __DT_CLONE_TARGETS__ void filmic_chroma_v1(const float *const restrict in, float *const restrict out, const dt_iop_order_iccprofile_info_t *const work_profile, const dt_iop_filmicrgb_data_t *const data, const dt_iop_filmic_rgb_spline_t spline, const int variant, const size_t width, const size_t height)
static __DT_CLONE_TARGETS__ void filmic_split_v4(const float *const restrict in, float *const restrict out, const dt_iop_order_iccprofile_info_t *const work_profile, const dt_iop_order_iccprofile_info_t *const export_profile, const dt_iop_filmicrgb_data_t *const data, const dt_iop_filmic_rgb_spline_t spline, const int variant, const size_t width, const size_t height, const size_t ch, const dt_iop_filmicrgb_colorscience_type_t colorscience_version, const float display_black, const float display_white)
void gui_init(dt_iop_module_t *self)
dt_iop_filmicrgb_methods_type_t
@ DT_FILMIC_METHOD_POWER_NORM
@ DT_FILMIC_METHOD_EUCLIDEAN_NORM_V1
@ DT_FILMIC_METHOD_MAX_RGB
@ DT_FILMIC_METHOD_EUCLIDEAN_NORM_V2
@ DT_FILMIC_METHOD_LUMINANCE
static __DT_CLONE_TARGETS__ void filmic_split_v2_v3(const float *const restrict in, float *const restrict out, const dt_iop_order_iccprofile_info_t *const work_profile, const dt_iop_filmicrgb_data_t *const data, const dt_iop_filmic_rgb_spline_t spline, const size_t width, const size_t height)
static float log_tonemapping(const float x, const float grey, const float black, const float dynamic_range)
dt_iop_filmicrgb_reconstruction_type_t
@ DT_FILMIC_RECONSTRUCT_RATIOS
@ DT_FILMIC_RECONSTRUCT_RGB
static void filmic_v3_legacy_to_direct(const dt_iop_filmicrgb_params_t *const p, float *const toe, float *const shoulder)
void gui_changed(dt_iop_module_t *self, GtkWidget *w, void *previous)
dt_iop_filmicrgb_gui_button_t
@ DT_FILMIC_GUI_BUTTON_LAST
@ DT_FILMIC_GUI_BUTTON_LABELS
@ DT_FILMIC_GUI_BUTTON_TYPE
void tiling_callback(struct dt_iop_module_t *self, const struct dt_dev_pixelpipe_t *pipe, const struct dt_dev_pixelpipe_iop_t *piece, struct dt_develop_tiling_t *tiling)
static __DT_CLONE_TARGETS__ int get_scales(const dt_dev_pixelpipe_t *const pipe, const dt_iop_roi_t *roi_in, const dt_dev_pixelpipe_iop_t *const piece)
static int reconstruct_highlights(const dt_dev_pixelpipe_t *const pipe, const float *const restrict in, const float *const restrict mask, float *const restrict reconstructed, const dt_iop_filmicrgb_reconstruction_type_t variant, const size_t ch, const dt_iop_filmicrgb_data_t *const data, const dt_dev_pixelpipe_iop_t *piece, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out)
void commit_params(dt_iop_module_t *self, dt_iop_params_t *p1, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece)
static void apply_auto_white_point_source(dt_iop_module_t *self, const dt_iop_order_iccprofile_info_t *const work_profile)
static float exp_tonemapping_v2(const float x, const float grey, const float black, const float dynamic_range)
void cleanup_global(dt_iop_module_so_t *module)
static void filmic_prepare_simd_matrices(const dt_colormatrix_t input_matrix, const dt_colormatrix_t output_matrix, const dt_colormatrix_t export_input_matrix, const dt_colormatrix_t export_output_matrix, dt_iop_filmicrgb_simd_matrices_t *const simd_matrices)
static gboolean area_enter_notify(GtkWidget *widget, GdkEventCrossing *event, gpointer user_data)
void cleanup_pipe(dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece)
static __DT_CLONE_TARGETS__ gint mask_clipped_pixels(const float *const restrict in, float *const restrict mask, const float normalize, const float feathering, const size_t width, const size_t height, const size_t ch)
int default_colorspace(dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, const dt_dev_pixelpipe_iop_t *piece)
void input_format(dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece, dt_iop_buffer_dsc_t *dsc)
static gboolean area_motion_notify(GtkWidget *widget, GdkEventMotion *event, gpointer user_data)
static void inpaint_noise(const float *const in, const float *const mask, float *const inpainted, const float noise_level, const float threshold, const dt_noise_distribution_t noise_distribution, const size_t width, const size_t height)
static void apply_autotune(dt_iop_module_t *self, const dt_iop_order_iccprofile_info_t *const work_profile)
static __DT_CLONE_TARGETS__ void filmic_v5(const float *const restrict in, float *const restrict out, const dt_iop_order_iccprofile_info_t *const work_profile, const dt_iop_order_iccprofile_info_t *const export_profile, const dt_iop_filmicrgb_data_t *const data, const dt_iop_filmic_rgb_spline_t spline, const size_t width, const size_t height, const size_t ch, const float display_black, const float display_white)
static gboolean filmic_v3_compute_geometry(const dt_iop_filmicrgb_params_t *const p, dt_iop_filmicrgb_v3_geometry_t *const geometry)
static void show_mask_callback(GtkToggleButton *button, GdkEventButton *event, gpointer user_data)
static __DT_CLONE_TARGETS__ void wavelets_detail_level(const float *const restrict detail, const float *const restrict LF, float *const restrict HF, float *const restrict texture, const size_t width, const size_t height, const size_t ch)
static void convert_to_spline_v3(dt_iop_filmicrgb_params_t *n)
static __DT_CLONE_TARGETS__ void compute_ratios(const float *const restrict in, float *const restrict norms, float *const restrict ratios, const dt_iop_order_iccprofile_info_t *const work_profile, const int variant, const size_t width, const size_t height)
static void filmic_v3_direct_to_legacy(const dt_iop_filmicrgb_params_t *const p, const float toe, const float shoulder, float *const latitude, float *const balance)
dt_iop_filmicrgb_spline_version_type_t
@ DT_FILMIC_SPLINE_VERSION_V2
@ DT_FILMIC_SPLINE_VERSION_V3
@ DT_FILMIC_SPLINE_VERSION_V1
void init_pipe(dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece)
static void filmic_gui_sync_toe_shoulder(dt_iop_module_t *self)
void init_global(dt_iop_module_so_t *module)
void autoset(struct dt_iop_module_t *self, const struct dt_dev_pixelpipe_t *pipe, const struct dt_dev_pixelpipe_iop_t *piece, const void *i)
static gboolean filmic_v3_compute_nodes_from_legacy(const dt_iop_filmicrgb_params_t *const p, dt_iop_filmicrgb_v3_geometry_t *const geometry, dt_iop_filmicrgb_v3_nodes_t *const nodes)
int process_cl(struct dt_iop_module_t *self, const dt_dev_pixelpipe_t *pipe, const dt_dev_pixelpipe_iop_t *piece, cl_mem dev_in, cl_mem dev_out)
static __DT_CLONE_TARGETS__ void init_reconstruct(const float *const restrict in, const float *const restrict mask, float *const restrict reconstructed, const size_t width, const size_t height)
void color_picker_apply(dt_iop_module_t *self, GtkWidget *picker, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece)
static float linear_saturation(const float x, const float luminance, const float saturation)
static gboolean dt_iop_filmic_rgb_compute_spline(const dt_iop_filmicrgb_params_t *const p, struct dt_iop_filmic_rgb_spline_t *const spline)
static __DT_CLONE_TARGETS__ void restore_ratios(float *const restrict ratios, const float *const restrict norms, const size_t width, const size_t height)
int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, void *new_params, const int new_version)
static int gauss_solve(double *A, double *b, int n)
GtkWidget * dt_ui_resizable_drawing_area(GtkWidget *area, char *config_str, int default_height, int min_height)
Make a self-drawing widget (typically a GtkDrawingArea graph or scope) vertically resizable.
GtkWidget * dt_ui_notebook_page(GtkNotebook *notebook, const char *text, const char *tooltip)
GtkNotebook * dt_ui_notebook_new()
void dt_gui_set_pango_resolution(PangoLayout *layout)
void dt_gui_add_class(GtkWidget *widget, const gchar *class_name)
static cairo_surface_t * dt_cairo_image_surface_create(cairo_format_t format, int width, int height)
static GtkWidget * dt_ui_section_label_new(const gchar *str)
#define DT_GUI_BOX_SPACING
#define DT_PIXEL_APPLY_DPI(value)
static GtkWidget * dt_ui_label_new(const gchar *str)
void dt_iop_request_focus(dt_iop_module_t *module)
const char ** dt_iop_set_description(dt_iop_module_t *module, const char *main_text, const char *purpose, const char *input, const char *process, const char *output)
float dt_dev_get_module_scale(const dt_dev_pixelpipe_t *const pipe, const dt_iop_roi_t *const roi_in)
void dt_iop_set_cache_bypass(dt_iop_module_t *module, gboolean state)
#define dt_omploop_sfence()
#define dt_iop_fmt_log(module, fmt,...)
Debug helper to trace a module's input-format-driven decisions on the -d pipe channel (DT_DEBUG_PIPE)...
@ IOP_FLAGS_INCLUDE_IN_STYLES
@ IOP_FLAGS_SUPPORTS_BLENDING
#define IOP_GUI_ALLOC(module)
GtkWidget * dt_iop_togglebutton_new(dt_iop_module_t *self, const char *section, const gchar *label, const gchar *ctrl_label, GCallback callback, gboolean local, guint accel_key, GdkModifierType mods, DTGTKCairoPaintIconFunc paint, GtkWidget *box)
GtkWidget * dt_bauhaus_toggle_from_params(dt_iop_module_t *self, const char *param)
GtkWidget * dt_bauhaus_slider_from_params(dt_iop_module_t *self, const char *param)
GtkWidget * dt_bauhaus_combobox_from_params(dt_iop_module_t *self, const char *param)
dt_iop_order_iccprofile_info_t * dt_ioppr_get_pipe_output_profile_info(const struct dt_dev_pixelpipe_t *pipe)
dt_iop_order_iccprofile_info_t * dt_ioppr_get_pipe_work_profile_info(const struct dt_dev_pixelpipe_t *pipe)
dt_iop_order_iccprofile_info_t * dt_ioppr_get_pipe_current_profile_info(dt_iop_module_t *module, const struct dt_dev_pixelpipe_t *pipe)
void dt_ioppr_free_iccprofile_params_cl(dt_colorspaces_iccprofile_info_cl_t **_profile_info_cl, cl_float **_profile_lut_cl, cl_mem *_dev_profile_info, cl_mem *_dev_profile_lut)
dt_iop_order_iccprofile_info_t * dt_ioppr_get_iop_work_profile_info(struct dt_iop_module_t *module, GList *iop_list)
cl_int dt_ioppr_build_iccprofile_params_cl(const dt_iop_order_iccprofile_info_t *const profile_info, const int devid, dt_colorspaces_iccprofile_info_cl_t **_profile_info_cl, cl_float **_profile_lut_cl, cl_mem *_dev_profile_info, cl_mem *_dev_profile_lut)
const float *const const float coeff[3]
float *const restrict luminance
float *const restrict const size_t k
float *const restrict const size_t const size_t ch
#define CLAMPF(a, mn, mx)
float DT_ALIGNED_ARRAY dt_colormatrix_t[4][4]
static void transpose_3xSSE(const dt_colormatrix_t input, dt_colormatrix_t output)
static void pack_3xSSE_to_3x4(const dt_colormatrix_t input, float output[12])
static void dt_colormatrix_mul(dt_colormatrix_t dst, const dt_colormatrix_t m1, const dt_colormatrix_t m2)
float dt_aligned_pixel_t[4]
int dt_opencl_local_buffer_opt(const int devid, const int kernel, dt_opencl_local_buffer_t *factors)
int dt_opencl_enqueue_kernel_2d(const int dev, const int kernel, const size_t *sizes)
void * dt_opencl_alloc_device_buffer(const int devid, const size_t size)
void * dt_opencl_alloc_device(const int devid, const int width, const int height, const int bpp)
int dt_opencl_create_kernel(const int prog, const char *name)
void * dt_opencl_copy_host_to_device_constant(const int devid, const size_t size, void *host)
int dt_opencl_write_buffer_to_device(const int devid, void *host, void *device, const size_t offset, const size_t size, const int blocking)
int dt_opencl_enqueue_copy_image(const int devid, cl_mem src, cl_mem dst, size_t *orig_src, size_t *orig_dst, size_t *region)
int dt_opencl_read_buffer_from_device(const int devid, void *host, void *device, const size_t offset, const size_t size, const int blocking)
void dt_opencl_free_kernel(const int kernel)
int dt_opencl_set_kernel_arg(const int dev, const int kernel, const int num, const size_t size, const void *arg)
int dt_opencl_enqueue_kernel_2d_with_local(const int dev, const int kernel, const size_t *sizes, const size_t *local)
void dt_opencl_release_mem_object(cl_mem mem)
static float fmaxabsf(const float a, const float b)
static float clamp_simd(const float x)
struct _GtkWidget GtkWidget
const float uint32_t state[4]
const float const int flip
int32_t num_openmp_threads
struct dt_gui_gtk_t * gui
struct dt_bauhaus_t * bauhaus
struct dt_develop_t * develop
PangoFontDescription * pango_font_desc
dt_iop_buffer_dsc_t dsc_in
struct dt_iop_module_t *void * data
dt_dev_pixelpipe_type_t type
dt_iop_buffer_type_t datatype
dt_iop_filmicrgb_curve_type_t type[2]
int high_quality_reconstruction
float reconstruct_feather
float reconstruct_structure_vs_texture
float reconstruct_grey_vs_color
dt_noise_distribution_t noise_distribution
float reconstruct_bloom_vs_details
struct dt_iop_filmic_rgb_spline_t spline DT_ALIGNED_ARRAY
float reconstruct_threshold
int kernel_filmic_rgb_chroma
int kernel_filmic_bspline_vertical
int kernel_filmic_rgb_split
int kernel_filmic_wavelets_reconstruct
int kernel_filmic_wavelets_detail
int kernel_filmic_show_mask
int kernel_filmic_compute_ratios
int kernel_filmic_init_reconstruct
int kernel_filmic_restore_ratios
int kernel_filmic_bspline_vertical_local
int kernel_filmic_bspline_horizontal
int kernel_filmic_inpaint_noise
int kernel_filmic_bspline_horizontal_local
GtkWidget * high_quality_reconstruction
GtkWidget * autoset_display_gamma
GtkWidget * reconstruct_grey_vs_color
GtkWidget * auto_hardness
dt_iop_filmicrgb_gui_button_data_t buttons[DT_FILMIC_GUI_BUTTON_LAST]
GtkWidget * reconstruct_bloom_vs_details
GtkWidget * reconstruct_threshold
GtkWidget * show_highlight_mask
GtkWidget * white_point_target
GtkWidget * grey_point_source
GtkStyleContext * context
GtkWidget * preserve_color
dt_iop_filmicrgb_gui_button_t active_button
GtkWidget * grey_point_target
dt_iop_filmic_rgb_gui_mode_t gui_mode
GtkWidget * black_point_source
GtkWidget * reconstruct_structure_vs_texture
GtkWidget * reconstruct_feather
GtkWidget * noise_distribution
GtkWidget * black_point_target
struct dt_iop_filmic_rgb_spline_t spline DT_ALIGNED_ARRAY
GtkWidget * white_point_source
GtkWidget * security_factor
GtkWidget * compensate_icc_black
float reconstruct_threshold
float reconstruct_grey_vs_color
float reconstruct_feather
dt_iop_filmicrgb_curve_type_t shadows
dt_iop_filmicrgb_spline_version_type_t spline_version
dt_iop_filmicrgb_colorscience_type_t version
dt_iop_filmic_noise_distribution_t noise_distribution
dt_iop_filmicrgb_methods_type_t preserve_color
int high_quality_reconstruction
dt_iop_filmicrgb_curve_type_t highlights
float reconstruct_bloom_vs_details
gboolean compensate_icc_black
float reconstruct_structure_vs_texture
dt_aligned_pixel_simd_t input[3]
dt_aligned_pixel_simd_t output[3]
dt_aligned_pixel_simd_t export_output[3]
dt_aligned_pixel_simd_t export_input[3]
gboolean contrast_clamped
dt_iop_global_data_t * data
GtkDarktableToggleButton * off
dt_iop_params_t * default_params
struct dt_develop_t * dev
dt_iop_gui_data_t * gui_data
dt_iop_global_data_t * global_data
gboolean workflow_enabled
dt_aligned_pixel_t picked_color_min
dt_aligned_pixel_t picked_color_max
dt_aligned_pixel_t picked_color
dt_colormatrix_t matrix_out
dt_colormatrix_t matrix_in_transposed
dt_colormatrix_t matrix_in
Region of interest passed through the pixelpipe.