11 #include "byteorder.h"
15 uint16_t width, height;
17 uint16_t offs, frames;
21 struct lbx_image *lbximg_fopen(FILE *f)
23 struct lbx_image tmp = {.f = f}, *new;
25 if (fread(&tmp.width, sizeof tmp.width, 1, f) != 1) goto readerr;
26 if (fread(&tmp.height, sizeof tmp.height, 1, f) != 1) goto readerr;
27 if (fread(&tmp.wtf1, sizeof tmp.wtf1, 1, f) != 1) goto readerr;
28 if (fread(&tmp.offs, sizeof tmp.offs, 1, f) != 1) goto readerr;
29 if (fread(&tmp.frames, sizeof tmp.frames, 1, f) != 1) goto readerr;
30 if (fread(&tmp.wtf2, sizeof tmp.wtf2, 1, f) != 1) goto readerr;
32 tmp.width = letohs(tmp.width);
33 tmp.height = letohs(tmp.height);
34 tmp.wtf1 = letohs(tmp.wtf1);
35 tmp.offs = letohs(tmp.offs);
36 tmp.frames = letohs(tmp.frames);
37 tmp.wtf2 = letohs(tmp.wtf2);
40 * DEBUG ONLY. These assertions exist to catch otherwise valid image
41 * files which differ from what I believe to be true of all LBX images.
42 * If we never find any exceptions, we can replace the assertions with
45 assert(tmp.wtf1 == 0);
46 assert(tmp.offs == tmp.frames + 1);
48 new = malloc(sizeof *new + tmp.offs * sizeof *new->offsets);
56 if (fread(new->offsets, sizeof *new->offsets, new->offs, f) != new->offs)
71 void lbximg_close(struct lbx_image *img)