Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
imageio_profile.c File Reference
#include "imageio/imageio_profile.h"
#include "colorprofiles/colorspaces.h"
#include "common/image.h"
#include "caches/image_cache.h"
#include "common/logging.h"
#include "system/macros.h"
#include "system/mem_alloc.h"
#include <lcms2.h>
#include <string.h>
#include "imageio/imageio_jpeg.h"
#include "imageio/imageio_png.h"
#include "imageio/imageio_tiff.h"
+ Include dependency graph for imageio_profile.c:

Go to the source code of this file.

Functions

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)
 
static const dt_colorspaces_color_profile_t_build_embedded_profile (const int32_t imgid, dt_colorspaces_color_profile_type_t *type)
 
struct dt_colorspaces_color_profile_tdt_image_get_input_profile (const int32_t imgid, const dt_colorspaces_color_profile_type_t requested, const char *camera_makermodel, dt_colorspaces_color_profile_type_t *resolved)
 Resolve an image's own input profile into an opaque container, whatever kind it is.
 
struct dt_colorspaces_color_profile_tdt_image_get_embedded_output_profile (const int32_t imgid, dt_colorspaces_color_profile_type_t *type)
 Resolve the ICC profile embedded in an image's own file, into an opaque container.
 
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)
 
dt_colorspaces_color_profile_type_t dt_colorspaces_cicp_to_type (const dt_colorspaces_cicp_t *cicp, const char *filename)
 

Function Documentation

◆ _build_embedded_profile()

◆ dt_colorspaces_cicp_to_type()

◆ 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 411 of file imageio_profile.c.

References dt_image_find_best_color_profile(), L, and type.

Referenced by _build_embedded_profile(), and dt_image_get_embedded_output_profile().

◆ 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 308 of file imageio_profile.c.

References dt_image_t::adobe_XYZ_to_CAM, dt_image_t::d65_color_matrix, 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, IS_NULL_PTR, L, dt_image_t::profile, dt_image_t::profile_size, TRUE, and type.

Referenced by dt_image_get_input_profile().

◆ dt_colorspaces_get_output_profile()

◆ 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 87 of file imageio_profile.c.

References dt_image_t::adobe_XYZ_to_CAM, dt_image_t::colorspace, dt_image_t::d65_color_matrix, 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_cleanup_profile(), 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_ROLE_INPUT, FALSE, dt_image_t::flags, IS_NULL_PTR, L, 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().

◆ dt_image_get_embedded_output_profile()

struct dt_colorspaces_color_profile_t * dt_image_get_embedded_output_profile ( const int32_t  imgid,
dt_colorspaces_color_profile_type_t type 
)

Resolve the ICC profile embedded in an image's own file, into an opaque container.

The export counterpart of dt_image_get_input_profile(): when an export names no output profile, the image's embedded one is used. Same ownership contract – the container knows whether it created the handle, so the caller does not.

Parameters
imgidimage whose embedded profile is wanted.
typereceives the profile type resolved. Must not be NULL.
Returns
A container to release with dt_colorspaces_free_image_profile(), or NULL when the image has no usable embedded profile.

Definition at line 540 of file imageio_profile.c.

References container(), dt_colorspaces_cleanup_profile(), dt_colorspaces_get_embedded_profile(), dt_colorspaces_new_image_profile(), FALSE, IS_NULL_PTR, L, dt_colorspaces_color_profile_t::profile, and type.

Referenced by commit_params().

◆ dt_image_get_input_profile()

struct dt_colorspaces_color_profile_t * dt_image_get_input_profile ( const int32_t  imgid,
const dt_colorspaces_color_profile_type_t  requested,
const char *  camera_makermodel,
dt_colorspaces_color_profile_type_t resolved 
)

Resolve an image's own input profile into an opaque container, whatever kind it is.

The six image-derived profile types (DT_COLORSPACE_EMBEDDED_ICC through DT_COLORSPACE_ALTERNATE_MATRIX) are the ones that are NOT in the application profile list and cannot be resolved by identity, because their matrices come from this one image's camera data. Three of them are built from the camera model, three from the file's own contents, and iop/colorin.c used to open-code the cascade between them – holding a raw cmsHPROFILE and a separate "did I create this one" flag it had to get right on every early return.

This resolves all six and hands back a container that carries the ownership answer with it, so a caller never decides whether to close a handle. Pass it straight to dt_colorspaces_prepare_conversion() as an endpoint's resolved field.

Parameters
imgidimage whose profile is wanted.
requestedone of the six image-derived types. Any other type returns NULL, since those are resolvable by identity and belong to the profile list.
camera_makermodelthe image's camera_makermodel, needed by the three built-from-the-camera types. May be NULL, which makes those three fail over to the embedded-ICC branch exactly as a missing matrix does.
resolvedif not NULL, receives the type actually resolved, which may differ from requested when a fallback fired (a camera with no matrix in the table, an image with no embedded ICC). Set to DT_COLORSPACE_NONE when NULL is returned.
Returns
A container to release with dt_colorspaces_free_image_profile(), or NULL when nothing could be resolved. The caller owns it and must outlive anything derived from it.

Definition at line 482 of file imageio_profile.c.

References container(), DT_COLORSPACE_ALTERNATE_MATRIX, DT_COLORSPACE_EMBEDDED_ICC, DT_COLORSPACE_EMBEDDED_MATRIX, DT_COLORSPACE_ENHANCED_MATRIX, DT_COLORSPACE_NONE, DT_COLORSPACE_STANDARD_MATRIX, DT_COLORSPACE_VENDOR_MATRIX, dt_colorspaces_cleanup_profile(), dt_colorspaces_create_alternate_profile(), dt_colorspaces_create_darktable_profile(), dt_colorspaces_create_vendor_profile(), dt_colorspaces_get_input_profile_from_image(), dt_colorspaces_new_image_profile(), FALSE, IS_NULL_PTR, L, dt_colorspaces_color_profile_t::profile, TRUE, and type.

Referenced by commit_params().