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 2116 */
uint8_t flags; /* must be 1 */
uint16_t count;
uint8_t unused;
} mit_head;
#pragma pack(pop)
/* fixed-size */
#define MIT_WIDTH 64
#define MIT_HEIGHT 32
int conv_mit(FILE *fl, uint32_t sz, char *f) {
uint32_t i, k, l;
mit_head head;
char s[260];
uint8_t *p;
fseek(fl, 0, SEEK_SET);
readdata(fl, &head, sizeof(head));
if (
(sz <= sizeof(head)) || (head.magic != 2116) || (head.flags != 1) || (!head.count) ||
(sz <= (sizeof(head) + (head.count * 4)))
) {
return(3);
}
newext(f, "");
for (i = 0; i < head.count; i++) {
sprintf(s, "%s.%04u.tga", f, i + 1);
printf("%s\n", s);
readdata(fl, &k, 4);
l = sizeof(tga_head) + (MIT_WIDTH * MIT_HEIGHT * 2);
p = (uint8_t *) malloc(k + l);
if (p) {
tga_init(&p[k], MIT_WIDTH, MIT_HEIGHT);
readdata(fl, p, k);
spr_unpack(p, k, &p[k + sizeof(tga_head)], MIT_WIDTH, MIT_HEIGHT);
dumpdata(s, &p[k], l);
free(p);
} else {
fseek(fl, ftell(fl) + k, SEEK_SET);
}
}
return(0);
}