Mail Archives: djgpp/1997/08/02/08:18:33
David Orme wrote:
>
> I'm displaying PCX files to the screen in VESA mode 0x101 (640x480x256, all
> calls being VESA 1.2 for convenience). The problem is that the palette
> either:
> a) isn't being loaded correctly, or
> b) isn't being set correctly.
>
> This is what I'm doing:
>
> byte pal[768];
> FILE f;
>
> /* open the file and load the palette */
> f=fopen("file.pcx","rb");
> fseek(f,-768,SEEK_END);
> fread(pal,1,768,f);
> fclose(f);
> /* set the vga palette */
> outportb(0x3c8,0);
^_______ THIS IS WHERE YOUR MISTAKE IS ***** !!!!!
*****
> for(i=0;i<768;i++)
> outportb(0x3c9,pal[i]);
Your problem is, you're only setting the *first* colour in your palette.
For EACH entry, from 0 to 255, you have to outportb(0x3c8, i) where 0 <
i < 255.
This should do the trick:
for(i=0;i<768;i+=3)
{
outportb(0x3c8,i/3);
outportb(0x3c9,pal[i]);
outportb(0x3c9,pal[i+1]);
outportb(0x3c9,pal[i+2]);
}
Another problem with PCX files you will encounter, is that many programs
save each rgb entry in 8 bits ie a number from 0-255, but the VGA CLUT
is 6 bits ie from 0 to 63. You will probably need to shift each entry
from the palette 2 bits to the right before feeding it to the VGA card,
otherwise the colours will come out looking wrong. That is:
for(i=0;i<768;i+=3)
{
outportb(0x3c8,i/3);
outportb(0x3c9,pal[i]>>2);
outportb(0x3c9,pal[i+1]>>2);
outportb(0x3c9,pal[i+2]>>2);
}
--
------------ Elliott Oti ---------------
------------- http://www.fys.ruu.nl/~oti ---------
- Raw text -