graphics: splash - correct rounding in alpha blending
authorTerje Gundersen <terje.gundersen@appeartv.com>
Tue, 24 Dec 2013 09:51:57 +0000 (10:51 +0100)
committerTom Gundersen <teg@jklm.no>
Tue, 24 Dec 2013 10:05:25 +0000 (11:05 +0100)
"(X >> 8)" always rounds down, but "(X + 0x80) >> 8)" rounds to
the nearest integer.

src/efi/graphics.c

index d3f674b..062ce27 100644 (file)
@@ -222,8 +222,8 @@ static void pixel_blend(UINT32 *dst, const UINT32 source) {
         dst_g  = (*dst & 0x00ff00);
 
         /* blend */
-        rb = ((((src_rb - dst_rb) * alpha) >> 8) + dst_rb) & 0xff00ff;
-        g  = ((((src_g  -  dst_g) * alpha) >> 8) +  dst_g) & 0x00ff00;
+        rb = ((((src_rb - dst_rb) * alpha + 0x800080) >> 8) + dst_rb) & 0xff00ff;
+        g  = ((((src_g  -  dst_g) * alpha + 0x008000) >> 8) +  dst_g) & 0x00ff00;
 
         *dst = (rb | g);
 }