- struct lbx_image tmp = {.f = f}, *new = NULL;
-
- if (fread(&tmp.width, sizeof tmp.width, 1, f) != 1) goto readerr;
- if (fread(&tmp.height, sizeof tmp.height, 1, f) != 1) goto readerr;
- if (fread(&tmp.wtf1, sizeof tmp.wtf1, 1, f) != 1) goto readerr;
- if (fread(&tmp.offs, sizeof tmp.offs, 1, f) != 1) goto readerr;
- if (fread(&tmp.frames, sizeof tmp.frames, 1, f) != 1) goto readerr;
- if (fread(&tmp.pal, sizeof tmp.pal, 1, f) != 1) goto readerr;
-
- tmp.width = letohs(tmp.width); tmp.foff += sizeof tmp.width;
- tmp.height = letohs(tmp.height); tmp.foff += sizeof tmp.height;
- tmp.wtf1 = letohs(tmp.wtf1); tmp.foff += sizeof tmp.wtf1;
- tmp.offs = letohs(tmp.offs); tmp.foff += sizeof tmp.offs;
- tmp.frames = letohs(tmp.frames); tmp.foff += sizeof tmp.frames;
- tmp.pal = letohs(tmp.pal); tmp.foff += sizeof tmp.pal;
-
- /* For some reason, the format seems to need this. */
- tmp.offs++;
- tmp.frames++;
-
- /* Format constraints. */
- if (tmp.offs <= tmp.frames) {
- lbx_errno = LBX_EFORMAT;
+ unsigned short nframes = unpack_16_le(hdr+6);
+ struct lbx_image_priv *img;
+
+ img = malloc(sizeof *img + sizeof img->offsets[0] * (nframes+1));
+ if (!img) {
+ lbx_error_raise(LBX_ENOMEM);