[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55022] trunk/blender: Fix for image transparency backwards compatibility.

Brecht Van Lommel brechtvanlommel at pandora.be
Mon Mar 4 14:18:14 CET 2013


Revision: 55022
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55022
Author:   blendix
Date:     2013-03-04 13:18:14 +0000 (Mon, 04 Mar 2013)
Log Message:
-----------
Fix for image transparency backwards compatibility. Now the texture datablock has
a Use Alpha option again. This makes the case where you enabled Premultiply on the
image and disabled Use Alpha on the texture work again.

That's mostly useful when you have a straight alpha image file which has no useful
RGB colors in zero alpha regions (e.g. renders). Then sometimes you don't want to
use the alpha for the texture stack mixing, but you still want to multiply it into
the RGB channels to avoid a blocky transition into zero alpha regions.

This also removes the version patch that copied image datablocks because it's not
reliable and might be causing bug #34434. This does mean we are no longer backwards
compatible for cases where two different texture datablocks with Use Alpha enabled
and disabled where using the same image.

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_ui/properties_texture.py
    trunk/blender/source/blender/blenkernel/BKE_blender.h
    trunk/blender/source/blender/blenkernel/intern/texture.c
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/blender/gpu/intern/gpu_material.c
    trunk/blender/source/blender/makesdna/DNA_texture_types.h
    trunk/blender/source/blender/makesrna/intern/rna_texture.c
    trunk/blender/source/blender/render/intern/source/imagetexture.c

Modified: trunk/blender/release/scripts/startup/bl_ui/properties_texture.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/properties_texture.py	2013-03-04 13:14:21 UTC (rev 55021)
+++ trunk/blender/release/scripts/startup/bl_ui/properties_texture.py	2013-03-04 13:18:14 UTC (rev 55022)
@@ -448,6 +448,9 @@
 
         col = split.column()
         col.label(text="Alpha:")
+        row = col.row()
+        row.active = tex.image and tex.image.use_alpha
+        row.prop(tex, "use_alpha", text="Use")
         col.prop(tex, "use_calculate_alpha", text="Calculate")
         col.prop(tex, "invert_alpha", text="Invert")
         col.separator()

Modified: trunk/blender/source/blender/blenkernel/BKE_blender.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_blender.h	2013-03-04 13:14:21 UTC (rev 55021)
+++ trunk/blender/source/blender/blenkernel/BKE_blender.h	2013-03-04 13:18:14 UTC (rev 55022)
@@ -42,7 +42,7 @@
  * and keep comment above the defines.
  * Use STRINGIFY() rather than defining with quotes */
 #define BLENDER_VERSION         266
-#define BLENDER_SUBVERSION      0
+#define BLENDER_SUBVERSION      1
 
 /* 262 was the last editmesh release but it has compatibility code for bmesh data */
 #define BLENDER_MINVERSION      262

Modified: trunk/blender/source/blender/blenkernel/intern/texture.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/texture.c	2013-03-04 13:14:21 UTC (rev 55021)
+++ trunk/blender/source/blender/blenkernel/intern/texture.c	2013-03-04 13:18:14 UTC (rev 55022)
@@ -440,7 +440,7 @@
 	tex->type = TEX_CLOUDS;
 	tex->stype = 0;
 	tex->flag = TEX_CHECKER_ODD;
-	tex->imaflag = TEX_INTERPOL | TEX_MIPMAP;
+	tex->imaflag = TEX_INTERPOL | TEX_MIPMAP | TEX_USEALPHA;
 	tex->extend = TEX_REPEAT;
 	tex->cropxmin = tex->cropymin = 0.0;
 	tex->cropxmax = tex->cropymax = 1.0;

Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c	2013-03-04 13:14:21 UTC (rev 55021)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c	2013-03-04 13:18:14 UTC (rev 55022)
@@ -8663,8 +8663,8 @@
 
 	if (main->versionfile < 265 || (main->versionfile == 265 && main->subversionfile < 5)) {
 		Scene *scene;
-		Image *image, *nimage;
-		Tex *tex, *otex;
+		Image *image;
+		Tex *tex;
 		bNodeTreeType *ntreetype;
 		bNodeTree *ntree;
 
@@ -8711,67 +8711,17 @@
 			else {
 				BKE_image_alpha_mode_from_extension(image);
 			}
-
-			image->flag &= ~IMA_DONE_TAG;
 		}
 
-		/* use alpha flag moved from texture to image datablock */
 		for (tex = main->tex.first; tex; tex = tex->id.next) {
 			if (tex->type == TEX_IMAGE && (tex->imaflag & TEX_USEALPHA) == 0) {
 				image = blo_do_versions_newlibadr(fd, tex->id.lib, tex->ima);
 
-				/* skip if no image or already tested */
-				if (!image || (image->flag & (IMA_DONE_TAG|IMA_IGNORE_ALPHA)))
-					continue;
-
-				image->flag |= IMA_DONE_TAG;
-
-				/* we might have some textures using alpha and others not, so we check if
-				 * they exist and duplicate the image datablock if necessary */
-				for (otex = main->tex.first; otex; otex = otex->id.next)
-					if (otex->type == TEX_IMAGE && (otex->imaflag & TEX_USEALPHA))
-						if (image == blo_do_versions_newlibadr(fd, otex->id.lib, otex->ima))
-							break;
-
-				/* no duplication if the texture and image datablock are not
-				 * from the same .blend file, the image datablock may not have
-				 * been loaded from a library file otherwise */
-				if (otex && (tex->id.lib == image->id.lib)) {
-					/* copy image datablock */
-					nimage = BKE_image_copy(main, image);
-					nimage->flag |= IMA_IGNORE_ALPHA|IMA_DONE_TAG;
-					nimage->id.us--;
-
-					/* we need to do some trickery to make file loading think
-					 * this new datablock is part of file we're loading */
-					blo_do_versions_oldnewmap_insert(fd->libmap, nimage, nimage, 0);
-					nimage->id.lib = image->id.lib;
-					nimage->id.flag |= (image->id.flag & LIB_NEED_LINK);
-
-					/* assign new image, and update the users counts accordingly */
-					for (otex = main->tex.first; otex; otex = otex->id.next) {
-						if (otex->type == TEX_IMAGE && (otex->imaflag & TEX_USEALPHA) == 0) {
-							if (image == blo_do_versions_newlibadr(fd, otex->id.lib, otex->ima)) {
-								if (!(otex->id.flag & LIB_NEED_LINK)) {
-									image->id.us--;
-									nimage->id.us++;
-								}
-								otex->ima = nimage;
-								break;
-							}
-						}
-					}
-				}
-				else {
-					/* no other textures using alpha, just set the flag */
+				if (image && (image->flag & IMA_DO_PREMUL) == 0)
 					image->flag |= IMA_IGNORE_ALPHA;
-				}
 			}
 		}
 
-		for (image = main->image.first; image; image = image->id.next)
-			image->flag &= ~IMA_DONE_TAG;
-
 		ntreetype = ntreeGetType(NTREE_COMPOSIT);
 		if (ntreetype && ntreetype->foreach_nodetree)
 			ntreetype->foreach_nodetree(main, fd, do_version_node_straight_image_alpha_workaround);
@@ -8779,7 +8729,16 @@
 		for (ntree = main->nodetree.first; ntree; ntree = ntree->id.next)
 			do_version_node_straight_image_alpha_workaround(fd, NULL, ntree);
 	}
+	else if (main->versionfile < 266 || (main->versionfile == 266 && main->subversionfile < 1)) {
+		/* texture use alpha was removed for 2.66 but added back again for 2.66a,
+		* for compatibility all textures assumed it to be enabled */
+		Tex *tex;
 
+		for (tex = main->tex.first; tex; tex = tex->id.next)
+			if (tex->type == TEX_IMAGE)
+				tex->imaflag |= TEX_USEALPHA;
+	}
+
 	if (main->versionfile < 265 || (main->versionfile == 265 && main->subversionfile < 7)) {
 		Curve *cu;
 

Modified: trunk/blender/source/blender/gpu/intern/gpu_material.c
===================================================================
--- trunk/blender/source/blender/gpu/intern/gpu_material.c	2013-03-04 13:14:21 UTC (rev 55021)
+++ trunk/blender/source/blender/gpu/intern/gpu_material.c	2013-03-04 13:18:14 UTC (rev 55022)
@@ -1035,7 +1035,7 @@
 				GPU_link(mat, "mtex_image", texco, GPU_image(tex->ima, &tex->iuser, FALSE), &tin, &trgb);
 				rgbnor= TEX_RGB;
 
-				talpha = (tex->ima->flag & IMA_IGNORE_ALPHA) == 0;
+				talpha = ((tex->imaflag & TEX_USEALPHA) && tex->ima && (tex->ima->flag & IMA_IGNORE_ALPHA) == 0);
 			}
 			else {
 				continue;

Modified: trunk/blender/source/blender/makesdna/DNA_texture_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_texture_types.h	2013-03-04 13:14:21 UTC (rev 55021)
+++ trunk/blender/source/blender/makesdna/DNA_texture_types.h	2013-03-04 13:18:14 UTC (rev 55022)
@@ -340,7 +340,7 @@
 
 /* imaflag */
 #define TEX_INTERPOL	1
-#define TEX_USEALPHA	2 /* deprecated, used for versioning only */
+#define TEX_USEALPHA	2
 #define TEX_MIPMAP		4
 #define TEX_IMAROT		16
 #define TEX_CALCALPHA	32

Modified: trunk/blender/source/blender/makesrna/intern/rna_texture.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_texture.c	2013-03-04 13:14:21 UTC (rev 55021)
+++ trunk/blender/source/blender/makesrna/intern/rna_texture.c	2013-03-04 13:18:14 UTC (rev 55022)
@@ -1196,6 +1196,11 @@
 	RNA_def_property_ui_text(prop, "Flip Axis", "Flip the texture's X and Y axis");
 	RNA_def_property_update(prop, 0, "rna_Texture_update");
 
+	prop = RNA_def_property(srna, "use_alpha", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "imaflag", TEX_USEALPHA);
+	RNA_def_property_ui_text(prop, "Use Alpha", "Use the alpha channel information in the image");
+	RNA_def_property_update(prop, 0, "rna_Texture_update");
+
 	prop = RNA_def_property(srna, "use_calculate_alpha", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "imaflag", TEX_CALCALPHA);
 	RNA_def_property_ui_text(prop, "Calculate Alpha", "Calculate an alpha channel based on RGB values in the image");

Modified: trunk/blender/source/blender/render/intern/source/imagetexture.c
===================================================================
--- trunk/blender/source/blender/render/intern/source/imagetexture.c	2013-03-04 13:14:21 UTC (rev 55021)
+++ trunk/blender/source/blender/render/intern/source/imagetexture.c	2013-03-04 13:18:14 UTC (rev 55022)
@@ -224,7 +224,7 @@
 	}
 
 	/* keep this before interpolation [#29761] */
-	if (tex->ima && (tex->ima->flag & IMA_IGNORE_ALPHA) == 0) {
+	if ((tex->imaflag & TEX_USEALPHA) && tex->ima && (tex->ima->flag & IMA_IGNORE_ALPHA) == 0) {
 		if ((tex->imaflag & TEX_CALCALPHA) == 0) {
 			texres->talpha = TRUE;
 		}
@@ -1098,7 +1098,7 @@
 	/* mipmap test */
 	image_mipmap_test(tex, ibuf);
 	
-	if (tex->ima && (tex->ima->flag & IMA_IGNORE_ALPHA) == 0) {
+	if ((tex->imaflag & TEX_USEALPHA) && tex->ima && (tex->ima->flag & IMA_IGNORE_ALPHA) == 0) {
 		if ((tex->imaflag & TEX_CALCALPHA) == 0)
 			texres->talpha = 1;
 	}
@@ -1514,7 +1514,7 @@
 	/* mipmap test */
 	image_mipmap_test(tex, ibuf);
 
-	if (tex->ima && (tex->ima->flag & IMA_IGNORE_ALPHA) == 0) {
+	if ((tex->imaflag & TEX_USEALPHA) && tex->ima && (tex->ima->flag & IMA_IGNORE_ALPHA) == 0) {
 		if ((tex->imaflag & TEX_CALCALPHA) == 0) {
 			texres->talpha = TRUE;
 		}




More information about the Bf-blender-cvs mailing list