                         
                                  
                                  PalGen           
                        Palette Gradient Generator 
                        by Blackbob (jim@jtan.com) 
                           

Overview

   PalGen is designed to take the guesswork out of generating palettes with
an interactive, WYSIWYG editor.  With PalGen, you can generate a palette 
consisting of between 32 and 256 colors with up to 15 perfectly smooth 
gradients in that palette.


System Requirements

   - 80486 CPU or higher
   - VGA
   - MS-DOS 3.3 or higher


Usage

   When PalGen is started, it will display the main screen with the default
palette (256 colors, starting at red and fading to blue).  Use the up and
down arrow keys to choose an item, left and right to adjust the value, and
ENTER to select an option.

   Current Color 
      The current main color that is being edited.  It is also shown
      in the "Current Color" box.
   
   Number of Colors
      The number of main colors in the palette.  For example, when PalGen
      is started, there are two main colors, red and blue.  There must be
      at least two colors and there is a maximum of 16.
   
   Palette Size
      The total number of palette entries.  Ranges from 32 to 256.
   
   Red, Green, Blue
      The individual red, green, and blue components of the currently
      selected color.  Values range from 0 to 63.
      
   Save PALETTE.PAL
      Saves the palette file to disk.  See below for the format.

   Exit
      Exits PalGen.

   If you don't understand what something does, try adjusting it.  It's
   easier to understand what it does when you see the results.


File Format and Loading

   Each color in the palette file outputted by PalGen is represented by
three bytes.  The bytes represent the 6-bit red, green, and blue values in
order.  For example:
      
File Byte     1  2  3  4  5  6  7  8  9  
Palette Entry {--1--}  {--2--}  {--3--}
Palette Color R  G  B  R  G  B  R  G  B  

Examples for a loading a 256-entry (768 byte) palette file directly to
the VGA:
   
   Psuedocode
   
   Open PALETTE.PAL
   Loop 768 times
      Read red value and send it to the video card
      Read green value and send it to the video card
      Read blue value and send it to the video card
   Close PALETTE.PAL

   Turbo/Borland C
     
   void loadpalette(void)
   {
      int counter;
      FILE *palfile;

      if((palfile=fopen("palette.pal","rb"))==NULL)
      {
         fprintf(stderr,"Error opening PALETTE.PAL!\n");
         exit(1);
      }
      outportb(0x3C8,0);      /* 0x3C8 = VGA DAC, initial color index */  
      for(counter=0;counter<768;counter++)
      {
         outportb(0x3C9,fgetc(palfile));  /* 0x3C9 = Red component   */
         outportb(0x3C9,fgetc(palfile));  /* 0x3C9 = Green component */
         outportb(0x3C9,fgetc(palfile));  /* 0x3C9 = Blue component  */
      }
      fclose(palfile);
   }

   Turbo Pascal
   
   procedure loadpalette;
   var
      palfile : file of byte;
      counter : integer;
      color   : byte;
   begin
      assign(palfile,'palette.pal');
      {$I-}
      reset(cdfile);
      {$I+}
      if ioresult <> 0 then
      begin
         writeln('Error opening PALETTE.PAL');
         halt(1);
      end;
      port[$3C8] := 0;      { $3C8 = VGA DAC, initial color index }
      for counter := 1 to 768 do 
      begin
         read(palfile,color);
         port[$3C9] := color;           { 0x3C9 = Red component   }
         read(palfile,color);
         port[$3C9] := color;           { 0x3C9 = Green component }
         read(palfile,color);
         port[$3C9] := color;           { 0x3C9 = Blue component  }
      end;
   end;


Notes

   All gradients are generated using a varient of Bresenham's line algorithm
and are guaranteed to be as smooth as possible.
   The palette data outputted is in the form of 6-bit RGB values because the
standard VGA DAC is limited to 6 bits.
   You may have trouble running this program in Windows or on a slow computer.
Because of the method that is used to get all 256 colors displayed in text
mode, any slowdowns (disk accesses in a multi-tasking environment, having
many programs running at once, etc.) may cause the display to flicker or not
work at all.  It will also only work in full-screen mode.  If it doesn't
seem to work, try quitting to DOS.
   PalGen has been tested on multiple 486 systems under DOS and Windows.

Credits

All code by Blackbob (jim@jtan.com).
If you have any questions, comments, suggestions, gripes, or briefcases
filled with small, unmarked bills, feel free to e-mail me.  :)
