Alpha blending fix from 1.x.
authorCarl Hetherington <cth@carlh.net>
Sun, 11 Jan 2015 02:58:18 +0000 (02:58 +0000)
committerCarl Hetherington <cth@carlh.net>
Sun, 11 Jan 2015 02:58:18 +0000 (02:58 +0000)
src/lib/image.cc

index ffe9f3e0b5f656eac2b8f5204a718e387922dd23..d16de5e551b46b2badfb50424bceeefc645fedea 100644 (file)
@@ -389,9 +389,9 @@ Image::alpha_blend (shared_ptr<const Image> other, Position<int> position)
                        uint8_t* op = other->data()[0] + oy * other->stride()[0];
                        for (int tx = start_tx, ox = start_ox; tx < size().width && ox < other->size().width; ++tx, ++ox) {
                                float const alpha = float (op[3]) / 255;
-                               tp[0] = op[0] + (tp[0] * (1 - alpha));
-                               tp[1] = op[1] + (tp[1] * (1 - alpha));
-                               tp[2] = op[2] + (tp[2] * (1 - alpha));
+                               tp[0] = op[0] * alpha + tp[0] * (1 - alpha);
+                               tp[1] = op[1] * alpha + tp[1] * (1 - alpha);
+                               tp[2] = op[2] * alpha + tp[2] * (1 - alpha);
                                
                                tp += this_bpp;
                                op += other_bpp;
@@ -408,10 +408,10 @@ Image::alpha_blend (shared_ptr<const Image> other, Position<int> position)
                        uint8_t* op = other->data()[0] + oy * other->stride()[0];
                        for (int tx = start_tx, ox = start_ox; tx < size().width && ox < other->size().width; ++tx, ++ox) {
                                float const alpha = float (op[3]) / 255;
-                               tp[0] = op[0] + (tp[0] * (1 - alpha));
-                               tp[1] = op[1] + (tp[1] * (1 - alpha));
-                               tp[2] = op[2] + (tp[2] * (1 - alpha));
-                               tp[3] = op[3] + (tp[3] * (1 - alpha));
+                               tp[0] = op[0] * alpha + tp[0] * (1 - alpha);
+                               tp[1] = op[1] * alpha + tp[1] * (1 - alpha);
+                               tp[2] = op[2] * alpha + tp[2] * (1 - alpha);
+                               tp[3] = op[3] * alpha + tp[3] * (1 - alpha);
                                
                                tp += this_bpp;
                                op += other_bpp;
@@ -428,9 +428,9 @@ Image::alpha_blend (shared_ptr<const Image> other, Position<int> position)
                        for (int tx = start_tx, ox = start_ox; tx < size().width && ox < other->size().width; ++tx, ++ox) {
                                float const alpha = float (op[3]) / 255;
                                /* Blend high bytes */
-                               tp[1] = op[0] + (tp[1] * (1 - alpha));
-                               tp[3] = op[1] + (tp[3] * (1 - alpha));
-                               tp[5] = op[2] + (tp[5] * (1 - alpha));
+                               tp[1] = op[0] * alpha + tp[1] * (1 - alpha);
+                               tp[3] = op[1] * alpha + tp[3] * (1 - alpha);
+                               tp[5] = op[2] * alpha + tp[5] * (1 - alpha);
                                
                                tp += this_bpp;
                                op += other_bpp;