From ae8dc3070a44c2fad90cba8037e54d1a575240df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Eric=20Janouch?= Date: Fri, 26 Jan 2024 19:53:55 +0100 Subject: Partially circumvent a Little CMS bug --- fiv-io-profile.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/fiv-io-profile.c b/fiv-io-profile.c index 84b310e..2c6f345 100644 --- a/fiv-io-profile.c +++ b/fiv-io-profile.c @@ -30,12 +30,16 @@ #include #endif // HAVE_LCMS2_FAST_FLOAT +// https://github.com/mm2/Little-CMS/issues/430 +static bool g_broken_cms_premul; + void fiv_io_profile_init(void) { // TODO(p): Use Little CMS with contexts instead. #ifdef HAVE_LCMS2_FAST_FLOAT - cmsPluginTHR(NULL, cmsFastFloatExtensions()); + if (cmsPluginTHR(NULL, cmsFastFloatExtensions())) + g_broken_cms_premul = LCMS_VERSION <= 2160; #endif // HAVE_LCMS2_FAST_FLOAT } @@ -300,6 +304,8 @@ fiv_io_profile_argb32(FivIoImage *image, { g_return_if_fail(image->format == CAIRO_FORMAT_ARGB32); + // TODO: With g_no_cms_premultiplication, + // this probably also needs to be wrapped in un-premultiplication. fiv_io_profile_rgb_direct(image->data, image->width, image->height, source, target, FIV_IO_PROFILE_ARGB32_PREMUL, FIV_IO_PROFILE_ARGB32_PREMUL); @@ -311,6 +317,9 @@ fiv_io_profile_argb32_premultiply( { if (image->format != CAIRO_FORMAT_ARGB32) { fiv_io_profile_xrgb32(image, source, target); + } else if (g_broken_cms_premul) { + fiv_io_profile_xrgb32(image, source, target); + fiv_io_premultiply_argb32(image); } else if (!fiv_io_profile_rgb_direct(image->data, image->width, image->height, source, target, FIV_IO_PROFILE_ARGB32, FIV_IO_PROFILE_ARGB32_PREMUL)) { -- cgit v1.2.3