This software and its source code (if available) are licensed under the Apache-2.0 license (unless otherwise specified) which DOES NOT APPLY to any third-party code (such as zlib for example) and borrowed Assembler code (ripped code from other software executable files).
#pragma pack(push, 1)
typedef struct {
uint16_t magic; /* must be 2119 */
uint8_t flags; /* must be 1 */
uint16_t count;
} mia_head;
typedef struct {
uint8_t data1;
uint16_t count;
} mia_data;
typedef struct {
uint8_t data1;
uint8_t count;
uint16_t data2;
} mia_item;
typedef struct {
uint32_t x1;
uint32_t y1;
uint32_t x2;
uint32_t y2;
} mia_rect;
#pragma pack(pop)
int conv_mia(FILE *fl, uint32_t sz, char *f) {
uint32_t i, j, k, l, r, x, y, info[2];
mia_head head;
mia_data data;
mia_item item;
mia_rect rect;
uint16_t *u[2];
uint8_t *p;
char s[260];
fseek(fl, 0, SEEK_SET);
readdata(fl, &head, sizeof(head));
if ((sz <= sizeof(head)) || (head.magic != 2119) || (head.flags != 1) || (!head.count)) {
return(3);
}
newext(f, "");
for (i = 0; i < head.count; i++) {
readdata(fl, &data, sizeof(data));
printf("%u\n", data.data1);
for (j = 0; j < data.count; j++) {
readdata(fl, &item, sizeof(item));
printf("%u %u\n", item.data1, item.data2);
for (k = 0; k < item.count; k++) {
sprintf(s, "%s.%03u-%03u-%03u.tga", f, i + 1, j + 1, k + 1);
readdata(fl, &rect, sizeof(rect));
info[0] = rect.x2 - rect.x1;
info[1] = rect.y2 - rect.y1;
r = info[0] + ((4 - (info[0] & 3)) & 3);
l = r * info[1] * 2;
p = (uint8_t *) malloc(sizeof(tga_head) + l);
if (p) {
tga_init(p, info[0], info[1]);
readdata(fl, &p[sizeof(tga_head)], l);
for (y = 0; y < info[1]; y++) {
u[0] = (uint16_t *) &p[sizeof(tga_head) + (y * r * 2)];
u[1] = (uint16_t *) &p[sizeof(tga_head) + (y * info[0] * 2)];
for (x = 0; x < info[0]; x++) {
u[1][x] = RGB565TO555(u[0][x]);
}
}
dumpdata(s, p, sizeof(tga_head) + (info[0] * info[1] * 2));
free(p);
} else {
fseek(fl, ftell(fl) + l, SEEK_SET);
}
readdata(fl, &info, sizeof(info));
printf("%u %u %u %u | %u %u | %s\n", rect.x1, rect.y1, rect.x2, rect.y2, info[0], info[1], s);
}
}
}
return(0);
}