Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
data/kernels/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 Pascal Obry.
6 * Copyright (C) 2021 David Koller.
7 *
8 * darktable is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * darktable is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with darktable. If not, see <http://www.gnu.org/licenses/>.
20 */
21
32
33static inline float
34dt_rgb_norm(const float4 in, const int norm, const int work_profile,
35 constant dt_colorspaces_iccprofile_info_cl_t *profile_info, read_only image2d_t lut)
36{
37 if (norm == DT_RGB_NORM_LUMINANCE)
38 {
39 return (work_profile == 0) ? dt_camera_rgb_luminance(in): get_rgb_matrix_luminance(in, profile_info, profile_info->matrix_in, lut);
40 }
41 else if (norm == DT_RGB_NORM_MAX)
42 {
43 return max(in.x, max(in.y, in.z));
44 }
45 else if (norm == DT_RGB_NORM_AVERAGE)
46 {
47 return (in.x + in.y + in.z) / 3.0f;
48 }
49 else if (norm == DT_RGB_NORM_SUM)
50 {
51 return in.x + in.y + in.z;
52 }
53 else if (norm == DT_RGB_NORM_NORM)
54 {
55 return native_powr(in.x * in.x + in.y * in.y + in.z * in.z, 0.5f);
56 }
57 else if (norm == DT_RGB_NORM_POWER)
58 {
59 float R, G, B;
60 R = in.x * in.x;
61 G = in.y * in.y;
62 B = in.z * in.z;
63 return (in.x * R + in.y * G + in.z * B) / (R + G + B);
64 }
65 else return (in.x + in.y + in.z) / 3.0f;
66}
67
68// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh
69// vim: shiftwidth=2 expandtab tabstop=2 cindent
70// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
static float dt_camera_rgb_luminance(const float4 rgb)
Definition color_conversion.h:166
static float get_rgb_matrix_luminance(const float4 rgb, constant const dt_colorspaces_iccprofile_info_cl_t *const profile_info, constant const float *const matrix, read_only image2d_t lut)
Definition color_conversion.h:130
#define B(y, x)
Definition colorspaces.c:187
const float max
Definition colorspaces_inline_conversions.h:721
static float dt_rgb_norm(const float4 in, const int norm, const int work_profile, constant dt_colorspaces_iccprofile_info_cl_t *profile_info, read_only image2d_t lut)
Definition data/kernels/rgb_norms.h:34
dt_iop_rgb_norms_t
Definition data/kernels/rgb_norms.h:23
@ DT_RGB_NORM_AVERAGE
Definition data/kernels/rgb_norms.h:27
@ DT_RGB_NORM_NORM
Definition data/kernels/rgb_norms.h:29
@ DT_RGB_NORM_NONE
Definition data/kernels/rgb_norms.h:24
@ DT_RGB_NORM_LUMINANCE
Definition data/kernels/rgb_norms.h:25
@ DT_RGB_NORM_SUM
Definition data/kernels/rgb_norms.h:28
@ DT_RGB_NORM_POWER
Definition data/kernels/rgb_norms.h:30
@ DT_RGB_NORM_MAX
Definition data/kernels/rgb_norms.h:26
static const float *const lut
Definition iop_profile.h:246
#define R
Definition color_conversion.h:42