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.c137
1 files changed, 134 insertions, 3 deletions
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index f16b1e6b4ec..08440849a4e 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -60,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"
@@ -313,6 +317,133 @@ 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) {
+ Image *iman= copy_image(ima);
+
+ iman->id.us= 0;
+
+ /* Remap paths of new ID using old library as base. */
+ BKE_id_lib_local_paths(bmain, &iman->id);
+
+ 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;
@@ -849,7 +980,7 @@ int BKE_add_image_extension(char *string, int imtype)
|| (G.have_quicktime && BLI_testextensie_array(string, imb_ext_image_qt))) {
return BLI_replace_extension(string, FILE_MAX, extension);
} else {
- strcat(string, extension);
+ return BLI_ensure_extension(string, FILE_MAX, extension);
return TRUE;
}
@@ -1368,7 +1499,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;
@@ -1816,7 +1947,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;