delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/08/02/08:18:33

Newsgroups: comp.os.msdos.djgpp
From: Elliott Oti <e DOT oti AT stud DOT warande DOT ruu DOT nl>
Subject: Re: URGENT! repost: palette problems, please help.
Sender: usenet AT fys DOT ruu DOT nl (News system Tijgertje)
Message-ID: <33E245D5.36B8@stud.warande.ruu.nl>
Date: Fri, 1 Aug 1997 20:23:49 GMT
Reply-To: e DOT oti AT stud DOT warande DOT ruu DOT nl
References: <5rpu2i$40p$1 AT grissom DOT powerup DOT com DOT au>
Mime-Version: 1.0
Organization: The Gauge Variance Promotion Society
Lines: 60
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019