diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-11-24 00:00:26 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-11-24 00:05:24 +0300 |
commit | 888ab78edfad4f9c2bdd31764eb95eb347a8c2d8 (patch) | |
tree | f7d60d20fa245facea2963d483eb6cf40d656101 /source | |
parent | 48a720055f736c5be257f85c22589f81f09247a8 (diff) |
Minor edits to T42649 fix
- only modify paths for newly loaded images
- don't attempt to read from library paths
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/BKE_image.h | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/image.c | 12 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_add.c | 10 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_edit.c | 11 |
4 files changed, 24 insertions, 10 deletions
diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h index dc3d9f38b21..a225a27a00b 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 54f5cb7a68e..eaf173a7382 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 33eb24ae92a..a22ccac5ecb 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 1eed56a750b..4e997d0eec3 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; |