Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
colorspaces.c File Reference
#include "common/colorspaces.h"
#include "common/colormatrices.c"
#include "common/darktable.h"
#include "common/debug.h"
#include "common/image_cache.h"
#include "common/file_location.h"
#include "common/math.h"
#include "common/matrices.h"
#include "common/srgb_tone_curve_values.h"
#include "common/utility.h"
#include "control/conf.h"
#include "control/control.h"
#include "develop/imageop.h"
#include <strings.h>
#include "common/imageio_jpeg.h"
#include "common/imageio_png.h"
#include "common/imageio_tiff.h"
+ Include dependency graph for colorspaces.c:

Go to the source code of this file.

Macros

#define generate_mat3inv_body(c_type, A, B)
 
#define A(y, x)   src[(y - 1) * 3 + (x - 1)]
 
#define B(y, x)   dst[(y - 1) * 3 + (x - 1)]
 

Functions

static dt_colorspaces_color_profile_t_create_profile (dt_colorspaces_color_profile_type_t type, cmsHPROFILE profile, const char *name, int in_pos, int out_pos, int display_pos, int category_pos, int work_pos)
 
int mat3inv_float (float *const dst, const float *const src)
 
int mat3inv (float *const dst, const float *const src)
 
int mat3inv_double (double *const dst, const double *const src)
 
static const dt_colorspaces_color_profile_t_get_profile (dt_colorspaces_t *self, dt_colorspaces_color_profile_type_t type, const char *filename, dt_colorspaces_profile_direction_t direction)
 
static __DT_CLONE_TARGETS__ int dt_colorspaces_get_matrix_from_profile (cmsHPROFILE prof, dt_colormatrix_t matrix, float *lutr, float *lutg, float *lutb, const int lutsize, const int input)
 
int dt_colorspaces_get_matrix_from_input_profile (cmsHPROFILE prof, dt_colormatrix_t matrix, float *lutr, float *lutg, float *lutb, const int lutsize)
 
int dt_colorspaces_get_matrix_from_output_profile (cmsHPROFILE prof, dt_colormatrix_t matrix, float *lutr, float *lutg, float *lutb, const int lutsize)
 
static cmsHPROFILE dt_colorspaces_create_lab_profile ()
 
static void _compute_prequantized_primaries (const cmsCIExyY *whitepoint, const cmsCIExyYTRIPLE *primaries, cmsCIEXYZTRIPLE *primaries_prequantized)
 
static cmsHPROFILE _create_lcms_profile (const char *desc, const char *dmdd, const cmsCIExyY *whitepoint, const cmsCIExyYTRIPLE *primaries, cmsToneCurve *trc, gboolean v2)
 
static double _PQ_fct (double x)
 
static double _HLG_fct (double x)
 
static cmsToneCurve * _colorspaces_create_transfer (int32_t size, double(*fct)(double))
 
static cmsHPROFILE _colorspaces_create_srgb_profile (gboolean v2)
 
static cmsHPROFILE dt_colorspaces_create_srgb_profile ()
 
static cmsHPROFILE dt_colorspaces_create_srgb_profile_v4 ()
 
static cmsHPROFILE dt_colorspaces_create_brg_profile ()
 
static cmsHPROFILE dt_colorspaces_create_gamma_rec709_rgb_profile (void)
 
static cmsHPROFILE dt_colorspaces_create_itur_bt1886_rgb_profile (void)
 
static cmsHPROFILE dt_colorspaces_create_adobergb_profile (void)
 
cmsHPROFILE dt_colorspaces_create_alternate_profile (const char *makermodel)
 
cmsHPROFILE dt_colorspaces_create_vendor_profile (const char *makermodel)
 
cmsHPROFILE dt_colorspaces_create_darktable_profile (const char *makermodel)
 
static cmsHPROFILE dt_colorspaces_create_xyz_profile (void)
 
static cmsHPROFILE dt_colorspaces_create_linear_rec709_rgb_profile (void)
 
static cmsHPROFILE dt_colorspaces_create_linear_rec2020_rgb_profile (void)
 
static cmsHPROFILE dt_colorspaces_create_pq_rec2020_rgb_profile (void)
 
static cmsHPROFILE dt_colorspaces_create_hlg_rec2020_rgb_profile (void)
 
static cmsHPROFILE dt_colorspaces_create_pq_p3_rgb_profile (void)
 
static cmsHPROFILE dt_colorspaces_create_hlg_p3_rgb_profile (void)
 
static cmsHPROFILE dt_colorspaces_create_display_p3_rgb_profile (void)
 
static cmsHPROFILE dt_colorspaces_create_linear_prophoto_rgb_profile (void)
 
static cmsHPROFILE dt_colorspaces_create_linear_infrared_profile (void)
 
const dt_colorspaces_color_profile_tdt_colorspaces_get_work_profile (const int32_t imgid)
 
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 whenever possible. This will also init the profile in the image cache.
 
dt_colorspaces_color_profile_type_t dt_colorspaces_get_input_profile_from_image (int32_t imgid, dt_colorspaces_color_profile_type_t requested, cmsHPROFILE *output, gboolean *new_profile)
 Resolve an embedded/matrix input profile for a given image, honoring the requested type when possible. For non-RAW images, falls back to dt_image_find_best_color_profile() to avoid invalid matrix usage.
 
const cmsHPROFILE dt_colorspaces_get_embedded_profile (const int32_t imgid, dt_colorspaces_color_profile_type_t *type, gboolean *new_profile)
 
const dt_colorspaces_color_profile_t_build_embedded_profile (const int32_t imgid, dt_colorspaces_color_profile_type_t *type)
 
const dt_colorspaces_color_profile_tdt_colorspaces_get_output_profile (const int32_t imgid, dt_colorspaces_color_profile_type_t *over_type, const char *over_filename)
 
static cmsHPROFILE dt_colorspaces_create_xyzmatrix_profile (const float mat[3][3])
 
cmsHPROFILE dt_colorspaces_create_xyzimatrix_profile (float mat[3][3])
 
static cmsHPROFILE _ensure_rgb_profile (cmsHPROFILE profile)
 
cmsHPROFILE dt_colorspaces_get_rgb_profile_from_mem (uint8_t *data, uint32_t size)
 
void dt_colorspaces_cleanup_profile (cmsHPROFILE p)
 
void dt_colorspaces_get_profile_name (cmsHPROFILE p, const char *language, const char *country, char *name, size_t len)
 
void rgb2hsl (const dt_aligned_pixel_t rgb, float *h, float *s, float *l)
 
static __attribute__ ((always_inline))
 
void hsl2rgb (dt_aligned_pixel_t rgb, float h, float s, float l)
 
static void _update_display_transforms (dt_colorspaces_t *self)
 
void dt_colorspaces_update_display_transforms ()
 
void dt_colorspaces_transform_rgba_float_row (const cmsHTRANSFORM transform, const float *in, float *out, const int width)
 
__DT_CLONE_TARGETS__ void dt_colorspaces_transform_rgba_float_image (const cmsHTRANSFORM transform, const float *image_in, float *image_out, const int width, const int height)
 
void dt_colorspaces_transform_rgba8_to_bgra8 (const cmsHTRANSFORM transform, const uint8_t *image_in, uint8_t *image_out, const int width, const int height)
 
static void _update_display_profile (guchar *tmp_data, gsize size, char *name, size_t name_size)
 
static void cms_error_handler (cmsContext ContextID, cmsUInt32Number ErrorCode, const char *text)
 
static gint _sort_profiles (gconstpointer a, gconstpointer b)
 
static GList * load_profile_from_dir (const char *subdir)
 
dt_colorspaces_tdt_colorspaces_init ()
 
void dt_colorspaces_cleanup (dt_colorspaces_t *self)
 
const char * dt_colorspaces_get_name (dt_colorspaces_color_profile_type_t type, const char *filename)
 
void dt_colorspaces_set_display_profile (const dt_colorspaces_color_profile_type_t profile_type)
 
static gboolean _colorspaces_is_base_name (const char *profile)
 
static const char * _colorspaces_get_base_name (const char *profile)
 
gboolean dt_colorspaces_is_profile_equal (const char *fullname, const char *filename)
 
dt_colorspaces_color_profile_type_t dt_colorspaces_cicp_to_type (const dt_colorspaces_cicp_t *cicp, const char *filename)
 
const dt_colorspaces_color_profile_tdt_colorspaces_get_profile (dt_colorspaces_color_profile_type_t type, const char *filename, dt_colorspaces_profile_direction_t direction)
 
static __DT_CLONE_TARGETS__ void dt_colorspaces_pseudoinverse (double(*in)[3], double(*out)[3], int size)
 
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])
 
__DT_CLONE_TARGETS__ int dt_colorspaces_conversion_matrices_rgb (const float adobe_XYZ_to_CAM[4][3], double out_RGB_to_CAM[4][3], double out_CAM_to_RGB[3][4], const float *embedded_matrix, double mul[4])
 
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)
 
__DT_CLONE_TARGETS__ void dt_colorspaces_cygm_to_rgb (float *out, int num, double CAM_to_RGB[3][4])
 
void dt_colorspaces_rgb_to_cygm (float *out, int num, double RGB_to_CAM[4][3])
 

Variables

static const cmsCIEXYZ d65 = {0.95045471, 1.00000000, 1.08905029}
 
static const cmsCIExyY D65xyY = {0.312700492, 0.329000939, 1.0}
 
static const cmsCIExyY D50xyY = {0.3457, 0.3585, 1.0}
 
static const cmsCIExyYTRIPLE sRGB_Primaries
 
static const cmsCIExyYTRIPLE Rec2020_Primaries
 
static const cmsCIExyYTRIPLE Rec709_Primaries
 
static const cmsCIExyYTRIPLE Adobe_Primaries
 
static const cmsCIExyYTRIPLE P3_Primaries
 
static const cmsCIExyYTRIPLE ProPhoto_Primaries
 
cmsCIEXYZTRIPLE Rec709_Primaries_Prequantized
 

Macro Definition Documentation

◆ A

#define A (   y,
  x 
)    src[(y - 1) * 3 + (x - 1)]

Definition at line 186 of file colorspaces.c.

◆ B

#define B (   y,
  x 
)    dst[(y - 1) * 3 + (x - 1)]

Definition at line 187 of file colorspaces.c.

◆ generate_mat3inv_body

#define generate_mat3inv_body (   c_type,
  A,
  B 
)
Value:
int mat3inv_##c_type(c_type *const dst, const c_type *const src) \
{ \
\
const c_type det = A(1, 1) * (A(3, 3) * A(2, 2) - A(3, 2) * A(2, 3)) \
- A(2, 1) * (A(3, 3) * A(1, 2) - A(3, 2) * A(1, 3)) \
+ A(3, 1) * (A(2, 3) * A(1, 2) - A(2, 2) * A(1, 3)); \
\
const c_type epsilon = 1e-7f; \
if(fabs(det) < epsilon) return 1; \
\
const c_type invDet = 1.0 / det; \
\
B(1, 1) = invDet * (A(3, 3) * A(2, 2) - A(3, 2) * A(2, 3)); \
B(1, 2) = -invDet * (A(3, 3) * A(1, 2) - A(3, 2) * A(1, 3)); \
B(1, 3) = invDet * (A(2, 3) * A(1, 2) - A(2, 2) * A(1, 3)); \
\
B(2, 1) = -invDet * (A(3, 3) * A(2, 1) - A(3, 1) * A(2, 3)); \
B(2, 2) = invDet * (A(3, 3) * A(1, 1) - A(3, 1) * A(1, 3)); \
B(2, 3) = -invDet * (A(2, 3) * A(1, 1) - A(2, 1) * A(1, 3)); \
\
B(3, 1) = invDet * (A(3, 2) * A(2, 1) - A(3, 1) * A(2, 2)); \
B(3, 2) = -invDet * (A(3, 2) * A(1, 1) - A(3, 1) * A(1, 2)); \
B(3, 3) = invDet * (A(2, 2) * A(1, 1) - A(2, 1) * A(1, 2)); \
return 0; \
}
#define A(y, x)

Definition at line 159 of file colorspaces.c.

Function Documentation

◆ __attribute__()

static __attribute__ ( (always_inline)  )
inlinestatic

Definition at line 1440 of file colorspaces.c.

◆ _build_embedded_profile()

◆ _colorspaces_create_srgb_profile()

static cmsHPROFILE _colorspaces_create_srgb_profile ( gboolean  v2)
static

◆ _colorspaces_create_transfer()

static cmsToneCurve * _colorspaces_create_transfer ( int32_t  size,
double(*)(double fct 
)
static

◆ _colorspaces_get_base_name()

static const char * _colorspaces_get_base_name ( const char *  profile)
static

Definition at line 2248 of file colorspaces.c.

References f.

Referenced by dt_colorspaces_is_profile_equal().

◆ _colorspaces_is_base_name()

static gboolean _colorspaces_is_base_name ( const char *  profile)
static

Definition at line 2237 of file colorspaces.c.

References f, FALSE, and TRUE.

Referenced by dt_colorspaces_is_profile_equal().

◆ _compute_prequantized_primaries()

static void _compute_prequantized_primaries ( const cmsCIExyY *  whitepoint,
const cmsCIExyYTRIPLE *  primaries,
cmsCIEXYZTRIPLE *  primaries_prequantized 
)
static

Definition at line 334 of file colorspaces.c.

References B, double(), and R.

Referenced by dt_colorspaces_init().

◆ _create_lcms_profile()

◆ _create_profile()

◆ _ensure_rgb_profile()

static cmsHPROFILE _ensure_rgb_profile ( cmsHPROFILE  profile)
static
Todo:
: we still use prequantized primaries here, we will probably want to rework this

Definition at line 1304 of file colorspaces.c.

References Rec709_Primaries_Prequantized.

Referenced by dt_colorspaces_get_rgb_profile_from_mem(), and load_profile_from_dir().

◆ _get_profile()

◆ _HLG_fct()

static double _HLG_fct ( double  x)
static

BT.2100 HLG EOTF inverse, mapping non-linear HLG code values to linear light. The standard is defined on [0, +inf), but we extend it by odd symmetry so profile round-trips keep signed RGB values continuous around black instead of clipping negative excursions.

Definition at line 419 of file colorspaces.c.

References A, B, C, sign, and x.

Referenced by dt_colorspaces_create_hlg_p3_rgb_profile(), and dt_colorspaces_create_hlg_rec2020_rgb_profile().

◆ _PQ_fct()

static double _PQ_fct ( double  x)
static

Definition at line 397 of file colorspaces.c.

References MAX, sign, and x.

Referenced by dt_colorspaces_create_pq_p3_rgb_profile(), and dt_colorspaces_create_pq_rec2020_rgb_profile().

◆ _sort_profiles()

static gint _sort_profiles ( gconstpointer  a,
gconstpointer  b 
)
static

Definition at line 1636 of file colorspaces.c.

References dt_free, and dt_colorspaces_color_profile_t::name.

Referenced by load_profile_from_dir().

◆ _update_display_profile()

◆ _update_display_transforms()

◆ cms_error_handler()

static void cms_error_handler ( cmsContext  ContextID,
cmsUInt32Number  ErrorCode,
const char *  text 
)
static

Definition at line 1631 of file colorspaces.c.

References DT_DEBUG_COLORPROFILE, and dt_print().

Referenced by dt_colorspaces_init().

◆ dt_colorspaces_cicp_to_type()

dt_colorspaces_color_profile_type_t dt_colorspaces_cicp_to_type ( const dt_colorspaces_cicp_t cicp,
const char *  filename 
)

◆ dt_colorspaces_cleanup()

◆ dt_colorspaces_cleanup_profile()

void dt_colorspaces_cleanup_profile ( cmsHPROFILE  p)

free the resources of a profile created with the functions above.

Definition at line 1359 of file colorspaces.c.

References IS_NULL_PTR, and p.

Referenced by _update_display_profile(), cleanup_pipe(), commit_params(), dt_colorspaces_cleanup(), and dt_colorspaces_get_input_profile_from_image().

◆ dt_colorspaces_conversion_matrices_rgb()

__DT_CLONE_TARGETS__ 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] 
)

Calculate CAM->RGB, RGB->CAM matrices and default WB multipliers

Definition at line 2598 of file colorspaces.c.

References dt_colorspaces_pseudoinverse(), FALSE, i, IS_NULL_PTR, k, and TRUE.

Referenced by calculate_bogus_daylight_wb(), commit_params(), get_white_balance_coeff(), legacy_params(), and reload_defaults().

◆ dt_colorspaces_conversion_matrices_xyz()

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] 
)

Calculate CAM->XYZ, XYZ->CAM matrices

Definition at line 2566 of file colorspaces.c.

References dt_colorspaces_pseudoinverse(), FALSE, i, and TRUE.

Referenced by prepare_matrices().

◆ dt_colorspaces_create_adobergb_profile()

static cmsHPROFILE dt_colorspaces_create_adobergb_profile ( void  )
static

Definition at line 522 of file colorspaces.c.

References _create_lcms_profile(), Adobe_Primaries, D65xyY, and TRUE.

Referenced by dt_colorspaces_init().

◆ dt_colorspaces_create_alternate_profile()

cmsHPROFILE dt_colorspaces_create_alternate_profile ( const char *  makermodel)

create a ICC virtual profile from the shipped alternate matrices in darktable.

Definition at line 536 of file colorspaces.c.

References dt_alternate_colormatrices, dt_alternate_colormatrix_cnt, IS_NULL_PTR, k, name, and preset.

Referenced by _resolve_input_profile().

◆ dt_colorspaces_create_brg_profile()

static cmsHPROFILE dt_colorspaces_create_brg_profile ( )
static

Definition at line 479 of file colorspaces.c.

References _create_lcms_profile(), D65xyY, sRGB_Primaries, and TRUE.

Referenced by dt_colorspaces_init().

◆ dt_colorspaces_create_darktable_profile()

cmsHPROFILE dt_colorspaces_create_darktable_profile ( const char *  makermodel)

create a ICC virtual profile from the shipped presets in darktable.

Definition at line 636 of file colorspaces.c.

References dt_profiled_colormatrices, dt_profiled_colormatrix_cnt, IS_NULL_PTR, k, name, and preset.

Referenced by _resolve_input_profile().

◆ dt_colorspaces_create_display_p3_rgb_profile()

static cmsHPROFILE dt_colorspaces_create_display_p3_rgb_profile ( void  )
static

Definition at line 784 of file colorspaces.c.

References _create_lcms_profile(), D65xyY, P3_Primaries, and TRUE.

Referenced by dt_colorspaces_init().

◆ dt_colorspaces_create_gamma_rec709_rgb_profile()

static cmsHPROFILE dt_colorspaces_create_gamma_rec709_rgb_profile ( void  )
static

Definition at line 494 of file colorspaces.c.

References _create_lcms_profile(), D65xyY, Rec709_Primaries, and TRUE.

Referenced by dt_colorspaces_init().

◆ dt_colorspaces_create_hlg_p3_rgb_profile()

static cmsHPROFILE dt_colorspaces_create_hlg_p3_rgb_profile ( void  )
static

◆ dt_colorspaces_create_hlg_rec2020_rgb_profile()

static cmsHPROFILE dt_colorspaces_create_hlg_rec2020_rgb_profile ( void  )
static

◆ dt_colorspaces_create_itur_bt1886_rgb_profile()

static cmsHPROFILE dt_colorspaces_create_itur_bt1886_rgb_profile ( void  )
static

Definition at line 507 of file colorspaces.c.

References _create_lcms_profile(), D65xyY, Rec709_Primaries, and TRUE.

Referenced by dt_colorspaces_init().

◆ dt_colorspaces_create_lab_profile()

static cmsHPROFILE dt_colorspaces_create_lab_profile ( )
static

Definition at line 329 of file colorspaces.c.

Referenced by dt_colorspaces_init().

◆ dt_colorspaces_create_linear_infrared_profile()

static cmsHPROFILE dt_colorspaces_create_linear_infrared_profile ( void  )
static

Definition at line 809 of file colorspaces.c.

References _create_lcms_profile(), D65xyY, FALSE, and sRGB_Primaries.

Referenced by dt_colorspaces_init().

◆ dt_colorspaces_create_linear_prophoto_rgb_profile()

static cmsHPROFILE dt_colorspaces_create_linear_prophoto_rgb_profile ( void  )
static

Definition at line 797 of file colorspaces.c.

References _create_lcms_profile(), D50xyY, ProPhoto_Primaries, and TRUE.

Referenced by dt_colorspaces_init().

◆ dt_colorspaces_create_linear_rec2020_rgb_profile()

static cmsHPROFILE dt_colorspaces_create_linear_rec2020_rgb_profile ( void  )
static

Definition at line 724 of file colorspaces.c.

References _create_lcms_profile(), D65xyY, Rec2020_Primaries, and TRUE.

Referenced by dt_colorspaces_init().

◆ dt_colorspaces_create_linear_rec709_rgb_profile()

static cmsHPROFILE dt_colorspaces_create_linear_rec709_rgb_profile ( void  )
static

Definition at line 712 of file colorspaces.c.

References _create_lcms_profile(), D65xyY, Rec709_Primaries, and TRUE.

Referenced by dt_colorspaces_init().

◆ dt_colorspaces_create_pq_p3_rgb_profile()

static cmsHPROFILE dt_colorspaces_create_pq_p3_rgb_profile ( void  )
static

◆ dt_colorspaces_create_pq_rec2020_rgb_profile()

static cmsHPROFILE dt_colorspaces_create_pq_rec2020_rgb_profile ( void  )
static

◆ dt_colorspaces_create_srgb_profile()

static cmsHPROFILE dt_colorspaces_create_srgb_profile ( )
static

Definition at line 469 of file colorspaces.c.

References _colorspaces_create_srgb_profile(), and TRUE.

Referenced by dt_colorspaces_init().

◆ dt_colorspaces_create_srgb_profile_v4()

static cmsHPROFILE dt_colorspaces_create_srgb_profile_v4 ( )
static

Definition at line 474 of file colorspaces.c.

References _colorspaces_create_srgb_profile(), and FALSE.

Referenced by dt_colorspaces_init().

◆ dt_colorspaces_create_vendor_profile()

cmsHPROFILE dt_colorspaces_create_vendor_profile ( const char *  makermodel)

create a ICC virtual profile from the shipped vendor matrices in darktable.

Definition at line 586 of file colorspaces.c.

References dt_vendor_colormatrices, dt_vendor_colormatrix_cnt, IS_NULL_PTR, k, name, and preset.

Referenced by _resolve_input_profile().

◆ dt_colorspaces_create_xyz_profile()

static cmsHPROFILE dt_colorspaces_create_xyz_profile ( void  )
static

Definition at line 686 of file colorspaces.c.

References IS_NULL_PTR.

Referenced by dt_colorspaces_init().

◆ dt_colorspaces_create_xyzimatrix_profile()

cmsHPROFILE dt_colorspaces_create_xyzimatrix_profile ( float  cam_xyz[3][3])

create a profile from a xyz->camera matrix.

Definition at line 1296 of file colorspaces.c.

References dt_colorspaces_create_xyzmatrix_profile(), and mat3inv().

Referenced by dt_colorspaces_get_input_profile_from_image(), and dt_image_find_best_color_profile().

◆ dt_colorspaces_create_xyzmatrix_profile()

static cmsHPROFILE dt_colorspaces_create_xyzmatrix_profile ( const float  mat[3][3])
static

Definition at line 1256 of file colorspaces.c.

References d65, IS_NULL_PTR, k, and x.

Referenced by dt_colorspaces_create_xyzimatrix_profile().

◆ dt_colorspaces_cygm_apply_coeffs_to_rgb()

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 
)

Applies CYGM WB coeffs to an image that's already been converted to RGB by dt_colorspaces_cygm_to_rgb

Todo:
: CRITICAL: why is this function NOT used anywhere ???

Definition at line 2678 of file colorspaces.c.

References __OMP_PARALLEL_FOR__, i, and out.

◆ dt_colorspaces_cygm_to_rgb()

__DT_CLONE_TARGETS__ void dt_colorspaces_cygm_to_rgb ( float *  out,
int  num,
double  CAM_to_RGB[3][4] 
)

convert CYGM buffer to RGB

Definition at line 2708 of file colorspaces.c.

References __OMP_PARALLEL_FOR__, i, k, and out.

Referenced by gui_update_from_coeffs(), and process().

◆ dt_colorspaces_get_embedded_profile()

const cmsHPROFILE dt_colorspaces_get_embedded_profile ( const int32_t  imgid,
dt_colorspaces_color_profile_type_t type,
gboolean *  new_profile 
)

return the embedded profile of a particular image

Definition at line 1169 of file colorspaces.c.

References dt_image_find_best_color_profile(), and type.

Referenced by _build_embedded_profile(), and commit_params().

◆ dt_colorspaces_get_input_profile_from_image()

dt_colorspaces_color_profile_type_t dt_colorspaces_get_input_profile_from_image ( int32_t  imgid,
dt_colorspaces_color_profile_type_t  requested,
cmsHPROFILE *  output,
gboolean *  new_profile 
)

Resolve an embedded/matrix input profile for a given image, honoring the requested type when possible. For non-RAW images, falls back to dt_image_find_best_color_profile() to avoid invalid matrix usage.

Parameters
imgidID of the picture
requestedRequested embedded/matrix profile type
outputIf not NULL, writes the generated color profile into this pointer.
new_profileWill be set to true if a new profile was generated (aka embedded profile) and will need to be freed.
Returns
dt_colorspaces_color_profile_type_t resolved type, or DT_COLORSPACE_NONE on error.

Definition at line 1064 of file colorspaces.c.

References dt_image_t::adobe_XYZ_to_CAM, dt_image_t::d65_color_matrix, darktable, DT_COLORSPACE_EMBEDDED_ICC, DT_COLORSPACE_EMBEDDED_MATRIX, DT_COLORSPACE_LIN_REC709, DT_COLORSPACE_NONE, DT_COLORSPACE_STANDARD_MATRIX, dt_colorspaces_cleanup_profile(), dt_colorspaces_create_xyzimatrix_profile(), dt_colorspaces_get_rgb_profile_from_mem(), dt_image_cache_get(), dt_image_cache_read_release(), dt_image_find_best_color_profile(), dt_image_is_matrix_correction_supported(), FALSE, darktable_t::image_cache, IS_NULL_PTR, dt_image_t::profile, dt_image_t::profile_size, TRUE, and type.

Referenced by _resolve_input_profile().

◆ dt_colorspaces_get_matrix_from_input_profile()

int dt_colorspaces_get_matrix_from_input_profile ( cmsHPROFILE  prof,
dt_colormatrix_t  matrix,
float *  lutr,
float *  lutg,
float *  lutb,
const int  lutsize 
)

extracts tonecurves and color matrix prof to XYZ from a given input profile, returns 0 on success (curves and matrix are inverted for input)

Definition at line 317 of file colorspaces.c.

References dt_colorspaces_get_matrix_from_profile(), lutsize, and matrix.

Referenced by commit_params(), dt_colorspaces_init(), and dt_ioppr_generate_profile_info().

◆ dt_colorspaces_get_matrix_from_output_profile()

int dt_colorspaces_get_matrix_from_output_profile ( cmsHPROFILE  prof,
dt_colormatrix_t  matrix,
float *  lutr,
float *  lutg,
float *  lutb,
const int  lutsize 
)

extracts tonecurves and color matrix prof to XYZ from a given output profile, returns 0 on success.

Definition at line 323 of file colorspaces.c.

References dt_colorspaces_get_matrix_from_profile(), lutsize, and matrix.

Referenced by commit_params(), dt_colorspaces_init(), and dt_ioppr_generate_profile_info().

◆ dt_colorspaces_get_matrix_from_profile()

static __DT_CLONE_TARGETS__ int dt_colorspaces_get_matrix_from_profile ( cmsHPROFILE  prof,
dt_colormatrix_t  matrix,
float *  lutr,
float *  lutg,
float *  lutb,
const int  lutsize,
const int  input 
)
static

◆ dt_colorspaces_get_name()

◆ dt_colorspaces_get_output_profile()

◆ dt_colorspaces_get_profile()

◆ dt_colorspaces_get_profile_name()

void dt_colorspaces_get_profile_name ( cmsHPROFILE  p,
const char *  language,
const char *  country,
char *  name,
size_t  len 
)

wrapper to get the name from a color profile. this tries to handle character encodings.

Definition at line 1365 of file colorspaces.c.

References dt_free, error(), IS_NULL_PTR, name, p, and size.

Referenced by _build_embedded_profile(), _update_display_profile(), load_profile_from_dir(), and write_image().

◆ dt_colorspaces_get_rgb_profile_from_mem()

cmsHPROFILE dt_colorspaces_get_rgb_profile_from_mem ( uint8_t *  data,
uint32_t  size 
)

return an rgb lcms2 profile from data. if data points to a grayscale profile a new rgb profile is created that has the same TRC, black and white point and rec709 primaries.

Definition at line 1352 of file colorspaces.c.

References _ensure_rgb_profile(), and size.

Referenced by dt_colorspaces_get_input_profile_from_image(), and dt_image_find_best_color_profile().

◆ dt_colorspaces_get_work_profile()

const dt_colorspaces_color_profile_t * dt_colorspaces_get_work_profile ( const int32_t  imgid)

return the work profile as set in colorin

Todo:
: does this work when using JPEG thumbs and the image was never opened?

Definition at line 824 of file colorspaces.c.

References darktable, darktable_t::db, DT_COLORSPACE_LIN_REC2020, dt_colorspaces_get_profile(), dt_database_get(), DT_DEBUG_SQLITE3_BIND_INT, DT_DEBUG_SQLITE3_PREPARE_V2, DT_PROFILE_DIRECTION_WORK, darktable_t::iop, IS_NULL_PTR, p, and type.

◆ dt_colorspaces_init()

dt_colorspaces_t * dt_colorspaces_init ( )

populate the global color profile lists

Todo:
: what about display?
Todo:
: do want to filter out non-RGB profiles for cases besides histogram profile? colorin is OK with RGB or XYZ, print is OK with anything which LCMS likes, otherwise things are more choosey

Definition at line 1717 of file colorspaces.c.

References _compute_prequantized_primaries(), _create_profile(), _update_display_transforms(), dt_colorspaces_color_profile_t::category_pos, cms_error_handler(), color_space, D65xyY, dt_colorspaces_t::display_filename, dt_colorspaces_t::display_intent, dt_colorspaces_color_profile_t::display_pos, dt_colorspaces_t::display_type, DT_COLORSPACE_ADOBERGB, DT_COLORSPACE_BRG, DT_COLORSPACE_DISPLAY, DT_COLORSPACE_DISPLAY_P3, DT_COLORSPACE_EXPORT, DT_COLORSPACE_FILE, DT_COLORSPACE_HLG_P3, DT_COLORSPACE_HLG_REC2020, DT_COLORSPACE_INFRARED, DT_COLORSPACE_ITUR_BT1886, DT_COLORSPACE_LAB, DT_COLORSPACE_LAST, DT_COLORSPACE_LIN_REC2020, DT_COLORSPACE_LIN_REC709, DT_COLORSPACE_PQ_P3, DT_COLORSPACE_PQ_REC2020, DT_COLORSPACE_PROPHOTO_RGB, DT_COLORSPACE_REC709, DT_COLORSPACE_SOFTPROOF, DT_COLORSPACE_SRGB, DT_COLORSPACE_WORK, DT_COLORSPACE_XYZ, dt_colorspaces_create_adobergb_profile(), dt_colorspaces_create_brg_profile(), dt_colorspaces_create_display_p3_rgb_profile(), dt_colorspaces_create_gamma_rec709_rgb_profile(), dt_colorspaces_create_hlg_p3_rgb_profile(), dt_colorspaces_create_hlg_rec2020_rgb_profile(), dt_colorspaces_create_itur_bt1886_rgb_profile(), dt_colorspaces_create_lab_profile(), dt_colorspaces_create_linear_infrared_profile(), dt_colorspaces_create_linear_prophoto_rgb_profile(), dt_colorspaces_create_linear_rec2020_rgb_profile(), dt_colorspaces_create_linear_rec709_rgb_profile(), dt_colorspaces_create_pq_p3_rgb_profile(), dt_colorspaces_create_pq_rec2020_rgb_profile(), dt_colorspaces_create_srgb_profile(), dt_colorspaces_create_srgb_profile_v4(), dt_colorspaces_create_xyz_profile(), dt_colorspaces_get_matrix_from_input_profile(), dt_colorspaces_get_matrix_from_output_profile(), dt_conf_get_bool(), dt_conf_get_int(), dt_conf_get_string_const(), DT_DEBUG_DEV, dt_print(), DT_PROFILE_GAMUTCHECK, DT_PROFILE_NORMAL, dt_colorspaces_color_profile_t::in_pos, load_profile_from_dir(), dt_colorspaces_t::mode, dt_colorspaces_color_profile_t::name, dt_colorspaces_color_profile_t::out_pos, dt_colorspaces_color_profile_t::profile, dt_colorspaces_t::profiles, Rec709_Primaries, Rec709_Primaries_Prequantized, dt_colorspaces_t::softproof_filename, dt_colorspaces_t::softproof_intent, dt_colorspaces_t::softproof_type, dt_colorspaces_color_profile_t::work_pos, and dt_colorspaces_t::xprofile_lock.

Referenced by dt_init().

◆ dt_colorspaces_is_profile_equal()

gboolean dt_colorspaces_is_profile_equal ( const char *  fullname,
const char *  filename 
)

check whether filename is the same profil as fullname, this is taking into account that fullname is always the fullpathname to the profile and filename may be a full pathname or just a base name

Definition at line 2259 of file colorspaces.c.

References _colorspaces_get_base_name(), and _colorspaces_is_base_name().

Referenced by _get_profile(), _resolve_work_profile(), and gui_update().

◆ dt_colorspaces_pseudoinverse()

static __DT_CLONE_TARGETS__ void dt_colorspaces_pseudoinverse ( double(*)  in[3],
double(*)  out[3],
int  size 
)
static

Definition at line 2535 of file colorspaces.c.

References i, k, out, and size.

Referenced by dt_colorspaces_conversion_matrices_rgb(), and dt_colorspaces_conversion_matrices_xyz().

◆ dt_colorspaces_rgb_to_cygm()

void dt_colorspaces_rgb_to_cygm ( float *  out,
int  num,
double  RGB_to_CAM[4][3] 
)

convert RGB buffer to CYGM

Definition at line 2723 of file colorspaces.c.

References __OMP_PARALLEL_FOR__, i, k, and out.

Referenced by colorpicker_callback(), and legacy_params().

◆ dt_colorspaces_set_display_profile()

◆ dt_colorspaces_transform_rgba8_to_bgra8()

void dt_colorspaces_transform_rgba8_to_bgra8 ( const cmsHTRANSFORM  transform,
const uint8_t *  image_in,
uint8_t *  image_out,
const int  width,
const int  height 
)

◆ dt_colorspaces_transform_rgba_float_image()

__DT_CLONE_TARGETS__ void dt_colorspaces_transform_rgba_float_image ( const cmsHTRANSFORM  transform,
const float *  image_in,
float *  image_out,
const int  width,
const int  height 
)

◆ dt_colorspaces_transform_rgba_float_row()

void dt_colorspaces_transform_rgba_float_row ( const cmsHTRANSFORM  transform,
const float *  in,
float *  out,
const int  width 
)

◆ dt_colorspaces_update_display_transforms()

void dt_colorspaces_update_display_transforms ( )

update the display transforms of srgb and adobergb to the display profile. make sure that darktable.color_profiles->xprofile_lock is held when calling this!

Definition at line 1543 of file colorspaces.c.

References _update_display_transforms(), darktable_t::color_profiles, and darktable.

Referenced by _update_display_profile(), intent_callback(), and profile_callback().

◆ dt_image_find_best_color_profile()

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 whenever possible. This will also init the profile in the image cache.

Parameters
imgidID of the picture
outputIf not NULL, writes the generated color profile into this pointer.
new_profileWill be set to true if a new profile was generated (aka embedded profile) and will need to be freed. If false and output profile is returned, the profile returned already exists on the public list of profiles and should not be freed.
Returns
dt_colorspaces_color_profile_type_t type of profile detected. This type is tested internally and guaranteed to work.

Definition at line 874 of file colorspaces.c.

References dt_image_t::adobe_XYZ_to_CAM, dt_image_t::colorspace, dt_image_t::d65_color_matrix, darktable, DT_COLORSPACE_ADOBERGB, DT_COLORSPACE_EMBEDDED_ICC, DT_COLORSPACE_EMBEDDED_MATRIX, DT_COLORSPACE_LIN_REC2020, DT_COLORSPACE_LIN_REC709, DT_COLORSPACE_NONE, DT_COLORSPACE_SRGB, DT_COLORSPACE_STANDARD_MATRIX, dt_colorspaces_cicp_to_type(), dt_colorspaces_create_xyzimatrix_profile(), dt_colorspaces_get_profile(), dt_colorspaces_get_rgb_profile_from_mem(), DT_DEBUG_COLORPROFILE, dt_free, DT_IMAGE_4BAYER, dt_image_cache_get(), DT_IMAGE_CACHE_RELAXED, dt_image_cache_write_release(), DT_IMAGE_COLORSPACE_ADOBE_RGB, DT_IMAGE_COLORSPACE_SRGB, dt_image_full_path(), dt_image_is_matrix_correction_supported(), dt_image_is_monochrome(), dt_imageio_avif_read_profile(), dt_imageio_heif_read_profile(), dt_imageio_j2k_read_profile(), dt_imageio_jpeg_read_header(), dt_imageio_jpeg_read_profile(), dt_imageio_png_read_profile(), dt_imageio_tiff_read_profile(), dt_print(), DT_PROFILE_DIRECTION_IN, FALSE, dt_image_t::flags, darktable_t::image_cache, IS_NULL_PTR, PATH_MAX, dt_colorspaces_color_profile_t::profile, dt_image_t::profile, dt_image_t::profile_size, and TRUE.

Referenced by dt_colorspaces_get_embedded_profile(), dt_colorspaces_get_input_profile_from_image(), and reload_defaults().

◆ hsl2rgb()

◆ load_profile_from_dir()

◆ mat3inv()

int mat3inv ( float *const  dst,
const float *const  src 
)

◆ mat3inv_double()

int mat3inv_double ( double *const  dst,
const double *const  src 
)

Definition at line 196 of file colorspaces.c.

◆ mat3inv_float()

int mat3inv_float ( float *const  dst,
const float *const  src 
)

inverts the given 3x3 matrix

Definition at line 189 of file colorspaces.c.

Referenced by mat3inv().

◆ rgb2hsl()

void rgb2hsl ( const dt_aligned_pixel_t  rgb,
float *  h,
float *  s,
float *  l 
)

common functions to change between colorspaces, used in iop modules

Definition at line 1408 of file colorspaces.c.

References delta, g, r, and rgb.

Referenced by color_picker_apply(), colorpick_callback(), process(), process_hsl_v1(), process_hsl_v2(), and set_HSL_sliders().

Variable Documentation

◆ Adobe_Primaries

const cmsCIExyYTRIPLE Adobe_Primaries
static
Initial value:
= {
{0.6400, 0.3300, 1.0},
{0.2100, 0.7100, 1.0},
{0.1500, 0.0600, 1.0}
}

Definition at line 135 of file colorspaces.c.

Referenced by dt_colorspaces_create_adobergb_profile().

◆ D50xyY

const cmsCIExyY D50xyY = {0.3457, 0.3585, 1.0}
static

Definition at line 111 of file colorspaces.c.

Referenced by dt_colorspaces_create_linear_prophoto_rgb_profile().

◆ d65

const cmsCIEXYZ d65 = {0.95045471, 1.00000000, 1.08905029}
static

Definition at line 102 of file colorspaces.c.

Referenced by dt_colorspaces_create_xyzmatrix_profile(), and dt_imageio_open_exr().

◆ D65xyY

◆ P3_Primaries

const cmsCIExyYTRIPLE P3_Primaries
static
Initial value:
= {
{0.680, 0.320, 1.0},
{0.265, 0.690, 1.0},
{0.150, 0.060, 1.0}
}

Definition at line 142 of file colorspaces.c.

Referenced by dt_colorspaces_create_display_p3_rgb_profile(), dt_colorspaces_create_hlg_p3_rgb_profile(), and dt_colorspaces_create_pq_p3_rgb_profile().

◆ ProPhoto_Primaries

const cmsCIExyYTRIPLE ProPhoto_Primaries
static
Initial value:
= {
{ 0.734699, 0.265301, 1.0000 },
{ 0.159597, 0.840403, 1.0000 },
{ 0.036598, 0.000105, 1.0000 },
}

Definition at line 150 of file colorspaces.c.

Referenced by dt_colorspaces_create_linear_prophoto_rgb_profile().

◆ Rec2020_Primaries

const cmsCIExyYTRIPLE Rec2020_Primaries
static
Initial value:
= {
{0.7080, 0.2920, 1.0},
{0.1700, 0.7970, 1.0},
{0.1310, 0.0460, 1.0}
}

Definition at line 121 of file colorspaces.c.

Referenced by dt_colorspaces_create_hlg_rec2020_rgb_profile(), dt_colorspaces_create_linear_rec2020_rgb_profile(), and dt_colorspaces_create_pq_rec2020_rgb_profile().

◆ Rec709_Primaries

const cmsCIExyYTRIPLE Rec709_Primaries
static
Initial value:
= {
{0.6400, 0.3300, 1.0},
{0.3000, 0.6000, 1.0},
{0.1500, 0.0600, 1.0}
}

Definition at line 128 of file colorspaces.c.

Referenced by dt_colorspaces_create_gamma_rec709_rgb_profile(), dt_colorspaces_create_itur_bt1886_rgb_profile(), dt_colorspaces_create_linear_rec709_rgb_profile(), and dt_colorspaces_init().

◆ Rec709_Primaries_Prequantized

cmsCIEXYZTRIPLE Rec709_Primaries_Prequantized

Definition at line 157 of file colorspaces.c.

Referenced by _ensure_rgb_profile(), and dt_colorspaces_init().

◆ sRGB_Primaries

const cmsCIExyYTRIPLE sRGB_Primaries
static
Initial value:
= {
{0.6400, 0.3300, 1.0},
{0.3000, 0.6000, 1.0},
{0.1500, 0.0600, 1.0}
}

Definition at line 114 of file colorspaces.c.

Referenced by _colorspaces_create_srgb_profile(), dt_colorspaces_create_brg_profile(), and dt_colorspaces_create_linear_infrared_profile().