Minor edits to T42649 fix

- only modify paths for newly loaded images
- don't attempt to read from library paths
This commit is contained in:
Campbell Barton 2014-11-23 22:00:26 +01:00
parent 48a720055f
commit 888ab78edf
4 changed files with 24 additions and 10 deletions

View File

@ -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 */

View File

@ -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)
{

View File

@ -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")) {

View File

@ -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;