|
|
|
/*
|
|
|
|
* Copyright 2021 Collabora, Ltd.
|
|
|
|
* Copyright 2021 Advanced Micro Devices, Inc.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
* next paragraph) shall be included in all copies or substantial
|
|
|
|
* portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef WESTON_COLOR_LCMS_H
|
|
|
|
#define WESTON_COLOR_LCMS_H
|
|
|
|
|
|
|
|
#include <lcms2.h>
|
|
|
|
#include <libweston/libweston.h>
|
|
|
|
|
|
|
|
#include "color.h"
|
|
|
|
#include "shared/helpers.h"
|
|
|
|
|
|
|
|
struct weston_color_manager_lcms {
|
|
|
|
struct weston_color_manager base;
|
|
|
|
cmsContext lcms_ctx;
|
|
|
|
|
|
|
|
struct wl_list color_transform_list; /* cmlcms_color_transform::link */
|
color: introduce weston_color_profile
Roughly speaking, a color profile describes the color space of content
or an output. Under the hood, the description includes one or more ways
to map colors between the profile space and some standard profile
connecting space (PCS).
This object is not called a color space. A color space has a unique
definition, while a color profile may contain multiple different
mappings depending on render intent. Some of these mappings may be
subjective, with an artistic touch.
When a source color profile and a destination color profile are combined
under a specific render intent, they produce a color transformation.
Color transformations are already preresented by weston_color_transform.
This patch adds the basic API for color profile objects. Everything
worthwhile of these objects is implemented in the color managers:
color-noop never creates these, and in color-lcms they are basically a
container for cmsHPROFILE, the Little CMS object for color profiles.
Color profile objects will not be interpreted outside of the color
managers, unlike color transformations.
For a start, the color manager API has one function to create color
profiles: from ICC profile data. More creation functions for other
sources will be added later.
The API has errmsg return parameter for error messages. These are not
simply weston_log()'d, because CM&HDR protocol will allow clients to
trigger errors and the protocol handles that gracefully. Therefore
instead of flooding the compositor logs, the error messages will
probably need to be relayed back to clients.
Color-lcms is expected to create a cmsHPROFILE for all kinds of color
profiles, not just for those created from ICC profile data. Hence,
color-lcms will fingerprint color profiles by the MD5 hash which Little
CMS computes for us. The fingerprint is used for de-duplication: instead
of creating copies, reference existing color profiles.
This code is very much based on Sebastian Wick's earlier work on Weston
color management, but structured and named differently.
Co-authored-by: Sebastian Wick <sebastian@sebastianwick.net>
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
4 years ago
|
|
|
struct wl_list color_profile_list; /* cmlcms_color_profile::link */
|
|
|
|
struct cmlcms_color_profile *sRGB_profile; /* stock profile */
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct weston_color_manager_lcms *
|
|
|
|
get_cmlcms(struct weston_color_manager *cm_base)
|
|
|
|
{
|
|
|
|
return container_of(cm_base, struct weston_color_manager_lcms, base);
|
|
|
|
}
|
|
|
|
|
color: introduce weston_color_profile
Roughly speaking, a color profile describes the color space of content
or an output. Under the hood, the description includes one or more ways
to map colors between the profile space and some standard profile
connecting space (PCS).
This object is not called a color space. A color space has a unique
definition, while a color profile may contain multiple different
mappings depending on render intent. Some of these mappings may be
subjective, with an artistic touch.
When a source color profile and a destination color profile are combined
under a specific render intent, they produce a color transformation.
Color transformations are already preresented by weston_color_transform.
This patch adds the basic API for color profile objects. Everything
worthwhile of these objects is implemented in the color managers:
color-noop never creates these, and in color-lcms they are basically a
container for cmsHPROFILE, the Little CMS object for color profiles.
Color profile objects will not be interpreted outside of the color
managers, unlike color transformations.
For a start, the color manager API has one function to create color
profiles: from ICC profile data. More creation functions for other
sources will be added later.
The API has errmsg return parameter for error messages. These are not
simply weston_log()'d, because CM&HDR protocol will allow clients to
trigger errors and the protocol handles that gracefully. Therefore
instead of flooding the compositor logs, the error messages will
probably need to be relayed back to clients.
Color-lcms is expected to create a cmsHPROFILE for all kinds of color
profiles, not just for those created from ICC profile data. Hence,
color-lcms will fingerprint color profiles by the MD5 hash which Little
CMS computes for us. The fingerprint is used for de-duplication: instead
of creating copies, reference existing color profiles.
This code is very much based on Sebastian Wick's earlier work on Weston
color management, but structured and named differently.
Co-authored-by: Sebastian Wick <sebastian@sebastianwick.net>
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
4 years ago
|
|
|
struct cmlcms_md5_sum {
|
|
|
|
uint8_t bytes[16];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct cmlcms_color_profile {
|
|
|
|
struct weston_color_profile base;
|
|
|
|
|
|
|
|
/* struct weston_color_manager_lcms::color_profile_list */
|
|
|
|
struct wl_list link;
|
|
|
|
|
|
|
|
cmsHPROFILE profile;
|
|
|
|
struct cmlcms_md5_sum md5sum;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If the profile does support being an output profile and it is used as an
|
|
|
|
* output then this field represents a light linearizing transfer function
|
|
|
|
* and it can not be null. The field is null only if the profile is not
|
|
|
|
* usable as an output profile. The field is set when cmlcms_color_profile
|
|
|
|
* is created.
|
|
|
|
*/
|
|
|
|
cmsToneCurve *output_eotf[3];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If the profile does support being an output profile and it is used as an
|
|
|
|
* output then this field represents a concatenation of inverse EOTF + VCGT,
|
|
|
|
* if the tag exists and it can not be null.
|
|
|
|
* VCGT is part of monitor calibration which means: even though we must
|
|
|
|
* apply VCGT in the compositor, we pretend that it happens inside the
|
|
|
|
* monitor. This is how the classic color management and ICC profiles work.
|
|
|
|
* The ICC profile (ignoring the VCGT tag) characterizes the output which
|
|
|
|
* is VCGT + monitor behavior. The field is null only if the profile is not
|
|
|
|
* usable as an output profile. The field is set when cmlcms_color_profile
|
|
|
|
* is created.
|
|
|
|
*/
|
|
|
|
cmsToneCurve *output_inv_eotf_vcgt[3];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* VCGT tag cached from output profile, it could be null if not exist
|
|
|
|
*/
|
|
|
|
cmsToneCurve *vcgt[3];
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Type of LCMS transforms
|
|
|
|
*/
|
|
|
|
enum cmlcms_category {
|
|
|
|
/**
|
|
|
|
* Uses combination of input profile with output profile, but
|
|
|
|
* without INV EOTF or with additional EOTF in the transform pipeline
|
|
|
|
* input→blend = input profile + output profile + output EOTF
|
|
|
|
*/
|
|
|
|
CMLCMS_CATEGORY_INPUT_TO_BLEND = 0,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Uses INV EOTF only concatenated with VCGT tag if present
|
|
|
|
* blend→output = output inverse EOTF + VCGT
|
|
|
|
*/
|
|
|
|
CMLCMS_CATEGORY_BLEND_TO_OUTPUT,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transform uses input profile and output profile as is
|
|
|
|
* input→output = input profile + output profile + VCGT
|
|
|
|
*/
|
|
|
|
CMLCMS_CATEGORY_INPUT_TO_OUTPUT,
|
color: introduce weston_color_profile
Roughly speaking, a color profile describes the color space of content
or an output. Under the hood, the description includes one or more ways
to map colors between the profile space and some standard profile
connecting space (PCS).
This object is not called a color space. A color space has a unique
definition, while a color profile may contain multiple different
mappings depending on render intent. Some of these mappings may be
subjective, with an artistic touch.
When a source color profile and a destination color profile are combined
under a specific render intent, they produce a color transformation.
Color transformations are already preresented by weston_color_transform.
This patch adds the basic API for color profile objects. Everything
worthwhile of these objects is implemented in the color managers:
color-noop never creates these, and in color-lcms they are basically a
container for cmsHPROFILE, the Little CMS object for color profiles.
Color profile objects will not be interpreted outside of the color
managers, unlike color transformations.
For a start, the color manager API has one function to create color
profiles: from ICC profile data. More creation functions for other
sources will be added later.
The API has errmsg return parameter for error messages. These are not
simply weston_log()'d, because CM&HDR protocol will allow clients to
trigger errors and the protocol handles that gracefully. Therefore
instead of flooding the compositor logs, the error messages will
probably need to be relayed back to clients.
Color-lcms is expected to create a cmsHPROFILE for all kinds of color
profiles, not just for those created from ICC profile data. Hence,
color-lcms will fingerprint color profiles by the MD5 hash which Little
CMS computes for us. The fingerprint is used for de-duplication: instead
of creating copies, reference existing color profiles.
This code is very much based on Sebastian Wick's earlier work on Weston
color management, but structured and named differently.
Co-authored-by: Sebastian Wick <sebastian@sebastianwick.net>
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
4 years ago
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct cmlcms_color_profile *
|
|
|
|
get_cprof(struct weston_color_profile *cprof_base)
|
|
|
|
{
|
|
|
|
return container_of(cprof_base, struct cmlcms_color_profile, base);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
cmlcms_get_color_profile_from_icc(struct weston_color_manager *cm,
|
|
|
|
const void *icc_data,
|
|
|
|
size_t icc_len,
|
|
|
|
const char *name_part,
|
|
|
|
struct weston_color_profile **cprof_out,
|
|
|
|
char **errmsg);
|
|
|
|
|
|
|
|
void
|
|
|
|
cmlcms_destroy_color_profile(struct weston_color_profile *cprof_base);
|
|
|
|
|
|
|
|
|
|
|
|
struct cmlcms_color_transform_search_param {
|
|
|
|
enum cmlcms_category category;
|
|
|
|
struct cmlcms_color_profile *input_profile;
|
|
|
|
struct cmlcms_color_profile *output_profile;
|
|
|
|
cmsUInt32Number intent_output; /* selected intent from output profile */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct cmlcms_color_transform {
|
|
|
|
struct weston_color_transform base;
|
|
|
|
|
|
|
|
/* weston_color_manager_lcms::color_transform_list */
|
|
|
|
struct wl_list link;
|
|
|
|
|
|
|
|
struct cmlcms_color_transform_search_param search_key;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 3D LUT color mapping part of the transformation, if needed.
|
|
|
|
* For category CMLCMS_CATEGORY_INPUT_TO_OUTPUT it includes pre-curve and
|
|
|
|
* post-curve.
|
|
|
|
* For category CMLCMS_CATEGORY_INPUT_TO_BLEND it includes pre-curve.
|
|
|
|
* For category CMLCMS_CATEGORY_BLEND_TO_OUTPUT and when identity it is
|
|
|
|
* not used
|
|
|
|
*/
|
|
|
|
cmsHTRANSFORM cmap_3dlut;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct cmlcms_color_transform *
|
|
|
|
get_xform(struct weston_color_transform *xform_base)
|
|
|
|
{
|
|
|
|
return container_of(xform_base, struct cmlcms_color_transform, base);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct cmlcms_color_transform *
|
|
|
|
cmlcms_color_transform_get(struct weston_color_manager_lcms *cm,
|
|
|
|
const struct cmlcms_color_transform_search_param *param);
|
|
|
|
|
|
|
|
void
|
|
|
|
cmlcms_color_transform_destroy(struct cmlcms_color_transform *xform);
|
|
|
|
|
|
|
|
struct cmlcms_color_profile *
|
|
|
|
ref_cprof(struct cmlcms_color_profile *cprof);
|
|
|
|
|
|
|
|
void
|
|
|
|
unref_cprof(struct cmlcms_color_profile *cprof);
|
|
|
|
|
|
|
|
bool
|
|
|
|
cmlcms_create_stock_profile(struct weston_color_manager_lcms *cm);
|
|
|
|
|
|
|
|
void
|
|
|
|
cmlcms_color_profile_destroy(struct cmlcms_color_profile *cprof);
|
|
|
|
|
|
|
|
bool
|
|
|
|
retrieve_eotf_and_output_inv_eotf(cmsContext lcms_ctx,
|
|
|
|
cmsHPROFILE hProfile,
|
|
|
|
cmsToneCurve *output_eotf[3],
|
|
|
|
cmsToneCurve *output_inv_eotf_vcgt[3],
|
|
|
|
cmsToneCurve *vcgt[3],
|
|
|
|
unsigned int num_points);
|
|
|
|
|
|
|
|
unsigned int
|
|
|
|
cmlcms_reasonable_1D_points(void);
|
|
|
|
|
|
|
|
#endif /* WESTON_COLOR_LCMS_H */
|