changeset 2403:5e74f972baca

Be more efficient with alpha channel support in BPG.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 08 Dec 2016 16:11:05 +0200
parents e8439b3f9831
children 084d650233f0
files src/image_load_bpg.c
diffstat 1 files changed, 7 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/image_load_bpg.c	Thu Dec 08 13:12:46 2016 +0200
+++ b/src/image_load_bpg.c	Thu Dec 08 16:11:05 2016 +0200
@@ -56,7 +56,7 @@
 	BPGDecoderContext *img = bpg_decoder_open();
 	BPGImageInfo info_s, *info = &info_s;
 	guchar *pixels = NULL;
-	gint rowstride, y;
+	gint rowstride, y, bpp;
 	gsize bytes;
 
 	if (bpg_decoder_decode(img, buf, count) < 0)
@@ -72,8 +72,9 @@
 		goto err;
 	}
 
-	rowstride = info->width * 4;
-	if (rowstride / 4 != info->width)
+	bpp = info->has_alpha ? 4 : 3;
+	rowstride = info->width * bpp;
+	if (rowstride / bpp != info->width)
 	{
 		DEBUG_1("Dimensions of BPG image too large");
 		goto err;
@@ -86,7 +87,7 @@
 		goto err;
 	}
 
-	bpg_decoder_start(img, BPG_OUTPUT_FORMAT_RGBA32);
+	bpg_decoder_start(img, info->has_alpha ? BPG_OUTPUT_FORMAT_RGBA32 : BPG_OUTPUT_FORMAT_RGB24);
 
 	lt->requested_width = info->width;
 	lt->requested_height = info->height;
@@ -99,7 +100,7 @@
 		goto err;
 	}
 
-	lt->pixbuf = gdk_pixbuf_new_from_data(pixels, GDK_COLORSPACE_RGB, TRUE, 8, info->width, info->height, rowstride, free_buffer, NULL);
+	lt->pixbuf = gdk_pixbuf_new_from_data(pixels, GDK_COLORSPACE_RGB, info->has_alpha, 8, info->width, info->height, rowstride, free_buffer, NULL);
 	if (!lt->pixbuf)
 	{
 		g_free(pixels);
@@ -114,7 +115,7 @@
 		if (lt->abort)
 			break;
 
-		bpg_decoder_get_line(img, pixels + y * info->width * 4);
+		bpg_decoder_get_line(img, pixels + y * info->width * bpp);
 
 		lt->area_updated_cb(loader, 0, y, info->width, 1, lt->data);
 	}