- 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.wtf2, sizeof tmp.wtf2, 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.wtf2 = letohs(tmp.wtf2); tmp.foff += sizeof tmp.wtf2;
+ unsigned char hdr_buf[HDR_LEN];
+ struct lbx_image *img;
+
+ if (fops->read(hdr_buf, sizeof hdr_buf, f) != sizeof hdr_buf) {
+ lbx_errno = -errno;
+ if (fops->eof(f))
+ lbx_errno = LBX_EEOF;
+ return NULL;
+ }
+
+ img = lbximg_init(hdr_buf);
+ if (!img)
+ return NULL;
+
+ img->f = f;
+ img->fops = fops;
+ img->dtor = destructor;