]> git.draconx.ca Git - liblbx.git/blobdiff - src/gui/lbxgui.c
lbxgui: Split frame rendering into a separate source file.
[liblbx.git] / src / gui / lbxgui.c
index 2cceca3e60e4d78f5a41e786930c60a82f28030b..965268b328a612f6c85a51a310affdd224550757 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "lbx.h"
 #include "image.h"
+#include "render.h"
 
 #include "bg.xbm"
 
@@ -17,12 +18,8 @@ static GtkWidget *canvas;
 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];
 
-GdkPixbuf *framebuf;
+static GdkPixbuf *framebuf;
 
 void play_toggled(GtkToggleButton *button, gpointer data)
 {
@@ -42,63 +39,11 @@ void play_toggled(GtkToggleButton *button, gpointer data)
        }
 }
 
-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);
 }
 
@@ -214,7 +159,7 @@ static int img_close(void *handle)
        return 0;
 }
 
-void set_override_data(GtkComboBox *combo)
+void set_override(GtkComboBox *combo)
 {
        GtkTreeIter iter;
        gpointer lbx;
@@ -247,7 +192,7 @@ void set_override_data(GtkComboBox *combo)
        }
 }
 
-void set_palette_data(GtkComboBox *combo)
+void set_palette(GtkComboBox *combo)
 {
        GtkTreeIter iter;
        gpointer lbx;
@@ -273,7 +218,7 @@ void set_palette_data(GtkComboBox *combo)
        init_framedata(0);
 }
 
-void set_image_data(GtkComboBox *combo)
+void set_image(GtkComboBox *combo)
 {
        GtkTreeIter iter;
        gpointer lbx;
@@ -327,7 +272,7 @@ void show_about(GtkWidget *widget)
                NULL);
 }
 
-int load_archive(const char *path)
+static int load_archive(const char *path)
 {
        gchar *basename;
        GtkTreeIter iter1, iter2;
@@ -362,7 +307,7 @@ int load_archive(const char *path)
        return 0;
 }
 
-void load_error(const char *name, GtkWindow *window)
+static void load_error(const char *name, GtkWindow *window)
 {
        GtkWidget *dialog;
 
@@ -444,7 +389,7 @@ static void init_combobox(GtkBuilder *builder, const char *name)
                GTK_STOCK_CLEAR);
 }
 
-static void interface_init(void)
+static void init_interface(void)
 {
        GtkTreeViewColumn *column;
        GtkCellRenderer *renderer;
@@ -464,7 +409,7 @@ static void interface_init(void)
        init_combobox(builder, "overchooser");
 }
 
-GdkBitmap *init_bg(GdkDrawable *drawable, GdkGC *gc)
+static GdkBitmap *init_background(GdkDrawable *drawable, GdkGC *gc)
 {
        GdkColor fg = { .red = 0x6666, .green = 0x6666, .blue = 0x6666 };
        GdkColor bg = { .red = 0x9999, .green = 0x9999, .blue = 0x9999 };
@@ -505,13 +450,13 @@ int main(int argc, char **argv)
        window = GTK_WIDGET(gtk_builder_get_object(builder, "mainwindow"));
        canvas = GTK_WIDGET(gtk_builder_get_object(builder, "canvas"));
 
-       interface_init();
+       init_interface();
        gtk_builder_connect_signals(builder, window);
 
        g_timeout_add(10, timeout, NULL);
        gtk_widget_show_all(window);
 
        bg_gc = gdk_gc_new(canvas->window);
-       init_bg(canvas->window, bg_gc);
+       init_background(canvas->window, bg_gc);
        gtk_main();
 }