Difference between revisions of "PAL"
(5 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
+ | PAL files contain the colour palettes for various in-game objects. | ||
+ | |||
== Format == | == Format == | ||
The PAL file format is very simple. | The PAL file format is very simple. | ||
− | It is a series of colours, represented by 3 bytes | + | It is a series of 256 colours, each represented by 3 bytes in the RGB format: |
− | + | struct PAL{ | |
− | + | unsigned char red; | |
− | + | unsigned char green; | |
− | + | unsigned char blue; | |
− | + | } colours[256]; | |
+ | |||
+ | Each colour value (red, green and blue) is represented by 6 bits only, which means {{tt|63}} is the highest a colour value can get (rather than 255). For example, pure red would be represented as {{tt|00111111}} ({{tt|63}} in decimal) in the red byte. The highest two bits are always zero, so that one colour value still takes 8 bits in the file. | ||
+ | |||
+ | However, the game converts this 18-bit palette to true 16-bit ([https://en.wikipedia.org/wiki/High_color Hi-Colour]) by ignoring the least significant bit of the red and blue channels. Therefore it's best to design custom palettes in a {{tt|5:6:5}} format to avoid colour loss (in RGB terms, the red and blue color values should be divisible by 8 while green can be divisible by 4). This conversion effect is demonstrated [https://ppmforums.com/viewtopic.php?t=40996 here]. | ||
− | + | == Relation with SHPs == | |
− | |||
− | + | [[SHP|SHP files]] refer to the colour indices in a PAL file. Depending on the object type and PAL file, some indices have very specific effects tied to them: | |
+ | <ul> | ||
+ | <li>In all SHPs, the first colour of the PAL (index #0, the first 3 bytes) is used as the transparent colour of the SHP image (i.e. it will not be copied to the screen when drawn).</li> | ||
+ | <li>In all shadow frames, all colours aside from #0 (transparent) will be rendered as shadow. A convention is to use colour #1 as in the original [[TS]]/[[RA2]].</li> | ||
+ | <li>In all SHPs using UNIT'''xxx'''.PAL (where '''xxx''' is the [[Theatres|theatre]] ID): | ||
+ | <ul> | ||
+ | <li>In all remappable images, the colours #16 to #31 are the different remap stages.</li> | ||
+ | <li>Depending on the object type, some or all colours on the range #204 to #254 are ignored, causing the pixels to be rendered magenta in-game. See [https://ppmforums.com/viewtopic.php?t=33829 this topic] for more information.</li> | ||
+ | <li>In all SHPs, colours #240 to #254 are not affected by map brightness (similar to [[UseNormalLight]]), hence they're useful for making things like muzzle flashes glow in the dark.</li> | ||
+ | </ul> | ||
+ | </li> | ||
+ | </ul> | ||
[[Category:General_Editing_Information]] | [[Category:General_Editing_Information]] | ||
[[Category:File Formats]] | [[Category:File Formats]] |
Latest revision as of 20:38, 6 April 2024
PAL files contain the colour palettes for various in-game objects.
Format
The PAL file format is very simple. It is a series of 256 colours, each represented by 3 bytes in the RGB format:
struct PAL{ unsigned char red; unsigned char green; unsigned char blue; } colours[256];
Each colour value (red, green and blue) is represented by 6 bits only, which means 63 is the highest a colour value can get (rather than 255). For example, pure red would be represented as 00111111 (63 in decimal) in the red byte. The highest two bits are always zero, so that one colour value still takes 8 bits in the file.
However, the game converts this 18-bit palette to true 16-bit (Hi-Colour) by ignoring the least significant bit of the red and blue channels. Therefore it's best to design custom palettes in a 5:6:5 format to avoid colour loss (in RGB terms, the red and blue color values should be divisible by 8 while green can be divisible by 4). This conversion effect is demonstrated here.
Relation with SHPs
SHP files refer to the colour indices in a PAL file. Depending on the object type and PAL file, some indices have very specific effects tied to them:
- In all SHPs, the first colour of the PAL (index #0, the first 3 bytes) is used as the transparent colour of the SHP image (i.e. it will not be copied to the screen when drawn).
- In all shadow frames, all colours aside from #0 (transparent) will be rendered as shadow. A convention is to use colour #1 as in the original TS/RA2.
- In all SHPs using UNITxxx.PAL (where xxx is the theatre ID):
- In all remappable images, the colours #16 to #31 are the different remap stages.
- Depending on the object type, some or all colours on the range #204 to #254 are ignored, causing the pixels to be rendered magenta in-game. See this topic for more information.
- In all SHPs, colours #240 to #254 are not affected by map brightness (similar to UseNormalLight), hence they're useful for making things like muzzle flashes glow in the dark.