[Bf-blender-cvs] [fde03ec] input_method_editor: Minor edits to T42649 fix
Campbell Barton
noreply at git.blender.org
Mon Nov 24 00:45:46 CET 2014
Commit: fde03ec5789be41731db82d72394fdc50fc3ba10
Author: Campbell Barton
Date: Sun Nov 23 22:00:26 2014 +0100
Branches: input_method_editor
https://developer.blender.org/rBfde03ec5789be41731db82d72394fdc50fc3ba10
Minor edits to T42649 fix
- only modify paths for newly loaded images
- don't attempt to read from library paths
===================================================================
M source/blender/blenkernel/BKE_image.h
M source/blender/blenkernel/intern/image.c
M source/blender/editors/space_node/node_add.c
M source/blender/editors/space_view3d/view3d_edit.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h
index dc3d9f3..a225a27 100644
--- a/source/blender/blenkernel/BKE_image.h
+++ b/source/blender/blenkernel/BKE_image.h
@@ -162,6 +162,7 @@ void BKE_image_alpha_mode_from_extension(struct Image *image);
/* returns a new image or NULL if it can't load */
struct Image *BKE_image_load(struct Main *bmain, const char *filepath);
/* returns existing Image when filename/type is same (frame optional) */
+struct Image *BKE_image_load_exists_ex(const char *filepath, bool *r_exists);
struct Image *BKE_image_load_exists(const char *filepath);
/* adds image, adds ibuf, generates color or pattern */
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index 54f5cb7..eaf173a 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -661,7 +661,7 @@ Image *BKE_image_load(Main *bmain, const char *filepath)
/* otherwise creates new. */
/* does not load ibuf itself */
/* pass on optional frame for #name images */
-Image *BKE_image_load_exists(const char *filepath)
+Image *BKE_image_load_exists_ex(const char *filepath, bool *r_exists)
{
Image *ima;
char str[FILE_MAX], strtest[FILE_MAX];
@@ -681,16 +681,24 @@ Image *BKE_image_load_exists(const char *filepath)
ima->id.us++; /* officially should not, it doesn't link here! */
if (ima->ok == 0)
ima->ok = IMA_OK;
- /* RETURN! */
+ if (r_exists)
+ *r_exists = true;
return ima;
}
}
}
}
+ if (r_exists)
+ *r_exists = false;
return BKE_image_load(G.main, filepath);
}
+Image *BKE_image_load_exists(const char *filepath)
+{
+ return BKE_image_load_exists_ex(filepath, NULL);
+}
+
static ImBuf *add_ibuf_size(unsigned int width, unsigned int height, const char *name, int depth, int floatbuf, short gen_type,
const float color[4], ColorManagedColorspaceSettings *colorspace_settings)
{
diff --git a/source/blender/editors/space_node/node_add.c b/source/blender/editors/space_node/node_add.c
index 33eb24a..a22ccac 100644
--- a/source/blender/editors/space_node/node_add.c
+++ b/source/blender/editors/space_node/node_add.c
@@ -307,6 +307,7 @@ static int node_add_file_exec(bContext *C, wmOperator *op)
bNode *node;
Image *ima = NULL;
int type = 0;
+ bool exists = false;
const bool is_relative_path = RNA_boolean_get(op->ptr, "relative_path");
@@ -317,7 +318,7 @@ static int node_add_file_exec(bContext *C, wmOperator *op)
errno = 0;
- ima = BKE_image_load_exists(path);
+ ima = BKE_image_load_exists_ex(path, &exists);
if (!ima) {
BKE_reportf(op->reports, RPT_ERROR, "Cannot read image '%s': %s",
@@ -326,9 +327,10 @@ static int node_add_file_exec(bContext *C, wmOperator *op)
}
if (is_relative_path) {
- Main *bmain = CTX_data_main(C);
- const char *relbase = ID_BLEND_PATH(bmain, &ima->id);
- BLI_path_rel(ima->name, relbase);
+ if (exists == false) {
+ Main *bmain = CTX_data_main(C);
+ BLI_path_rel(ima->name, bmain->name);
+ }
}
}
else if (RNA_struct_property_is_set(op->ptr, "name")) {
diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c
index 1eed56a..4e997d0 100644
--- a/source/blender/editors/space_view3d/view3d_edit.c
+++ b/source/blender/editors/space_view3d/view3d_edit.c
@@ -4283,6 +4283,7 @@ static int background_image_add_invoke(bContext *C, wmOperator *op, const wmEven
Image *ima = NULL;
BGpic *bgpic;
char name[MAX_ID_NAME - 2];
+ bool exists = false;
const bool is_relative_path = RNA_boolean_get(op->ptr, "relative_path");
@@ -4291,20 +4292,22 @@ static int background_image_add_invoke(bContext *C, wmOperator *op, const wmEven
char path[FILE_MAX];
RNA_string_get(op->ptr, "filepath", path);
- ima = BKE_image_load_exists(path);
+ ima = BKE_image_load_exists_ex(path, &exists);
}
else if (RNA_struct_property_is_set(op->ptr, "name")) {
RNA_string_get(op->ptr, "name", name);
ima = (Image *)BKE_libblock_find_name(ID_IM, name);
+ exists = true;
}
bgpic = background_image_add(C);
if (ima) {
if (is_relative_path) {
- Main *bmain = CTX_data_main(C);
- const char *relbase = ID_BLEND_PATH(bmain, &ima->id);
- BLI_path_rel(ima->name, relbase);
+ if (exists == false) {
+ Main *bmain = CTX_data_main(C);
+ BLI_path_rel(ima->name, bmain->name);
+ }
}
bgpic->ima = ima;
More information about the Bf-blender-cvs
mailing list