+ img->palstart = unpack_16_le(buf+0);
+ img->palcount = unpack_16_le(buf+2);
+ img->paloff = fops->tell(f);
+
+ if (img->palstart + img->palcount > 256) {
+ lbx_errno = LBX_EFORMAT;
+ free(img);
+ return NULL;
+ }
+ }
+
+ return img;
+}
+
+static int pipe_close(void *f)
+{
+ struct lbx_pipe_state *p = f;
+ int rc;
+
+ rc = fclose(p->f);
+ free(p);
+ return rc;
+}
+
+static int file_close(void *f)
+{
+ return fclose((FILE *)f);
+}
+
+struct lbx_image *lbximg_fopen(const char *file)
+{
+ struct lbx_pipe_state *p;
+ FILE *f;
+
+ f = fopen(file, "rb");
+ if (!f)
+ return NULL;
+
+ if (fseek(f, 0, SEEK_CUR) == 0)
+ return lbximg_open(f, &lbx_default_fops, file_close);
+
+ p = malloc(sizeof *p);
+ if (!p) {
+ fclose(f);
+ return NULL;