delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/01/20/11:55:26

From: Rob Vasquez <digital DOT fx AT worldnet DOT att DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: allegro palette
Date: Sun, 19 Jan 1997 20:49:18 -0500
Organization: Digital Fx
Lines: 42
Message-ID: <32E2CF1E.7BA8@worldnet.att.net>
References: <5brn0b$di4 AT news DOT asu DOT edu>
NNTP-Posting-Host: 207.147.48.122
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

> Has anybody created a good palette for allegro. I noticed that the 
> palette contains the same 16 colors at all the 256 places.
> 
> An even better solution would be an algorithm to choose rgb values

I use a paint program to edit or load palettes, then I save blank pcx 
files and save the palette to the pcx file. Then I use this function I 
wrote to extract the palette from the pcx and load that in:

// use it for whatever you want. It should work, but this isnt the 
// computer I have djgpp on, so the 8bit to 6bit conversions may be 
// incorrectly done  -- sorry

void get_pcx_palette(char* filename)
{
 // extracts the palette from a pcx file
 // pal is an array of 256 rgb unsigned char values - pal.r pal.g pal.b

 FILE *pcxfile = fopen(filename, "rb");    // open pcx file
 int index;
 PALETTE pal;

 fseek(pcxfile, -768, SEEK_END);           // go to 768 bytes before end 
of file

 for (index = 0; index < 256; index++)
  {
   pal[index].r = getc(pcxfile);
   pal[index].g = getc(pcxfile);
   pal[index].b = getc(pcxfile);
  }

 set_palette(pal);
}

// thats it it should work, call "get_pcx_palette("your_pic.pcx");"

-- 
               Rob Vasquez
               Digital Fx '97
               
   email:   digital DOT fx AT worldnet DOT att DOT net

- Raw text -


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