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:37:32 +0300
committerSergey Sharybin <sergey@blender.org>2022-07-01 10:44:07 +0300
commit72b9e07cf26ddeb26ea8773004b951a7f1bff7c5 (patch)
treeb76794bee925c8509ea1ba203938f51e671655e9 /source/blender/blenkernel/intern/image.cc
parentdfa5bd689e470ad9b8fc7328927afdbe0159e0c1 (diff)
Add helper function to replace buffer of a single-frame image
Very similar to BKE_image_add_from_imbuf with the exception that no new image data-block is created, but instead the given one is modified.
Diffstat (limited to 'source/blender/blenkernel/intern/image.cc')
-rw-r--r--source/blender/blenkernel/intern/image.cc40
1 files changed, 27 insertions, 13 deletions
diff --git a/source/blender/blenkernel/intern/image.cc b/source/blender/blenkernel/intern/image.cc
index b6294eb058c..92e98935e83 100644
--- a/source/blender/blenkernel/intern/image.cc
+++ b/source/blender/blenkernel/intern/image.cc
@@ -1216,23 +1216,37 @@ Image *BKE_image_add_from_imbuf(Main *bmain, ImBuf *ibuf, const char *name)
return nullptr;
}
- if (source == IMA_SRC_FILE) {
- STRNCPY(ima->filepath, ibuf->name);
- }
- 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;
- }
+ BKE_image_replace_imbuf(ima, ibuf);
+
+ return ima;
+}
+
+void BKE_image_replace_imbuf(Image *image, ImBuf *ibuf)
+{
+ BLI_assert(image->type == IMA_TYPE_IMAGE &&
+ ELEM(image->source, IMA_SRC_FILE, IMA_SRC_GENERATED));
+
+ BKE_image_free_buffers(image);
- image_assign_ibuf(ima, ibuf, IMA_NO_INDEX, 0);
- image_colorspace_from_imbuf(ima, ibuf);
+ image_assign_ibuf(image, ibuf, IMA_NO_INDEX, 0);
+ image_colorspace_from_imbuf(image, ibuf);
+
+ /* Keep generated image type flags consistent with the image buffer. */
+ if (image->source == IMA_SRC_GENERATED) {
+ if (ibuf->rect_float) {
+ image->gen_flag |= IMA_GEN_FLOAT;
+ }
+ else {
+ image->gen_flag &= ~IMA_GEN_FLOAT;
+ }
+
+ image->gen_x = ibuf->x;
+ image->gen_y = ibuf->y;
+ }
/* 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;
+ BKE_image_mark_dirty(image, ibuf);
}
/** Pack image buffer to memory as PNG or EXR. */