From 2a803755fdf4e13d8f3e6d1c496d519388cb10f7 Mon Sep 17 00:00:00 2001 From: William Skaggs Date: Sun, 25 Jul 2004 21:02:31 +0000 Subject: [PATCH] Bill Skaggs * plug-ins/common/decompose.c: clamp results of LAB decomposition so that out-of-gamut conversions do not overflow and get badly distorted. Fixes bug #147603. Note that it would probably be a good idea to do similar things for other conversion types. --- ChangeLog | 7 +++++++ plug-ins/common/decompose.c | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 47fa0619cb..0a5dc90046 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2004-07-25 Bill Skaggs + + * plug-ins/common/decompose.c: clamp results of LAB decomposition + so that out-of-gamut conversions do not overflow and get + badly distorted. Fixes bug #147603. Note that it would probably + be a good idea to do similar things for other conversion types. + 2004-07-25 Shlomi Fish * plug-ins/gimpressionist/: converted checks for initialization of diff --git a/plug-ins/common/decompose.c b/plug-ins/common/decompose.c index 6fbe61e9b4..77d3009743 100644 --- a/plug-ins/common/decompose.c +++ b/plug-ins/common/decompose.c @@ -1043,9 +1043,9 @@ extract_lab (guchar *src, ftx = ((tx = x/Xn) > 0.008856) ? cbrt (tx) : 7.78 * tx + sixteenth; ftz = ((tz = z/Zn) > 0.008856) ? cbrt (tz) : 7.78 * tz + sixteenth; - *l_dst++ = (guchar) (l * 2.5599); - *a_dst++ = (guchar) (128.0 + (ftx - fty) * 635 ); - *b_dst++ = (guchar) (128.0 + (fty - ftz) * 254 ); + *l_dst++ = (guchar) CLAMP (l * 2.5599, 0., 256.); + *a_dst++ = (guchar) CLAMP (128.0 + (ftx - fty) * 635, 0., 256.); + *b_dst++ = (guchar) CLAMP (128.0 + (fty - ftz) * 254, 0., 256.); rgb_src += offset; }