- struct lbx_image tmp = {.f = f}, *new = NULL;
- size_t rc;
-
- 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.frames, sizeof tmp.frames, 1, f) != 1) goto readerr;
- if (fread(&tmp.leadin, sizeof tmp.leadin, 1, f) != 1) goto readerr;
- if (fread(&tmp.flags, sizeof tmp.flags, 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.frames = letohs(tmp.frames); tmp.foff += sizeof tmp.frames;
- tmp.leadin = letohs(tmp.leadin); tmp.foff += sizeof tmp.leadin;
- tmp.flags = letohs(tmp.flags); tmp.foff += sizeof tmp.flags;
-
- /* Format constraints. */
- if (tmp.frames <= tmp.leadin) {
- 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);