diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2013-02-08 19:56:14 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2013-02-08 19:56:14 +0400 |
commit | 32a6a3eb63b80e47fb083d49814090b89541e9ab (patch) | |
tree | 9575675b6a615906de50834b3ec0b39c2fa12c0b /source/blender/blenloader | |
parent | 95b28a65f366c4a1f571f35dabd79edaa94cfe51 (diff) |
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.
Diffstat (limited to 'source/blender/blenloader')
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 53 |
1 files changed, 50 insertions, 3 deletions
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 8a695ab4edb..1d76bef8dc1 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -8644,8 +8644,8 @@ static void do_versions(FileData *fd, Library *lib, Main *main) 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 @@ static void do_versions(FileData *fd, Library *lib, Main *main) 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)) { |