]> git.draconx.ca Git - liblbx.git/commitdiff
liblbx: Add support for "raw" LBX images.
authorNick Bowler <nbowler@draconx.ca>
Tue, 9 Feb 2010 04:14:16 +0000 (23:14 -0500)
committerNick Bowler <nbowler@draconx.ca>
Tue, 9 Feb 2010 04:29:35 +0000 (23:29 -0500)
There is a new image format in town.  If a particular flag bit is set,
then there are no row headers and data for every pixel of a frame is
simply stored in row-major order.  An example of such an image is
starbg.lbx.009, as well as several others in the same archive.

Don't you just *love* the designers of this format?

src/image.c
tests/regress.zsh

index 76fbfed3528ccf2d8561c7ee1bf9502e7d6eef99..21f5a8eb79de5f8bda4c44b951e6af51f219f8de 100644 (file)
 #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
 
@@ -265,6 +266,33 @@ static unsigned char **allocframebuffer(size_t width, size_t height)
        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) {
@@ -284,6 +312,9 @@ unsigned char **lbximg_getframe(struct lbx_image *img, int frame)
                        return NULL;
        }
 
+       if (img->flags & FLAG_RAW)
+               return read_raw_frame(img, frame);
+
        if (img->flags & FLAG_OVERWRITE) {
                /* Clear the slate. */
                img->currentframe = -1;
index 20239b5087fb4c7024cfb467815ad0657c2670fa..0131fbd6d3445693a53384a5421fdb051e14c0d4 100755 (executable)
@@ -75,6 +75,13 @@ echo "ships.lbx.042: single frame, external+override palette, transparency:"
 $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."