X-Git-Url: http://git.draconx.ca/gitweb/liblbx.git/blobdiff_plain/e5fa9ca748b73c6008754ce2c48e9a85a78a1f17..bf1ea9667a3de66ed46e1b876ad3ce3ebba7e9b5:/src/gui/render.c?ds=sidebyside
diff --git a/src/gui/render.c b/src/gui/render.c
index 584cfd2..a96cc06 100644
--- a/src/gui/render.c
+++ b/src/gui/render.c
@@ -16,6 +16,8 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
+
+#include
#include
#include
@@ -27,6 +29,13 @@ struct lbx_colour palette_external[256];
struct lbx_colour palette_internal[256];
struct lbx_colour palette_override[256];
+static inline unsigned scale6to8(unsigned x)
+{
+ assert(x <= 0x3f);
+
+ return x*0xff / 0x3f;
+}
+
static void get_colour(unsigned char index, unsigned char out[static 4])
{
struct lbx_colour *colour;
@@ -38,23 +47,21 @@ static void get_colour(unsigned char index, unsigned char out[static 4])
else if (palette_external[index].active)
colour = palette_external + index;
else
- colour = &(struct lbx_colour) { .red = 0xff, .blue = 0xff };
+ colour = &(struct lbx_colour) { .red = 0x3f, .blue = 0x3f };
- out[0] = colour->red;
- out[1] = colour->green;
- out[2] = colour->blue;
+ out[0] = scale6to8(colour->red);
+ out[1] = scale6to8(colour->green);
+ out[2] = scale6to8(colour->blue);
out[3] = -1; /* opaque */
}
-int render_to_pixbuf(LBXimg *image, GdkPixbuf *pixbuf, unsigned frame)
+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 +70,10 @@ int render_to_pixbuf(LBXimg *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