X-Git-Url: http://git.draconx.ca/gitweb/liblbx.git/blobdiff_plain/bbcffc80c95c69d02635b02d37e78912c7f12305..5cd07246cf1e87f099c88e89c6aa0a4cfb3b202b:/src/image.c diff --git a/src/image.c b/src/image.c index f98238e..76fbfed 100644 --- a/src/image.c +++ b/src/image.c @@ -31,9 +31,11 @@ #include "image.h" #define FLAG_OVERWRITE 0x0400 /* Draw each frame on a clean slate (unsure). */ +#define FLAG_BUILDING 0x0800 /* Buildings have this, related to shadow? */ #define FLAG_PALETTE 0x1000 /* Image contains embedded palette. */ #define FLAG_LOOPING 0x2000 /* Loop over all frames in the image (unsure). */ -#define FLAG_ALL (FLAG_OVERWRITE|FLAG_PALETTE|FLAG_LOOPING) + +#define FLAG_ALL (FLAG_OVERWRITE|FLAG_BUILDING|FLAG_PALETTE|FLAG_LOOPING) #define HDR_LEN 12 @@ -282,15 +284,18 @@ unsigned char **lbximg_getframe(struct lbx_image *img, int frame) return NULL; } - /* Start over if we are backtracking. */ - if (img->currentframe > frame) - img->currentframe == -1; - if (img->flags & FLAG_OVERWRITE) { /* Clear the slate. */ + img->currentframe = -1; memset(img->framedata[0], 0, img->width * img->height); memset(img->mask[0], 0, img->width * img->height); } else { + /* Start over if we are backtracking. */ + if (img->currentframe > frame) { + memset(img->mask[0], 0, img->width * img->height); + img->currentframe = -1; + } + /* We must have previous frame decoded to continue. */ if (frame > img->currentframe + 1) { if (!lbximg_getframe(img, frame-1)) @@ -323,13 +328,15 @@ unsigned char **lbximg_getframe(struct lbx_image *img, int frame) return img->framedata; } -int lbximg_loadpalette(FILE *f, struct lbx_colour palette[static 256]) +int +lbximg_loadpalette(void *f, const struct lbx_file_ops *fops, + struct lbx_colour palette[static 256]) { unsigned char entry[4]; int i; for (i = 0; i < 256; i++) { - if (fread(entry, sizeof entry, 1, f) != 1) { + if (fops->read(entry, sizeof entry, f) != sizeof entry) { lbx_errno = (feof(f)) ? LBX_EEOF : -errno; return -1; } @@ -339,10 +346,11 @@ int lbximg_loadpalette(FILE *f, struct lbx_colour palette[static 256]) return -1; } - palette[i] = (struct lbx_colour){ - .red = entry[1] << 2, - .green = entry[2] << 2, - .blue = entry[3] << 2, + palette[i] = (struct lbx_colour) { + .red = entry[1] << 2, + .green = entry[2] << 2, + .blue = entry[3] << 2, + .active = 1, }; } @@ -367,7 +375,6 @@ lbximg_getpalette(struct lbx_image *img, struct lbx_colour palette[static 256]) for (i = 0; i < img->palcount; i++) { rc = img->fops->read(entry, sizeof entry, img->f); - if (rc < sizeof entry) { goto readerr; } @@ -378,9 +385,10 @@ lbximg_getpalette(struct lbx_image *img, struct lbx_colour palette[static 256]) } palette[img->palstart + i] = (struct lbx_colour){ - .red = entry[1] << 2, - .green = entry[2] << 2, - .blue = entry[3] << 2, + .red = entry[1] << 2, + .green = entry[2] << 2, + .blue = entry[3] << 2, + .active = 1, }; }