[AD] Bug in the difference blender

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



Hi!

It seems that there's a bug in the difference blender.

Normally, it should be:
new_dest = old_dest - source * fact / 256

However, the code currently does:
new_dest = source * fact + dest * (255 - 2 * fact)

Which just seems wrong.

Here's a patch (already applied) to fix this.

Considering that the add blender was *also* wrong (not any more), I'm begining to wonder if all of them wouldn't happen to have inverted source and dest at some point...

Add and Trans blenders (and now Difference blender) are ok.

btw, will the commit to CVS make it in both 4.0.x and 4.x branches?


--
- 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	6 Nov 2001 15:30:46 -0000	1.4
+++ colblend.c	10 Feb 2002 03:14:05 -0000
@@ -209,9 +209,9 @@
  */
 unsigned long _blender_difference24(unsigned long x, unsigned long y, unsigned long n)
 {
-   return BLEND(24, ABS(getr24(x) - getr24(y)),
-		    ABS(getg24(x) - getg24(y)),
-		    ABS(getb24(x) - getb24(y)));
+   return BLEND(24, ABS(getr24(y) - getr24(x)),
+		    ABS(getg24(y) - getg24(x)),
+		    ABS(getb24(y) - getb24(x)));
 }
 
 
@@ -496,9 +496,9 @@
  */
 unsigned long _blender_difference16(unsigned long x, unsigned long y, unsigned long n)
 {
-   return BLEND(16, ABS(getr16(x) - getr16(y)),
-		    ABS(getg16(x) - getg16(y)),
-		    ABS(getb16(x) - getb16(y)));
+   return BLEND(16, ABS(getr16(y) - getr16(x)),
+		    ABS(getg16(y) - getg16(x)),
+		    ABS(getb16(y) - getb16(x)));
 }
 
 
@@ -776,9 +776,9 @@
  */
 unsigned long _blender_difference15(unsigned long x, unsigned long y, unsigned long n)
 {
-   return BLEND(15, ABS(getr15(x) - getr15(y)),
-		    ABS(getg15(x) - getg15(y)),
-		    ABS(getb15(x) - getb15(y)));
+   return BLEND(15, ABS(getr15(y) - getr15(x)),
+		    ABS(getg15(y) - getg15(x)),
+		    ABS(getb15(y) - getb15(x)));
 }
 
 


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