[AD] Color blending bug fig

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]



Hi,

It seems that the trans blender would produce incorrect results under certain circumstances if the trans factor is 255. This patch fixes that behavior.



--
- Robert J Ohannessian
"Microsoft code is probably O(n^20)" (my CS prof)
http://pages.infinit.net/voidstar/
Index: colblend.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/colblend.c,v
retrieving revision 1.4
diff -u -b -r1.4 colblend.c
--- colblend.c	2001/11/06 15:30:46	1.4
+++ colblend.c	2001/11/19 03:30:15
@@ -57,10 +57,10 @@
    if (n)
       n++;
 
-   res = ((x & 0xFF00FF) - (y & 0xFF00FF)) * n / 256 + y;
+   res = ((((x & 0xFF00FF) - (y & 0xFF00FF)) * n) >> 8) + y;
    y &= 0xFF00;
    x &= 0xFF00;
-   g = (x - y) * n / 256 + y;
+   g = (((x - y) * n) >> 8) + y;
 
    res &= 0xFF00FF;
    g &= 0xFF00;
@@ -86,10 +86,10 @@
    if (n)
       n++;
 
-   res = ((xx & 0xFF00FF) - (y & 0xFF00FF)) * n / 256 + y;
+   res = ((((xx & 0xFF00FF) - (y & 0xFF00FF)) * n) >> 8) + y;
    y &= 0xFF00;
    xx &= 0xFF00;
-   g = (xx - y) * n / 256 + y;
+   g = (((xx - y) * n) >> 8) + y;
 
    res &= 0xFF00FF;
    g &= 0xFF00;
@@ -111,10 +111,10 @@
    if (n)
       n++;
 
-   res = ((x & 0xFF00FF) - (y & 0xFF00FF)) * n / 256 + y;
+   res = ((((x & 0xFF00FF) - (y & 0xFF00FF)) * n) >> 8) + y;
    y &= 0xFF00;
    x &= 0xFF00;
-   g = (x - y) * n / 256 + y;
+   g = (((x - y) * n) >> 8) + y;
 
    res &= 0xFF00FF;
    g &= 0xFF00;
@@ -139,10 +139,10 @@
 
    x = ((x>>16)&0xFF) | (x&0xFF00) | ((x<<16)&0xFF0000);
 
-   res = ((x & 0xFF00FF) - (y & 0xFF00FF)) * n / 256 + y;
+   res = ((((x & 0xFF00FF) - (y & 0xFF00FF)) * n) >> 8) + y;
    y &= 0xFF00;
    x &= 0xFF00;
-   g = (x - y) * n / 256 + y;
+   g = (((x - y) * n) >> 8) + y;
 
    res &= 0xFF00FF;
    g &= 0xFF00;
@@ -157,9 +157,9 @@
  */
 unsigned long _blender_add24(unsigned long x, unsigned long y, unsigned long n)
 {
-   int r = getr24(y) + getr24(x) * n / 256;
-   int g = getg24(y) + getg24(x) * n / 256;
-   int b = getb24(y) + getb24(x) * n / 256;
+   int r = getr24(y) + (getr24(x) * n) >> 8;
+   int g = getg24(y) + (getg24(x) * n) >> 8;
+   int b = getb24(y) + (getb24(x) * n) >> 8;
 
    r = MIN(r, 255);
    g = MIN(g, 255);


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/