Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2016-07-10 17:44:09 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2016-07-10 18:14:45 +0300
commitad5918d2781f5359e157728d3b25d34f0f810653 (patch)
treedc412058bcc8d83ecc87bc0e30f287d88b309bca /source/blender/blenkernel/intern/image.c
parentf35320bddfe745f348d19476654a34df611b37ba (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).
Diffstat (limited to 'source/blender/blenkernel/intern/image.c')
-rw-r--r--source/blender/blenkernel/intern/image.c153
1 files changed, 15 insertions, 138 deletions
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);
}
}
}