diff options
author | Pekka Paalanen <pekka.paalanen@collabora.com> | 2024-02-27 15:51:19 +0200 |
---|---|---|
committer | Pekka Paalanen <pq@iki.fi> | 2024-03-07 14:50:47 +0000 |
commit | fd63243c02dffb27c1bba9d65a1f05b3f870e067 (patch) | |
tree | f06a9d14f04682e694131d8cfa6cf0cd04889d0f | |
parent | 236ee19ed47848580933714a31a9d059335ba2b9 (diff) |
color-lcms: convert output eotf from curves to lcmsProfilePtr
We need it as a cms profile, so let's make it one to start with. We even
gain non-fatal error handling.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
-rw-r--r-- | libweston/color-lcms/color-lcms.h | 2 | ||||
-rw-r--r-- | libweston/color-lcms/color-profile.c | 28 | ||||
-rw-r--r-- | libweston/color-lcms/color-transform.c | 3 |
3 files changed, 22 insertions, 11 deletions
diff --git a/libweston/color-lcms/color-lcms.h b/libweston/color-lcms/color-lcms.h index 5c9a960a..9c1be82a 100644 --- a/libweston/color-lcms/color-lcms.h +++ b/libweston/color-lcms/color-lcms.h @@ -82,7 +82,7 @@ struct cmlcms_output_profile_extract { * For ICC profiles, if the profile type is matrix-shaper, then eotf * contains the TRC, otherwise eotf contains an approximated EOTF. */ - cmsToneCurve *eotf[3]; + struct lcmsProfilePtr eotf; /** * This field represents a concatenation of inverse EOTF + VCGT, diff --git a/libweston/color-lcms/color-profile.c b/libweston/color-lcms/color-profile.c index e7efc4d2..5d5af408 100644 --- a/libweston/color-lcms/color-profile.c +++ b/libweston/color-lcms/color-profile.c @@ -191,6 +191,7 @@ ensure_output_profile_extract_icc(struct cmlcms_output_profile_extract *extract, { cmsToneCurve *curve = NULL; const cmsToneCurve * const *vcgt_curves; + cmsToneCurve *eotf_curves[3] = {}; unsigned i; cmsTagSignature tags[] = { cmsSigRedTRCTag, cmsSigGreenTRCTag, cmsSigBlueTRCTag @@ -209,8 +210,8 @@ ensure_output_profile_extract_icc(struct cmlcms_output_profile_extract *extract, *err_msg = "TRC tag missing from matrix-shaper ICC profile"; goto fail; } - extract->eotf[i] = cmsDupToneCurve(curve); - if (!extract->eotf[i]) { + eotf_curves[i] = cmsDupToneCurve(curve); + if (!eotf_curves[i]) { *err_msg = "out of memory"; goto fail; } @@ -221,14 +222,20 @@ ensure_output_profile_extract_icc(struct cmlcms_output_profile_extract *extract, * linearization that produces sampled curves. */ if (!build_eotf_from_clut_profile(lcms_ctx, hProfile, - extract->eotf, num_points)) { + eotf_curves, num_points)) { *err_msg = "estimating EOTF failed"; goto fail; } } + extract->eotf.p = cmsCreateLinearizationDeviceLinkTHR(lcms_ctx, cmsSigRgbData, eotf_curves); + if (!extract->eotf.p) { + *err_msg = "out of memory"; + goto fail; + } + for (i = 0; i < 3; i++) { - curve = cmsReverseToneCurve(extract->eotf[i]); + curve = cmsReverseToneCurve(eotf_curves[i]); if (!curve) { *err_msg = "inverting EOTF failed"; goto fail; @@ -254,10 +261,15 @@ ensure_output_profile_extract_icc(struct cmlcms_output_profile_extract *extract, } } } + + cmsFreeToneCurveTriple(eotf_curves); + return true; fail: - cmsFreeToneCurveTriple(extract->eotf); + cmsCloseProfile(extract->eotf.p); + extract->eotf.p = NULL; + cmsFreeToneCurveTriple(eotf_curves); cmsFreeToneCurveTriple(extract->output_inv_eotf_vcgt); cmsFreeToneCurveTriple(extract->vcgt); return false; @@ -272,14 +284,14 @@ ensure_output_profile_extract(struct cmlcms_color_profile *cprof, bool ret; /* Everything already computed */ - if (cprof->extract.eotf[0]) + if (cprof->extract.eotf.p) return true; ret = ensure_output_profile_extract_icc(&cprof->extract, lcms_ctx, cprof->profile, num_points, err_msg); if (ret) - weston_assert_ptr(cprof->base.cm->compositor, cprof->extract.eotf[0]); + weston_assert_ptr(cprof->base.cm->compositor, cprof->extract.eotf.p); return ret; } @@ -376,7 +388,7 @@ cmlcms_color_profile_destroy(struct cmlcms_color_profile *cprof) wl_list_remove(&cprof->link); cmsFreeToneCurveTriple(cprof->extract.vcgt); - cmsFreeToneCurveTriple(cprof->extract.eotf); + cmsCloseProfile(cprof->extract.eotf.p); cmsFreeToneCurveTriple(cprof->extract.output_inv_eotf_vcgt); cmsCloseProfile(cprof->profile.p); diff --git a/libweston/color-lcms/color-transform.c b/libweston/color-lcms/color-transform.c index fb3ff6a6..5933e8be 100644 --- a/libweston/color-lcms/color-transform.c +++ b/libweston/color-lcms/color-transform.c @@ -894,8 +894,7 @@ xform_realize_chain(struct cmlcms_color_transform *xform) switch (xform->search_key.category) { case CMLCMS_CATEGORY_INPUT_TO_BLEND: /* Add linearization step to make blending well-defined. */ - extra = profile_from_rgb_curves(cm->lcms_ctx, output_profile->extract.eotf); - chain[chain_len++] = extra; + chain[chain_len++] = output_profile->extract.eotf; break; case CMLCMS_CATEGORY_INPUT_TO_OUTPUT: /* Just add VCGT if it is provided. */ |