Post by kijanek6 on Nov 4, 2010 7:53:13 GMT -8
As I have a lot of work, I can't work on WAP32-related projects. I decided to publish informations on formats used in WAP32 games, so someone else can work on that stuff. If you have any questions, feel free to ask.
First of all, few terms, which I'll be using in this documentation:
All values are little endian.
int - signed integer value, built using 4 bytes
dword - unsigned long value, built using 4 bytes
byte/char - unsigned char, built using 1 byte
PID - images
PID is very similiar to PCX format, which was very popular in '90s. It makes use of palettes (color indexing) - they had to be loaded separately in first versions, and may be included in newer versions. It consist of three parts:
Header
Header consist of:
ID is almost always set to 10 (0x0A) - purpose of this value is unknown, it may be magic-number. However it's settable with PCX2PID.
Flags are composed by bitwise operations from these elements:
Width is image's width in pixels, and so is Height.
U are user values (as described in PCX2PID). First two of them are offset values, second two are comments (hardly ever used).
Image data
Image data is always compressed. There are two methods: default and (called that by PCX2PID) RLE. You can determine which one is used by 0x20 flag in Flags value in header. If that flag is set, you have RLE compression, otherwise it is default method.
Note: if you have to put pixel with color of ID = 43, that means you have to get 43. color from palette.
Default
Pseudocode:
RLE
Pseudocode:
Palette
Palette contains 256 colors in RGB format, so first three bytes define first color, next three bytes define second color and so on. If you need to know colors before reading image data, you can seek to -768 byte from the end, read the palette and then seek to 32 byte (image data beginning).
Also note that if transparency flag is set, first color in palette acts as transparent.
First of all, few terms, which I'll be using in this documentation:
All values are little endian.
int - signed integer value, built using 4 bytes
dword - unsigned long value, built using 4 bytes
byte/char - unsigned char, built using 1 byte
PID - images
PID is very similiar to PCX format, which was very popular in '90s. It makes use of palettes (color indexing) - they had to be loaded separately in first versions, and may be included in newer versions. It consist of three parts:
- PID header (32 bytes - constant size; required)
- Image data (variable size; required)
- Palette (768 bytes - constant size; optional)
Header
Header consist of:
- ID - int
- Flags - int
- Width - int
- Height - int
- U[4] - int
ID is almost always set to 10 (0x0A) - purpose of this value is unknown, it may be magic-number. However it's settable with PCX2PID.
Flags are composed by bitwise operations from these elements:
use transparency = 1 (0x01)
use video memory = 2 (0x02)
use system memory = 4 (0x04)
mirror = 8 (0x08) //flip image horizontally
invert = 16 (0x10) //flip image vertically
compression = 32 (0x20)
lights = 64 (0x40) //unknown
containts palette = 128 (0x80) //if this is set, PID contains it's own palette
Width is image's width in pixels, and so is Height.
U are user values (as described in PCX2PID). First two of them are offset values, second two are comments (hardly ever used).
Image data
Image data is always compressed. There are two methods: default and (called that by PCX2PID) RLE. You can determine which one is used by 0x20 flag in Flags value in header. If that flag is set, you have RLE compression, otherwise it is default method.
Note: if you have to put pixel with color of ID = 43, that means you have to get 43. color from palette.
Default
Pseudocode:
//A - temporary byte, B - color ID, N - number of pixels
//repeat until end of image reached
- read byte (A)
- if A > 192
-- N = A - 192
-- read byte (B)
- else
-- N = 1
-- B = A
//put N pixels of B color
RLE
Pseudocode:
//A - temporary byte, J - jump times, B - color ID
- read byte (A)
- if A > 128
-- J = A - 128
-//jump J times (fill J pixels with black, or transparent if 0x01 flag is set
- else
-- do A times
--- read byte (B)
--//put one pixel of B color
Palette
Palette contains 256 colors in RGB format, so first three bytes define first color, next three bytes define second color and so on. If you need to know colors before reading image data, you can seek to -768 byte from the end, read the palette and then seek to 32 byte (image data beginning).
Also note that if transparency flag is set, first color in palette acts as transparent.