[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [59401] trunk/blender/source/blender/imbuf /intern/imageprocess.c: Fix #36535: Color difference when saving image
Sergey Sharybin
sergey.vfx at gmail.com
Fri Aug 23 10:27:01 CEST 2013
Revision: 59401
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59401
Author: nazgul
Date: 2013-08-23 08:27:01 +0000 (Fri, 23 Aug 2013)
Log Message:
-----------
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 :)
Modified Paths:
--------------
trunk/blender/source/blender/imbuf/intern/imageprocess.c
Modified: trunk/blender/source/blender/imbuf/intern/imageprocess.c
===================================================================
--- trunk/blender/source/blender/imbuf/intern/imageprocess.c 2013-08-23 07:14:22 UTC (rev 59400)
+++ trunk/blender/source/blender/imbuf/intern/imageprocess.c 2013-08-23 08:27:01 UTC (rev 59401)
@@ -359,17 +359,21 @@
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;
More information about the Bf-blender-cvs
mailing list