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:
Diffstat (limited to 'source/blender/blenkernel/intern/image.c')
-rw-r--r--source/blender/blenkernel/intern/image.c138
1 files changed, 134 insertions, 4 deletions
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index 37982e7fec9..8bce7515695 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -1,6 +1,4 @@
/*
- * $Id$
- *
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
@@ -62,10 +60,14 @@
#include "DNA_camera_types.h"
#include "DNA_sequence_types.h"
#include "DNA_userdef_types.h"
+#include "DNA_brush_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
#include "BLI_blenlib.h"
#include "BLI_threads.h"
#include "BLI_utildefines.h"
+#include "BLI_bpath.h"
#include "BKE_bmfont.h"
#include "BKE_global.h"
@@ -315,6 +317,134 @@ Image *copy_image(Image *ima)
return nima;
}
+static void extern_local_image(Image *UNUSED(ima))
+{
+ /* Nothing to do: images don't link to other IDs. This function exists to
+ match id_make_local pattern. */
+}
+
+void make_local_image(struct Image *ima)
+{
+ Main *bmain= G.main;
+ Tex *tex;
+ Brush *brush;
+ Mesh *me;
+ int is_local= FALSE, is_lib= FALSE;
+
+ /* - only lib users: do nothing
+ * - only local users: set flag
+ * - mixed: make copy
+ */
+
+ if(ima->id.lib==NULL) 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);
+ return;
+ }
+#endif
+
+ for(tex= bmain->tex.first; tex; tex= tex->id.next) {
+ if(tex->ima == ima) {
+ if(tex->id.lib) is_lib= TRUE;
+ else is_local= TRUE;
+ }
+ }
+ for(brush= bmain->brush.first; brush; brush= brush->id.next) {
+ if(brush->clone.image == ima) {
+ if(brush->id.lib) 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(me->id.lib) is_lib= TRUE;
+ else is_local= TRUE;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if(is_local && is_lib == FALSE) {
+ id_clear_lib_data(bmain, &ima->id);
+ extern_local_image(ima);
+ }
+ else if(is_local && is_lib) {
+ char *bpath_user_data[2]= {bmain->name, ima->id.lib->filepath};
+ Image *iman= copy_image(ima);
+
+ iman->id.us= 0;
+
+ /* Remap paths of new ID using old library as base. */
+ bpath_traverse_id(bmain, &iman->id, bpath_relocate_visitor, 0, bpath_user_data);
+
+ tex= bmain->tex.first;
+ while(tex) {
+ if(tex->id.lib==NULL) {
+ if(tex->ima==ima) {
+ tex->ima = iman;
+ iman->id.us++;
+ ima->id.us--;
+ }
+ }
+ tex= tex->id.next;
+ }
+ brush= bmain->brush.first;
+ while(brush) {
+ if(brush->id.lib==NULL) {
+ if(brush->clone.image==ima) {
+ brush->clone.image = iman;
+ iman->id.us++;
+ ima->id.us--;
+ }
+ }
+ 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 = iman;
+ if(iman->id.us == 0) {
+ tface->tpage->id.us= 1;
+ }
+ id_lib_extern((ID*)iman);
+ }
+ }
+ }
+ }
+ }
+ me= me->id.next;
+ }
+ }
+}
+
void BKE_image_merge(Image *dest, Image *source)
{
ImBuf *ibuf;
@@ -1370,7 +1500,7 @@ void BKE_makepicstring(char *string, const char *base, int frame, int imtype, co
}
/* used by sequencer too */
-struct anim *openanim(char *name, int flags, int streamindex)
+struct anim *openanim(const char *name, int flags, int streamindex)
{
struct anim *anim;
struct ImBuf *ibuf;
@@ -1818,7 +1948,7 @@ static ImBuf *image_load_image_file(Image *ima, ImageUser *iuser, int cfra)
flag = IB_rect|IB_multilayer;
if(ima->flag & IMA_DO_PREMUL) flag |= IB_premul;
- ibuf = IMB_ibImageFromMemory((unsigned char*)ima->packedfile->data, ima->packedfile->size, flag);
+ ibuf = IMB_ibImageFromMemory((unsigned char*)ima->packedfile->data, ima->packedfile->size, flag, "<packed data>");
}
else {
flag= IB_rect|IB_multilayer|IB_metadata;