diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2016-07-10 17:44:09 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2016-07-10 18:14:45 +0300 |
commit | ad5918d2781f5359e157728d3b25d34f0f810653 (patch) | |
tree | dc412058bcc8d83ecc87bc0e30f287d88b309bca | |
parent | f35320bddfe745f348d19476654a34df611b37ba (diff) |
Refactor/enhance BKE_image_make_local().
Now using modern features from libquery/libremap areas.
Provides same kind of fixes/improvements as for BKE_object_make_local() (see rBd1a4ae3f395a6).
-rw-r--r-- | source/blender/blenkernel/BKE_image.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/image.c | 153 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/library.c | 2 |
3 files changed, 17 insertions, 140 deletions
diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h index eb98268c9f0..0895feef983 100644 --- a/source/blender/blenkernel/BKE_image.h +++ b/source/blender/blenkernel/BKE_image.h @@ -108,7 +108,7 @@ struct anim *openanim_noload(const char *name, int flags, int streamindex, char void BKE_image_de_interlace(struct Image *ima, int odd); -void BKE_image_make_local(struct Image *ima); +void BKE_image_make_local(struct Main *bmain, struct Image *ima); void BKE_image_tag_time(struct Image *ima); diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index 790b6c6854b..587912c8fed 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -72,6 +72,8 @@ #include "BKE_icons.h" #include "BKE_image.h" #include "BKE_library.h" +#include "BKE_library_query.h" +#include "BKE_library_remap.h" #include "BKE_main.h" #include "BKE_packedFile.h" #include "BKE_report.h" @@ -470,12 +472,8 @@ static void extern_local_image(Image *UNUSED(ima)) * match id_make_local pattern. */ } -void BKE_image_make_local(struct Image *ima) +void BKE_image_make_local(Main *bmain, Image *ima) { - Main *bmain = G.main; - Tex *tex; - Brush *brush; - Mesh *me; bool is_local = false, is_lib = false; /* - only lib users: do nothing @@ -483,147 +481,26 @@ void BKE_image_make_local(struct Image *ima) * - mixed: make copy */ - if (!ID_IS_LINKED_DATABLOCK(ima)) return; - - /* Can't take short cut here: must check meshes at least because of bogus - * texface ID refs. - z0r */ -#if 0 - if (ima->id.us == 1) { - id_clear_lib_data(bmain, &ima->id); - extern_local_image(ima); + if (!ID_IS_LINKED_DATABLOCK(ima)) { return; } -#endif - - for (tex = bmain->tex.first; tex; tex = tex->id.next) { - if (tex->ima == ima) { - if (ID_IS_LINKED_DATABLOCK(tex)) is_lib = true; - else is_local = true; - } - } - for (brush = bmain->brush.first; brush; brush = brush->id.next) { - if (brush->clone.image == ima) { - if (ID_IS_LINKED_DATABLOCK(brush)) is_lib = true; - else is_local = true; - } - } - for (me = bmain->mesh.first; me; me = me->id.next) { - if (me->mtface) { - MTFace *tface; - int a, i; - - for (i = 0; i < me->fdata.totlayer; i++) { - if (me->fdata.layers[i].type == CD_MTFACE) { - tface = (MTFace *)me->fdata.layers[i].data; - - for (a = 0; a < me->totface; a++, tface++) { - if (tface->tpage == ima) { - if (ID_IS_LINKED_DATABLOCK(me)) is_lib = true; - else is_local = true; - } - } - } - } - } - - if (me->mtpoly) { - MTexPoly *mtpoly; - int a, i; - for (i = 0; i < me->pdata.totlayer; i++) { - if (me->pdata.layers[i].type == CD_MTEXPOLY) { - mtpoly = (MTexPoly *)me->pdata.layers[i].data; + BKE_library_ID_test_usages(bmain, ima, &is_local, &is_lib); - for (a = 0; a < me->totpoly; a++, mtpoly++) { - if (mtpoly->tpage == ima) { - if (ID_IS_LINKED_DATABLOCK(me)) is_lib = true; - else is_local = true; - } - } - } - } + if (is_local) { + if (!is_lib) { + id_clear_lib_data(bmain, &ima->id); + extern_local_image(ima); } + else { + Image *ima_new = BKE_image_copy(bmain, ima); - } - - if (is_local && is_lib == false) { - id_clear_lib_data(bmain, &ima->id); - extern_local_image(ima); - } - else if (is_local && is_lib) { - Image *ima_new = BKE_image_copy(bmain, ima); - - ima_new->id.us = 0; - - /* Remap paths of new ID using old library as base. */ - BKE_id_lib_local_paths(bmain, ima->id.lib, &ima_new->id); - - tex = bmain->tex.first; - while (tex) { - if (!ID_IS_LINKED_DATABLOCK(tex)) { - if (tex->ima == ima) { - tex->ima = ima_new; - id_us_plus(&ima_new->id); - id_us_min(&ima->id); - } - } - tex = tex->id.next; - } - brush = bmain->brush.first; - while (brush) { - if (!ID_IS_LINKED_DATABLOCK(brush)) { - if (brush->clone.image == ima) { - brush->clone.image = ima_new; - id_us_plus(&ima_new->id); - id_us_min(&ima->id); - } - } - brush = brush->id.next; - } - /* Transfer references in texfaces. Texfaces don't add to image ID - * user count *unless* there are no other users. See - * readfile.c:lib_link_mtface. */ - me = bmain->mesh.first; - while (me) { - if (me->mtface) { - MTFace *tface; - int a, i; - - for (i = 0; i < me->fdata.totlayer; i++) { - if (me->fdata.layers[i].type == CD_MTFACE) { - tface = (MTFace *)me->fdata.layers[i].data; - - for (a = 0; a < me->totface; a++, tface++) { - if (tface->tpage == ima) { - tface->tpage = ima_new; - id_us_ensure_real((ID *)ima_new); - id_lib_extern((ID *)ima_new); - } - } - } - } - } - - if (me->mtpoly) { - MTexPoly *mtpoly; - int a, i; - - for (i = 0; i < me->pdata.totlayer; i++) { - if (me->pdata.layers[i].type == CD_MTEXPOLY) { - mtpoly = (MTexPoly *)me->pdata.layers[i].data; + ima_new->id.us = 0; - for (a = 0; a < me->totpoly; a++, mtpoly++) { - if (mtpoly->tpage == ima) { - mtpoly->tpage = ima_new; - id_us_ensure_real((ID *)ima_new); - id_lib_extern((ID *)ima_new); - } - } - } - } - } + /* Remap paths of new ID using old library as base. */ + BKE_id_lib_local_paths(bmain, ima->id.lib, &ima_new->id); - me = me->id.next; + BKE_libblock_remap(bmain, ima, ima_new, ID_REMAP_SKIP_INDIRECT_USAGE); } } } diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index faa28f71cfd..5f548b45fb1 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -282,7 +282,7 @@ bool id_make_local(Main *bmain, ID *id, bool test) if (!test) BKE_texture_make_local(bmain, (Tex *)id); return true; case ID_IM: - if (!test) BKE_image_make_local((Image *)id); + if (!test) BKE_image_make_local(bmain, (Image *)id); return true; case ID_LT: if (!test) BKE_lattice_make_local(bmain, (Lattice *)id); |