Inside .res file there is 'PICC' entry resources.
PICC specification
+0x00 : Unknow
+0x04 : Nb PICC entry
+0x08 : Entry Data (view class CResEntry)
CResEntry
An entry can be represented by this structure :
00000000 CResEntry struc ; (sizeof=0xC)
00000000 Width dw ?
00000002 Height dw ?
00000004 IsCompressed dd ?
00000008 SizeFile dd ?
0000000C CResEntry ends
If the field IsCompressed is set to 1, data are compressed using zlib version 1.1.3.
Pseudo-Code to read PICC
magic_number = read(4)
unknow = read(4)
if (magic_number == 0x43434950):
unknow = read(4)
nb_PICC_entry = read(4)
for i in xrange(0, nb_PICC_entry):
width = read(4)
height = read(4)
is_compressed = read(4)
size = read(4)
data = read(size)
if is_compressed == 1:
data = zlib.decompress(data)
Then the data are simply image in 16 bits format, you can convert it into 24 bits, with the following pseudo-code :
void setRGB(png_byte *ptr, unsigned char r,
unsigned char g, unsigned char b)
{
ptr[0] = r;
ptr[1] = g;
ptr[2] = b;
}
...
int x, y;
for (y = 0 ; y < height ; y++)
{
for (x = 0 ; x < width ; x++)
{
int a;
unsigned short *tab;
unsigned short color;
a = = (x + (y * width)) * 2;
tab = (unsigned short*)(buffer + a);
color = *tab;
setRGB(&(row[x * 3]),
(color >> 11 << 8) / 32,
(((color >> 5) & 0x3F) << 8) / 64,
((color & 0x1F) << 8) / 32);
}
png_write_row(png_ptr, row);
}