diff options
author | Pekka Paalanen <pekka.paalanen@collabora.com> | 2024-02-28 13:42:30 +0200 |
---|---|---|
committer | Pekka Paalanen <pq@iki.fi> | 2024-03-07 14:50:47 +0000 |
commit | 98454720be3abf03d55b6bf4f45115773f0f5630 (patch) | |
tree | 91625e00e926ff384b2ec2b1fa57d9f5401fdf73 | |
parent | fd63243c02dffb27c1bba9d65a1f05b3f870e067 (diff) |
color-lcms: convert VCGT curves to lcmsProfilePtr
We need it as a cms profile, so let's make it one to start with. We even
gain non-datal error handling.
This will also be useful in rewriting output_inv_eotf_vcgt next.
The type change of vcgt_curves is required to be able to call
cmsCreateLinearizationDeviceLinkTHR(), even though everything about
vcgt_curves should be doubly const. The curves are populated on demand
and cached in cmsHPROFILE, so we also must not explicitly free them.
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 | 19 | ||||
-rw-r--r-- | libweston/color-lcms/color-transform.c | 22 |
3 files changed, 14 insertions, 29 deletions
diff --git a/libweston/color-lcms/color-lcms.h b/libweston/color-lcms/color-lcms.h index 9c1be82a..fe9e87f1 100644 --- a/libweston/color-lcms/color-lcms.h +++ b/libweston/color-lcms/color-lcms.h @@ -98,7 +98,7 @@ struct cmlcms_output_profile_extract { /** * VCGT tag cached from output profile, it could be null if not exist */ - cmsToneCurve *vcgt[3]; + struct lcmsProfilePtr vcgt; }; struct cmlcms_color_profile { diff --git a/libweston/color-lcms/color-profile.c b/libweston/color-lcms/color-profile.c index 5d5af408..ca4c3abb 100644 --- a/libweston/color-lcms/color-profile.c +++ b/libweston/color-lcms/color-profile.c @@ -190,7 +190,7 @@ ensure_output_profile_extract_icc(struct cmlcms_output_profile_extract *extract, const char **err_msg) { cmsToneCurve *curve = NULL; - const cmsToneCurve * const *vcgt_curves; + cmsToneCurve **vcgt_curves; cmsToneCurve *eotf_curves[3] = {}; unsigned i; cmsTagSignature tags[] = { @@ -244,6 +244,12 @@ ensure_output_profile_extract_icc(struct cmlcms_output_profile_extract *extract, } vcgt_curves = cmsReadTag(hProfile.p, cmsSigVcgtTag); if (vcgt_curves && vcgt_curves[0] && vcgt_curves[1] && vcgt_curves[2]) { + extract->vcgt.p = cmsCreateLinearizationDeviceLinkTHR(lcms_ctx, cmsSigRgbData, vcgt_curves); + if (!extract->vcgt.p) { + *err_msg = "out of memory"; + goto fail; + } + for (i = 0; i < 3; i++) { curve = lcmsJoinToneCurve(lcms_ctx, extract->output_inv_eotf_vcgt[i], @@ -254,11 +260,6 @@ ensure_output_profile_extract_icc(struct cmlcms_output_profile_extract *extract, } cmsFreeToneCurve(extract->output_inv_eotf_vcgt[i]); extract->output_inv_eotf_vcgt[i] = curve; - extract->vcgt[i] = cmsDupToneCurve(vcgt_curves[i]); - if (!extract->vcgt[i]) { - *err_msg = "out of memory"; - goto fail; - } } } @@ -267,11 +268,13 @@ ensure_output_profile_extract_icc(struct cmlcms_output_profile_extract *extract, return true; fail: + cmsCloseProfile(extract->vcgt.p); + extract->vcgt.p = NULL; + cmsCloseProfile(extract->eotf.p); extract->eotf.p = NULL; cmsFreeToneCurveTriple(eotf_curves); cmsFreeToneCurveTriple(extract->output_inv_eotf_vcgt); - cmsFreeToneCurveTriple(extract->vcgt); return false; } @@ -387,7 +390,7 @@ cmlcms_color_profile_destroy(struct cmlcms_color_profile *cprof) struct weston_color_manager_lcms *cm = to_cmlcms(cprof->base.cm); wl_list_remove(&cprof->link); - cmsFreeToneCurveTriple(cprof->extract.vcgt); + cmsCloseProfile(cprof->extract.vcgt.p); 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 5933e8be..4ade4932 100644 --- a/libweston/color-lcms/color-transform.c +++ b/libweston/color-lcms/color-transform.c @@ -863,21 +863,6 @@ lcms_xform_error_logger(cmsContext context_id, text); } -static struct lcmsProfilePtr -profile_from_rgb_curves(cmsContext ctx, cmsToneCurve *const curveset[3]) -{ - struct lcmsProfilePtr p; - int i; - - for (i = 0; i < 3; i++) - assert(curveset[i]); - - p.p = cmsCreateLinearizationDeviceLinkTHR(ctx, cmsSigRgbData, curveset); - abort_oom_if_null(p.p); - - return p; -} - static bool xform_realize_chain(struct cmlcms_color_transform *xform) { @@ -898,11 +883,8 @@ xform_realize_chain(struct cmlcms_color_transform *xform) break; case CMLCMS_CATEGORY_INPUT_TO_OUTPUT: /* Just add VCGT if it is provided. */ - if (output_profile->extract.vcgt[0]) { - extra = profile_from_rgb_curves(cm->lcms_ctx, - output_profile->extract.vcgt); - chain[chain_len++] = extra; - } + if (output_profile->extract.vcgt.p) + chain[chain_len++] = output_profile->extract.vcgt; break; case CMLCMS_CATEGORY_BLEND_TO_OUTPUT: assert(0 && "category handled in the caller"); |