[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [59103] trunk/blender/source/blender/imbuf /intern/bmp.c: add support for loading 8bit BMP images

Campbell Barton ideasman42 at gmail.com
Tue Aug 13 09:18:08 CEST 2013


Revision: 59103
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59103
Author:   campbellbarton
Date:     2013-08-13 07:18:07 +0000 (Tue, 13 Aug 2013)
Log Message:
-----------
add support for loading 8bit BMP images

Modified Paths:
--------------
    trunk/blender/source/blender/imbuf/intern/bmp.c

Modified: trunk/blender/source/blender/imbuf/intern/bmp.c
===================================================================
--- trunk/blender/source/blender/imbuf/intern/bmp.c	2013-08-13 06:21:39 UTC (rev 59102)
+++ trunk/blender/source/blender/imbuf/intern/bmp.c	2013-08-13 07:18:07 UTC (rev 59103)
@@ -100,11 +100,11 @@
 		memcpy(&bmi, mem, sizeof(bmi));
 
 		u = LITTLE_LONG(bmi.biSize);
-		/* we only support uncompressed 24 or 32 bits images for now */
+		/* we only support uncompressed images for now. */
 		if (u >= sizeof(BMPINFOHEADER)) {
-			if ((bmi.biCompression == 0) && (bmi.biClrUsed == 0)) {
+			if (bmi.biCompression == 0) {
 				u = LITTLE_SHORT(bmi.biBitCount);
-				if (u >= 16) {
+				if (u >= 8) {
 					ret_val = 1;
 				}
 			}
@@ -125,7 +125,7 @@
 {
 	struct ImBuf *ibuf = NULL;
 	BMPINFOHEADER bmi;
-	int x, y, depth, skip, i;
+	int x, y, depth, ibuf_depth, skip, i;
 	unsigned char *bmp, *rect;
 	unsigned short col;
 	double xppm, yppm;
@@ -151,6 +151,13 @@
 	xppm = LITTLE_LONG(bmi.biXPelsPerMeter);
 	yppm = LITTLE_LONG(bmi.biYPelsPerMeter);
 
+	if (depth <= 8) {
+		ibuf_depth = 24;
+	}
+	else {
+		ibuf_depth = depth;
+	}
+
 #if 0
 	printf("skip: %d, x: %d y: %d, depth: %d (%x)\n", skip, x, y,
 	       depth, bmi.biBitCount);
@@ -159,14 +166,33 @@
 #endif
 
 	if (flags & IB_test) {
-		ibuf = IMB_allocImBuf(x, y, depth, 0);
+		ibuf = IMB_allocImBuf(x, y, ibuf_depth, 0);
 	}
 	else {
-		ibuf = IMB_allocImBuf(x, y, depth, IB_rect);
+		ibuf = IMB_allocImBuf(x, y, ibuf_depth, IB_rect);
 		bmp = mem + skip;
 		rect = (unsigned char *) ibuf->rect;
 
-		if (depth == 16) {
+		if (depth == 8) {
+			const int x_pad = (4 - (x % 4)) % 4;
+			const char (*palette)[4] = (void *)bmp;
+			bmp += bmi.biClrUsed * 4;
+			for (i = y; i > 0; i--) {
+				int j;
+				for (j = x; j > 0; j--) {
+					const char *pcol = palette[bmp[0]];
+					rect[0] = pcol[0];
+					rect[1] = pcol[1];
+					rect[2] = pcol[2];
+
+					rect[3] = 255;
+					rect += 4; bmp += 1;
+				}
+				/* rows are padded to multiples of 4 */
+				bmp += x_pad;
+			}
+		}
+		else if (depth == 16) {
 			for (i = x * y; i > 0; i--) {
 				col = bmp[0] + (bmp[1] << 8);
 				rect[0] = ((col >> 10) & 0x1f) << 3;
@@ -179,6 +205,7 @@
 
 		}
 		else if (depth == 24) {
+			const int x_pad = x % 4;
 			for (i = y; i > 0; i--) {
 				int j;
 				for (j = x; j > 0; j--) {
@@ -190,7 +217,7 @@
 					rect += 4; bmp += 3;
 				}
 				/* for 24-bit images, rows are padded to multiples of 4 */
-				bmp += x % 4;
+				bmp += x_pad;
 			}
 		}
 		else if (depth == 32) {




More information about the Bf-blender-cvs mailing list