Re: [AD] Other bugs in C version |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
From: <stickman2000@xxxxxxxxxx>
Sent: Tuesday, September 05, 2000 9:53 PM
> I don't understand how swapping the arguments would really change
> anything. How did it fix the problem?
I'll try to explain : in fact (in version 3.9.33) 8 bits *lit routines work
well but truecolor routines don't. Why ?
In src/c/cscan.h, the FUNC_*_LIT functions compute the lit color this way :
unsigned long color = PS_BLEND(blender, GET_MEMORY_PIXEL(s), (c
>>16));
This is wrong because :
1. in 15, 16 and 24 bits functions GET_MEMORY_PIXEL does not return an
unsigned long result (arguments of _blender_func have to be unsigned long -
cf. the Allegro docs)
2. arguments of PS_BLEND are given in the wrong order : when the macros are
"translated", the line above becomes (for 15 bits colordepth) :
unsigned long color = _blender_func15(c >> 16, _blender_col15, *s);
and it should be :
... = _blender_func15( *s, _blender_col15, c>>16); /* arguments
(*s) and (c>>16) are swapped */
i.e. the lit color should be interpolated between *s (the texture color) and
_blender_col15 (the reference color) at the step (c>>16). So, in order to
fix both those bugs we have to write :
unsigned long color = GET_MEMORY_PIXEL(s); /* convert
GET_MEMORY_PIXEL to unsigned long */
color = PS_BLEND(blender, (c>>16), color); /* swap the last
2 arguments of PS_BLEND */
Ok, now truecolor routines work well but 8 bits functions don't give the
good result anymore. This is because we have swapped the arguments of
PS_BLEND (it's a bit tricky isn' it? :-). In order to fix that last bug we
shall swap the arguments of PS_BLEND one more time in its definition for the
8 bits case (in src/c/cdefs8.h) :
#define PS_BLEND(b,o,c) ((b)->data[(c) & 0xFF][(o) & 0xFF])
is replaced by :
#define PS_BLEND(b,o,c) ((b)->data[(o) & 0xFF][(c) & 0xFF]) /* c
and o are swapped */
Now, the arguments of PS_BLEND are given the good way whether the colordepth
is 8 or not.
Phewwww !!! Those explanations are (very) confused and I speak english so
badly. I hope you'll understand :-)
Good night, sweet dreams !
Bertrand.