]> git.draconx.ca Git - liblbx.git/commitdiff
liblbx: Remove now-redundant fields from lbx_imginfo.
authorNick Bowler <nbowler@draconx.ca>
Mon, 5 Dec 2011 04:28:37 +0000 (23:28 -0500)
committerNick Bowler <nbowler@draconx.ca>
Mon, 5 Dec 2011 04:28:37 +0000 (23:28 -0500)
Ideally I'd like to kill this structure completely, but there's still
some non-trivial logic in it.  So leave those fields for now.

src/gui/lbxgui.c
src/gui/render.c
src/image.c
src/image.h
src/lbximg.c

index a3212a65e6f3f606f3168e0865d1a4263541faf6..ca6edecca16fd7737158ca2e0807d06690ca5026 100644 (file)
@@ -101,7 +101,7 @@ static void tick(void *p, double delta)
        while (elapsed > seconds_per_frame) {
                elapsed -= seconds_per_frame;
 
-               if (++newframe >= info.nframes) {
+               if (++newframe >= image->frames) {
                        if (!info.looping) {
                                gtk_toggle_button_set_active(play, FALSE);
                                break;
@@ -154,22 +154,20 @@ gboolean canvas_expose(GtkWidget *canvas, GdkEventExpose *event, gpointer data)
 
 static int alloc_framebuffer(struct lbx_image *image)
 {
-       struct lbx_imginfo info;
        GtkSpinButton *spin;
 
        if (framebuf)
                g_object_unref(framebuf);
 
-       lbx_img_getinfo(image, &info);
        framebuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8,
-               info.width, info.height);
+               image->width, image->height);
        g_return_val_if_fail(framebuf, -1);
 
        spin = GTK_SPIN_BUTTON(gtk_builder_get_object(builder, "framespin"));
-       gtk_spin_button_set_range(spin, 0, info.nframes-1);
+       gtk_spin_button_set_range(spin, 0, image->frames-1);
        gtk_spin_button_set_value(spin, 0);
 
-       gtk_widget_set_size_request(canvas, info.width, info.height);
+       gtk_widget_set_size_request(canvas, image->width, image->height);
        return 0;
 }
 
index 370c816dff8d0037a8eb31c5d13ae8728aa8d6ba..c2101b53a415df4b4554144787caabef61e91b24 100644 (file)
@@ -49,12 +49,10 @@ static void get_colour(unsigned char index, unsigned char out[static 4])
 int render_to_pixbuf(struct lbx_image *image, GdkPixbuf *pixbuf, unsigned frame)
 {
        unsigned char **framedata, **framemask, *outbuf;
-       struct lbx_imginfo info;
        unsigned stride;
 
-       lbx_img_getinfo(image, &info);
-       assert(info.width  == gdk_pixbuf_get_width(pixbuf));
-       assert(info.height == gdk_pixbuf_get_height(pixbuf));
+       assert(image->width  == gdk_pixbuf_get_width(pixbuf));
+       assert(image->height == gdk_pixbuf_get_height(pixbuf));
 
        framedata = lbx_img_getframe(image, frame);
        g_return_val_if_fail(framedata, -1);
@@ -63,10 +61,10 @@ int render_to_pixbuf(struct lbx_image *image, GdkPixbuf *pixbuf, unsigned frame)
        outbuf = gdk_pixbuf_get_pixels(pixbuf);
        stride = gdk_pixbuf_get_rowstride(pixbuf);
 
-       for (unsigned i = 0; i < info.height; i++) {
+       for (unsigned i = 0; i < image->height; i++) {
                unsigned char (*px)[4] = (void *)(outbuf + i*stride);
 
-               for (unsigned j = 0; j < info.width; j++) {
+               for (unsigned j = 0; j < image->width; j++) {
                        if (framemask[i][j])
                                get_colour(framedata[i][j], px[j]);
                        else
index c3abf3f643524d14e9948e54bb24529ab6685b91..f407a2d72d594157f4d05b353364c5720baa8f9d 100644 (file)
@@ -467,10 +467,6 @@ void lbx_img_getinfo(struct lbx_image *pub, struct lbx_imginfo *info)
        struct lbx_image_priv *img = (struct lbx_image_priv *)pub;
 
        *info = (struct lbx_imginfo) {
-               .width      = pub->width,
-               .height     = pub->height,
-               .nframes    = pub->frames,
-               .chunk      = pub->chunk,
                .palettesz  = (img->flags & FLAG_PALETTE) ? img->palcount : 0,
        };
 
index 2679babcc34ff40cbebf515252daa7f02dec5aa5..b51b3600dea242e92676c949fab04bc2ef7d0e9e 100644 (file)
@@ -18,8 +18,7 @@ struct lbx_colour {
 };
 
 struct lbx_imginfo {
-       unsigned short width, height;
-       unsigned char  nframes, loopstart, chunk;
+       unsigned char loopstart;
        int palettesz, looping;
 };
 
index 43406f1d8ae61de012c393de7890b68a9db23772..af59f5fbaf718a776270fab68352df8f811e08d5 100644 (file)
@@ -61,14 +61,14 @@ enum {
        MODE_IDENT,
 };
 
-int parserange(struct lbx_imginfo *info, char *str, unsigned char *bits)
+int parserange(unsigned frames, char *str, unsigned char *bits)
 {
        unsigned long start, end;
        unsigned int i;
        char *endptr;
 
        start = strtoul(str, &endptr, 0);
-       if (start >= info->nframes) {
+       if (start >= frames) {
                errmsg("frame %lu out of range.\n", start);
                return -1;
        }
@@ -84,13 +84,13 @@ int parserange(struct lbx_imginfo *info, char *str, unsigned char *bits)
                break;
        case '-':
                end = strtoul(endptr+1, &endptr, 0);
-               if (end >= info->nframes) {
+               if (end >= frames) {
                        errmsg("frame %lu out of range.\n", end);
                        return -1;
                }
 
                if (endptr == str)
-                       end = info->nframes - 1;
+                       end = frames - 1;
                break;
        default:
                errmsg("invalid frame range: %s.\n", str);
@@ -316,7 +316,7 @@ int decode(struct lbx_image *img, FILE *palf, FILE *override, char **argv)
 
        lbx_img_getinfo(img, &info);
 
-       framebits = calloc(1, info.nframes / CHAR_BIT + 1);
+       framebits = calloc(1, img->frames / CHAR_BIT + 1);
        if (!framebits) {
                return EXIT_FAILURE;
        }
@@ -324,10 +324,10 @@ int decode(struct lbx_image *img, FILE *palf, FILE *override, char **argv)
        /* Figure out what images we're extracting. */
        if (!argv[0]) {
                /* extract all images by default. */
-               memset(framebits, -1, info.nframes / CHAR_BIT + 1);
+               memset(framebits, -1, img->frames / CHAR_BIT + 1);
        } else {
                for (i = 0; argv[i]; i++) {
-                       parserange(&info, argv[i], framebits);
+                       parserange(img->frames, argv[i], framebits);
                }
        }
 
@@ -336,7 +336,7 @@ int decode(struct lbx_image *img, FILE *palf, FILE *override, char **argv)
        }
 
        /* Extract the images, in order. */
-       for (i = 0; i < info.nframes; i++) {
+       for (i = 0; i < img->frames; i++) {
                unsigned char **data;
                unsigned char **mask;
 
@@ -351,7 +351,7 @@ int decode(struct lbx_image *img, FILE *palf, FILE *override, char **argv)
 
                mask = lbx_img_getmask(img);
 
-               if (!outpng(i, data, mask, info.width, info.height, palette)) {
+               if (!outpng(i, data, mask, img->width, img->height, palette)) {
                        extracted = 1;
                }
        }
@@ -465,9 +465,9 @@ int main(int argc, char **argv)
 
                lbx_img_getinfo(img, &info);
                printf("%s is %ux%u LBX image, %u frame(s)%s%s\n",
-                      file, info.width, info.height, info.nframes,
+                      file, img->width, img->height, img->frames,
                       info.palettesz ? ", embedded palette" : "",
-                      info.chunk     ? ", chunked" : "",
+                      img->chunk     ? ", chunked" : "",
                       info.looping   ? ", loops" : "");
        }