diff --git a/libweston/color-lcms/color-lcms.c b/libweston/color-lcms/color-lcms.c index 18340a39..6e9d9fa5 100644 --- a/libweston/color-lcms/color-lcms.c +++ b/libweston/color-lcms/color-lcms.c @@ -165,6 +165,10 @@ cmlcms_init(struct weston_color_manager *cm_base) cmsSetLogErrorHandlerTHR(cm->lcms_ctx, lcms_error_logger); + if (!cmlcms_create_stock_profile(cm)) { + weston_log("color-lcms: error: cmlcms_create_stock_profile failed\n"); + return false; + } weston_log("LittleCMS %d initialized.\n", cmsGetEncodedCMMversion()); return true; @@ -175,6 +179,8 @@ cmlcms_destroy(struct weston_color_manager *cm_base) { struct weston_color_manager_lcms *cm = get_cmlcms(cm_base); + if (cm->sRGB_profile) + cmlcms_color_profile_destroy(cm->sRGB_profile); assert(wl_list_empty(&cm->color_transform_list)); assert(wl_list_empty(&cm->color_profile_list)); diff --git a/libweston/color-lcms/color-lcms.h b/libweston/color-lcms/color-lcms.h index 05fa940a..eb34847c 100644 --- a/libweston/color-lcms/color-lcms.h +++ b/libweston/color-lcms/color-lcms.h @@ -39,6 +39,7 @@ struct weston_color_manager_lcms { struct wl_list color_transform_list; /* cmlcms_color_transform::link */ 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 * @@ -186,4 +187,10 @@ 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); + #endif /* WESTON_COLOR_LCMS_H */ diff --git a/libweston/color-lcms/color-profile.c b/libweston/color-lcms/color-profile.c index 0d11439d..3f477100 100644 --- a/libweston/color-lcms/color-profile.c +++ b/libweston/color-lcms/color-profile.c @@ -102,7 +102,7 @@ cmlcms_color_profile_create(struct weston_color_manager_lcms *cm, return cprof; } -static void +void cmlcms_color_profile_destroy(struct cmlcms_color_profile *cprof) { wl_list_remove(&cprof->link); @@ -153,6 +153,44 @@ make_icc_file_description(cmsHPROFILE profile, return desc; } +/** + * + * Build stock profile which available for clients unaware of color management + */ +bool +cmlcms_create_stock_profile(struct weston_color_manager_lcms *cm) +{ + cmsHPROFILE profile; + struct cmlcms_md5_sum md5sum; + char *desc = NULL; + + profile = cmsCreate_sRGBProfileTHR(cm->lcms_ctx); + if (!profile) { + weston_log("color-lcms: error: cmsCreate_sRGBProfileTHR failed\n"); + return false; + } + if (!cmsMD5computeID(profile)) { + weston_log("Failed to compute MD5 for ICC profile\n"); + goto err_close; + } + + cmsGetHeaderProfileID(profile, md5sum.bytes); + desc = make_icc_file_description(profile, &md5sum, "sRGB stock"); + if (!desc) + goto err_close; + + cm->sRGB_profile = cmlcms_color_profile_create(cm, profile, desc, NULL); + if (!cm->sRGB_profile) + goto err_close; + + return true; + +err_close: + free(desc); + cmsCloseProfile(profile); + return false; +} + bool cmlcms_get_color_profile_from_icc(struct weston_color_manager *cm_base, const void *icc_data,