From 68592d3cd1a5468a76965861db6ac3223b0bf843 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Fri, 23 Aug 2013 08:27:01 +0000 Subject: Fix #36535: Color difference when saving image Issue was caused by precision loss in alpha under code. Now it might be slower a bit, but it's as precise as it could be. At least i hope so :) --- source/blender/imbuf/intern/imageprocess.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'source/blender/imbuf/intern/imageprocess.c') diff --git a/source/blender/imbuf/intern/imageprocess.c b/source/blender/imbuf/intern/imageprocess.c index 26dd0f2977a..bde17e17419 100644 --- a/source/blender/imbuf/intern/imageprocess.c +++ b/source/blender/imbuf/intern/imageprocess.c @@ -359,17 +359,21 @@ void IMB_alpha_under_color_byte(unsigned char *rect, int x, int y, float backcol unsigned char *cp = rect; while (a--) { - if (cp[3] == 0) { + if (cp[3] == 255) { + /* pass */ + } + else if (cp[3] == 0) { cp[0] = backcol[0] * 255; cp[1] = backcol[1] * 255; cp[2] = backcol[2] * 255; } else { - int mul = 255 - cp[3]; + float alpha = cp[3] / 255.0; + float mul = 1.0f - alpha; - cp[0] = (cp[0] * cp[3] >> 8) + mul * backcol[0] / 255; - cp[1] = (cp[1] * cp[3] >> 8) + mul * backcol[1] / 255; - cp[2] = (cp[2] * cp[3] >> 8) + mul * backcol[2] / 255; + cp[0] = (cp[0] * alpha) + mul * backcol[0]; + cp[1] = (cp[1] * alpha) + mul * backcol[1]; + cp[2] = (cp[2] * alpha) + mul * backcol[2]; } cp[3] = 255; -- cgit v1.2.3