JASC Pallete File Format
========================
By Rohan Bernett roxor128@yahoo.com

The JASC pallete format written by Paint Shop Pro is actually just a plain DOS text file. It's probably one of the simplest formats around, even if it's not the most efficent way of storing a pallete.

The first line of the file contains the file id tag. The tag reads "JASC-PAL" (without the quotes). The second line is the version number. This always reads "0100" (again, without the quotes). Line number 3 has the number of entries in the pallete. This is usually either 16 or 256, although I can't see any reason why it couldn't be any other number. So, in theory, you could have a pallete with 4 billion entries if you wanted. Lines 4 and onwards are the actual pallete entries. They consist of 3 numbers from 0 to 255, each representing the red, green, or blue values for each colour.

Here is a sample file.

JASC-PAL
0100
16
0 0 0
0 0 128
0 128 0
0 128 128
128 0 0
128 0 128
128 128 0
128 128 128
0 0 0
0 0 255
0 255 0
0 255 255
255 0 0
255 0 255
255 255 0
255 255 255

Here's some sample pseudocode. It returns a Pallete object and assumes that the Pallete object has the appropriate member functions set_size(size) and set_colour(index,r,g,b). You'll have to make the appropriate changes for your language of choice.

Pallete load_jasc_pal_file(filename)
{
 ifstream input;
 input.open(filename);
 if(input not open correctly)
 {
  print error;
  exit;
 }
 read first line;
 if (first line != "JASC-PAL")
 {
  print error;
  exit;
 }
 read second line;
 if (first line != "0100")
 {
  print error;
  exit;
 }
 int colours = 3rd line from file;
 Pallete pal;
 pal.set_size(colours);
 for (int cnt=0; cnt< colours; cnt++)
 {  
  pal.set_colour(cnt, input.readtextval(), input.readtextval(), input.readtextval());
 }
 input.close();
 return pal;
}

