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:
authorSergey Sharybin <sergey@blender.org>2022-06-30 16:17:30 +0300
committerSergey Sharybin <sergey@blender.org>2022-07-01 10:44:07 +0300
commitc922b9e2c145b0c945fdb9d99f1209df3bf8bad0 (patch)
tree0a9ef081505cf0caaad36aa764b3db770622481c /source/blender/blenkernel/intern/image.cc
parentb872ad037aaaffb6783cee9339ce4d876fc1ffca (diff)
Fix image-from-imbuf resulting in invalid image configuration
The image which source is set to file is not expected to have empty file path. If it happens it becomes very tricky to save the image on exit using the standard quit dialog. This change makes it so if the image buffer does not have file path then the new image is set to the "generated" source and it behaves as if the image was created like so and was fully painted on. Additionally, mark image as dirty, so that quitting Blender after such image was added will warn about possible data loss.
Diffstat (limited to 'source/blender/blenkernel/intern/image.cc')
-rw-r--r--source/blender/blenkernel/intern/image.cc27
1 files changed, 22 insertions, 5 deletions
diff --git a/source/blender/blenkernel/intern/image.cc b/source/blender/blenkernel/intern/image.cc
index 0c4dc3c87f3..ed8652ca470 100644
--- a/source/blender/blenkernel/intern/image.cc
+++ b/source/blender/blenkernel/intern/image.cc
@@ -1174,18 +1174,35 @@ Image *BKE_image_add_generated(Main *bmain,
Image *BKE_image_add_from_imbuf(Main *bmain, ImBuf *ibuf, const char *name)
{
- Image *ima;
-
if (name == nullptr) {
name = BLI_path_basename(ibuf->name);
}
- ima = image_alloc(bmain, name, IMA_SRC_FILE, IMA_TYPE_IMAGE);
+ /* When the image buffer has valid path create a new image with "file" source and copy the path
+ * from the image buffer.
+ * Otherwise create "generated" image, avoiding invalid configuration with an empty file path. */
+ const eImageSource source = ibuf->name[0] != '\0' ? IMA_SRC_FILE : IMA_SRC_GENERATED;
- if (ima) {
+ Image *ima = image_alloc(bmain, name, source, IMA_TYPE_IMAGE);
+
+ if (!ima) {
+ return nullptr;
+ }
+
+ if (source == IMA_SRC_FILE) {
STRNCPY(ima->filepath, ibuf->name);
- image_assign_ibuf(ima, ibuf, IMA_NO_INDEX, 0);
}
+ else if (ibuf->rect_float) {
+ /* For the consistency with manual image creation: when the image buffer is float reflect it in
+ * the generated flags. */
+ ima->gen_flag |= IMA_GEN_FLOAT;
+ }
+
+ image_assign_ibuf(ima, ibuf, IMA_NO_INDEX, 0);
+
+ /* Consider image dirty since its content can not be re-created unless the image is explicitly
+ * saved. */
+ BKE_image_mark_dirty(ima, ibuf);
return ima;
}