Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
src/common/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#include "common/iop_profile.h"
24
25 typedef enum dt_iop_rgb_norms_t
26 {
27 DT_RGB_NORM_NONE = 0, // $DESCRIPTION: "none"
28 DT_RGB_NORM_LUMINANCE = 1, // $DESCRIPTION: "luminance"
29 DT_RGB_NORM_MAX = 2, // $DESCRIPTION: "max RGB"
30 DT_RGB_NORM_AVERAGE = 3, // $DESCRIPTION: "average RGB"
31 DT_RGB_NORM_SUM = 4, // $DESCRIPTION: "sum RGB"
32 DT_RGB_NORM_NORM = 5, // $DESCRIPTION: "norm RGB"
33 DT_RGB_NORM_POWER = 6, // $DESCRIPTION: "basic power"
35
36static inline float dt_rgb_norm(const float *in, const int norm, const dt_iop_order_iccprofile_info_t *const work_profile)
37{
38 if (norm == DT_RGB_NORM_LUMINANCE)
39 {
40 // TODO: unpack work_profile members higher, at loop level, to enable more optimizations
41 return (work_profile) ? dt_ioppr_get_rgb_matrix_luminance(in,
42 work_profile->matrix_in,
43 work_profile->lut_in,
44 work_profile->unbounded_coeffs_in,
45 work_profile->lutsize,
46 work_profile->nonlinearlut)
48 }
49 else if (norm == DT_RGB_NORM_MAX)
50 {
51 return fmaxf(in[0], fmaxf(in[1], in[2]));
52 }
53 else if (norm == DT_RGB_NORM_AVERAGE)
54 {
55 return (in[0] + in[1] + in[2]) / 3.0f;
56 }
57 else if (norm == DT_RGB_NORM_SUM)
58 {
59 return in[0] + in[1] + in[2];
60 }
61 else if (norm == DT_RGB_NORM_NORM)
62 {
63 return powf(in[0] * in[0] + in[1] * in[1] + in[2] * in[2], 0.5f);
64 }
65 else if (norm == DT_RGB_NORM_POWER)
66 {
67 float R, G, B;
68 R = in[0] * in[0];
69 G = in[1] * in[1];
70 B = in[2] * in[2];
71 return (in[0] * R + in[1] * G + in[2] * B) / (R + G + B);
72 }
73 else return (in[0] + in[1] + in[2]) / 3.0f;
74}
75
76// clang-format off
77// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
78// vim: shiftwidth=2 expandtab tabstop=2 cindent
79// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
80// clang-format on
81
static float dt_camera_rgb_luminance(const float4 rgb)
Definition color_conversion.h:166
#define B(y, x)
Definition colorspaces.c:187
dt_iop_rgb_norms_t
Definition data/kernels/rgb_norms.h:23
static float dt_ioppr_get_rgb_matrix_luminance(const dt_aligned_pixel_t rgb, const dt_colormatrix_t matrix_in, float *const lut_in[3], const float unbounded_coeffs_in[3][3], const int lutsize, const int nonlinearlut)
Definition iop_profile.h:276
#define R
dt_iop_rgb_norms_t
Definition src/common/rgb_norms.h:26
@ DT_RGB_NORM_AVERAGE
Definition src/common/rgb_norms.h:30
@ DT_RGB_NORM_NORM
Definition src/common/rgb_norms.h:32
@ DT_RGB_NORM_NONE
Definition src/common/rgb_norms.h:27
@ DT_RGB_NORM_LUMINANCE
Definition src/common/rgb_norms.h:28
@ DT_RGB_NORM_SUM
Definition src/common/rgb_norms.h:31
@ DT_RGB_NORM_POWER
Definition src/common/rgb_norms.h:33
@ DT_RGB_NORM_MAX
Definition src/common/rgb_norms.h:29
static float dt_rgb_norm(const float *in, const int norm, const dt_iop_order_iccprofile_info_t *const work_profile)
Definition src/common/rgb_norms.h:36
Definition iop_profile.h:52
int nonlinearlut
Definition iop_profile.h:63
int lutsize
Definition iop_profile.h:58
float * lut_in[3]
Definition iop_profile.h:59
dt_colormatrix_t matrix_in
Definition iop_profile.h:56