Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
colorspaces.h
Go to the documentation of this file.
1/*
2 This file is part of ansel,
3 Copyright (C) 2010-2022 darktable developers.
4 Copyright (C) 2023 ansel developers.
5
6 ansel is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 ansel is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with ansel. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#pragma once
21
22#include "common/darktable.h"
23#include "common/matrices.h"
24
25#include <lcms2.h>
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31// this was removed from lcms2 in 2.4
32#ifndef TYPE_XYZA_FLT
33 #define TYPE_XYZA_FLT (FLOAT_SH(1)|COLORSPACE_SH(PT_XYZ)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(4))
34#endif
35
36// max iccprofile file name length
37#define DT_IOP_COLOR_ICC_LEN 512
38#define LUT_SAMPLES 0x10000
39
40
41// constants fit to the ones from lcms.h:
43{
44 DT_INTENT_PERCEPTUAL = INTENT_PERCEPTUAL, // 0
45 DT_INTENT_RELATIVE_COLORIMETRIC = INTENT_RELATIVE_COLORIMETRIC, // 1
46 DT_INTENT_SATURATION = INTENT_SATURATION, // 2
47 DT_INTENT_ABSOLUTE_COLORIMETRIC = INTENT_ABSOLUTE_COLORIMETRIC, // 3
50
59
93
100
114
115/* CICP color primaries (Recommendation ITU-T H.273) */
124
125/* CICP transfer characteristics (Recommendation ITU-T H.273) */
138
139/* CICP matrix coefficients (Recommendation ITU-T H.273) */
150
174
176{
177 dt_colorspaces_color_profile_type_t type; // filename is only used for type DT_COLORSPACE_FILE
178 char filename[DT_IOP_COLOR_ICC_LEN]; // icc file name
179 char name[512]; // product name, displayed in GUI
180 cmsHPROFILE profile; // the actual profile
181 int in_pos; // position in input combo box, -1 if not applicable
182 int out_pos; // position in output combo box, -1 if not applicable
183 int display_pos; // position in display combo box, -1 if not applicable
184 int category_pos; // position in category combo box, -1 if not applicable
185 int work_pos; // position in working combo box, -1 if not applicable
187
194
195int mat3inv_float(float *const dst, const float *const src);
196int mat3inv(float *const dst, const float *const src);
197
200
203
205cmsHPROFILE dt_colorspaces_create_xyzimatrix_profile(float cam_xyz[3][3]);
206
208cmsHPROFILE dt_colorspaces_create_darktable_profile(const char *makermodel);
209
211cmsHPROFILE dt_colorspaces_create_vendor_profile(const char *makermodel);
212
214cmsHPROFILE dt_colorspaces_create_alternate_profile(const char *makermodel);
215
218
220const cmsHPROFILE dt_colorspaces_get_embedded_profile(const int32_t imgid, dt_colorspaces_color_profile_type_t *type, gboolean *new_profile);
221
225 const char *over_filename);
226
229cmsHPROFILE dt_colorspaces_get_rgb_profile_from_mem(uint8_t *data, uint32_t size);
230
232void dt_colorspaces_cleanup_profile(cmsHPROFILE p);
233
236int dt_colorspaces_get_matrix_from_input_profile(cmsHPROFILE prof, dt_colormatrix_t matrix, float *lutr, float *lutg,
237 float *lutb, const int lutsize);
238
240int dt_colorspaces_get_matrix_from_output_profile(cmsHPROFILE prof, dt_colormatrix_t matrix, float *lutr, float *lutg,
241 float *lutb, const int lutsize);
242
244void dt_colorspaces_get_profile_name(cmsHPROFILE p, const char *language, const char *country, char *name,
245 size_t len);
246
248const char *dt_colorspaces_get_name(dt_colorspaces_color_profile_type_t type, const char *filename);
249
251void rgb2hsl(const dt_aligned_pixel_t rgb, float *h, float *s, float *l);
252void hsl2rgb(dt_aligned_pixel_t rgb, float h, float s, float l);
253
256
262
266gboolean dt_colorspaces_is_profile_equal(const char *fullname, const char *filename);
267
270
274
276int dt_colorspaces_conversion_matrices_xyz(const float adobe_XYZ_to_CAM[4][3], float in_XYZ_to_CAM[9], double XYZ_to_CAM[4][3], double CAM_to_XYZ[3][4]);
277
279int dt_colorspaces_conversion_matrices_rgb(const float adobe_XYZ_to_CAM[4][3], double RGB_to_CAM[4][3], double CAM_to_RGB[3][4], const float *embedded_matrix, double mul[4]);
280
282// FIXME: CRITICAL: why is this function NOT used anywhere ???
283void dt_colorspaces_cygm_apply_coeffs_to_rgb(float *out, const float *in, int num, double RGB_to_CAM[4][3], double CAM_to_RGB[3][4], dt_aligned_pixel_t coeffs);
284
286void dt_colorspaces_cygm_to_rgb(float *out, int num, double CAM_to_RGB[3][4]);
287
289void dt_colorspaces_rgb_to_cygm(float *out, int num, double RGB_to_CAM[4][3]);
290
291
293{
294 // Remap unused colorspaces to valid ones
295 if(colorspace == DT_COLORSPACE_DISPLAY2)
297 else
299}
300
301
312dt_colorspaces_color_profile_type_t dt_image_find_best_color_profile(int32_t imgid, cmsHPROFILE *output, gboolean *new_profile);
313
314#ifdef __cplusplus
315}
316#endif
317
318// clang-format off
319// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
320// vim: shiftwidth=2 expandtab tabstop=2 cindent
321// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
322// clang-format on
static dt_colorspaces_color_profile_type_t sanitize_colorspaces(dt_colorspaces_color_profile_type_t colorspace)
Definition colorspaces.h:292
cmsHPROFILE dt_colorspaces_create_xyzimatrix_profile(float cam_xyz[3][3])
Definition colorspaces.c:1160
dt_iop_color_intent_t
Definition colorspaces.h:43
@ DT_INTENT_ABSOLUTE_COLORIMETRIC
Definition colorspaces.h:47
@ DT_INTENT_RELATIVE_COLORIMETRIC
Definition colorspaces.h:45
@ DT_INTENT_PERCEPTUAL
Definition colorspaces.h:44
@ DT_INTENT_SATURATION
Definition colorspaces.h:46
@ DT_INTENT_LAST
Definition colorspaces.h:48
const dt_colorspaces_color_profile_t * dt_colorspaces_get_profile(dt_colorspaces_color_profile_type_t type, const char *filename, dt_colorspaces_profile_direction_t direction)
Definition colorspaces.c:2310
void dt_colorspaces_rgb_to_cygm(float *out, int num, double RGB_to_CAM[4][3])
Definition colorspaces.c:2509
void rgb2hsl(const dt_aligned_pixel_t rgb, float *h, float *s, float *l)
Definition colorspaces.c:1272
int dt_colorspaces_conversion_matrices_rgb(const float adobe_XYZ_to_CAM[4][3], double RGB_to_CAM[4][3], double CAM_to_RGB[3][4], const float *embedded_matrix, double mul[4])
Definition colorspaces.c:2380
const dt_colorspaces_color_profile_t * dt_colorspaces_get_output_profile(const int32_t imgid, dt_colorspaces_color_profile_type_t *over_type, const char *over_filename)
Definition colorspaces.c:1064
int dt_colorspaces_get_matrix_from_output_profile(cmsHPROFILE prof, dt_colormatrix_t matrix, float *lutr, float *lutg, float *lutb, const int lutsize)
Definition colorspaces.c:284
void dt_colorspaces_update_display_transforms()
Definition colorspaces.c:1396
const cmsHPROFILE dt_colorspaces_get_embedded_profile(const int32_t imgid, dt_colorspaces_color_profile_type_t *type, gboolean *new_profile)
Definition colorspaces.c:1033
#define DT_IOP_COLOR_ICC_LEN
Definition colorspaces.h:37
cmsHPROFILE dt_colorspaces_create_vendor_profile(const char *makermodel)
Definition colorspaces.c:554
int dt_colorspaces_get_matrix_from_input_profile(cmsHPROFILE prof, dt_colormatrix_t matrix, float *lutr, float *lutg, float *lutb, const int lutsize)
Definition colorspaces.c:278
dt_colorspaces_color_profile_type_t
Definition colorspaces.h:61
@ DT_COLORSPACE_ADOBERGB
Definition colorspaces.h:65
@ DT_COLORSPACE_PROPHOTO_RGB
Definition colorspaces.h:84
@ DT_COLORSPACE_EMBEDDED_MATRIX
Definition colorspaces.h:73
@ DT_COLORSPACE_EMBEDDED_ICC
Definition colorspaces.h:72
@ DT_COLORSPACE_FILE
Definition colorspaces.h:63
@ DT_COLORSPACE_DISPLAY
Definition colorspaces.h:71
@ DT_COLORSPACE_SRGB
Definition colorspaces.h:64
@ DT_COLORSPACE_INFRARED
Definition colorspaces.h:70
@ DT_COLORSPACE_EXPORT
Definition colorspaces.h:79
@ DT_COLORSPACE_LAB
Definition colorspaces.h:69
@ DT_COLORSPACE_REC709
Definition colorspaces.h:83
@ DT_COLORSPACE_HLG_P3
Definition colorspaces.h:88
@ DT_COLORSPACE_PQ_P3
Definition colorspaces.h:87
@ DT_COLORSPACE_PQ_REC2020
Definition colorspaces.h:85
@ DT_COLORSPACE_DISPLAY2
Definition colorspaces.h:82
@ DT_COLORSPACE_NONE
Definition colorspaces.h:62
@ DT_COLORSPACE_HLG_REC2020
Definition colorspaces.h:86
@ DT_COLORSPACE_WORK
Definition colorspaces.h:81
@ DT_COLORSPACE_LAST
Definition colorspaces.h:91
@ DT_COLORSPACE_ENHANCED_MATRIX
Definition colorspaces.h:75
@ DT_COLORSPACE_LIN_REC2020
Definition colorspaces.h:67
@ DT_COLORSPACE_DISPLAY_P3
Definition colorspaces.h:90
@ DT_COLORSPACE_STANDARD_MATRIX
Definition colorspaces.h:74
@ DT_COLORSPACE_XYZ
Definition colorspaces.h:68
@ DT_COLORSPACE_BRG
Definition colorspaces.h:78
@ DT_COLORSPACE_VENDOR_MATRIX
Definition colorspaces.h:76
@ DT_COLORSPACE_SOFTPROOF
Definition colorspaces.h:80
@ DT_COLORSPACE_ITUR_BT1886
Definition colorspaces.h:89
@ DT_COLORSPACE_LIN_REC709
Definition colorspaces.h:66
@ DT_COLORSPACE_ALTERNATE_MATRIX
Definition colorspaces.h:77
int mat3inv(float *const dst, const float *const src)
Definition colorspaces.c:153
dt_colorspaces_profile_type_t
Definition colorspaces.h:52
@ DT_COLORSPACES_PROFILE_TYPE_DISPLAY
Definition colorspaces.h:56
@ DT_COLORSPACES_PROFILE_TYPE_EXPORT
Definition colorspaces.h:55
@ DT_COLORSPACES_PROFILE_TYPE_SOFTPROOF
Definition colorspaces.h:57
@ DT_COLORSPACES_PROFILE_TYPE_INPUT
Definition colorspaces.h:53
@ DT_COLORSPACES_PROFILE_TYPE_WORK
Definition colorspaces.h:54
dt_colorspaces_profile_direction_t
Definition colorspaces.h:102
@ DT_PROFILE_DIRECTION_CATEGORY
Definition colorspaces.h:106
@ DT_PROFILE_DIRECTION_DISPLAY2
Definition colorspaces.h:108
@ DT_PROFILE_DIRECTION_IN
Definition colorspaces.h:103
@ DT_PROFILE_DIRECTION_OUT
Definition colorspaces.h:104
@ DT_PROFILE_DIRECTION_DISPLAY
Definition colorspaces.h:105
@ DT_PROFILE_DIRECTION_WORK
Definition colorspaces.h:107
@ DT_PROFILE_DIRECTION_ANY
Definition colorspaces.h:109
void dt_colorspaces_cleanup(dt_colorspaces_t *self)
Definition colorspaces.c:1705
cmsHPROFILE dt_colorspaces_create_darktable_profile(const char *makermodel)
Definition colorspaces.c:604
int dt_colorspaces_conversion_matrices_xyz(const float adobe_XYZ_to_CAM[4][3], float in_XYZ_to_CAM[9], double XYZ_to_CAM[4][3], double CAM_to_XYZ[3][4])
Definition colorspaces.c:2349
dt_colorspaces_cicp_transfer_characteristics_t
Definition colorspaces.h:127
@ DT_CICP_TRANSFER_CHARACTERISTICS_UNSPECIFIED
Definition colorspaces.h:129
@ DT_CICP_TRANSFER_CHARACTERISTICS_LINEAR
Definition colorspaces.h:131
@ DT_CICP_TRANSFER_CHARACTERISTICS_HLG
Definition colorspaces.h:136
@ DT_CICP_TRANSFER_CHARACTERISTICS_REC2020_12B
Definition colorspaces.h:134
@ DT_CICP_TRANSFER_CHARACTERISTICS_REC709
Definition colorspaces.h:128
@ DT_CICP_TRANSFER_CHARACTERISTICS_PQ
Definition colorspaces.h:135
@ DT_CICP_TRANSFER_CHARACTERISTICS_REC2020_10B
Definition colorspaces.h:133
@ DT_CICP_TRANSFER_CHARACTERISTICS_REC601
Definition colorspaces.h:130
@ DT_CICP_TRANSFER_CHARACTERISTICS_SRGB
Definition colorspaces.h:132
void dt_colorspaces_cleanup_profile(cmsHPROFILE p)
Definition colorspaces.c:1223
dt_colorspaces_color_profile_type_t dt_image_find_best_color_profile(int32_t imgid, cmsHPROFILE *output, gboolean *new_profile)
Best effort to find a suitable (input) color profile for a given image, using embedded ICC or EXIF wh...
Definition colorspaces.c:842
const dt_colorspaces_color_profile_t * dt_colorspaces_get_work_profile(const int32_t imgid)
Definition colorspaces.c:792
dt_colorspaces_t * dt_colorspaces_init()
Definition colorspaces.c:1514
cmsHPROFILE dt_colorspaces_get_rgb_profile_from_mem(uint8_t *data, uint32_t size)
Definition colorspaces.c:1216
const char * dt_colorspaces_get_name(dt_colorspaces_color_profile_type_t type, const char *filename)
Definition colorspaces.c:1739
void dt_colorspaces_get_profile_name(cmsHPROFILE p, const char *language, const char *country, char *name, size_t len)
Definition colorspaces.c:1229
dt_colorspaces_color_mode_t
Definition colorspaces.h:95
@ DT_PROFILE_GAMUTCHECK
Definition colorspaces.h:98
@ DT_PROFILE_SOFTPROOF
Definition colorspaces.h:97
@ DT_PROFILE_NORMAL
Definition colorspaces.h:96
void dt_colorspaces_set_display_profile(const dt_colorspaces_color_profile_type_t profile_type)
Definition colorspaces.c:1881
cmsHPROFILE dt_colorspaces_create_alternate_profile(const char *makermodel)
Definition colorspaces.c:504
void hsl2rgb(dt_aligned_pixel_t rgb, float h, float s, float l)
Definition colorspaces.c:1316
gboolean dt_colorspaces_is_profile_equal(const char *fullname, const char *filename)
Definition colorspaces.c:2043
dt_colorspaces_color_profile_type_t dt_colorspaces_cicp_to_type(const dt_colorspaces_cicp_t *cicp, const char *filename)
Definition colorspaces.c:2053
void dt_colorspaces_cygm_apply_coeffs_to_rgb(float *out, const float *in, int num, double RGB_to_CAM[4][3], double CAM_to_RGB[3][4], dt_aligned_pixel_t coeffs)
Definition colorspaces.c:2460
dt_colorspaces_cicp_color_primaries_t
Definition colorspaces.h:117
@ DT_CICP_COLOR_PRIMARIES_REC2020
Definition colorspaces.h:120
@ DT_CICP_COLOR_PRIMARIES_UNSPECIFIED
Definition colorspaces.h:119
@ DT_CICP_COLOR_PRIMARIES_P3
Definition colorspaces.h:122
@ DT_CICP_COLOR_PRIMARIES_REC709
Definition colorspaces.h:118
@ DT_CICP_COLOR_PRIMARIES_XYZ
Definition colorspaces.h:121
int mat3inv_float(float *const dst, const float *const src)
Definition colorspaces.c:151
dt_colorspaces_cicp_matrix_coefficients_t
Definition colorspaces.h:141
@ DT_CICP_MATRIX_COEFFICIENTS_REC601
Definition colorspaces.h:146
@ DT_CICP_MATRIX_COEFFICIENTS_REC2020_NCL
Definition colorspaces.h:147
@ DT_CICP_MATRIX_COEFFICIENTS_UNSPECIFIED
Definition colorspaces.h:144
@ DT_CICP_MATRIX_COEFFICIENTS_IDENTITY
Definition colorspaces.h:142
@ DT_CICP_MATRIX_COEFFICIENTS_SYCC
Definition colorspaces.h:145
@ DT_CICP_MATRIX_COEFFICIENTS_REC709
Definition colorspaces.h:143
@ DT_CICP_MATRIX_COEFFICIENTS_CHROMA_DERIVED_NCL
Definition colorspaces.h:148
void dt_colorspaces_cygm_to_rgb(float *out, int num, double CAM_to_RGB[3][4])
Definition colorspaces.c:2492
int type
Definition common/metadata.c:42
char * name
Definition common/metadata.c:41
float DT_ALIGNED_ARRAY dt_colormatrix_t[4][4]
Definition matrices.h:24
size_t size
Definition mipmap_cache.c:3
Definition colorspaces.h:189
dt_colorspaces_cicp_matrix_coefficients_t matrix_coefficients
Definition colorspaces.h:192
dt_colorspaces_cicp_transfer_characteristics_t transfer_characteristics
Definition colorspaces.h:191
dt_colorspaces_cicp_color_primaries_t color_primaries
Definition colorspaces.h:190
Definition colorspaces.h:176
cmsHPROFILE profile
Definition colorspaces.h:180
int work_pos
Definition colorspaces.h:185
int display_pos
Definition colorspaces.h:183
dt_colorspaces_color_profile_type_t type
Definition colorspaces.h:177
int out_pos
Definition colorspaces.h:182
char filename[512]
Definition colorspaces.h:178
int in_pos
Definition colorspaces.h:181
char name[512]
Definition colorspaces.h:179
int category_pos
Definition colorspaces.h:184
Definition colorspaces.h:152
GList * profiles
Definition colorspaces.h:153
cmsHTRANSFORM transform_adobe_rgb_to_display
Definition colorspaces.h:171
dt_colorspaces_color_profile_type_t softproof_type
Definition colorspaces.h:163
gchar * colord_profile_file
Definition colorspaces.h:157
cmsHTRANSFORM transform_srgb_to_display
Definition colorspaces.h:171
cmsHTRANSFORM transform_xyz_to_display
Definition colorspaces.h:171
pthread_rwlock_t xprofile_lock
Definition colorspaces.h:156
dt_colorspaces_color_mode_t mode
Definition colorspaces.h:169
int xprofile_size
Definition colorspaces.h:159
char softproof_filename[512]
Definition colorspaces.h:165
uint8_t * xprofile_data
Definition colorspaces.h:158
dt_colorspaces_color_profile_type_t display_type
Definition colorspaces.h:162
char display_filename[512]
Definition colorspaces.h:164
dt_iop_color_intent_t softproof_intent
Definition colorspaces.h:167
dt_iop_color_intent_t display_intent
Definition colorspaces.h:166
#define MIN(a, b)
Definition thinplate.c:23