[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [54392] trunk/blender/source/blender: Fix #33747: do better backwards compatibility for image transparency changes.

Brecht Van Lommel brechtvanlommel at pandora.be
Fri Feb 8 16:56:14 CET 2013


Revision: 54392
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=54392
Author:   blendix
Date:     2013-02-08 15:56:14 +0000 (Fri, 08 Feb 2013)
Log Message:
-----------
Fix #33747: do better backwards compatibility for image transparency changes.
The use alpha option moved from the texture datablock to the image, and now it
will duplicate the image datablock in case you have one texture using alpha and
the other not.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_image.h
    trunk/blender/source/blender/blenkernel/intern/image.c
    trunk/blender/source/blender/blenkernel/intern/library.c
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/blender/makesdna/DNA_image_types.h

Modified: trunk/blender/source/blender/blenkernel/BKE_image.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_image.h	2013-02-08 15:16:57 UTC (rev 54391)
+++ trunk/blender/source/blender/blenkernel/BKE_image.h	2013-02-08 15:56:14 UTC (rev 54392)
@@ -205,7 +205,7 @@
 void BKE_image_print_memlist(void);
 
 /* empty image block, of similar type and filename */
-struct Image *BKE_image_copy(struct Image *ima);
+struct Image *BKE_image_copy(struct Main *bmain, struct Image *ima);
 
 /* merge source into dest, and free source */
 void BKE_image_merge(struct Image *dest, struct Image *source);

Modified: trunk/blender/source/blender/blenkernel/intern/image.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/image.c	2013-02-08 15:16:57 UTC (rev 54391)
+++ trunk/blender/source/blender/blenkernel/intern/image.c	2013-02-08 15:56:14 UTC (rev 54392)
@@ -323,9 +323,9 @@
 }
 
 /* empty image block, of similar type and filename */
-Image *BKE_image_copy(Image *ima)
+Image *BKE_image_copy(Main *bmain, Image *ima)
 {
-	Image *nima = image_alloc(G.main, ima->id.name + 2, ima->source, ima->type);
+	Image *nima = image_alloc(bmain, ima->id.name + 2, ima->source, ima->type);
 
 	BLI_strncpy(nima->name, ima->name, sizeof(ima->name));
 
@@ -343,6 +343,9 @@
 
 	BKE_color_managed_colorspace_settings_copy(&nima->colorspace_settings, &ima->colorspace_settings);
 
+	if (ima->packedfile)
+		nima->packedfile = dupPackedFile(ima->packedfile);
+
 	return nima;
 }
 
@@ -433,7 +436,7 @@
 		extern_local_image(ima);
 	}
 	else if (is_local && is_lib) {
-		Image *ima_new = BKE_image_copy(ima);
+		Image *ima_new = BKE_image_copy(bmain, ima);
 
 		ima_new->id.us = 0;
 

Modified: trunk/blender/source/blender/blenkernel/intern/library.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/library.c	2013-02-08 15:16:57 UTC (rev 54391)
+++ trunk/blender/source/blender/blenkernel/intern/library.c	2013-02-08 15:56:14 UTC (rev 54392)
@@ -312,7 +312,7 @@
 			if (!test) *newid = (ID *)BKE_texture_copy((Tex *)id);
 			return 1;
 		case ID_IM:
-			if (!test) *newid = (ID *)BKE_image_copy((Image *)id);
+			if (!test) *newid = (ID *)BKE_image_copy(G.main, (Image *)id);
 			return 1;
 		case ID_LT:
 			if (!test) *newid = (ID *)BKE_lattice_copy((Lattice *)id);

Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c	2013-02-08 15:16:57 UTC (rev 54391)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c	2013-02-08 15:56:14 UTC (rev 54392)
@@ -8644,8 +8644,8 @@
 
 	if (main->versionfile < 265 || (main->versionfile == 265 && main->subversionfile < 5)) {
 		Scene *scene;
-		Image *image;
-		Tex *tex;
+		Image *image, *nimage;
+		Tex *tex, *otex;
 
 		for (scene = main->scene.first; scene; scene = scene->id.next) {
 			Sequence *seq;
@@ -8664,16 +8664,63 @@
 		for (image = main->image.first; image; image = image->id.next) {
 			if (image->flag & IMA_DO_PREMUL)
 				image->alpha_mode = IMA_ALPHA_STRAIGHT;
+
+			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);
 
-				if (image)
+				/* 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;
+
+				if (otex) {
+					/* 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 */
 					image->flag |= IMA_IGNORE_ALPHA;
+				}
 			}
 		}
+
+		for (image = main->image.first; image; image = image->id.next)
+			image->flag &= ~IMA_DONE_TAG;
 	}
 
 	if (main->versionfile < 265 || (main->versionfile == 265 && main->subversionfile < 7)) {

Modified: trunk/blender/source/blender/makesdna/DNA_image_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_image_types.h	2013-02-08 15:16:57 UTC (rev 54391)
+++ trunk/blender/source/blender/makesdna/DNA_image_types.h	2013-02-08 15:56:14 UTC (rev 54392)
@@ -125,7 +125,7 @@
 #define IMA_DO_PREMUL		4    /* deprecated, should not be used */
 #define IMA_REFLECT			16
 #define IMA_NOCOLLECT   	32
-#define IMA_DEPRECATED		64
+#define IMA_DONE_TAG		64
 #define IMA_OLD_PREMUL		128
 /*#define IMA_CM_PREDIVIDE	256*/  /* deprecated, should not be used */
 #define IMA_USED_FOR_RENDER	512




More information about the Bf-blender-cvs mailing list