Re: palette fading

Search this archive.

From: Matan Ziv-Av (matan@svgalib.org)
Date: Fri 03 Nov 2000 - 14:33:36 IST


On Fri, 3 Nov 2000, Remenic wrote:

> 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...

you don't make sure that r>=shade, before calculating r-shade, so r
becomes negative. (((-1)>>2)&0x3f)==0x3f (think of how negative numbers
are represented.)
A better way to fade is by scaling the colors down:
have shade going from 255 (or any other value down to 0), and calculate
r as r=r*255/shade.

> 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;
>     g = g - shade;
>     b = b - shade;
>     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++;
>  }
> }


-- 
Matan Ziv-Av.                         matan@svgalib.org


------------------------------------------------------------------
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