]> git.draconx.ca Git - liblbx.git/commitdiff
liblbx: Add support for "chunked" images.
authorNick Bowler <nbowler@draconx.ca>
Tue, 9 Feb 2010 05:27:30 +0000 (00:27 -0500)
committerNick Bowler <nbowler@draconx.ca>
Tue, 9 Feb 2010 05:53:03 +0000 (00:53 -0500)
It appears that the frame count fields aren't actually two 16-bit
fields, but rather four 8-bit fields.  The images in monster.lbx
appear to have "chunks" of animation and what was previously thought to
be the most significant byte of the lead-in now seems to be the length
of a "chunk".

These images are much like any other, except that the first frame of
every chunk is drawn on a clean slate.  Examples are found in
monster.lbx.

src/image.c
src/image.h
src/lbximg.c
tests/regress.zsh

index 21f5a8eb79de5f8bda4c44b951e6af51f219f8de..5f3a6e320c51f62010d12f24ac8fac28a0d9bd63 100644 (file)
@@ -43,7 +43,7 @@
 struct lbx_image {
        unsigned short width, height;
        unsigned short wtf, flags;
-       unsigned short frames, leadin;
+       unsigned char  frames, wtf2, leadin, chunk;
        unsigned short palstart, palcount;
 
        const struct lbx_file_ops *fops;
@@ -75,8 +75,10 @@ static struct lbx_image *lbximg_init(unsigned char hdr[static HDR_LEN])
                .width  = unpack_16_le(hdr+0),
                .height = unpack_16_le(hdr+2),
                .wtf    = unpack_16_le(hdr+4),
-               .frames = unpack_16_le(hdr+6),
-               .leadin = unpack_16_le(hdr+8),
+               .frames = hdr[6],
+               .wtf2   = hdr[7],
+               .leadin = hdr[8],
+               .chunk  = hdr[9],
                .flags  = unpack_16_le(hdr+10),
 
                .currentframe = -1,
@@ -109,11 +111,12 @@ struct lbx_image *lbximg_open(void *f, const struct lbx_file_ops *fops,
        /*
         * DEBUG ONLY.  These assertions exist to catch otherwise valid image
         * files which differ from what I believe to be true of all LBX images.
-        * If we never find any exceptions, we can replace the assertions with
-        * assumptions.
+        * When we can decode every image, then these assertions should be
+        * replaced with constraints.
         */
-       _lbx_assert(img->wtf == 0); /* version? */
-       _lbx_assert(img->frames > img->leadin); /* cmbtshp.lbx breaks this. */
+       _lbx_assert(img->wtf  == 0); /* version? */
+       _lbx_assert(img->wtf2 == 0); /* very likely is simply reserved. */
+       _lbx_assert(img->frames > img->leadin);
        _lbx_assert(!(img->flags & ~FLAG_ALL));
 
        /* Read all offsets.  Should be merged with identical code in lbx.c */
@@ -315,7 +318,8 @@ unsigned char **lbximg_getframe(struct lbx_image *img, int frame)
        if (img->flags & FLAG_RAW)
                return read_raw_frame(img, frame);
 
-       if (img->flags & FLAG_OVERWRITE) {
+       if ((img->flags & FLAG_OVERWRITE)
+            || (img->chunk && !(frame % img->chunk))) {
                /* Clear the slate. */
                img->currentframe = -1;
                memset(img->framedata[0], 0, img->width * img->height);
@@ -435,6 +439,7 @@ void lbximg_getinfo(struct lbx_image *img, struct lbx_imginfo *info)
                .width      = img->width,
                .height     = img->height,
                .nframes    = img->frames,
+               .chunk      = img->chunk,
                .palettesz  = (img->flags & FLAG_PALETTE) ? img->palcount : 0,
        };
 
index 2f427d10c9111cadbcd641e1dcc22546f0ee7cc1..9bd41eb1ac1aa35b3ff93a9dc2275b6a0569eb4b 100644 (file)
@@ -14,10 +14,9 @@ struct lbx_colour {
 };
 
 struct lbx_imginfo {
-       unsigned int width, height;
-       unsigned int nframes, loopstart;
-       int palettesz;
-       int looping;
+       unsigned short width, height;
+       unsigned char  nframes, loopstart, chunk;
+       int palettesz, looping;
 };
 
 LBX_IMG *lbximg_open(void *f, const struct lbx_file_ops *fops,
index 67d8635a8feaf4ba64d75cf1d89d4c026772e243..933e1e079abef22c84b709f12539448ecc0a50ae 100644 (file)
@@ -468,6 +468,7 @@ int main(int argc, char **argv)
                printf("%s is %ux%u LBX image, %u frame(s)%s%s\n",
                       name, info.width, info.height, info.nframes,
                       info.palettesz ? ", embedded palette" : "",
+                      info.chunk     ? ", chunked" : "",
                       info.looping   ? ", loops" : "");
        }
 
index 0131fbd6d3445693a53384a5421fdb051e14c0d4..041e83f184cfd09b424b1abc30f1cdb00fbb1876 100755 (executable)
@@ -82,6 +82,15 @@ echo "starbg.lbx.009: single frame, raw data:"
 $LBXIMG -df starbg.lbx.009 -p fonts.lbx.005
 compare 0 cfc5d92b6503951c4962498c7dcfea31
 
+# Monsters
+$LBXTOOL -xf $DATADIR/monster.lbx monster.lbx.{007,014}
+
+echo "monster.lbx.007: multi frame, chunked:"
+$LBXIMG -df monster.lbx.007 -p fonts.lbx.004 -O monster.lbx.014 0 5 19
+compare  0 59399c8d2d74116ff4b330a2cc1f3cc2
+compare  5 6947e108f7c8d2d2d626c67af3fdb7e2
+compare 19 03d86257527f0d7a91c2cde57059e734
+
 # Clean up
 if [[ $FAILED -eq 0 ]]; then
        echo "All tests completed successfully."