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-2020 darktable developers.
4 *
5 * darktable is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * darktable is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with darktable. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include "common/iop_profile.h"
20
21 typedef enum dt_iop_rgb_norms_t
22 {
23 DT_RGB_NORM_NONE = 0, // $DESCRIPTION: "none"
24 DT_RGB_NORM_LUMINANCE = 1, // $DESCRIPTION: "luminance"
25 DT_RGB_NORM_MAX = 2, // $DESCRIPTION: "max RGB"
26 DT_RGB_NORM_AVERAGE = 3, // $DESCRIPTION: "average RGB"
27 DT_RGB_NORM_SUM = 4, // $DESCRIPTION: "sum RGB"
28 DT_RGB_NORM_NORM = 5, // $DESCRIPTION: "norm RGB"
29 DT_RGB_NORM_POWER = 6, // $DESCRIPTION: "basic power"
31
32static inline float dt_rgb_norm(const float *in, const int norm, const dt_iop_order_iccprofile_info_t *const work_profile)
33{
34 if (norm == DT_RGB_NORM_LUMINANCE)
35 {
36 // TODO: unpack work_profile members higher, at loop level, to enable more optimizations
37 return (work_profile) ? dt_ioppr_get_rgb_matrix_luminance(in,
38 work_profile->matrix_in,
39 work_profile->lut_in,
40 work_profile->unbounded_coeffs_in,
41 work_profile->lutsize,
42 work_profile->nonlinearlut)
44 }
45 else if (norm == DT_RGB_NORM_MAX)
46 {
47 return fmaxf(in[0], fmaxf(in[1], in[2]));
48 }
49 else if (norm == DT_RGB_NORM_AVERAGE)
50 {
51 return (in[0] + in[1] + in[2]) / 3.0f;
52 }
53 else if (norm == DT_RGB_NORM_SUM)
54 {
55 return in[0] + in[1] + in[2];
56 }
57 else if (norm == DT_RGB_NORM_NORM)
58 {
59 return powf(in[0] * in[0] + in[1] * in[1] + in[2] * in[2], 0.5f);
60 }
61 else if (norm == DT_RGB_NORM_POWER)
62 {
63 float R, G, B;
64 R = in[0] * in[0];
65 G = in[1] * in[1];
66 B = in[2] * in[2];
67 return (in[0] * R + in[1] * G + in[2] * B) / (R + G + B);
68 }
69 else return (in[0] + in[1] + in[2]) / 3.0f;
70}
71
72// clang-format off
73// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
74// vim: shiftwidth=2 expandtab tabstop=2 cindent
75// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
76// clang-format on
77
static float dt_camera_rgb_luminance(const float4 rgb)
Definition color_conversion.h:152
#define B(y, x)
Definition colorspaces.c:149
dt_iop_rgb_norms_t
Definition data/kernels/rgb_norms.h:20
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:258
#define R
dt_iop_rgb_norms_t
Definition src/common/rgb_norms.h:22
@ DT_RGB_NORM_AVERAGE
Definition src/common/rgb_norms.h:26
@ DT_RGB_NORM_NORM
Definition src/common/rgb_norms.h:28
@ DT_RGB_NORM_NONE
Definition src/common/rgb_norms.h:23
@ DT_RGB_NORM_LUMINANCE
Definition src/common/rgb_norms.h:24
@ DT_RGB_NORM_SUM
Definition src/common/rgb_norms.h:27
@ DT_RGB_NORM_POWER
Definition src/common/rgb_norms.h:29
@ DT_RGB_NORM_MAX
Definition src/common/rgb_norms.h:25
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:32
Definition iop_profile.h:41
int nonlinearlut
Definition iop_profile.h:52
int lutsize
Definition iop_profile.h:47
float * lut_in[3]
Definition iop_profile.h:48
dt_colormatrix_t matrix_in
Definition iop_profile.h:45