#include #include "rtv.h" #define MIN(x,y) ((x) < (y) ? (x) : (y)) u16 rtv_to_u16(unsigned char ** pp) { unsigned char * p; u16 r; p = *pp; r = *p++; r <<= 8; r |= *p++; *pp = p; return r; } u32 rtv_to_u32(unsigned char ** pp) { unsigned char * p; u32 r; p = *pp; r = rtv_to_u16(&p); r <<= 16; r |= rtv_to_u16(&p); *pp = p; return r; } void le_from_u16(unsigned char ** pp, u16 v) { unsigned char * p; p = *pp; *p++ = v & 0x00ff; *p++ = (v & 0xff00) >> 8; *pp = p; } void le_from_u32(unsigned char ** pp, u32 v) { unsigned char * p; p = *pp; le_from_u16(&p, (u16)(v & 0x0000ffff)); le_from_u16(&p, (u16)((v & 0xffff0000) >> 16)); *pp = p; } char * typestr(u32 type) { static char buf[32]; switch(type) { case 0x10808: strcpy(buf, "bmp"); break; case 0x80820: strcpy(buf, "jpg"); break; case 0x200820: strcpy(buf, "bmx"); break; default: sprintf(buf, "unknown.%lx", type); break; } return buf; } static char bmp_colors[256][4] = { {255, 0, 255, 0}, {1, 1, 1, 0}, {9, 9, 9, 0}, {17, 17, 17, 0}, {25, 25, 25, 0}, {33, 33, 33, 0}, {41, 41, 41, 0}, {49, 49, 49, 0}, {57, 57, 57, 0}, {65, 65, 65, 0}, {73, 73, 73, 0}, {81, 81, 81, 0}, {89, 89, 89, 0}, {97, 97, 97, 0}, {105, 105, 105, 0}, {113, 113, 113, 0}, {120, 120, 120, 0}, {128, 128, 128, 0}, {136, 136, 136, 0}, {144, 144, 144, 0}, {152, 152, 152, 0}, {160, 160, 160, 0}, {168, 168, 168, 0}, {176, 176, 176, 0}, {184, 184, 184, 0}, {192, 192, 192, 0}, {200, 200, 200, 0}, {208, 208, 208, 0}, {216, 216, 216, 0}, {224, 224, 224, 0}, {232, 232, 232, 0}, {240, 240, 240, 0}, {0, 0, 110, 0}, {0, 55, 110, 0}, {0, 110, 110, 0}, {0, 110, 0, 0}, {120, 25, 25, 0}, {70, 0, 65, 0}, {128, 0, 89, 0}, {0, 0, 220, 0}, {0, 110, 220, 0}, {0, 220, 220, 0}, {0, 220, 0, 0}, {240, 50, 50, 0}, {181, 0, 92, 0}, {255, 0, 178, 0}, {78, 80, 234, 0}, {85, 163, 243, 0}, {134, 240, 240, 0}, {128, 240, 128, 0}, {240, 129, 129, 0}, {255, 95, 186, 0}, {255, 158, 234, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {255, 0, 255, 0}, {0, 0, 55, 0}, {0, 0, 95, 0}, {0, 0, 133, 0}, {0, 0, 172, 0}, {0, 0, 211, 0}, {27, 27, 213, 0}, {54, 54, 217, 0}, {80, 80, 220, 0}, {108, 107, 224, 0}, {135, 134, 227, 0}, {162, 161, 230, 0}, {189, 188, 233, 0}, {215, 214, 236, 0}, {75, 135, 75, 0}, {14, 71, 16, 0}, {45, 56, 45, 0}, {28, 28, 28, 0}, {56, 56, 56, 0}, {85, 85, 85, 0}, {113, 113, 113, 0}, {142, 142, 142, 0}, {170, 170, 170, 0}, {199, 199, 199, 0}, {227, 227, 227, 0}, {1, 1, 1, 0}, {1, 1, 1, 0}, {1, 1, 1, 0}, {1, 1, 1, 0}, {230, 230, 230, 0}, {230, 230, 230, 0}, {230, 230, 230, 0}, {230, 230, 230, 0}, {0, 0, 0, 0}, {6, 1, 0, 0}, {52, 4, 0, 0}, {60, 12, 8, 0}, {68, 20, 16, 0}, {75, 27, 23, 0}, {83, 35, 31, 0}, {91, 43, 39, 0}, {98, 50, 46, 0}, {106, 58, 54, 0}, {114, 66, 62, 0}, {121, 73, 69, 0}, {129, 81, 77, 0}, {137, 89, 85, 0}, {144, 96, 92, 0}, {152, 104, 100, 0}, {159, 111, 107, 0}, {166, 118, 114, 0}, {174, 126, 122, 0}, {182, 134, 130, 0}, {189, 141, 137, 0}, {197, 149, 145, 0}, {205, 157, 153, 0}, {212, 164, 160, 0}, {220, 172, 168, 0}, {228, 180, 176, 0}, {235, 187, 183, 0}, {243, 195, 191, 0}, {251, 203, 199, 0}, {255, 211, 207, 0}, {255, 218, 215, 0}, {255, 228, 226, 0}, {5, 19, 24, 0}, {43, 57, 62, 0}, {102, 116, 121, 0}, {178, 192, 197, 0}, {63, 15, 11, 0}, {101, 53, 49, 0}, {160, 112, 108, 0}, {236, 188, 184, 0}, {63, 15, 11, 0}, {101, 53, 49, 0}, {160, 112, 108, 0}, {236, 188, 184, 0}, {63, 15, 11, 0}, {101, 53, 49, 0}, {160, 112, 108, 0}, {236, 188, 184, 0}, {0, 0, 0, 0}, {0, 1, 1, 0}, {0, 9, 12, 0}, {0, 16, 21, 0}, {0, 24, 32, 0}, {0, 32, 43, 0}, {0, 40, 54, 0}, {0, 47, 64, 0}, {0, 55, 75, 0}, {0, 62, 84, 0}, {0, 70, 95, 0}, {0, 78, 106, 0}, {0, 85, 116, 0}, {0, 93, 127, 0}, {0, 101, 138, 0}, {0, 108, 148, 0}, {0, 115, 157, 0}, {0, 122, 167, 0}, {0, 130, 178, 0}, {0, 138, 189, 0}, {0, 146, 200, 0}, {0, 153, 209, 0}, {0, 161, 220, 0}, {0, 168, 230, 0}, {6, 176, 239, 0}, {14, 184, 247, 0}, {21, 191, 254, 0}, {48, 199, 255, 0}, {78, 207, 255, 0}, {104, 214, 255, 0}, {133, 222, 255, 0}, {163, 230, 255, 0}, {41, 12, 12, 0}, {56, 27, 27, 0}, {71, 42, 42, 0}, {86, 57, 57, 0}, {101, 72, 72, 0}, {116, 87, 87, 0}, {131, 102, 102, 0}, {146, 117, 117, 0}, {161, 132, 132, 0}, {176, 147, 147, 0}, {191, 162, 162, 0}, {206, 177, 177, 0}, {221, 192, 192, 0}, {236, 207, 207, 0}, {251, 222, 222, 0}, {255, 239, 239, 0}, }; void dump_bitmap(FILE * ifp, long start, long length, char * base, int filenum, u32 type, u32 width, u32 height) { char filename[128]; FILE * ofp; unsigned char buf[4096]; long togo, thistime; sprintf(filename, "%s.%d.%s", base, filenum, typestr(type)); ofp = fopen(filename, "w"); if (!ofp) perror("open write"); if (type == 0x10808) { unsigned char header[14 + 40]; unsigned char * p; p = header; *p++ = 'B'; *p++ = 'M'; le_from_u32(&p, length + 14 + 40 + 256 * 4); /* filesize */ le_from_u32(&p, 0); le_from_u32(&p, 14 + 40 + 256 * 4); /* data offset */ le_from_u32(&p, 40); /* secondary header size */ le_from_u32(&p, width); le_from_u32(&p, height); le_from_u16(&p, 1); /* planes */ le_from_u16(&p, 8); /* bits per pixel */ le_from_u32(&p, 1); /* compression */ le_from_u32(&p, length); /* data size */ le_from_u32(&p, 2834); /* X pixels per meter */ le_from_u32(&p, 2834); /* Y pixels per meter */ le_from_u32(&p, 256); /* colors ued */ le_from_u32(&p, 0); /* colors important */ fwrite(header, sizeof header, 1, ofp); fwrite(bmp_colors, sizeof bmp_colors, 1, ofp); } fseek(ifp, start, SEEK_SET); togo = length; while (togo) { thistime = MIN(togo, sizeof buf); fread(buf, thistime, 1, ifp); fwrite(buf, thistime, 1, ofp); togo -= thistime; } fclose(ofp); } int main(int argc, char ** argv) { FILE * idx_fp, *bitmap_i_fp; unsigned char buf[4096]; unsigned char * p; int i = 0; int numrecs, recsize; sprintf(buf, "%s.Bitmaps.idx", argv[1]); idx_fp = fopen(buf, "r"); if (!idx_fp) perror("Open index"); sprintf(buf, "%s.Bitmaps.dat", argv[1]); bitmap_i_fp = fopen(buf, "r"); if (!bitmap_i_fp) perror("Open Bitmaps"); fread(buf, 4096, 1, idx_fp); p = buf+8; numrecs = rtv_to_u32(&p); recsize = rtv_to_u32(&p); while (i < numrecs) { u32 start, length, width, height, type, must_be_0; must_be_0 = rtv_to_u32(&p); start = rtv_to_u32(&p); length = rtv_to_u32(&p); width = rtv_to_u32(&p); height = rtv_to_u32(&p); type = rtv_to_u32(&p); if (must_be_0 == 0) dump_bitmap(bitmap_i_fp, start, length, argv[1], i, type, width, height); i++; if (4096 - (p - buf) < recsize) { fread(buf, 4096, 1, idx_fp); p = buf; } } }