69 for(
int i = 0;
i < 3;
i++)
71 profile_info->
lut_in[
i][0] = -1.0f;
78 const char *filename,
const int intent,
const int direction)
80 cmsHTRANSFORM *xform = NULL;
81 cmsHPROFILE *rgb_profile = NULL;
82 cmsHPROFILE *lab_profile = NULL;
90 if(profile) rgb_profile = profile->
profile;
96 cmsColorSpaceSignature rgb_color_space = cmsGetColorSpace(rgb_profile);
97 if(rgb_color_space != cmsSigRgbData)
99 fprintf(stderr,
"working profile color space `%c%c%c%c' not supported\n",
100 (
char)(rgb_color_space>>24),
101 (
char)(rgb_color_space>>16),
102 (
char)(rgb_color_space>>8),
103 (
char)(rgb_color_space));
110 fprintf(stderr, _(
"unsupported working profile %s has been replaced by Rec2020 RGB!\n"), filename);
115 cmsHPROFILE *input_profile = NULL;
116 cmsHPROFILE *output_profile = NULL;
122 input_profile = rgb_profile;
124 output_profile = lab_profile;
129 input_profile = lab_profile;
131 output_profile = rgb_profile;
145 fprintf(stderr,
"[_transform_from_to_rgb_lab_lcms2] cannot create transform\n");
147 if(xform) cmsDeleteTransform(xform);
150static inline __attribute__((always_inline))
void _transform_rgb_to_rgb_lcms2(
const float *
const image_in,
float *
const image_out,
const int width,
152 const char *filename_from,
156 cmsHTRANSFORM *xform = NULL;
157 cmsHPROFILE *from_rgb_profile = NULL;
158 cmsHPROFILE *to_rgb_profile = NULL;
167 if(profile_from) from_rgb_profile = profile_from->
profile;
171 fprintf(stderr,
"[_transform_rgb_to_rgb_lcms2] invalid from profile\n");
178 if(profile_to) to_rgb_profile = profile_to->
profile;
182 fprintf(stderr,
"[_transform_rgb_to_rgb_lcms2] invalid to profile\n");
187 cmsColorSpaceSignature rgb_color_space = cmsGetColorSpace(from_rgb_profile);
188 if(rgb_color_space != cmsSigRgbData)
190 fprintf(stderr,
"[_transform_rgb_to_rgb_lcms2] profile color space `%c%c%c%c' not supported\n",
191 (
char)(rgb_color_space >> 24), (
char)(rgb_color_space >> 16), (
char)(rgb_color_space >> 8),
192 (
char)(rgb_color_space));
193 from_rgb_profile = NULL;
198 cmsColorSpaceSignature rgb_color_space = cmsGetColorSpace(to_rgb_profile);
199 if(rgb_color_space != cmsSigRgbData)
201 fprintf(stderr,
"[_transform_rgb_to_rgb_lcms2] profile color space `%c%c%c%c' not supported\n",
202 (
char)(rgb_color_space >> 24), (
char)(rgb_color_space >> 16), (
char)(rgb_color_space >> 8),
203 (
char)(rgb_color_space));
204 to_rgb_profile = NULL;
208 cmsHPROFILE *input_profile = NULL;
209 cmsHPROFILE *output_profile = NULL;
213 input_profile = from_rgb_profile;
215 output_profile = to_rgb_profile;
218 if(input_profile && output_profile)
229 fprintf(stderr,
"[_transform_rgb_to_rgb_lcms2] cannot create transform\n");
231 if(xform) cmsDeleteTransform(xform);
235 const int width,
const int height,
const int cst_from,
const int cst_to,
238 if(cst_from == cst_to)
240 *converted_cst = cst_to;
244 *converted_cst = cst_to;
249 "[_transform_lcms2] transfoming from RGB to Lab (%s %s)\n", self->
op, self->
multi_name);
256 "[_transform_lcms2] transfoming from Lab to RGB (%s %s)\n", self->
op, self->
multi_name);
262 *converted_cst = cst_from;
263 fprintf(stderr,
"[_transform_lcms2] invalid conversion from %i to %i\n", cst_from, cst_to);
267static inline __attribute__((always_inline))
void _transform_lcms2_rgb(
const float *
const image_in,
float *
const image_out,
const int width,
272 _transform_rgb_to_rgb_lcms2(image_in, image_out,
width,
height, profile_info_from->
type,
279 float *
const unbounded_coeffsr,
float *
const unbounded_coeffsg,
float *
const unbounded_coeffsb,
const int lutsize)
281 int nonlinearlut = 0;
282 float *
lut[3] = { lutr, lutg, lutb };
283 float *
unbounded_coeffs[3] = { unbounded_coeffsr, unbounded_coeffsg, unbounded_coeffsb };
285 for(
int k = 0;
k < 3;
k++)
288 if(
lut[
k][0] >= 0.0f)
309 const float *
const restrict lutr,
310 const float *
const restrict lutg,
311 const float *
const restrict lutb,
312 const float *
const restrict unbounded_coeffsr,
313 const float *
const restrict unbounded_coeffsg,
314 const float *
const restrict unbounded_coeffsb,
318 const float *
const lut[3] = { lutr, lutg, lutb };
319 const float *
const unbounded_coeffs[3] = { unbounded_coeffsr, unbounded_coeffsg, unbounded_coeffsb };
323 if((
lut[0][0] >= 0.0f) && (
lut[1][0] >= 0.0f) && (
lut[2][0] >= 0.0f))
326 for(
size_t k = 0;
k < stride;
k +=
ch)
328 for(
int c = 0; c < 3; c++)
334 else if((
lut[0][0] >= 0.0f) || (
lut[1][0] >= 0.0f) || (
lut[2][0] >= 0.0f))
337 for(
size_t k = 0;
k < stride;
k +=
ch)
339 for(
int c = 0; c < 3; c++)
341 if(
lut[c][0] >= 0.0f)
359 const dt_aligned_pixel_simd_t m0 = dt_colormatrix_row_to_simd(*matrix_ptr, 0);
360 const dt_aligned_pixel_simd_t m1 = dt_colormatrix_row_to_simd(*matrix_ptr, 1);
361 const dt_aligned_pixel_simd_t m2 = dt_colormatrix_row_to_simd(*matrix_ptr, 2);
367 profile_info->
lut_in[2], profile_info->unbounded_coeffs_in[0],
368 profile_info->unbounded_coeffs_in[1], profile_info->unbounded_coeffs_in[2],
371 for(
size_t y = 0; y < stride; y +=
ch)
373 float *
const restrict in = __builtin_assume_aligned(image_out + y, 16);
375 const dt_aligned_pixel_simd_t vin = dt_load_simd_aligned(in);
383 for(
size_t y = 0; y < stride; y +=
ch)
385 const float *
const restrict in = __builtin_assume_aligned(image_in + y, 16);
386 float *
const restrict
out = __builtin_assume_aligned(image_out + y, 16);
389 const dt_aligned_pixel_simd_t vin = dt_load_simd_aligned(in);
404 const int use_nontemporal = !profile_info->
nonlinearlut;
406 const dt_aligned_pixel_simd_t m0 = dt_colormatrix_row_to_simd(*matrix_ptr, 0);
407 const dt_aligned_pixel_simd_t m1 = dt_colormatrix_row_to_simd(*matrix_ptr, 1);
408 const dt_aligned_pixel_simd_t m2 = dt_colormatrix_row_to_simd(*matrix_ptr, 2);
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];
418 const dt_aligned_pixel_simd_t vxyz = dt_load_simd_aligned(xyz);
419 dt_aligned_pixel_simd_t
rgb = dt_mat3x4_mul_vec4(vxyz, m0, m1, m2);
422 dt_store_simd_nontemporal(
out,
rgb);
434 profile_info->
lut_out[2], profile_info->unbounded_coeffs_out[0],
435 profile_info->unbounded_coeffs_out[1], profile_info->unbounded_coeffs_out[2],
443 float *
const restrict image_out,
457 const dt_aligned_pixel_simd_t m0 = dt_colormatrix_row_to_simd(
matrix, 0);
458 const dt_aligned_pixel_simd_t m1 = dt_colormatrix_row_to_simd(
matrix, 1);
459 const dt_aligned_pixel_simd_t m2 = dt_colormatrix_row_to_simd(
matrix, 2);
463 const int use_nontemporal = !profile_info_to->
nonlinearlut;
465 (profile_info_from->
lut_in[1][0] >= 0.0f),
466 (profile_info_from->
lut_in[2][0] >= 0.0f) };
469 (profile_info_to->
lut_out[1][0] >= 0.0f),
470 (profile_info_to->
lut_out[2][0] >= 0.0f) };
472 for(
size_t y = 0; y < stride; y += 4)
474 const float *
const restrict in = __builtin_assume_aligned(image_in + y, 16);
475 float *
const restrict
out = __builtin_assume_aligned(image_out + y, 16);
481 for(
size_t c = 0; c < 3; c++)
483 rgb[c] = (run_lut_in[c]
484 ? dt_ioppr_eval_trc(in[c], profile_info_from->
lut_in[c],
485 profile_info_from->unbounded_coeffs_in[c], profile_info_from->
lutsize)
499 const dt_aligned_pixel_simd_t vrgb = dt_load_simd_aligned(
rgb);
503 for(
size_t c = 0; c < 3; c++)
505 out[c] = (run_lut_out[c]
506 ? dt_ioppr_eval_trc(temp[c], profile_info_to->
lut_out[c],
507 profile_info_to->unbounded_coeffs_out[c], profile_info_to->
lutsize)
514 const dt_aligned_pixel_simd_t vrgb = dt_load_simd_aligned(
rgb);
516 dt_store_simd_nontemporal(
out, dt_mat3x4_mul_vec4(vrgb, m0, m1, m2));
528 for(
size_t y = 0; y < stride; y += 4)
530 const float *
const restrict in = __builtin_assume_aligned(image_in + y, 16);
531 float *
const restrict
out = __builtin_assume_aligned(image_out + y, 16);
533 const dt_aligned_pixel_simd_t vin = dt_load_simd_aligned(in);
534 dt_store_simd_nontemporal(
out, dt_mat3x4_mul_vec4(vin, m0, m1, m2));
542 const float *
const restrict image_in,
543 float *
const restrict image_out,
550 if(cst_from == cst_to)
552 *converted_cst = cst_to;
556 *converted_cst = cst_to;
568 *converted_cst = cst_from;
569 fprintf(stderr,
"[_transform_matrix] invalid conversion from %i to %i\n", cst_from, cst_to);
574#define DT_IOPPR_LUT_SAMPLES 0x10000
582 _mark_as_nonmatrix_profile(profile_info);
583 profile_info->unbounded_coeffs_in[0][0] = profile_info->unbounded_coeffs_in[1][0] = profile_info->unbounded_coeffs_in[2][0] = -1.0f;
584 profile_info->unbounded_coeffs_out[0][0] = profile_info->unbounded_coeffs_out[1][0] = profile_info->unbounded_coeffs_out[2][0] = -1.0f;
586 profile_info->
grey = 0.f;
588 for(
int i = 0;
i < 3;
i++)
591 profile_info->
lut_in[
i][0] = -1.0f;
593 profile_info->
lut_out[
i][0] = -1.0f;
597#undef DT_IOPPR_LUT_SAMPLES
601 for(
int i = 0;
i < 3;
i++)
604 profile_info->
lut_in[
i] = NULL;
618 cmsHPROFILE *rgb_profile = NULL;
620 _mark_as_nonmatrix_profile(profile_info);
624 profile_info->
grey = 0.1842f;
627 g_strlcpy(profile_info->
filename, filename,
sizeof(profile_info->
filename));
628 profile_info->
intent = intent;
635 if(profile) rgb_profile = profile->
profile;
643 cmsColorSpaceSignature rgb_color_space = cmsGetColorSpace(rgb_profile);
644 if(rgb_color_space != cmsSigRgbData)
646 fprintf(stderr,
"working profile color space `%c%c%c%c' not supported\n",
647 (
char)(rgb_color_space>>24),
648 (
char)(rgb_color_space>>16),
649 (
char)(rgb_color_space>>8),
650 (
char)(rgb_color_space));
665 _mark_as_nonmatrix_profile(profile_info);
670 _mark_as_nonmatrix_profile(profile_info);
687 profile_info->unbounded_coeffs_in[0], profile_info->unbounded_coeffs_in[1], profile_info->unbounded_coeffs_in[2], profile_info->
lutsize);
689 profile_info->unbounded_coeffs_out[0], profile_info->unbounded_coeffs_out[1], profile_info->unbounded_coeffs_out[2], profile_info->
lutsize);
705 const char *profile_filename)
709 for(GList *profiles = dev->
allprofile_info; profiles; profiles = g_list_next(profiles))
712 if(prof->
type == profile_type && strcmp(prof->
filename, profile_filename) == 0)
725 const char *profile_filename,
752 gboolean in_between =
FALSE;
754 for(GList *modules = iop_list; modules; modules = g_list_next(modules))
759 if(strcmp(mod->
op, module->
op) == 0)
break;
762 if(strcmp(mod->
op,
"colorout") == 0)
769 if(strcmp(mod->
op,
"colorin") == 0)
779 const char *filename = NULL;
793 const char *filename,
800 fprintf(stderr,
"[dt_ioppr_set_pipe_work_profile_info] unsupported working profile %i %s, it will be replaced with linear Rec2020\n",
type, filename);
812 const char *filename,
821 "[dt_ioppr_set_pipe_input_profile_info] unsupported input profile %i %s, it will be replaced with "
846 const char *filename,
858 "[dt_ioppr_set_pipe_output_profile_info] unsupported output"
859 " profile %i %s, it will be replaced with sRGB\n",
891 const int current_module_order =
module->iop_order;
893 if(current_module_order < colorin_order)
895 else if(current_module_order < colorout_order)
900 return color_profile;
907 const char **profile_filename)
910 *profile_filename = NULL;
915 for(
const GList *modules =
darktable.
iop; modules; modules = g_list_next(modules))
918 if(!strcmp(module_so->
op,
"colorin"))
920 colorin_so = module_so;
924 if(colorin_so && colorin_so->get_p)
926 for(
const GList *modules = dev->
iop; modules; modules = g_list_next(modules))
929 if(!strcmp(module->op,
"colorin"))
939 char *_filename = colorin_so->get_p(colorin->
params,
"filename_work");
940 if(_type && _filename)
942 *profile_type = *_type;
943 *profile_filename = _filename;
946 fprintf(stderr,
"[dt_ioppr_get_work_profile_type] can't get colorin parameters\n");
949 fprintf(stderr,
"[dt_ioppr_get_work_profile_type] can't find colorin iop\n");
954 const char **profile_filename)
957 *profile_filename = NULL;
962 for(
const GList *modules = g_list_last(
darktable.
iop); modules; modules = g_list_previous(modules))
965 if(!strcmp(module_so->
op,
"colorout"))
967 colorout_so = module_so;
971 if(colorout_so && colorout_so->get_p)
973 for(
const GList *modules = g_list_last(dev->
iop); modules; modules = g_list_previous(modules))
976 if(!strcmp(module->op,
"colorout"))
986 char *_filename = colorout_so->get_p(colorout->
params,
"filename");
987 if(_type && _filename)
989 *profile_type = *_type;
990 *profile_filename = _filename;
993 fprintf(stderr,
"[dt_ioppr_get_export_profile_type] can't get colorout parameters\n");
996 fprintf(stderr,
"[dt_ioppr_get_export_profile_type] can't find colorout iop\n");
1000 float *
const image_out,
const int width,
const int height,
1001 const int cst_from,
const int cst_to,
int *converted_cst,
1004 if(cst_from == cst_to)
1006 *converted_cst = cst_to;
1011 *converted_cst = cst_to;
1016 *converted_cst = cst_from;
1021 *converted_cst = cst_from;
1025 dt_times_t start_time = { 0 }, end_time = { 0 };
1036 fprintf(stderr,
"image colorspace transform %s-->%s took %.3f secs (%.3f CPU) [%s %s]\n",
1049 fprintf(stderr,
"image colorspace transform %s-->%s took %.3f secs (%.3f lcms2) [%s %s]\n",
1056 if(*converted_cst == cst_from)
1057 fprintf(stderr,
"[dt_ioppr_transform_image_colorspace] invalid conversion from %i to %i\n", cst_from, cst_to);
1065 const char *message)
1071 if(profile_info_from->
type == profile_info_to->
type
1074 if(image_in != image_out)
1075 memcpy(image_out, image_in,
sizeof(
float) * 4 *
width *
height);
1080 dt_times_t start_time = { 0 }, end_time = { 0 };
1083 if(!isnan(profile_info_from->
matrix_in[0][0]) && !isnan(profile_info_from->
matrix_out[0][0])
1091 fprintf(stderr,
"image colorspace transform RGB-->RGB took %.3f secs (%.3f CPU) [%s]\n",
1092 end_time.clock - start_time.
clock, end_time.user - start_time.
user, (message) ? message :
"");
1097 _transform_lcms2_rgb(image_in, image_out,
width,
height, profile_info_from, profile_info_to);
1102 fprintf(stderr,
"image colorspace transform RGB-->RGB took %.3f secs (%.3f lcms2) [%s]\n",
1103 end_time.clock - start_time.
clock, end_time.user - start_time.
user, (message) ? message :
"");
1113 const int program = 23;
1115 g->kernel_colorspaces_transform_rgb_matrix_to_lab =
dt_opencl_create_kernel(program,
"colorspaces_transform_rgb_matrix_to_lab");
1116 g->kernel_colorspaces_transform_rgb_matrix_to_rgb
1135 for(
int i = 0;
i < 9;
i++)
1141 for(
int i = 0;
i < 3;
i++)
1143 for(
int j = 0; j < 3; j++)
1150 profile_info_cl->
grey = profile_info->
grey;
1155 cl_float *trc = malloc(
sizeof(cl_float) * 6 * profile_info->
lutsize);
1159 for(
int c = 0; c < 3; c++)
1160 for(
int y = 0; y < profile_info->
lutsize; y++,
x++)
1161 trc[
x] = profile_info->
lut_in[c][y];
1162 for(
int c = 0; c < 3; c++)
1163 for(
int y = 0; y < profile_info->
lutsize; y++,
x++)
1164 trc[
x] = profile_info->
lut_out[c][y];
1171 cl_float **_profile_lut_cl, cl_mem *_dev_profile_info,
1172 cl_mem *_dev_profile_lut)
1174 cl_int err = CL_SUCCESS;
1177 cl_float *profile_lut_cl = NULL;
1178 cl_mem dev_profile_info = NULL;
1179 cl_mem dev_profile_lut = NULL;
1189 fprintf(stderr,
"[dt_ioppr_build_iccprofile_params_cl] error allocating memory 5\n");
1190 err = CL_MEM_OBJECT_ALLOCATION_FAILURE;
1197 fprintf(stderr,
"[dt_ioppr_build_iccprofile_params_cl] error allocating memory 6\n");
1198 err = CL_MEM_OBJECT_ALLOCATION_FAILURE;
1204 profile_lut_cl = malloc(
sizeof(cl_float) * 1 * 6);
1209 fprintf(stderr,
"[dt_ioppr_build_iccprofile_params_cl] error allocating memory 7\n");
1210 err = CL_MEM_OBJECT_ALLOCATION_FAILURE;
1216 *_profile_info_cl = profile_info_cl;
1217 *_profile_lut_cl = profile_lut_cl;
1218 *_dev_profile_info = dev_profile_info;
1219 *_dev_profile_lut = dev_profile_lut;
1225 cl_float **_profile_lut_cl, cl_mem *_dev_profile_info,
1226 cl_mem *_dev_profile_lut)
1229 cl_float *profile_lut_cl = *_profile_lut_cl;
1230 cl_mem dev_profile_info = *_dev_profile_info;
1231 cl_mem dev_profile_lut = *_dev_profile_lut;
1241 *_profile_info_cl = NULL;
1242 *_profile_lut_cl = NULL;
1243 *_dev_profile_info = NULL;
1244 *_dev_profile_lut = NULL;
1248 cl_mem dev_img_out,
const int width,
const int height,
1249 const int cst_from,
const int cst_to,
int *converted_cst,
1252 cl_int err = CL_SUCCESS;
1256 assert(dev_img_in != dev_img_out);
1258 if(cst_from == cst_to)
1260 *converted_cst = cst_to;
1265 *converted_cst = cst_to;
1270 *converted_cst = cst_from;
1275 *converted_cst = cst_from;
1279 const size_t ch = 4;
1280 float *src_buffer = NULL;
1282 int kernel_transform = 0;
1283 cl_mem dev_profile_info = NULL;
1284 cl_mem dev_lut = NULL;
1286 cl_float *lut_cl = NULL;
1288 *converted_cst = cst_from;
1293 dt_times_t start_time = { 0 }, end_time = { 0 };
1306 err = CL_INVALID_KERNEL;
1307 *converted_cst = cst_from;
1308 fprintf(stderr,
"[dt_ioppr_transform_image_colorspace_cl] invalid conversion from %i to %i\n", cst_from, cst_to);
1318 fprintf(stderr,
"[dt_ioppr_transform_image_colorspace_cl] error allocating memory for color transformation 5\n");
1319 err = CL_MEM_OBJECT_ALLOCATION_FAILURE;
1325 fprintf(stderr,
"[dt_ioppr_transform_image_colorspace_cl] error allocating memory for color transformation 6\n");
1326 err = CL_MEM_OBJECT_ALLOCATION_FAILURE;
1339 if(err != CL_SUCCESS)
1341 fprintf(stderr,
"[dt_ioppr_transform_image_colorspace_cl] error %i enqueue kernel for color transformation\n", err);
1345 *converted_cst = cst_to;
1350 fprintf(stderr,
"image colorspace transform %s-->%s took %.3f secs (%.3f GPU) [%s %s]\n",
1362 fprintf(stderr,
"[dt_ioppr_transform_image_colorspace_cl] error allocating memory for color transformation 1\n");
1363 err = CL_MEM_OBJECT_ALLOCATION_FAILURE;
1368 if(err != CL_SUCCESS)
1370 fprintf(stderr,
"[dt_ioppr_transform_image_colorspace_cl] error allocating memory for color transformation 2\n");
1376 converted_cst, profile_info);
1379 if(err != CL_SUCCESS)
1381 fprintf(stderr,
"[dt_ioppr_transform_image_colorspace_cl] error allocating memory for color transformation 3\n");
1392 return (err == CL_SUCCESS) ?
TRUE :
FALSE;
1399 const char *message)
1401 cl_int err = CL_SUCCESS;
1407 if(profile_info_from->
type == profile_info_to->
type
1410 if(dev_img_in != dev_img_out)
1412 size_t origin[] = { 0, 0, 0 };
1416 if(err != CL_SUCCESS)
1419 "[dt_ioppr_transform_image_colorspace_rgb_cl] error on copy image for color transformation\n");
1427 const size_t ch = 4;
1428 float *src_buffer_in = NULL;
1429 float *src_buffer_out = NULL;
1430 int in_place = (dev_img_in == dev_img_out);
1432 int kernel_transform = 0;
1433 cl_mem dev_tmp = NULL;
1435 cl_mem dev_profile_info_from = NULL;
1436 cl_mem dev_lut_from = NULL;
1438 cl_float *lut_from_cl = NULL;
1440 cl_mem dev_profile_info_to = NULL;
1441 cl_mem dev_lut_to = NULL;
1443 cl_float *lut_to_cl = NULL;
1445 cl_mem matrix_cl = NULL;
1448 if(!isnan(profile_info_from->
matrix_in[0][0]) && !isnan(profile_info_from->
matrix_out[0][0])
1451 dt_times_t start_time = { 0 }, end_time = { 0 };
1454 size_t origin[] = { 0, 0, 0 };
1475 "[dt_ioppr_transform_image_colorspace_rgb_cl] error allocating memory for color transformation 4\n");
1476 err = CL_MEM_OBJECT_ALLOCATION_FAILURE;
1481 if(err != CL_SUCCESS)
1484 "[dt_ioppr_transform_image_colorspace_rgb_cl] error on copy image for color transformation\n");
1490 dev_tmp = dev_img_in;
1493 dev_profile_info_from
1498 "[dt_ioppr_transform_image_colorspace_rgb_cl] error allocating memory for color transformation 5\n");
1499 err = CL_MEM_OBJECT_ALLOCATION_FAILURE;
1506 "[dt_ioppr_transform_image_colorspace_rgb_cl] error allocating memory for color transformation 6\n");
1507 err = CL_MEM_OBJECT_ALLOCATION_FAILURE;
1516 "[dt_ioppr_transform_image_colorspace_rgb_cl] error allocating memory for color transformation 7\n");
1517 err = CL_MEM_OBJECT_ALLOCATION_FAILURE;
1524 "[dt_ioppr_transform_image_colorspace_rgb_cl] error allocating memory for color transformation 8\n");
1525 err = CL_MEM_OBJECT_ALLOCATION_FAILURE;
1528 float matrix3x4[12];
1534 "[dt_ioppr_transform_image_colorspace_rgb_cl] error allocating memory for color transformation 7\n");
1535 err = CL_MEM_OBJECT_ALLOCATION_FAILURE;
1551 if(err != CL_SUCCESS)
1554 "[dt_ioppr_transform_image_colorspace_rgb_cl] error %i enqueue kernel for color transformation\n",
1562 fprintf(stderr,
"image colorspace transform RGB-->RGB took %.3f secs (%.3f GPU) [%s]\n",
1563 end_time.clock - start_time.
clock, end_time.user - start_time.
user, (message) ? message :
"");
1574 "[dt_ioppr_transform_image_colorspace_rgb_cl] error allocating memory for color transformation 1\n");
1575 err = CL_MEM_OBJECT_ALLOCATION_FAILURE;
1580 if(err != CL_SUCCESS)
1583 "[dt_ioppr_transform_image_colorspace_rgb_cl] error allocating memory for color transformation 2\n");
1589 profile_info_to, message);
1592 if(err != CL_SUCCESS)
1595 "[dt_ioppr_transform_image_colorspace_rgb_cl] error allocating memory for color transformation 3\n");
1615 return (err == CL_SUCCESS) ?
TRUE :
FALSE;
1619#undef DT_IOP_ORDER_PROFILE
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)
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)
__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)
int dt_colorspaces_get_matrix_from_output_profile(cmsHPROFILE prof, dt_colormatrix_t matrix, float *lutr, float *lutg, float *lutb, const int lutsize)
int dt_colorspaces_get_matrix_from_input_profile(cmsHPROFILE prof, dt_colormatrix_t matrix, float *lutr, float *lutg, float *lutb, const int lutsize)
dt_colorspaces_color_profile_type_t
@ DT_COLORSPACE_EMBEDDED_ICC
@ DT_COLORSPACE_LIN_REC2020
@ DT_COLORSPACE_ALTERNATE_MATRIX
@ DT_PROFILE_DIRECTION_WORK
@ DT_PROFILE_DIRECTION_ANY
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)
void dt_print(dt_debug_thread_t thread, const char *msg,...)
#define dt_free_align(ptr)
#define for_each_channel(_var,...)
#define dt_pixelpipe_cache_alloc_align_float_cache(pixels, id)
static float * dt_alloc_align_float(size_t pixels)
float dt_aligned_pixel_simd_t __attribute__((vector_size(16), aligned(16)))
Enable aggressive floating-point arithmetic optimizations, in denormals handling. Set through user pr...
static void dt_get_times(dt_times_t *t)
#define dt_pixelpipe_cache_free_align(mem)
#define __DT_CLONE_TARGETS__
#define __OMP_PARALLEL_FOR__(...)
#define __OMP_PARALLEL_FOR_SIMD__(...)
#define IS_NULL_PTR(p)
C is way too permissive with !=, == and if(var) checks, which can mean too many things depending on w...
#define dt_omploop_sfence()
static gboolean dt_iop_colorspace_is_rgb(const dt_iop_colorspace_type_t cst)
static void dt_iop_estimate_exp(const float *const x, const float *const y, const int num, float *coeff)
int dt_ioppr_get_iop_order(GList *iop_order_list, const char *op_name, const int multi_priority)
Return the iop_order for a given operation/instance pair.
static __DT_CLONE_TARGETS__ 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)
static __DT_CLONE_TARGETS__ 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)
static void _transform_matrix(struct dt_iop_module_t *self, 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)
dt_iop_order_iccprofile_info_t * dt_ioppr_get_pipe_output_profile_info(const struct dt_dev_pixelpipe_t *pipe)
static __DT_CLONE_TARGETS__ void _clear_lut_curves(dt_iop_order_iccprofile_info_t *const profile_info)
dt_iop_order_iccprofile_info_t * dt_ioppr_add_profile_info_to_list(struct dt_develop_t *dev, const dt_colorspaces_color_profile_type_t profile_type, const char *profile_filename, const int intent)
void dt_ioppr_transform_image_colorspace(struct dt_iop_module_t *self, 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)
#define DT_IOPPR_LUT_SAMPLES
void dt_ioppr_get_work_profile_type(struct dt_develop_t *dev, dt_colorspaces_color_profile_type_t *profile_type, const char **profile_filename)
dt_iop_order_iccprofile_info_t * dt_ioppr_get_pipe_work_profile_info(const struct dt_dev_pixelpipe_t *pipe)
dt_iop_order_iccprofile_info_t * dt_ioppr_set_pipe_work_profile_info(struct dt_develop_t *dev, struct dt_dev_pixelpipe_t *pipe, const dt_colorspaces_color_profile_type_t type, const char *filename, const int intent)
static void _transform_lcms2(struct dt_iop_module_t *self, 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)
static __DT_CLONE_TARGETS__ int dt_ioppr_generate_profile_info(dt_iop_order_iccprofile_info_t *profile_info, const int type, const char *filename, const int intent)
dt_iop_order_iccprofile_info_t * dt_ioppr_set_pipe_output_profile_info(struct dt_develop_t *dev, struct dt_dev_pixelpipe_t *pipe, const dt_colorspaces_color_profile_type_t type, const char *filename, const int intent)
dt_iop_order_iccprofile_info_t * dt_ioppr_get_pipe_current_profile_info(dt_iop_module_t *module, const struct dt_dev_pixelpipe_t *pipe)
int dt_ioppr_transform_image_colorspace_cl(struct dt_iop_module_t *self, 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)
__DT_CLONE_TARGETS__ dt_iop_order_iccprofile_info_t * dt_ioppr_get_profile_info_from_list(struct dt_develop_t *dev, const dt_colorspaces_color_profile_type_t profile_type, const char *profile_filename)
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)
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)
__DT_CLONE_TARGETS__ void dt_ioppr_init_profile_info(dt_iop_order_iccprofile_info_t *profile_info, const int lutsize)
void dt_colorspaces_free_cl_global(dt_colorspaces_cl_global_t *g)
dt_iop_order_iccprofile_info_t * dt_ioppr_get_pipe_input_profile_info(const struct dt_dev_pixelpipe_t *pipe)
static __DT_CLONE_TARGETS__ 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 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_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)
static int _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)
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)
dt_colorspaces_cl_global_t * dt_colorspaces_init_cl_global()
dt_iop_order_iccprofile_info_t * dt_ioppr_get_iop_work_profile_info(struct dt_iop_module_t *module, GList *iop_list)
cl_float * dt_ioppr_get_trc_cl(const dt_iop_order_iccprofile_info_t *const profile_info)
void dt_ioppr_cleanup_profile_info(dt_iop_order_iccprofile_info_t *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)
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)
dt_iop_order_iccprofile_info_t * dt_ioppr_set_pipe_input_profile_info(struct dt_develop_t *dev, struct dt_dev_pixelpipe_t *pipe, const dt_colorspaces_color_profile_type_t type, const char *filename, const int intent, const dt_colormatrix_t matrix_in)
void dt_ioppr_get_export_profile_type(struct dt_develop_t *dev, dt_colorspaces_color_profile_type_t *profile_type, const char **profile_filename)
const float const int lutsize
static dt_aligned_pixel_t float *const const float unbounded_coeffs[3][3]
float *const restrict const size_t k
float *const restrict const size_t const size_t ch
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)
static int mat3SSEinv(dt_colormatrix_t dst, const dt_colormatrix_t src)
float dt_aligned_pixel_t[4]
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)
struct dt_colorspaces_t * color_profiles
struct dt_opencl_t * opencl
int kernel_colorspaces_transform_rgb_matrix_to_rgb
int kernel_colorspaces_transform_lab_to_rgb_matrix
int kernel_colorspaces_transform_rgb_matrix_to_lab
float unbounded_coeffs_out[3][3]
float unbounded_coeffs_in[3][3]
pthread_rwlock_t xprofile_lock
struct dt_iop_order_iccprofile_info_t * work_profile_info
struct dt_iop_order_iccprofile_info_t * input_profile_info
struct dt_iop_order_iccprofile_info_t * output_profile_info
GModule *dt_dev_operation_t op
struct dt_develop_t * dev
GModule *dt_dev_operation_t op
dt_iop_color_intent_t intent
dt_colormatrix_t matrix_out_transposed
dt_colorspaces_color_profile_type_t type
dt_colormatrix_t matrix_out
char filename[DT_IOP_COLOR_ICC_LEN]
dt_colormatrix_t matrix_in_transposed
dt_colormatrix_t matrix_in
struct dt_colorspaces_cl_global_t * colorspaces