This is part two of my walkthrough of the Dune image files. (Part one can be found here). This part focuses on the color definitions, palettes, that can be found in almost all the images files.
Generally a palettes can be found at the start of a file and in a few cases, several palettes can be found among the file’s sub-parts. The palette in the beginning I have decided to call the Default palette and the other definitions I call Alternative palettes. Both type of palettes are formatted in the same way.
The default palette is not always defined. If it is, it will be between the first two bytes (a word) and the offset those bytes points to. If it doesn’t exists the first two bytes will equal the value of 0x002 and point direct to the next word.
The Palette section
The palettes found in files do not define a full 256 colors VGA palette, it only defines colors that will be used by the images in the file. The palette definitions are divided into groups of colors where each group starts with a byte that point to a position in the VGA palette, a second byte in the group tells the number of colors in the group and lastly 3 bytes for each color in the group. The three bytes define Red, Green and Blue values for the colors.
In the above example from jess.HSQ, there is a default palette defining three palette group with 1, 15 and 7 colors. The first group should be placed at location 0 (0x0), the second at 32 (0x20) and the third on 48 (0x30).
The palette section ends when both values for number of position and length for a group is 0xFF.
The palette can end before the next section begins. The is because the next section will always be “word aligned”, meaning it will always start on an even number offset. This was done because old processors would work with words much faster if they had even address locations.
In the example above you can see a “junk” byte with value 0x24 at position 0x4F.
The Color Bytes
Reading the color bytes and use them as is, will not produce the right values for Red, Green and Blue. The Color bytes needs to be shifted to the left two bits to get the correct value. (They are stored in that way because that is the format used when sending color definitions to the VGA card.) So if a RGB color is defined with bytes 0x0B, 0x16 and 0x32 in a file, it should be 0x2C, 0x58 and 0xC8 when “showed on screen”.
Below is the result of reading the default palette in jess.HSQ
When alternative palettes are present they are used for animation and other effects. They can define colors used by other images than those found in the same file. Below is how different palettes in sky.HSQ is used to simulate different times of the day. The bigger image on the left is from dunes2.HSQ and the smaller image to the right is from sky.HSQ. The later is, as you might guess, used to create the sky in the game.
Next post will be about the image definitions. Stay tuned.