Microsoft PAL Format Intel byte order By Alef Sterk Contact me at: a.sterk@wxs.nl DISCLAIMER: THIS MATERIAL IS PROVIDED "AS IS". I cannot guarantee that all of the information in this document is correct. Use the information at your own risk! I am not responsible for direct or indirect damage by using this document. If you don't agree with this, then don't use the information. If you discover incorrect information, please let me know. You can contact me at the e-mail adres above. The Microsoft PAL file is actually an ordinary RIFF file (just like WAV and AVI files. Therefore a PAL file starts with a standard RIFF header. Table 1: The RIFF file header =============================================================== Offset Length Description 0x00 1 DWORD Signature (always 0x52494646) 0x04 1 DWORD File length minus 8 0x08 1 DWORD RIFF type (always 0x50414C20) After the RIFF header follow so called 'chunks'. (In an AVI file mulptiple chunks can follow but in a PAL file just one chunk folows after the RIFF header.) The structure of a RIFF chunk is defined as follows. Table 2: The structure of a RIFF chunk =============================================================== Offset Length Description 0x0B 1 DWORD Signature (always 0x64617461) 0x10 1 DWORD Chunk Size (File Size minus 20) 0x14 n BYTES Data The data has a length which is described in the chunk size field of the RIFF chunk. The first DWORD of the data area contains information of the palette. You can divide this DWORD into 2 WORDs. The hi WORD contains the number of colors in the palette. In other words how many palette entries follow after this DWORD. The lo WORD of the first DWORD contains the palette version which is currently 0x0300. After the first DWORD follows a continuous sequence of DWORDs which represent the palette entries. The number of entries is described in the hi WORD of the first DWORD in the data area (as I said before). A single entry is coded as follows: 0xrrggbb00, where r stands for red, g stands for green and b stands for blue. UPDATE: at least Photoshop 7 uses a 0xrrgg00bb format for each palette entry in stead of a 0xrrggbb00 format. So be alert for different entry formats! I thank Torsten Curdt for this useful information. Because the information might look a little bit hazy, I added a hex dump of a palette which contains 128 colors. The total file length is 536 bytes. 00000000: 5249 4646 1002 0000 5041 4C20 6461 7461 00000010: 0402 0000 0003 8000 0000 0000 0404 0400 00000020: 0808 0800 0C0C 0C00 1010 1000 1414 1400 00000030: 1818 1800 1C1C 1C00 2020 2000 2424 2400 00000040: 2828 2800 2C2C 2C00 3030 3000 3434 3400 00000050: 3838 3800 3C3C 3C00 4040 4000 4444 4400 00000060: 4848 4800 4C4C 4C00 5050 5000 5454 5400 00000070: 5858 5800 5C5C 5C00 6060 6000 6464 6400 00000080: 6868 6800 6C6C 6C00 7070 7000 7474 7400 00000090: 7878 7800 7C7C 7C00 8080 8000 8484 8400 000000A0: 8888 8800 8C8C 8C00 9090 9000 9494 9400 000000B0: 9898 9800 9C9C 9C00 A0A0 A000 A4A4 A400 000000C0: A8A8 A800 ACAC AC00 B0B0 B000 B4B4 B400 000000D0: B8B8 B800 BCBC BC00 C0C0 C000 C4C4 C400 000000E0: C8C8 C800 CCCC CC00 D0D0 D000 D4D4 D400 000000F0: D8D8 D800 DCDC DC00 E0E0 E000 E4E4 E400 00000100: E8E8 E800 ECEC EC00 F0F0 F000 F4F4 F400 00000110: F8F8 F800 FCFC FC00 FFFF FF00 FBFB FF00 00000120: F7F7 FF00 F3F3 FF00 EFEF FF00 EBEB FF00 00000130: E7E7 FF00 E3E3 FF00 DFDF FF00 DBDB FF00 00000140: D7D7 FF00 D3D3 FF00 CFCF FF00 CBCB FF00 00000150: C7C7 FF00 C3C3 FF00 BFBF FF00 BBBB FF00 00000160: B7B7 FF00 B3B3 FF00 AFAF FF00 ABAB FF00 00000170: A7A7 FF00 A3A3 FF00 9F9F FF00 9B9B FF00 00000180: 9797 FF00 9393 FF00 8F8F FF00 8B8B FF00 00000190: 8787 FF00 8383 FF00 7F7F FF00 7B7B FF00 000001A0: 7777 FF00 7373 FF00 6F6F FF00 6B6B FF00 000001B0: 6767 FF00 6363 FF00 5F5F FF00 5B5B FF00 000001C0: 5757 FF00 5353 FF00 4F4F FF00 4B4B FF00 000001D0: 4747 FF00 4343 FF00 3F3F FF00 3B3B FF00 000001E0: 3737 FF00 3333 FF00 2F2F FF00 2B2B FF00 000001F0: 2727 FF00 2323 FF00 1F1F FF00 1B1B FF00 00000200: 1717 FF00 1313 FF00 0F0F FF00 0B0B FF00 00000210: 0707 FF00 0303 FF00 If you still have questions (I doubt if I can answer them since this is all the information I have) or comments, you can mail me at: a.sterk@wxs.nl