#include "lbx.h"
#include "image.h"
+#define FLAG_RAW 0x0100 /* Image is stored as a flat array of bytes. */
#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_BUILDING|FLAG_PALETTE|FLAG_LOOPING)
+#define FLAG_ALL (FLAG_RAW|FLAG_OVERWRITE|FLAG_BUILDING|FLAG_PALETTE|FLAG_LOOPING)
#define HDR_LEN 12
return new;
}
+static unsigned char **read_raw_frame(struct lbx_image *img, int frame)
+{
+ unsigned long size = img->width * img->height;
+
+ assert(img->flags & FLAG_RAW);
+
+ if (img->fops->seek(img->f, img->offsets[frame], SEEK_SET)) {
+ lbx_errno = -errno;
+ return NULL;
+ }
+
+ if (img->fops->read(img->framedata[0], size, img->f) != size) {
+ lbx_errno = -errno;
+ if (img->fops->eof(img->f))
+ lbx_errno = LBX_EEOF;
+ return NULL;
+ }
+ memset(img->mask[0], 1, size);
+
+ if (img->fops->tell(img->f) > img->offsets[frame+1]) {
+ lbx_errno = LBX_EFORMAT;
+ return NULL;
+ }
+
+ return img->framedata;
+}
+
unsigned char **lbximg_getframe(struct lbx_image *img, int frame)
{
if (frame >= img->frames || frame < 0) {
return NULL;
}
+ if (img->flags & FLAG_RAW)
+ return read_raw_frame(img, frame);
+
if (img->flags & FLAG_OVERWRITE) {
/* Clear the slate. */
img->currentframe = -1;
$LBXIMG -df ships.lbx.042 -p fonts.lbx.012 -O ships.lbx.049
compare 0 bd643736d46ef387bcffcc8803aabb83
+# Nebulae
+$LBXTOOL -xf $DATADIR/starbg.lbx starbg.lbx.009
+
+echo "starbg.lbx.009: single frame, raw data:"
+$LBXIMG -df starbg.lbx.009 -p fonts.lbx.005
+compare 0 cfc5d92b6503951c4962498c7dcfea31
+
# Clean up
if [[ $FAILED -eq 0 ]]; then
echo "All tests completed successfully."