Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
src/pixel/rgb_norms.h
Go to the documentation of this file.
1/*
2 * This file is part of darktable,
3 * Copyright (C) 2019 Aurélien PIERRE.
4 * Copyright (C) 2019 Philippe Weyland.
5 * Copyright (C) 2020 Diederik Ter Rahe.
6 * Copyright (C) 2020 Pascal Obry.
7 * Copyright (C) 2022 Martin Bařinka.
8 *
9 * darktable is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * darktable is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with darktable. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23#ifndef DT_PIXEL_RGB_NORMS_H
24#define DT_PIXEL_RGB_NORMS_H
25
27
28 typedef enum dt_iop_rgb_norms_t
29 {
30 DT_RGB_NORM_NONE = 0, // $DESCRIPTION: "none"
31 DT_RGB_NORM_LUMINANCE = 1, // $DESCRIPTION: "luminance"
32 DT_RGB_NORM_MAX = 2, // $DESCRIPTION: "max RGB"
33 DT_RGB_NORM_AVERAGE = 3, // $DESCRIPTION: "average RGB"
34 DT_RGB_NORM_SUM = 4, // $DESCRIPTION: "sum RGB"
35 DT_RGB_NORM_NORM = 5, // $DESCRIPTION: "norm RGB"
36 DT_RGB_NORM_POWER = 6, // $DESCRIPTION: "basic power"
38
39static inline float dt_rgb_norm(const float *in, const int norm, const dt_iop_order_iccprofile_info_t *const work_profile)
40{
41 if (norm == DT_RGB_NORM_LUMINANCE)
42 {
43 // TODO: unpack work_profile members higher, at loop level, to enable more optimizations
44 return (work_profile) ? dt_ioppr_get_rgb_matrix_luminance(in,
45 work_profile->matrix_in,
46 work_profile->lut_in,
47 work_profile->unbounded_coeffs_in,
48 work_profile->lutsize,
49 work_profile->nonlinearlut)
51 }
52 else if (norm == DT_RGB_NORM_MAX)
53 {
54 return fmaxf(in[0], fmaxf(in[1], in[2]));
55 }
56 else if (norm == DT_RGB_NORM_AVERAGE)
57 {
58 return (in[0] + in[1] + in[2]) / 3.0f;
59 }
60 else if (norm == DT_RGB_NORM_SUM)
61 {
62 return in[0] + in[1] + in[2];
63 }
64 else if (norm == DT_RGB_NORM_NORM)
65 {
66 return powf(in[0] * in[0] + in[1] * in[1] + in[2] * in[2], 0.5f);
67 }
68 else if (norm == DT_RGB_NORM_POWER)
69 {
70 float R, G, B;
71 R = in[0] * in[0];
72 G = in[1] * in[1];
73 B = in[2] * in[2];
74 return (in[0] * R + in[1] * G + in[2] * B) / (R + G + B);
75 }
76 else return (in[0] + in[1] + in[2]) / 3.0f;
77}
78
79#endif // DT_PIXEL_RGB_NORMS_H
80
81// clang-format off
82// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
83// vim: shiftwidth=2 expandtab tabstop=2 cindent
84// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
85// clang-format on
86
static float dt_camera_rgb_luminance(const float4 rgb)
The colour-profile struct and the maths over it: the derived matrix/LUT engine.
#define B(y, x)
#define R
dt_iop_rgb_norms_t
@ DT_RGB_NORM_AVERAGE
@ DT_RGB_NORM_NORM
@ DT_RGB_NORM_NONE
@ DT_RGB_NORM_LUMINANCE
@ DT_RGB_NORM_SUM
@ DT_RGB_NORM_POWER
@ DT_RGB_NORM_MAX
static float dt_rgb_norm(const float *in, const int norm, const dt_iop_order_iccprofile_info_t *const work_profile)
A profile reduced to the arithmetic the pixel loop can run: two matrices and six tone-curve LUTs,...
int nonlinearlut
Non-zero when the profile has tone curves at all; tested as a boolean everywhere, but it is really th...
int lutsize
Entry count of each of the six LUTs. Always 65536 in practice: both callers of dt_ioppr_init_profile_...
float * lut_in[3]
Per-channel encoded -> linear tone curve, lutsize entries each, sampled over [0,1]....
dt_colormatrix_t matrix_in
RGB -> XYZ (D50), row-major. matrix_in[1][*] is the luminance row. NaN in [0][0] marks the whole prof...