[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [33401] trunk/blender/source/blender: bugfix [#22638] Alpha channel not saved when using texture paint

Campbell Barton ideasman42 at gmail.com
Wed Dec 1 00:38:31 CET 2010


Revision: 33401
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=33401
Author:   campbellbarton
Date:     2010-12-01 00:38:31 +0100 (Wed, 01 Dec 2010)

Log Message:
-----------
bugfix [#22638] Alpha channel not saved when using texture paint
check for alpha channel while saving images that have been painted onto.
It would be nicer to do this while in paint mode except this isn't so simple with project paint using multiple images at once.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_image.h
    trunk/blender/source/blender/blenkernel/intern/image.c
    trunk/blender/source/blender/editors/space_image/image_ops.c

Modified: trunk/blender/source/blender/blenkernel/BKE_image.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_image.h	2010-11-30 22:39:41 UTC (rev 33400)
+++ trunk/blender/source/blender/blenkernel/BKE_image.h	2010-11-30 23:38:31 UTC (rev 33401)
@@ -46,6 +46,7 @@
 
 void	BKE_stamp_info(struct Scene *scene, struct ImBuf *ibuf);
 void	BKE_stamp_buf(struct Scene *scene, unsigned char *rect, float *rectf, int width, int height, int channels);
+int		BKE_alphatest_ibuf(struct ImBuf *ibuf);
 int		BKE_write_ibuf(struct Scene *scene, struct ImBuf *ibuf, const char *name, int imtype, int subimtype, int quality);
 void	BKE_makepicstring(char *string, const char *base, int frame, int imtype, const short use_ext, const short use_frames);
 int		BKE_add_image_extension(char *string, int imtype);

Modified: trunk/blender/source/blender/blenkernel/intern/image.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/image.c	2010-11-30 22:39:41 UTC (rev 33400)
+++ trunk/blender/source/blender/blenkernel/intern/image.c	2010-11-30 23:38:31 UTC (rev 33401)
@@ -1188,6 +1188,29 @@
 	if (stamp_data.rendertime[0]) IMB_metadata_change_field (ibuf, "RenderTime", stamp_data.rendertime);
 }
 
+int BKE_alphatest_ibuf(ImBuf *ibuf)
+{
+	int tot;
+	if(ibuf->rect_float) {
+		float *buf= ibuf->rect_float;
+		for(tot= ibuf->x * ibuf->y; tot--; buf+=4) {
+			if(buf[3] < 1.0f) {
+				return TRUE;
+			}
+		}
+	}
+	else if (ibuf->rect) {
+		unsigned char *buf= (unsigned char *)ibuf->rect;
+		for(tot= ibuf->x * ibuf->y; tot--; buf+=4) {
+			if(buf[3] != 255) {
+				return TRUE;
+			}
+		}
+	}
+
+	return FALSE;
+}
+
 int BKE_write_ibuf(Scene *scene, ImBuf *ibuf, const char *name, int imtype, int subimtype, int quality)
 {
 	int ok;

Modified: trunk/blender/source/blender/editors/space_image/image_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_image/image_ops.c	2010-11-30 22:39:41 UTC (rev 33400)
+++ trunk/blender/source/blender/editors/space_image/image_ops.c	2010-11-30 23:38:31 UTC (rev 33401)
@@ -888,6 +888,13 @@
 				ibuf->depth= 24;
 			}
 		}
+		else {
+			/* TODO, better solution, if a 24bit image is painted onto it may contain alpha */
+			if(ibuf->userflags & IB_BITMAPDIRTY) { /* it has been painted onto */
+				/* checks each pixel, not ideal */
+				ibuf->depth= BKE_alphatest_ibuf(ibuf) ? 32 : 24;
+			}
+		}
 
 		if(scene->r.scemode & R_EXTENSION)  {
 			BKE_add_image_extension(path, sima->imtypenr);





More information about the Bf-blender-cvs mailing list