From c662f1b43f04744ac50ffc9f6a08b3b64290b084 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Thu, 14 Jan 2010 22:57:04 -0500 Subject: Some color handling fixes. --- libdimension/color.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'libdimension') diff --git a/libdimension/color.c b/libdimension/color.c index 9e1ef4f..abda9bb 100644 --- a/libdimension/color.c +++ b/libdimension/color.c @@ -314,11 +314,13 @@ dmnsn_color_add(dmnsn_color c1, dmnsn_color c2) dmnsn_color ret = dmnsn_color_from_sRGB(sRGB); /* Weighted average of transparencies by intensity */ - dmnsn_CIE_Lab Lab1 = dmnsn_Lab_from_color(ret, dmnsn_whitepoint); - dmnsn_CIE_Lab Lab2 = dmnsn_Lab_from_color(ret, dmnsn_whitepoint); - if (Lab1.L + Lab2.L) { - ret.filter = (Lab1.L*c1.filter + Lab2.L*c2.filter)/(Lab1.L + Lab2.L); - ret.trans = (Lab1.L*c1.trans + Lab2.L*c2.trans )/(Lab1.L + Lab2.L); + dmnsn_CIE_Lab Lab1 = dmnsn_Lab_from_color(c1, dmnsn_whitepoint); + dmnsn_CIE_Lab Lab2 = dmnsn_Lab_from_color(c2, dmnsn_whitepoint); + double L1 = Lab1.L*(1.0 - c1.filter - c1.trans); + double L2 = Lab2.L*(1.0 - c2.filter - c2.trans); + if (L1 + L2) { + ret.filter = (L1*c1.filter + L2*c2.filter)/(L1 + L2); + ret.trans = (L1*c1.trans + L2*c2.trans) /(L1 + L2); } return ret; } @@ -366,7 +368,8 @@ dmnsn_color_filter(dmnsn_color color, dmnsn_color filter) dmnsn_color_illuminate(filter, color)); dmnsn_color ret = dmnsn_color_add(transmitted, filtered); - ret.filter = filter.filter*color.filter; + ret.filter = filter.filter*(color.filter + color.trans)/2 + + color.filter*(filter.filter + filter.trans)/2; ret.trans = filter.trans*color.trans; return ret; } -- cgit v1.2.3