The graphic above shows the colors on a 16 color palette (most commonly used for icons, solid color graphics, and gifs. Row one shows colors 0 to 7, and row 2 shows colors 8 to 15. If you have a reason to directly manipulate bytes of pixel data in a program it is important to understand how color data representation changes when the pixel format of the image changes. Of particular interest to me are the pixel formats 4 bit, 8 bit, and 24 bit true color images, and the 16 color palette and the 256 color palette, and the changes that take place in pixel representation at the byte level when color resolution is changed in an image. This page deal with conversions that take place when increasing the image resolution of an image which has a 16 color palette.
There are easy ways to translate an image from a lower resolution to a higher resolution image. For example the following code fragment will copy the lower resolution image into a higher resolution bitmap while correctly making all the translations in color representation. Bitmap.Canvas.Draw(0,0, somebitmap); Understanding how to make these translations at the byte level by directly manipulating the pixel data of a graphic is only required if for some reason you need to have direct control over the bytes in a graphic. A program I am working on requires this level of control so I am investigating the representation of 16 and 256 color palettes in 4 bit, 8 bit, and 24 bit pixel format, as well as working on a way to easily encapsulate this data in reusable program code.
A 16 color palette is most efficiently represented by a 4 bit pixel format (which is capable of encoding a maximum of 16 values and only uses a nibble (half a byte) to store a single pixel. When the sixteen color palette is encoded in 4 bits the encoding is straight forward. Black, color number 0 is encoded as 0, color number 1 is 1, and so on up to the last color, number 15 on the bottom row on the far right in the graphic above. Each byte in a 4 bit pixelformat encodes two pixels so in order to access the pixel data and decode the color reference it is neccesary to apply a mask to the byte. The mask '11110000' when applied to the byte with an AND operation will pull out the high order bits in the byte, and then when the bytes are shifted right four places the correct color number stored in the high order bits is decoded. Similarly the mask '00001111' applied to the byte with an AND operation will exclude the high order bits and pull out the four lower order bits representing the pixel. The following simple code shows first the byte x being given two values, which are then pulled out with a mask (in hexadecimal, four bits are represented by one symbol and so the high order mask becomes $F0 and the low order mask becomes $0F.
procedure TForm1.Button1Click(Sender: TObject);
var x, high,low, z:byte;
begin
x := 4 + 176; {two pixels of color data}
high := x and $F0; {apply the mask}
z := high shr 4; {shift the bits 4 to the right}
low := x and $0F; {apply the low nibble mask}
ShowMessage('The byte : ' + inttostr(x) + chr(13) +
'The low : ' + inttostr(low) + chr(13) +
'The high : ' + inttostr(high) +chr(13) +
'which is color : ' + inttostr(z));
end;
The chart below shows the way 16 color palette data is encoded in 4 bit, 8 bit, and 24 bit pixelformat bitmaps. There are a variety of ways in which the information could be made accessible to a program (an array of constants, or even simply a list of constants Red8, Red24. The situation with the 256 bit palette gets a little more complex because there are 256 values to consider, and discovering the mathematical relationship between these numbers would be a more ideal solution (if there is one - the assignment seems arbitrary, in the case of the 8 bit format and the assignment seems related to intensity of red green and blue in the 24 bit pixel format : for example the Vivid Green color has an intensity of 255 for the second byte, probably the green byte of RGB structure, and zero for the other two bytes - the blue color, color number 12 has 255 set for the first byte, and zero for the other two, which would indicate that the bytes are stored in the order Blue Green Red - if you load a bitmap palette in the order Red Green Blue and then construct a palette you get a backwards colored bitmap).
After doing some more research it seems that the best way to convert an 8 bit (256 color) bitmap to 24 bit is to simply use the entries in the palette table for the 8 bit bitmap. The raw pixel data for a 24 bit bitmap encodes RGB triplets and the palette table for the 8 bit bitmap is encoded as RGB triplets (with one left over 'flag' field to keep the data aligned along double word boundaries). The bytes on the bit map point to one of 256 of these palette entries, and the data needed to make a conversion to 24 bit true color byte values is found in this palette table.
COLOR 4bit
0 Black
1 RedBrown
2 Green
3 BrownGreen
4 Dark Blue
5 Purple
6 BlueGreen
7 Dark Grey
8 Light Grey
9 OrangeRed
10 Vivid Green
11 Yellow
12 Blue
13 PinkPurple
14 Light Blue
15 White
8 bit
0
3
18
21
108
111
126
129
172
5
30
35
180
185
210
215
24 bit
0 0 0
0 0 132
0 132 0
0 132 132
132 0 0
132 0 132
132 132 0
132 132 132
198 198 198
0 0 255
0 255 0
0 255 255
255 0 0
255 0 255
255 255 0
255 255 255
A Unified Field Theory
![]()
The Unified Field Theory
is also available as a zip file -> unified.zip
Introduction :The Pioneer Effect and the New Physics. A brief description of the new physics required to explain the 'Pioneer Effect', which is the constant deceleration of space craft as they fly through space.

