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:
authorBrecht Van Lommel <brechtvanlommel@gmail.com>2018-03-05 00:45:22 +0300
committerBrecht Van Lommel <brechtvanlommel@gmail.com>2019-05-17 21:03:26 +0300
commit3022dd2b27fdfd8aca369bfb0e390965de448b7a (patch)
treeeea6afe132dd000bcf57cc5a35fc3261588d73ec /source/blender/editors/space_image
parent60a4342557f19dab8e17825800bca4fbb3cccb85 (diff)
Images: changes to avoid losing new images that have not been saved
The basic idea is that such new images will be packed into the .blend file when saving all modified images from the quit dialog. To make this workflow nicer a number of changes were made to how this type of packed image is handled. * "Save Modified Images" now packs generated images into the .blend file. * "Save As" for packed images now automatically unpacks the image, so that it's easy to save automatically packed images. "Save Copy" keeps it packed. * "Save" for packed images now re-saves the image into the .blend file, so that it's effectively the equivalent of "Save" for non-packed images. * Empty image filepaths are no longer remapped when saving the .blend file. Previously it would become e.g. "//../../" which makes no sense for generated images with no filepath yet. * Hide unpack button and filepath for such packed images with no filepath. Unpacking does not work in a predictable way without a filepath, better to just "Save As".
Diffstat (limited to 'source/blender/editors/space_image')
-rw-r--r--source/blender/editors/space_image/image_buttons.c13
-rw-r--r--source/blender/editors/space_image/image_ops.c121
2 files changed, 86 insertions, 48 deletions
diff --git a/source/blender/editors/space_image/image_buttons.c b/source/blender/editors/space_image/image_buttons.c
index 59896391cca..68af854e367 100644
--- a/source/blender/editors/space_image/image_buttons.c
+++ b/source/blender/editors/space_image/image_buttons.c
@@ -928,11 +928,16 @@ void uiTemplateImage(uiLayout *layout,
layout = uiLayoutColumn(layout, false);
uiLayoutSetEnabled(layout, !is_dirty);
+ /* Image source */
uiItemR(layout, &imaptr, "source", 0, NULL, ICON_NONE);
- if (ima->source != IMA_SRC_GENERATED) {
+ /* Filepath */
+ const bool is_packed = BKE_image_has_packedfile(ima);
+ const bool no_filepath = is_packed && !BKE_image_has_filepath(ima);
+
+ if ((ima->source != IMA_SRC_GENERATED) && !no_filepath) {
row = uiLayoutRow(layout, true);
- if (BKE_image_has_packedfile(ima)) {
+ if (is_packed) {
uiItemO(row, "", ICON_PACKAGE, "image.unpack");
}
else {
@@ -940,12 +945,12 @@ void uiTemplateImage(uiLayout *layout,
}
row = uiLayoutRow(row, true);
- uiLayoutSetEnabled(row, BKE_image_has_packedfile(ima) == false);
+ uiLayoutSetEnabled(row, is_packed == false);
uiItemR(row, &imaptr, "filepath", 0, "", ICON_NONE);
uiItemO(row, "", ICON_FILE_REFRESH, "image.reload");
}
- /* multilayer? */
+ /* Image layers and Info */
if (ima->type == IMA_TYPE_MULTILAYER && ima->rr) {
const float dpi_fac = UI_DPI_FAC;
uiblock_layer_pass_buttons(layout, ima, ima->rr, iuser, 230 * dpi_fac, NULL);
diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c
index 03e1d80e267..07c2d216a93 100644
--- a/source/blender/editors/space_image/image_ops.c
+++ b/source/blender/editors/space_image/image_ops.c
@@ -244,42 +244,6 @@ static bool imbuf_format_writeable(const ImBuf *ibuf)
return (BKE_image_imtype_to_ftype(im_format.imtype, &options_dummy) == ibuf->ftype);
}
-static bool space_image_file_exists_poll(bContext *C)
-{
- if (image_buffer_exists_from_context(C) == false) {
- return false;
- }
-
- Main *bmain = CTX_data_main(C);
- Image *ima = image_from_context(C);
- ImageUser *iuser = image_user_from_context(C);
- void *lock;
- ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, &lock);
- bool ret = false;
-
- if (ibuf) {
- char name[FILE_MAX];
- BLI_strncpy(name, ibuf->name, FILE_MAX);
- BLI_path_abs(name, BKE_main_blendfile_path(bmain));
-
- if (BLI_exists(name) == false) {
- CTX_wm_operator_poll_msg_set(C, "image file not found");
- }
- else if (!BLI_file_is_writable(name)) {
- CTX_wm_operator_poll_msg_set(C, "image path can't be written to");
- }
- else if (!imbuf_format_writeable(ibuf)) {
- CTX_wm_operator_poll_msg_set(C, "image format is read-only");
- }
- else {
- ret = true;
- }
- }
-
- BKE_image_release_ibuf(ima, ibuf, lock);
- return ret;
-}
-
bool space_image_main_region_poll(bContext *C)
{
SpaceImage *sima = CTX_wm_space_image(C);
@@ -1882,7 +1846,12 @@ static int image_save_as_exec(bContext *C, wmOperator *op)
save_image_op(C, op, &opts);
+ if (opts.save_copy == false) {
+ BKE_image_free_packedfiles(image);
+ }
+
image_save_as_free(op);
+
return OPERATOR_FINISHED;
}
@@ -2035,6 +2004,61 @@ void IMAGE_OT_save_as(wmOperatorType *ot)
/******************** save image operator ********************/
+static bool image_file_path_saveable(bContext *C, Image *ima, ImageUser *iuser)
+{
+ /* Can always repack images. */
+ if (BKE_image_has_packedfile(ima)) {
+ return true;
+ }
+
+ /* Test for valid filepath. */
+ void *lock;
+ ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, &lock);
+ bool ret = false;
+
+ if (ibuf) {
+ Main *bmain = CTX_data_main(C);
+ char name[FILE_MAX];
+ BLI_strncpy(name, ibuf->name, FILE_MAX);
+ BLI_path_abs(name, BKE_main_blendfile_path(bmain));
+
+ if (BLI_exists(name) == false) {
+ CTX_wm_operator_poll_msg_set(C, "image file not found");
+ }
+ else if (!BLI_file_is_writable(name)) {
+ CTX_wm_operator_poll_msg_set(C, "image path can't be written to");
+ }
+ else if (!imbuf_format_writeable(ibuf)) {
+ CTX_wm_operator_poll_msg_set(C, "image format is read-only");
+ }
+ else {
+ ret = true;
+ }
+ }
+
+ BKE_image_release_ibuf(ima, ibuf, lock);
+ return ret;
+}
+
+static bool image_save_poll(bContext *C)
+{
+ /* Can't save if there are no pixels. */
+ if (image_buffer_exists_from_context(C) == false) {
+ return false;
+ }
+
+ Image *ima = image_from_context(C);
+ ImageUser *iuser = image_user_from_context(C);
+
+ /* Images without a filepath will go to save as. */
+ if (!BKE_image_has_filepath(ima)) {
+ return true;
+ }
+
+ /* Check if there is a valid file path and image format we can write. */
+ return image_file_path_saveable(C, ima, iuser);
+}
+
static int image_save_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
@@ -2043,6 +2067,12 @@ static int image_save_exec(bContext *C, wmOperator *op)
Scene *scene = CTX_data_scene(C);
ImageSaveOptions opts;
+ if (BKE_image_has_packedfile(image)) {
+ /* Save packed files to memory. */
+ BKE_image_memorypack(image);
+ return OPERATOR_FINISHED;
+ }
+
BKE_image_save_options_init(&opts, bmain, scene);
if (image_save_options_init(bmain, &opts, image, iuser, false, false) == 0) {
return OPERATOR_CANCELLED;
@@ -2066,13 +2096,15 @@ static int image_save_exec(bContext *C, wmOperator *op)
static int image_save_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
- if (space_image_file_exists_poll(C)) {
- return image_save_exec(C, op);
- }
- else {
+ Image *ima = image_from_context(C);
+
+ if (!BKE_image_has_packedfile(ima) && !BKE_image_has_filepath(ima)) {
WM_operator_name_call(C, "IMAGE_OT_save_as", WM_OP_INVOKE_DEFAULT, NULL);
return OPERATOR_CANCELLED;
}
+ else {
+ return image_save_exec(C, op);
+ }
}
void IMAGE_OT_save(wmOperatorType *ot)
@@ -2085,7 +2117,7 @@ void IMAGE_OT_save(wmOperatorType *ot)
/* api callbacks */
ot->exec = image_save_exec;
ot->invoke = image_save_invoke;
- ot->poll = image_save_as_poll;
+ ot->poll = image_save_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@@ -2192,7 +2224,8 @@ static bool image_should_be_saved_when_modified(Image *ima)
static bool image_should_be_saved(Image *ima)
{
- if (BKE_image_is_dirty(ima) && (ima->source == IMA_SRC_FILE)) {
+ if (BKE_image_is_dirty(ima) &&
+ (ima->source == IMA_SRC_FILE || ima->source == IMA_SRC_GENERATED)) {
return image_should_be_saved_when_modified(ima);
}
else {
@@ -2219,7 +2252,7 @@ int ED_image_save_all_modified_info(const bContext *C, ReportList *reports)
for (Image *ima = bmain->images.first; ima; ima = ima->id.next) {
if (image_should_be_saved(ima)) {
- if (BKE_image_has_packedfile(ima)) {
+ if (BKE_image_has_packedfile(ima) || (ima->source == IMA_SRC_GENERATED)) {
if (ima->id.lib == NULL) {
num_saveable_images++;
}
@@ -2268,7 +2301,7 @@ bool ED_image_save_all_modified(const bContext *C, ReportList *reports)
for (Image *ima = bmain->images.first; ima; ima = ima->id.next) {
if (image_should_be_saved(ima)) {
- if (BKE_image_has_packedfile(ima)) {
+ if (BKE_image_has_packedfile(ima) || (ima->source == IMA_SRC_GENERATED)) {
BKE_image_memorypack(ima);
}
else {