Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2013-08-23 12:27:01 +0400
committerSergey Sharybin <sergey.vfx@gmail.com>2013-08-23 12:27:01 +0400
commit68592d3cd1a5468a76965861db6ac3223b0bf843 (patch)
tree0631094d37906477fabbc4534615b876a4352be5 /source/blender/imbuf/intern/imageprocess.c
parent6f4b79d5af8245ad88afbad43a813b6bf238c310 (diff)
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 :)
Diffstat (limited to 'source/blender/imbuf/intern/imageprocess.c')
-rw-r--r--source/blender/imbuf/intern/imageprocess.c14
1 files changed, 9 insertions, 5 deletions
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;