PAL: Difference between revisions
enhanced |
Added information about the internal palette conversion and special indices. |
||
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. | ||
Line 8: | Line 10: | ||
} colours[256]; | } 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). | 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. | ||
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. This conversion effect is demonstrated [https://ppmforums.com/viewtopic.php?t=40996 here]. | ||
== Relation with SHPs == | |||
SHP files refer to | [[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> | |||
In shadow frames, colour 1 is | <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> | ||
In | <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 #255 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]] |
Revision as of 12:32, 7 September 2018
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. 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 #255 are not affected by map brightness (similar to UseNormalLight), hence they're useful for making things like muzzle flashes glow in the dark.