#include "lbx.h"
#include "image.h"
+#include "render.h"
#include "bg.xbm"
static GdkGC *bg_gc;
static LBX_IMG *image;
-/* LBX images can have up to three palettes, with each superseding the last. */
-static struct lbx_colour palette_external[256];
-static struct lbx_colour palette_internal[256];
-static struct lbx_colour palette_override[256];
static GdkPixbuf *framebuf;
}
}
-static void get_colour(unsigned char index, unsigned char out[static 3])
-{
- struct lbx_colour *colour;
-
- if (palette_override[index].active)
- colour = palette_override + index;
- else if (palette_internal[index].active)
- colour = palette_internal + index;
- else if (palette_external[index].active)
- colour = palette_external + index;
- else
- colour = &(struct lbx_colour) { .red = 0xff, .blue = 0xff };
-
- out[0] = colour->red;
- out[1] = colour->green;
- out[2] = colour->blue;
-}
-
-static int render_frame(LBX_IMG *img, GdkPixbuf *buf, unsigned frame)
-{
- unsigned char **imgdata, **imgmask;
- struct lbx_imginfo info;
- unsigned char *data;
- unsigned stride;
-
- lbximg_getinfo(image, &info);
- imgdata = lbximg_getframe(image, frame);
- if (!imgdata) {
- printf("failed to decode frame %u\n", frame);
- return -1;
- }
- imgmask = lbximg_getmask(image);
-
- data = gdk_pixbuf_get_pixels(buf);
- stride = gdk_pixbuf_get_rowstride(buf);
-
- for (unsigned i = 0; i < info.height; i++) {
- unsigned char (*p)[4] = (void *)(data + i*stride);
-
- for (unsigned j = 0; j < info.width; j++) {
- if (imgmask[i][j]) {
- get_colour(imgdata[i][j], p[j]);
- p[j][3] = -1;
- } else {
- p[j][3] = 0;
- }
- }
- }
-
- return 0;
-}
-
void set_frame(GtkSpinButton *spin, gpointer data)
{
unsigned frame = gtk_spin_button_get_value_as_int(spin);
- render_frame(image, framebuf, frame);
+ render_to_pixbuf(image, framebuf, frame);
gdk_window_invalidate_rect(canvas->window, NULL, FALSE);
}