58#include <glib/gi18n.h>
86 for(
int i = 0;
i < 3;
i++)
88 profile_info->
lut_in[
i][0] = -1.0f;
95 const char *filename,
const int intent,
const int direction)
97 cmsHTRANSFORM *xform = NULL;
98 cmsHPROFILE *rgb_profile = NULL;
99 cmsHPROFILE *lab_profile = NULL;
109 if(profile) rgb_profile = profile->
profile;
112 cmsColorSpaceSignature rgb_color_space = cmsGetColorSpace(rgb_profile);
113 if(rgb_color_space != cmsSigRgbData)
115 fprintf(stderr,
"working profile color space `%c%c%c%c' not supported\n",
116 (
char)(rgb_color_space>>24),
117 (
char)(rgb_color_space>>16),
118 (
char)(rgb_color_space>>8),
119 (
char)(rgb_color_space));
126 fprintf(stderr, _(
"unsupported working profile %s has been replaced by Rec2020 RGB!\n"), filename);
131 cmsHPROFILE *input_profile = NULL;
132 cmsHPROFILE *output_profile = NULL;
138 input_profile = rgb_profile;
140 output_profile = lab_profile;
145 input_profile = lab_profile;
147 output_profile = rgb_profile;
160 fprintf(stderr,
"[_transform_from_to_rgb_lab_lcms2] cannot create transform\n");
162 if(xform) cmsDeleteTransform(xform);
165static inline __attribute__((always_inline))
void _transform_rgb_to_rgb_lcms2(
const float *
const image_in,
float *
const image_out,
const int width,
167 const char *filename_from,
171 cmsHTRANSFORM *xform = NULL;
172 cmsHPROFILE *from_rgb_profile = NULL;
173 cmsHPROFILE *to_rgb_profile = NULL;
192 if(profile_from) from_rgb_profile = profile_from->
profile;
196 fprintf(stderr,
"[_transform_rgb_to_rgb_lcms2] invalid from profile\n");
201 if(profile_to) to_rgb_profile = profile_to->
profile;
205 fprintf(stderr,
"[_transform_rgb_to_rgb_lcms2] invalid to profile\n");
210 cmsColorSpaceSignature rgb_color_space = cmsGetColorSpace(from_rgb_profile);
211 if(rgb_color_space != cmsSigRgbData)
213 fprintf(stderr,
"[_transform_rgb_to_rgb_lcms2] profile color space `%c%c%c%c' not supported\n",
214 (
char)(rgb_color_space >> 24), (
char)(rgb_color_space >> 16), (
char)(rgb_color_space >> 8),
215 (
char)(rgb_color_space));
216 from_rgb_profile = NULL;
221 cmsColorSpaceSignature rgb_color_space = cmsGetColorSpace(to_rgb_profile);
222 if(rgb_color_space != cmsSigRgbData)
224 fprintf(stderr,
"[_transform_rgb_to_rgb_lcms2] profile color space `%c%c%c%c' not supported\n",
225 (
char)(rgb_color_space >> 24), (
char)(rgb_color_space >> 16), (
char)(rgb_color_space >> 8),
226 (
char)(rgb_color_space));
227 to_rgb_profile = NULL;
231 cmsHPROFILE *input_profile = NULL;
232 cmsHPROFILE *output_profile = NULL;
236 input_profile = from_rgb_profile;
238 output_profile = to_rgb_profile;
241 if(input_profile && output_profile)
252 fprintf(stderr,
"[_transform_rgb_to_rgb_lcms2] cannot create transform\n");
254 if(xform) cmsDeleteTransform(xform);
263 if(cst_from == cst_to)
265 *converted_cst = cst_to;
269 *converted_cst = cst_to;
274 "[dt_ioppr_transform_lcms2] transfoming from RGB to Lab (%s %s)\n", op, multi_name);
281 "[dt_ioppr_transform_lcms2] transfoming from Lab to RGB (%s %s)\n", op, multi_name);
287 *converted_cst = cst_from;
288 fprintf(stderr,
"[dt_ioppr_transform_lcms2] invalid conversion from %i to %i\n", cst_from, cst_to);
292static inline __attribute__((always_inline))
void _transform_lcms2_rgb(
const float *
const image_in,
float *
const image_out,
const int width,
297 _transform_rgb_to_rgb_lcms2(image_in, image_out,
width,
height, profile_info_from->
type,
304 float *
const unbounded_coeffsr,
float *
const unbounded_coeffsg,
float *
const unbounded_coeffsb,
const int lutsize)
306 int nonlinearlut = 0;
307 float *
lut[3] = { lutr, lutg, lutb };
308 float *
unbounded_coeffs[3] = { unbounded_coeffsr, unbounded_coeffsg, unbounded_coeffsb };
310 for(
int k = 0;
k < 3;
k++)
313 if(
lut[
k][0] >= 0.0f)
334 const float *
const restrict lutr,
335 const float *
const restrict lutg,
336 const float *
const restrict lutb,
337 const float *
const restrict unbounded_coeffsr,
338 const float *
const restrict unbounded_coeffsg,
339 const float *
const restrict unbounded_coeffsb,
343 const float *
const lut[3] = { lutr, lutg, lutb };
344 const float *
const unbounded_coeffs[3] = { unbounded_coeffsr, unbounded_coeffsg, unbounded_coeffsb };
348 if((
lut[0][0] >= 0.0f) && (
lut[1][0] >= 0.0f) && (
lut[2][0] >= 0.0f))
351 for(
size_t k = 0;
k < stride;
k +=
ch)
353 for(
int c = 0; c < 3; c++)
359 else if((
lut[0][0] >= 0.0f) || (
lut[1][0] >= 0.0f) || (
lut[2][0] >= 0.0f))
362 for(
size_t k = 0;
k < stride;
k +=
ch)
364 for(
int c = 0; c < 3; c++)
366 if(
lut[c][0] >= 0.0f)
384 const dt_aligned_pixel_simd_t m0 = dt_colormatrix_row_to_simd(*matrix_ptr, 0);
385 const dt_aligned_pixel_simd_t m1 = dt_colormatrix_row_to_simd(*matrix_ptr, 1);
386 const dt_aligned_pixel_simd_t m2 = dt_colormatrix_row_to_simd(*matrix_ptr, 2);
392 profile_info->
lut_in[2], profile_info->unbounded_coeffs_in[0],
393 profile_info->unbounded_coeffs_in[1], profile_info->unbounded_coeffs_in[2],
396 for(
size_t y = 0; y < stride; y +=
ch)
398 float *
const restrict
in = __builtin_assume_aligned(image_out + y, 16);
400 const dt_aligned_pixel_simd_t vin = dt_load_simd_aligned(
in);
404 in[3] = image_in[y + 3];
410 for(
size_t y = 0; y < stride; y +=
ch)
412 const float *
const restrict
in = __builtin_assume_aligned(image_in + y, 16);
413 float *
const restrict
out = __builtin_assume_aligned(image_out + y, 16);
416 const float alpha =
in[3];
417 const dt_aligned_pixel_simd_t vin = dt_load_simd_aligned(
in);
433 const int use_nontemporal = !profile_info->
nonlinearlut;
435 const dt_aligned_pixel_simd_t m0 = dt_colormatrix_row_to_simd(*matrix_ptr, 0);
436 const dt_aligned_pixel_simd_t m1 = dt_colormatrix_row_to_simd(*matrix_ptr, 1);
437 const dt_aligned_pixel_simd_t m2 = dt_colormatrix_row_to_simd(*matrix_ptr, 2);
439 for(
size_t y = 0; y < stride; y +=
ch)
441 const float *
const restrict
in = __builtin_assume_aligned(image_in + y, 16);
442 float *
const restrict
out = __builtin_assume_aligned(image_out + y, 16);
445 const float alpha =
in[3];
447 const dt_aligned_pixel_simd_t vxyz = dt_load_simd_aligned(xyz);
448 dt_aligned_pixel_simd_t
rgb = dt_mat3x4_mul_vec4(vxyz, m0, m1, m2);
451 dt_store_simd_nontemporal(
out,
rgb);
463 profile_info->
lut_out[2], profile_info->unbounded_coeffs_out[0],
464 profile_info->unbounded_coeffs_out[1], profile_info->unbounded_coeffs_out[2],
472 float *
const restrict image_out,
486 const dt_aligned_pixel_simd_t m0 = dt_colormatrix_row_to_simd(
matrix, 0);
487 const dt_aligned_pixel_simd_t m1 = dt_colormatrix_row_to_simd(
matrix, 1);
488 const dt_aligned_pixel_simd_t m2 = dt_colormatrix_row_to_simd(
matrix, 2);
492 const int use_nontemporal = !profile_info_to->
nonlinearlut;
494 (profile_info_from->
lut_in[1][0] >= 0.0f),
495 (profile_info_from->
lut_in[2][0] >= 0.0f) };
498 (profile_info_to->
lut_out[1][0] >= 0.0f),
499 (profile_info_to->
lut_out[2][0] >= 0.0f) };
501 for(
size_t y = 0; y < stride; y += 4)
503 const float *
const restrict
in = __builtin_assume_aligned(image_in + y, 16);
504 float *
const restrict
out = __builtin_assume_aligned(image_out + y, 16);
510 for(
size_t c = 0; c < 3; c++)
512 rgb[c] = (run_lut_in[c]
513 ? dt_ioppr_eval_trc(
in[c], profile_info_from->
lut_in[c],
514 profile_info_from->unbounded_coeffs_in[c], profile_info_from->
lutsize)
528 const dt_aligned_pixel_simd_t vrgb = dt_load_simd_aligned(
rgb);
532 for(
size_t c = 0; c < 3; c++)
534 out[c] = (run_lut_out[c]
535 ? dt_ioppr_eval_trc(temp[c], profile_info_to->
lut_out[c],
536 profile_info_to->unbounded_coeffs_out[c], profile_info_to->
lutsize)
543 const dt_aligned_pixel_simd_t vrgb = dt_load_simd_aligned(
rgb);
545 dt_store_simd_nontemporal(
out, dt_mat3x4_mul_vec4(vrgb, m0, m1, m2));
557 for(
size_t y = 0; y < stride; y += 4)
559 const float *
const restrict
in = __builtin_assume_aligned(image_in + y, 16);
560 float *
const restrict
out = __builtin_assume_aligned(image_out + y, 16);
562 const dt_aligned_pixel_simd_t vin = dt_load_simd_aligned(
in);
563 dt_store_simd_nontemporal(
out, dt_mat3x4_mul_vec4(vin, m0, m1, m2));
571 const float *
const restrict image_in,
572 float *
const restrict image_out,
579 if(cst_from == cst_to)
581 *converted_cst = cst_to;
585 *converted_cst = cst_to;
597 *converted_cst = cst_from;
598 fprintf(stderr,
"[dt_ioppr_transform_matrix] invalid conversion from %i to %i\n", cst_from, cst_to);
603#define DT_IOPPR_LUT_SAMPLES 0x10000
611 dt_ioppr_mark_as_nonmatrix_profile(profile_info);
612 profile_info->unbounded_coeffs_in[0][0] = profile_info->unbounded_coeffs_in[1][0] = profile_info->unbounded_coeffs_in[2][0] = -1.0f;
613 profile_info->unbounded_coeffs_out[0][0] = profile_info->unbounded_coeffs_out[1][0] = profile_info->unbounded_coeffs_out[2][0] = -1.0f;
615 profile_info->
grey = 0.f;
617 for(
int i = 0;
i < 3;
i++)
620 profile_info->
lut_in[
i][0] = -1.0f;
622 profile_info->
lut_out[
i][0] = -1.0f;
626#undef DT_IOPPR_LUT_SAMPLES
637 for(
int i = 0;
i < 3;
i++)
640 (*profile_info)->lut_in[
i] = NULL;
642 (*profile_info)->lut_out[
i] = NULL;
646 *profile_info = NULL;
659 if(profile_info_from->
type == profile_info_to->
type
662 if(image_in != image_out)
668 dt_times_t start_time = { 0 }, end_time = { 0 };
671 if(!isnan(profile_info_from->
matrix_in[0][0]) && !isnan(profile_info_from->
matrix_out[0][0])
679 fprintf(stderr,
"image colorspace transform RGB-->RGB took %.3f secs (%.3f CPU) [%s]\n",
680 end_time.clock - start_time.
clock, end_time.user - start_time.
user, (message) ? message :
"");
685 _transform_lcms2_rgb(image_in, image_out,
width,
height, profile_info_from, profile_info_to);
690 fprintf(stderr,
"image colorspace transform RGB-->RGB took %.3f secs (%.3f lcms2) [%s]\n",
691 end_time.clock - start_time.
clock, end_time.user - start_time.
user, (message) ? message :
"");
708 const int program = 23;
709 g->kernel_colorspaces_transform_lab_to_rgb_matrix =
dt_opencl_create_kernel(program,
"colorspaces_transform_lab_to_rgb_matrix");
710 g->kernel_colorspaces_transform_rgb_matrix_to_lab =
dt_opencl_create_kernel(program,
"colorspaces_transform_rgb_matrix_to_lab");
711 g->kernel_colorspaces_transform_rgb_matrix_to_rgb
732 for(
int i = 0;
i < 9;
i++)
738 for(
int i = 0;
i < 3;
i++)
740 for(
int j = 0; j < 3; j++)
747 profile_info_cl->
grey = profile_info->
grey;
752 cl_float *trc = malloc(
sizeof(cl_float) * 6 * profile_info->
lutsize);
756 for(
int c = 0; c < 3; c++)
757 for(
int y = 0; y < profile_info->
lutsize; y++,
x++)
758 trc[
x] = profile_info->
lut_in[c][y];
759 for(
int c = 0; c < 3; c++)
760 for(
int y = 0; y < profile_info->
lutsize; y++,
x++)
761 trc[
x] = profile_info->
lut_out[c][y];
768 cl_float **_profile_lut_cl, cl_mem *_dev_profile_info,
769 cl_mem *_dev_profile_lut)
771 cl_int err = CL_SUCCESS;
774 cl_float *profile_lut_cl = NULL;
775 cl_mem dev_profile_info = NULL;
776 cl_mem dev_profile_lut = NULL;
786 fprintf(stderr,
"[dt_ioppr_build_iccprofile_params_cl] error allocating memory 5\n");
787 err = CL_MEM_OBJECT_ALLOCATION_FAILURE;
794 fprintf(stderr,
"[dt_ioppr_build_iccprofile_params_cl] error allocating memory 6\n");
795 err = CL_MEM_OBJECT_ALLOCATION_FAILURE;
801 profile_lut_cl = malloc(
sizeof(cl_float) * 1 * 6);
806 fprintf(stderr,
"[dt_ioppr_build_iccprofile_params_cl] error allocating memory 7\n");
807 err = CL_MEM_OBJECT_ALLOCATION_FAILURE;
813 *_profile_info_cl = profile_info_cl;
814 *_profile_lut_cl = profile_lut_cl;
815 *_dev_profile_info = dev_profile_info;
816 *_dev_profile_lut = dev_profile_lut;
822 cl_float **_profile_lut_cl, cl_mem *_dev_profile_info,
823 cl_mem *_dev_profile_lut)
826 cl_float *profile_lut_cl = *_profile_lut_cl;
827 cl_mem dev_profile_info = *_dev_profile_info;
828 cl_mem dev_profile_lut = *_dev_profile_lut;
838 *_profile_info_cl = NULL;
839 *_profile_lut_cl = NULL;
840 *_dev_profile_info = NULL;
841 *_dev_profile_lut = NULL;
850 cl_int err = CL_SUCCESS;
856 if(profile_info_from->
type == profile_info_to->
type
859 if(dev_img_in != dev_img_out)
861 size_t origin[] = { 0, 0, 0 };
865 if(err != CL_SUCCESS)
868 "[dt_ioppr_transform_image_colorspace_rgb_cl] error on copy image for color transformation\n");
877 float *src_buffer_in = NULL;
878 float *src_buffer_out = NULL;
879 int in_place = (dev_img_in == dev_img_out);
881 int kernel_transform = 0;
882 cl_mem dev_tmp = NULL;
884 cl_mem dev_profile_info_from = NULL;
885 cl_mem dev_lut_from = NULL;
887 cl_float *lut_from_cl = NULL;
889 cl_mem dev_profile_info_to = NULL;
890 cl_mem dev_lut_to = NULL;
892 cl_float *lut_to_cl = NULL;
894 cl_mem matrix_cl = NULL;
897 if(!isnan(profile_info_from->
matrix_in[0][0]) && !isnan(profile_info_from->
matrix_out[0][0])
900 dt_times_t start_time = { 0 }, end_time = { 0 };
903 size_t origin[] = { 0, 0, 0 };
924 "[dt_ioppr_transform_image_colorspace_rgb_cl] error allocating memory for color transformation 4\n");
925 err = CL_MEM_OBJECT_ALLOCATION_FAILURE;
930 if(err != CL_SUCCESS)
933 "[dt_ioppr_transform_image_colorspace_rgb_cl] error on copy image for color transformation\n");
939 dev_tmp = dev_img_in;
942 dev_profile_info_from
947 "[dt_ioppr_transform_image_colorspace_rgb_cl] error allocating memory for color transformation 5\n");
948 err = CL_MEM_OBJECT_ALLOCATION_FAILURE;
955 "[dt_ioppr_transform_image_colorspace_rgb_cl] error allocating memory for color transformation 6\n");
956 err = CL_MEM_OBJECT_ALLOCATION_FAILURE;
965 "[dt_ioppr_transform_image_colorspace_rgb_cl] error allocating memory for color transformation 7\n");
966 err = CL_MEM_OBJECT_ALLOCATION_FAILURE;
973 "[dt_ioppr_transform_image_colorspace_rgb_cl] error allocating memory for color transformation 8\n");
974 err = CL_MEM_OBJECT_ALLOCATION_FAILURE;
983 "[dt_ioppr_transform_image_colorspace_rgb_cl] error allocating memory for color transformation 7\n");
984 err = CL_MEM_OBJECT_ALLOCATION_FAILURE;
1000 if(err != CL_SUCCESS)
1003 "[dt_ioppr_transform_image_colorspace_rgb_cl] error %i enqueue kernel for color transformation\n",
1011 fprintf(stderr,
"image colorspace transform RGB-->RGB took %.3f secs (%.3f GPU) [%s]\n",
1012 end_time.clock - start_time.
clock, end_time.user - start_time.
user, (message) ? message :
"");
1023 "[dt_ioppr_transform_image_colorspace_rgb_cl] error allocating memory for color transformation 1\n");
1024 err = CL_MEM_OBJECT_ALLOCATION_FAILURE;
1029 if(err != CL_SUCCESS)
1032 "[dt_ioppr_transform_image_colorspace_rgb_cl] error allocating memory for color transformation 2\n");
1038 profile_info_to, message);
1041 if(err != CL_SUCCESS)
1044 "[dt_ioppr_transform_image_colorspace_rgb_cl] error allocating memory for color transformation 3\n");
1064 return (err == CL_SUCCESS) ?
TRUE :
FALSE;
1068#undef DT_IOP_ORDER_PROFILE
1148 GList *next = g_list_next(l);
1164 cmsHPROFILE *rgb_profile = NULL;
1166 dt_ioppr_mark_as_nonmatrix_profile(profile_info);
1170 profile_info->
grey = 0.1842f;
1173 g_strlcpy(profile_info->
filename, filename,
sizeof(profile_info->
filename));
1174 profile_info->
intent = intent;
1186 if(profile) rgb_profile = profile->
profile;
1191 cmsColorSpaceSignature rgb_color_space = cmsGetColorSpace(rgb_profile);
1192 if(rgb_color_space != cmsSigRgbData)
1194 fprintf(stderr,
"working profile color space `%c%c%c%c' not supported\n",
1195 (
char)(rgb_color_space>>24),
1196 (
char)(rgb_color_space>>16),
1197 (
char)(rgb_color_space>>8),
1198 (
char)(rgb_color_space));
1213 dt_ioppr_mark_as_nonmatrix_profile(profile_info);
1218 dt_ioppr_mark_as_nonmatrix_profile(profile_info);
1235 profile_info->unbounded_coeffs_in[0], profile_info->unbounded_coeffs_in[1], profile_info->unbounded_coeffs_in[2], profile_info->
lutsize);
1237 profile_info->unbounded_coeffs_out[0], profile_info->unbounded_coeffs_out[1], profile_info->unbounded_coeffs_out[2], profile_info->
lutsize);
1255 const char *profile_filename,
1262 for(GList *profiles =
_profile_info_memo; profiles; profiles = g_list_next(profiles))
1265 if(prof->
type == profile_type && prof->
intent == intent
1266 && strcmp(prof->
filename, profile_filename) == 0)
1268 profile_info = prof;
1273 return profile_info;
1278 const char *profile_filename,
1308 return profile_info;
1330 float *
const image_out,
const int width,
const int height,
1331 const int cst_from,
const int cst_to,
int *converted_cst,
1334 if(cst_from == cst_to)
1336 *converted_cst = cst_to;
1341 *converted_cst = cst_to;
1346 *converted_cst = cst_from;
1351 *converted_cst = cst_from;
1355 dt_times_t start_time = { 0 }, end_time = { 0 };
1366 fprintf(stderr,
"image colorspace transform %s-->%s took %.3f secs (%.3f CPU) [%s %s]\n",
1369 end_time.clock - start_time.
clock, end_time.user - start_time.
user, op_name, instance_name);
1379 fprintf(stderr,
"image colorspace transform %s-->%s took %.3f secs (%.3f lcms2) [%s %s]\n",
1382 end_time.clock - start_time.
clock, end_time.user - start_time.
user, op_name, instance_name);
1386 if(*converted_cst == cst_from)
1387 fprintf(stderr,
"[dt_colorspaces_apply_profile] invalid conversion from %i to %i\n", cst_from, cst_to);
1392 cl_mem dev_img_out,
const int width,
const int height,
1393 const int cst_from,
const int cst_to,
int *converted_cst,
1396 cl_int err = CL_SUCCESS;
1400 assert(dev_img_in != dev_img_out);
1402 if(cst_from == cst_to)
1404 *converted_cst = cst_to;
1409 *converted_cst = cst_to;
1414 *converted_cst = cst_from;
1419 *converted_cst = cst_from;
1423 const size_t ch = 4;
1424 float *src_buffer = NULL;
1426 int kernel_transform = 0;
1427 cl_mem dev_profile_info = NULL;
1428 cl_mem dev_lut = NULL;
1430 cl_float *lut_cl = NULL;
1432 *converted_cst = cst_from;
1437 dt_times_t start_time = { 0 }, end_time = { 0 };
1450 err = CL_INVALID_KERNEL;
1451 *converted_cst = cst_from;
1452 fprintf(stderr,
"[dt_colorspaces_apply_profile_cl] invalid conversion from %i to %i\n", cst_from, cst_to);
1462 fprintf(stderr,
"[dt_colorspaces_apply_profile_cl] error allocating memory for color transformation 5\n");
1463 err = CL_MEM_OBJECT_ALLOCATION_FAILURE;
1469 fprintf(stderr,
"[dt_colorspaces_apply_profile_cl] error allocating memory for color transformation 6\n");
1470 err = CL_MEM_OBJECT_ALLOCATION_FAILURE;
1483 if(err != CL_SUCCESS)
1485 fprintf(stderr,
"[dt_colorspaces_apply_profile_cl] error %i enqueue kernel for color transformation\n", err);
1489 *converted_cst = cst_to;
1494 fprintf(stderr,
"image colorspace transform %s-->%s took %.3f secs (%.3f GPU) [%s %s]\n",
1497 end_time.clock - start_time.
clock, end_time.user - start_time.
user, op_name, instance_name);
1506 fprintf(stderr,
"[dt_colorspaces_apply_profile_cl] error allocating memory for color transformation 1\n");
1507 err = CL_MEM_OBJECT_ALLOCATION_FAILURE;
1512 if(err != CL_SUCCESS)
1514 fprintf(stderr,
"[dt_colorspaces_apply_profile_cl] error allocating memory for color transformation 2\n");
1520 converted_cst, profile_info);
1523 if(err != CL_SUCCESS)
1525 fprintf(stderr,
"[dt_colorspaces_apply_profile_cl] error allocating memory for color transformation 3\n");
1536 return (err == CL_SUCCESS) ?
TRUE :
FALSE;
void cleanup(dt_imageio_module_format_t *self)
void output_format(dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece, dt_iop_buffer_dsc_t *dsc)
void input_format(dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece, dt_iop_buffer_dsc_t *dsc)
static dt_colorspaces_cl_global_t * _colorspaces_cl_global
int dt_colorspaces_apply_profile_cl(const char *const op_name, const char *const instance_name, const int devid, cl_mem dev_img_in, cl_mem dev_img_out, const int width, const int height, const int cst_from, const int cst_to, int *converted_cst, const dt_iop_order_iccprofile_info_t *const profile_info)
OpenCL counterpart of dt_colorspaces_apply_profile(), same contract.
dt_iop_order_iccprofile_info_t * dt_colorspaces_add_profile(const dt_colorspaces_color_profile_type_t profile_type, const char *profile_filename, const int intent)
Find-or-build the derived matrix/LUT data for a profile identity, memoised.
void dt_ioppr_cleanup_profile_info(dt_iop_order_iccprofile_info_t **profile_info)
Release a profile info: its tone-curve LUTs, the struct itself, and the caller's pointer – must be ca...
static void _transform_rgb_to_lab_matrix(const float *const restrict image_in, float *const restrict image_out, const int width, const int height, const dt_iop_order_iccprofile_info_t *const profile_info)
static dt_iop_order_iccprofile_info_t * _get_profile_info_from_list(const dt_colorspaces_color_profile_type_t profile_type, const char *profile_filename, const int intent)
#define DT_IOPPR_LUT_SAMPLES
void dt_colorspaces_init_cl_global(void)
Compile the colorspace kernels. Called once by common/opencl.c at device init.
int dt_ioppr_init_unbounded_coeffs(float *const lutr, float *const lutg, float *const lutb, float *const unbounded_coeffsr, float *const unbounded_coeffsg, float *const unbounded_coeffsb, const int lutsize)
Fit the power-law continuation of three tone curves past white.
void dt_ioppr_transform_image_colorspace_rgb(const float *const restrict image_in, float *const restrict image_out, const int width, const int height, const dt_iop_order_iccprofile_info_t *const profile_info_from, const dt_iop_order_iccprofile_info_t *const profile_info_to, const char *message)
static int _generate_profile_info(dt_iop_order_iccprofile_info_t *profile_info, const int type, const char *filename, const int intent)
void dt_ioppr_get_profile_info_cl(const dt_iop_order_iccprofile_info_t *const profile_info, dt_colorspaces_iccprofile_info_cl_t *profile_info_cl)
sets profile_info_cl using profile_info, to be used as a parameter when calling opencl.
static pthread_mutex_t _profile_info_lock
void dt_colorspaces_apply_profile(const char *const op_name, const char *const instance_name, const float *const image_in, float *const image_out, const int width, const int height, const int cst_from, const int cst_to, int *converted_cst, const dt_iop_order_iccprofile_info_t *const profile_info)
Convert a 4-channel float buffer between RGB and Lab through one profile.
static GList * _profile_info_memo
static void _transform_from_to_rgb_lab_lcms2(const float *const image_in, float *const image_out, const int width, const int height, const dt_colorspaces_color_profile_type_t type, const char *filename, const int intent, const int direction)
void dt_colorspaces_free_cl_global(void)
Release the kernels and the struct from dt_colorspaces_init_cl_global(). NULL-safe.
void dt_ioppr_free_iccprofile_params_cl(dt_colorspaces_iccprofile_info_cl_t **_profile_info_cl, cl_float **_profile_lut_cl, cl_mem *_dev_profile_info, cl_mem *_dev_profile_lut)
free parameters build with the previous function.
static GList * _profile_info_retired
static void _apply_tonecurves(const float *const image_in, float *const image_out, const int width, const int height, const float *const restrict lutr, const float *const restrict lutg, const float *const restrict lutb, const float *const restrict unbounded_coeffsr, const float *const restrict unbounded_coeffsg, const float *const restrict unbounded_coeffsb, const int lutsize)
void dt_colorspaces_invalidate_display_profile_memo(void)
Drop the memoised DT_COLORSPACE_DISPLAY entry, whose source profile this module replaces on a monitor...
void dt_ioppr_clear_lut_curves(dt_iop_order_iccprofile_info_t *const profile_info)
Mark all six tone curves linear, by writing -1.0 into entry 0 of each.
cl_float * dt_ioppr_get_trc_cl(const dt_iop_order_iccprofile_info_t *const profile_info)
returns the profile_info trc, to be used as a parameter when calling opencl.
void dt_ioppr_transform_matrix(const char *op, const char *multi_name, const float *const restrict image_in, float *const restrict image_out, const int width, const int height, const dt_iop_colorspace_type_t cst_from, const dt_iop_colorspace_type_t cst_to, dt_iop_colorspace_type_t *converted_cst, const dt_iop_order_iccprofile_info_t *const profile_info)
static void _transform_lab_to_rgb_matrix(const float *const image_in, float *const image_out, const int width, const int height, const dt_iop_order_iccprofile_info_t *const profile_info)
int dt_ioppr_transform_image_colorspace_rgb_cl(const int devid, cl_mem dev_img_in, cl_mem dev_img_out, const int width, const int height, const dt_iop_order_iccprofile_info_t *const profile_info_from, const dt_iop_order_iccprofile_info_t *const profile_info_to, const char *message)
OpenCL counterpart of dt_ioppr_transform_image_colorspace_rgb().
cl_int dt_ioppr_build_iccprofile_params_cl(const dt_iop_order_iccprofile_info_t *const profile_info, const int devid, dt_colorspaces_iccprofile_info_cl_t **_profile_info_cl, cl_float **_profile_lut_cl, cl_mem *_dev_profile_info, cl_mem *_dev_profile_lut)
build the required parameters for a kernel that uses a profile info.
static void _transform_matrix_rgb(const float *const restrict image_in, float *const restrict image_out, const int width, const int height, const dt_iop_order_iccprofile_info_t *const profile_info_from, const dt_iop_order_iccprofile_info_t *const profile_info_to)
void dt_colorspaces_flush_profile_memo(void)
Drop every memoised entry. Called by dt_colorprofiles_cleanup().
void dt_ioppr_transform_lcms2(const char *op, const char *multi_name, const float *const image_in, float *const image_out, const int width, const int height, const dt_iop_colorspace_type_t cst_from, const dt_iop_colorspace_type_t cst_to, dt_iop_colorspace_type_t *converted_cst, const dt_iop_order_iccprofile_info_t *const profile_info)
The lcms2 branch of dt_colorspaces_apply_profile(): RGB <-> Lab via cmsDoTransform.
void dt_ioppr_init_profile_info(dt_iop_order_iccprofile_info_t *profile_info, const int lutsize)
Put a freshly allocated dt_iop_order_iccprofile_info_t into its empty state – must be called before u...
The colour-profile struct and the maths over it: the derived matrix/LUT engine.
static dt_aligned_pixel_t float *const const float unbounded_coeffs[3][3]
const float const int lutsize
void dt_colorspaces_unlock_profile(const dt_colorspaces_color_profile_t *const profile)
__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)
Run a caller-owned LCMS transform over a whole RGBA float image, one OpenMP task per row.
const dt_colorspaces_color_profile_t * dt_colorspaces_get_profile(dt_colorspaces_color_profile_type_t type, const char *filename, dt_colorspaces_profile_role_t role)
Resolve a profile identity to its registered entry.
int dt_colorspaces_get_matrix_from_output_profile(cmsHPROFILE prof, dt_colormatrix_t matrix, float *lutr, float *lutg, float *lutb, const int lutsize)
Extract the XYZ->profile matrix and the inverse tone curves from an OUTPUT profile.
int dt_colorspaces_get_matrix_from_input_profile(cmsHPROFILE prof, dt_colormatrix_t matrix, float *lutr, float *lutg, float *lutb, const int lutsize)
Extract the profile->XYZ matrix and the per-channel tone curves from an INPUT profile.
void dt_colorspaces_lock_profile(const dt_colorspaces_color_profile_t *const profile)
The colour-profile module's API: which profiles exist, and how to apply one.
static dt_aligned_pixel_t rgb
const dt_colormatrix_t dt_aligned_pixel_t out
dt_store_simd_aligned(out, dt_mat3x4_mul_vec4(vin, dt_colormatrix_row_to_simd(matrix, 0), dt_colormatrix_row_to_simd(matrix, 1), dt_colormatrix_row_to_simd(matrix, 2)))
const dt_colormatrix_t matrix
void * dt_alloc_align(size_t size)
Allocate cacheline-aligned memory.
memcpy(roundtrip, origin, sizeof(roundtrip))
static void dt_iop_estimate_exp(const float *const x, const float *const y, const int num, float *coeff)
_lib_location_type_t type
int32_t dt_get_debug_flags(void)
void dt_print(dt_debug_thread_t thread, const char *msg,...) __attribute__((format(printf
Print to stdout when thread is enabled, prefixed with seconds since startup.
float *const restrict const size_t k
float *const restrict const size_t const size_t ch
#define IS_NULL_PTR(p)
C is way too permissive with !=, == and if(var) checks, which can mean too many things depending on w...
float DT_ALIGNED_ARRAY dt_colormatrix_t[4][4]
static void transpose_3xSSE(const dt_colormatrix_t input, dt_colormatrix_t output)
static void pack_3xSSE_to_3x4(const dt_colormatrix_t input, float output[12])
static void dt_colormatrix_mul(dt_colormatrix_t dst, const dt_colormatrix_t m1, const dt_colormatrix_t m2)
#define DT_ALIGNED_PIXEL
Align a 4-float pixel on 16 bytes, enough for SSE. Same struct-member caveat as DT_ALIGNED_ARRAY,...
#define dt_free_align(ptr)
Release memory from dt_alloc_align() and set ptr to NULL.
static float * dt_alloc_align_float(size_t pixels)
Allocate pixels floats, cacheline-aligned and marked as such.
#define dt_free(ptr)
g_free() ptr and set it to NULL, skipping both if it is already NULL.
int dt_opencl_enqueue_kernel_2d(const int dev, const int kernel, const size_t *sizes)
int dt_opencl_copy_device_to_host(const int devid, void *host, void *device, const int width, const int height, const int bpp)
void * dt_opencl_alloc_device(const int devid, const int width, const int height, const int bpp)
int dt_opencl_create_kernel(const int prog, const char *name)
void * dt_opencl_copy_host_to_device_constant(const int devid, const size_t size, void *host)
int dt_opencl_enqueue_copy_image(const int devid, cl_mem src, cl_mem dst, size_t *orig_src, size_t *orig_dst, size_t *region)
void dt_opencl_free_kernel(const int kernel)
int dt_opencl_set_kernel_arg(const int dev, const int kernel, const int num, const size_t size, const void *arg)
void * dt_opencl_copy_host_to_device(const int devid, void *host, const int width, const int height, const int bpp)
void dt_opencl_release_mem_object(cl_mem mem)
int dt_opencl_write_host_to_device(const int devid, void *host, void *device, const int width, const int height, const int bpp)
#define dt_omploop_sfence()
#define __OMP_PARALLEL_FOR__(...)
#define __OMP_PARALLEL_FOR_SIMD__(...)
#define dt_pixelpipe_cache_alloc_align_float_cache(pixels, id)
#define dt_pixelpipe_cache_free_align(mem)
dt_colorspaces_color_profile_type_t
@ DT_COLORSPACE_DISPLAY
The monitor profile – the one list entry that mutates after init.
@ DT_COLORSPACE_NONE
No profile / "take it from the image settings". Never matches a list entry.
@ DT_COLORSPACE_LIN_REC2020
@ DT_PROFILE_ROLE_WORKING
Listed in the working-profile combo (colorin).
@ DT_PROFILE_ROLE_ANY
All four roles, in registration order.
DT_ALIGNED_PIXEL float dt_aligned_pixel_t[4]
#define for_each_channel(_var,...)
float dt_aligned_pixel_simd_t __attribute__((vector_size(16), aligned(16)))
Apply one channel's tone curve to each of the three colour channels, or pass the channel through unto...
The three colorspace kernels, compiled once and held by common/opencl.c.
One registered profile: its identity, its LCMS handle, and where it sits in each combo box.
cmsHPROFILE profile
the actual profile; NULL for the three category entries
The device-side view of a dt_iop_order_iccprofile_info_t: the scalar fields only.
float unbounded_coeffs_out[3][3]
float unbounded_coeffs_in[3][3]
A profile reduced to the arithmetic the pixel loop can run: two matrices and six tone-curve LUTs,...
int nonlinearlut
Non-zero when the profile has tone curves at all; tested as a boolean everywhere, but it is really th...
int lutsize
Entry count of each of the six LUTs. Always 65536 in practice: both callers of dt_ioppr_init_profile_...
dt_iop_color_intent_t intent
Rendering intent, passed to cmsCreateTransform on the lcms2 fallback only. The matrix path ignores it...
dt_colormatrix_t matrix_out_transposed
float grey
Luminance of 18.42% grey through this profile, used by the tone-mapping modules to place middle grey....
dt_colorspaces_color_profile_type_t type
Profile identity, half of the memo key. DT_COLORSPACE_NONE means "unset" and makes every apply functi...
float * lut_out[3]
Per-channel linear -> encoded tone curve, same convention as lut_in.
dt_colormatrix_t matrix_out
XYZ (D50) -> RGB, row-major; the inverse of matrix_in.
float * lut_in[3]
Per-channel encoded -> linear tone curve, lutsize entries each, sampled over [0,1]....
char filename[DT_IOP_COLOR_ICC_LEN]
ICC file name, the other half of the memo key; "" for every built-in. Compared with strcmp,...
dt_colormatrix_t matrix_in_transposed
dt_colormatrix_t matrix_in
RGB -> XYZ (D50), row-major. matrix_in[1][*] is the luminance row. NaN in [0][0] marks the whole prof...
#define __DT_CLONE_TARGETS__
static void dt_get_times(dt_times_t *t)