7 /* LBX images can have up to three palettes, with each superseding the last. */
8 struct lbx_colour palette_external[256];
9 struct lbx_colour palette_internal[256];
10 struct lbx_colour palette_override[256];
12 static void get_colour(unsigned char index, unsigned char out[static 4])
14 struct lbx_colour *colour;
16 if (palette_override[index].active)
17 colour = palette_override + index;
18 else if (palette_internal[index].active)
19 colour = palette_internal + index;
20 else if (palette_external[index].active)
21 colour = palette_external + index;
23 colour = &(struct lbx_colour) { .red = 0xff, .blue = 0xff };
26 out[1] = colour->green;
27 out[2] = colour->blue;
28 out[3] = -1; /* opaque */
31 int render_to_pixbuf(LBX_IMG *image, GdkPixbuf *pixbuf, unsigned frame)
33 unsigned char **framedata, **framemask, *outbuf;
34 struct lbx_imginfo info;
37 lbximg_getinfo(image, &info);
38 assert(info.width == gdk_pixbuf_get_width(pixbuf));
39 assert(info.height == gdk_pixbuf_get_height(pixbuf));
41 framedata = lbximg_getframe(image, frame);
42 g_return_val_if_fail(framedata, -1);
43 framemask = lbximg_getmask(image);
45 outbuf = gdk_pixbuf_get_pixels(pixbuf);
46 stride = gdk_pixbuf_get_rowstride(pixbuf);
48 for (unsigned i = 0; i < info.height; i++) {
49 unsigned char (*px)[4] = (void *)(outbuf + i*stride);
51 for (unsigned j = 0; j < info.width; j++) {
53 get_colour(framedata[i][j], px[j]);
55 px[j][3] = 0; /* transparent */