[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [37492] trunk/blender/source/blender: fix [#27662] Storing png/tga images ignore Alpha settings

Campbell Barton ideasman42 at gmail.com
Wed Jun 15 03:56:50 CEST 2011


Revision: 37492
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37492
Author:   campbellbarton
Date:     2011-06-15 01:56:49 +0000 (Wed, 15 Jun 2011)
Log Message:
-----------
fix [#27662] Storing png/tga images ignore Alpha settings
- don't clear alpha when baking RGB images
- when baking results in partial alpha. set the depth to 32.

Modified Paths:
--------------
    trunk/blender/source/blender/blenpluginapi/iff.h
    trunk/blender/source/blender/editors/object/object_bake.c
    trunk/blender/source/blender/imbuf/IMB_imbuf.h
    trunk/blender/source/blender/imbuf/intern/rectop.c
    trunk/blender/source/blender/render/intern/source/rendercore.c

Modified: trunk/blender/source/blender/blenpluginapi/iff.h
===================================================================
--- trunk/blender/source/blender/blenpluginapi/iff.h	2011-06-15 00:16:30 UTC (rev 37491)
+++ trunk/blender/source/blender/blenpluginapi/iff.h	2011-06-15 01:56:49 UTC (rev 37492)
@@ -113,9 +113,10 @@
 LIBIMPORT void IMB_rectcpy(struct ImBuf *dbuf, struct ImBuf *sbuf, 
 	int destx, int desty, int srcx, int srcy, int width, int height);
 
-LIBIMPORT void IMB_rectfill(struct ImBuf *drect, float col[4]);
+LIBIMPORT void IMB_rectfill(struct ImBuf *drect, const float col[4]);
 LIBIMPORT void IMB_rectfill_area(struct ImBuf *ibuf, float *col, int x1, int y1, int x2, int y2);
 LIBIMPORT void buf_rectfill_area(unsigned char *rect, float *rectf, int width, int height, float *col, int x1, int y1, int x2, int y2);
+LIBIMPORT void IMB_rectfill_alpha(struct ImBuf *drect, const float value);
 
 #endif /* IFF_H */
 

Modified: trunk/blender/source/blender/editors/object/object_bake.c
===================================================================
--- trunk/blender/source/blender/editors/object/object_bake.c	2011-06-15 00:16:30 UTC (rev 37491)
+++ trunk/blender/source/blender/editors/object/object_bake.c	2011-06-15 01:56:49 UTC (rev 37492)
@@ -854,10 +854,14 @@
 		Image *ima= (Image*)link->data;
 		int i;
 		ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL);
+		short is_new_alpha;
 
 		if(ibuf->x<=0 || ibuf->y<=0)
 			continue;
 
+		/* must check before filtering */
+		is_new_alpha= (ibuf->depth != 32) && BKE_alphatest_ibuf(ibuf);
+
 		/* Margin */
 		if(bkr->bake_filter) {
 			char *temprect;
@@ -882,6 +886,18 @@
 				IMB_filter_extend(ibuf, (char *)ibuf->userdata);
 		}
 
+		/* if the bake results in new alpha then change the image setting */
+		if(is_new_alpha) {
+			ibuf->depth= 32;
+		}
+		else {
+			if(bkr->bake_filter) {
+				/* clear alpha added by filtering */
+				IMB_rectfill_alpha(ibuf, 1.0f);
+			}
+		}
+
+
 		ibuf->userflags|= IB_BITMAPDIRTY;
 		if(ibuf->mipmap[0]) {
 			ibuf->userflags|= IB_MIPMAP_INVALID;
@@ -1028,7 +1044,8 @@
 static void clear_images(MTFace *mtface, int totface)
 {
 	int a;
-	float vec[4]= {0.0f, 0.0f, 0.0f, 0.0f};
+	const float vec_alpha[4]= {0.0f, 0.0f, 0.0f, 0.0f};
+	const float vec_solid[4]= {0.0f, 0.0f, 0.0f, 1.0f};
 
 	for(a= 0; a<totface; a++)
 		mtface[a].tpage->id.flag&= ~LIB_DOIT;
@@ -1039,7 +1056,7 @@
 		if((ima->id.flag&LIB_DOIT)==0) {
 			ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL);
 
-			IMB_rectfill(ibuf, vec);
+			IMB_rectfill(ibuf, (ibuf->depth == 32) ? vec_alpha : vec_solid);
 			ima->id.flag|= LIB_DOIT;
 		}
 	}

Modified: trunk/blender/source/blender/imbuf/IMB_imbuf.h
===================================================================
--- trunk/blender/source/blender/imbuf/IMB_imbuf.h	2011-06-15 00:16:30 UTC (rev 37491)
+++ trunk/blender/source/blender/imbuf/IMB_imbuf.h	2011-06-15 01:56:49 UTC (rev 37492)
@@ -442,8 +442,9 @@
  *
  * @attention Defined in rectop.c
  */
-void IMB_rectfill(struct ImBuf *drect, float col[4]);
+void IMB_rectfill(struct ImBuf *drect, const float col[4]);
 void IMB_rectfill_area(struct ImBuf *ibuf, float *col, int x1, int y1, int x2, int y2);
+void IMB_rectfill_alpha(struct ImBuf *ibuf, const float value);
 
 /* this should not be here, really, we needed it for operating on render data, IMB_rectfill_area calls it */
 void buf_rectfill_area(unsigned char *rect, float *rectf, int width, int height, float *col, int x1, int y1, int x2, int y2);

Modified: trunk/blender/source/blender/imbuf/intern/rectop.c
===================================================================
--- trunk/blender/source/blender/imbuf/intern/rectop.c	2011-06-15 00:16:30 UTC (rev 37491)
+++ trunk/blender/source/blender/imbuf/intern/rectop.c	2011-06-15 01:56:49 UTC (rev 37492)
@@ -450,7 +450,7 @@
 
 /* fill */
 
-void IMB_rectfill(struct ImBuf *drect, float col[4])
+void IMB_rectfill(struct ImBuf *drect, const float col[4])
 {
 	int num;
 
@@ -561,3 +561,18 @@
 	if (!ibuf) return;
 	buf_rectfill_area((unsigned char *) ibuf->rect, ibuf->rect_float, ibuf->x, ibuf->y, col, x1, y1, x2, y2);
 }
+
+
+void IMB_rectfill_alpha(ImBuf *ibuf, const float value)
+{
+	int i;
+	if (ibuf->rect_float) {
+		float *fbuf= ibuf->rect_float + 3;
+		for (i = ibuf->x * ibuf->y; i > 0; i--, fbuf+= 4) { *fbuf = value; }
+	}
+	else {
+		const unsigned char cvalue= value * 255;
+		unsigned char *cbuf= ((unsigned char *)ibuf->rect) + 3;
+		for (i = ibuf->x * ibuf->y; i > 0; i--, cbuf+= 4) { *cbuf = cvalue; }
+	}
+}

Modified: trunk/blender/source/blender/render/intern/source/rendercore.c
===================================================================
--- trunk/blender/source/blender/render/intern/source/rendercore.c	2011-06-15 00:16:30 UTC (rev 37491)
+++ trunk/blender/source/blender/render/intern/source/rendercore.c	2011-06-15 01:56:49 UTC (rev 37492)
@@ -2464,7 +2464,8 @@
 				if(tface && tface->tpage) {
 					Image *ima= tface->tpage;
 					ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL);
-					float vec[4]= {0.0f, 0.0f, 0.0f, 0.0f};
+					const float vec_alpha[4]= {0.0f, 0.0f, 0.0f, 0.0f};
+					const float vec_solid[4]= {0.0f, 0.0f, 0.0f, 1.0f};
 					
 					if(ibuf==NULL)
 						continue;
@@ -2484,7 +2485,7 @@
 							imb_freerectImBuf(ibuf);
 						/* clear image */
 						if(R.r.bake_flag & R_BAKE_CLEAR)
-							IMB_rectfill(ibuf, vec);
+							IMB_rectfill(ibuf, (ibuf->depth == 32) ? vec_alpha : vec_solid);
 					
 						/* might be read by UI to set active image for display */
 						R.bakebuf= ima;
@@ -2671,10 +2672,14 @@
 	for(ima= G.main->image.first; ima; ima= ima->id.next) {
 		if((ima->id.flag & LIB_DOIT)==0) {
 			ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL);
+			short is_new_alpha;
 
 			if(!ibuf)
 				continue;
 
+			/* must check before filtering */
+			is_new_alpha= (ibuf->depth != 32) && BKE_alphatest_ibuf(ibuf);
+
 			if(re->r.bake_filter) {
 				if (usemask) {
 					/* extend the mask +2 pixels from the image,
@@ -2706,6 +2711,17 @@
 				}
 			}
 
+			/* if the bake results in new alpha then change the image setting */
+			if(is_new_alpha) {
+				ibuf->depth= 32;
+			}
+			else {
+				if(re->r.bake_filter) {
+					/* clear alpha added by filtering */
+					IMB_rectfill_alpha(ibuf, 1.0f);
+				}
+			}
+
 			ibuf->userflags |= IB_BITMAPDIRTY;
 			if (ibuf->rect_float) IMB_rect_from_float(ibuf);
 		}




More information about the Bf-blender-cvs mailing list