Re: palette fading

Search this archive.

From: Sergio Masci (sergio@titan.demon.co.uk)
Date: Fri 03 Nov 2000 - 15:41:08 IST


> 
> Hey,
> 
> I finally figured out how to adjust the palette (with help of the .pal files 
> from PSP7), however, I would like to know how to fade one... I tried creating 
> a loop, and decreased all the color numbers in it, however this didn't work. 
> Colors just got messed up for some _wierd_ reason...
> 
> I was hoping someone could take a look at the source, and tell me what's 
> wrong with it....
> 
> Here's the source:
> 

[snip]

> int getpalette(char *file, int shade) {
> 
>    ifstream pal(file);
> 
>    int r,g,b,svga_red,svga_green,svga_blue,c = 0;
> 
>    while (pal) {
>       pal >> r;
>       pal >> g;
>       pal >> b;
>       r = r - shade;

	// a color component can only go down to
	// 0 so cut it off if it goes negative,
	// anding it with a mask will not cut off
	// a negative value
	// try (2 - 3) & 0x3f

	if (r < 0)
	{	r = 0;
	}

>       g = g - shade;

	if (g < 0)
	{	g = 0;
	}

>       b = b - shade;

	if (b < 0)
	{	b = 0;
	}

>       svga_red = ((r >> 2) & 0x3f);
>       svga_green = ((g >> 2) & 0x3f);
>       svga_blue = ((b >> 2) & 0x3f);

>       gl_setpalettecolor(c,svga_red,svga_green,svga_blue);
>       c++;
>    }
> 
> }
> 

[snip]

> 
> The image only contains blue shades (and white ones), but when shading the 
> palette, I get red, and other colors that shouldn't be there.... Any help 
> would be appreciated.
> 
> thnx in advance,
> - Remenic.
> 

BTW although most svga cards tend to use only 6 bits per colour component
in the palette lookup table, some cards use more so you might like to make
your '0x3f' masks and '2' shift factors runtime selectable (i.e. use variables
not constants).

Regards
Sergio

------------------------------------------------------------------
Unsubscribe:  To:   listbot@svgalib.org
              Body: unsubscribe linux-svgalib


This archive was generated by hypermail 2.1.4 : Wed 21 Jan 2004 - 22:10:23 IST