Mail Archives: djgpp/1996/04/25/16:23:08
On Thu, 25 Apr 1996, Nicholas Marrone wrote:
> That last way works well, but when you fade out the palette it looks
> grey and uneven. A better way to do it so that it fades evenly is to
> take a variable and start it at 63 (for a 256 color palette). Compare
> it to each R, B, & G value in each color, and if they are equal then
> decrement it by one. Once you have gone through everything once,
> decrement the variable and do it over again until the variable is
> zero. This causes the screen to fade out to black evenly.
You will still get grey creeping in if you do it like that: eg. the color
(16, 32, 63) is going to fade out via (16, 32, 32) and then (16, 16, 16),
which probably isn't what you want. I think the best approach is to just
do a linear interpolation between the original rgb value and zero at each
step in the fade, so the ratio between r, g, and b remains unchanged and
the intensity is the only thing that alters. That results in bright colors
fading out in the same total time as dark ones, so you might want to alter
the fadeout speed depending on the intensity of the color, but I find it
looks ok without bothering.
Although in fact the eye percieves brightness logarithmically (successive
doublings of brightness are seen as equal increases) so a linear
interpolation is not really 'correct'...
This is how Allegro does the fade out:
/* fade_out:
* Fades the pallete gradually from the current pallete to a black screen.
* Speed is from 1 (the slowest) up to 64 (instant).
*/
void fade_out(int speed)
{
PALLETE temp, p;
int i, c;
get_pallete(p);
for (c=64; c>0; c-=speed) {
for (i=0; i<256; i++) {
temp[i].r = ((int)p[i].r * c) / 64;
temp[i].g = ((int)p[i].g * c) / 64;
temp[i].b = ((int)p[i].b * c) / 64;
}
set_pallete(temp);
}
set_pallete(black_pallete); /* just in case :-) */
}
Shawn Hargreaves. Why is 'phonetic' spelt with a ph?
Check out Allegro and FED on http://www.york.ac.uk/~slh100/
- Raw text -