|
1 | 1 | /* |
2 | 2 | This file is part of darktable, |
3 | | - Copyright (C) 2012-2023 darktable developers. |
| 3 | + Copyright (C) 2012-2025 darktable developers. |
4 | 4 |
|
5 | 5 | darktable is free software: you can redistribute it and/or modify |
6 | 6 | it under the terms of the GNU General Public License as published by |
@@ -418,6 +418,40 @@ int write_image(dt_imageio_module_data_t *j2k_tmp, const char *filename, const v |
418 | 418 | } |
419 | 419 | } |
420 | 420 |
|
| 421 | + /* Determine the actual (export vs colorout) color profile used */ |
| 422 | + const dt_colorspaces_color_profile_t *cp = dt_colorspaces_get_output_profile(imgid, over_type, over_filename); |
| 423 | + /* ICC writing doesn't work w/ OpenJPEG 2.5.3 and earlier (prefer runtime detection) */ |
| 424 | + const char *opj_ver = opj_version(); |
| 425 | + if(opj_ver[0] > '2' || (opj_ver[0] == '2' && (opj_ver[2] > '5' || (opj_ver[2] == '5' && opj_ver[4] > '3')))) |
| 426 | + { |
| 427 | + uint32_t icc_profile_len; |
| 428 | + cmsSaveProfileToMem(cp->profile, NULL, &icc_profile_len); |
| 429 | + if(icc_profile_len > 0) |
| 430 | + { |
| 431 | + uint8_t *icc_profile_buf = malloc(sizeof(uint8_t) * icc_profile_len); |
| 432 | + if(icc_profile_buf == NULL) |
| 433 | + { |
| 434 | + dt_print(DT_DEBUG_ALWAYS, "failed to allocate ICC profile"); |
| 435 | + opj_image_destroy(image); |
| 436 | + rc = 0; |
| 437 | + goto exit; |
| 438 | + } |
| 439 | + cmsSaveProfileToMem(cp->profile, icc_profile_buf, &icc_profile_len); |
| 440 | + image->icc_profile_buf = icc_profile_buf; /* freed later by opj_image_destroy() */ |
| 441 | + image->icc_profile_len = icc_profile_len; |
| 442 | + } |
| 443 | + } |
| 444 | + else |
| 445 | + { |
| 446 | + if(cp->type != DT_COLORSPACE_SRGB) |
| 447 | + { |
| 448 | + dt_control_log("%s", _("unable to attach output profile to JP2")); |
| 449 | + dt_print( |
| 450 | + DT_DEBUG_ALWAYS, |
| 451 | + "Warning: exporting with anything but sRGB profile might lead to wrong results when opening the image"); |
| 452 | + } |
| 453 | + } |
| 454 | + |
421 | 455 | /*Encoding image*/ |
422 | 456 |
|
423 | 457 | /* Decide if MCT should be used */ |
|
0 commit comments