Commit: a0912ff5663b950222ef00485a3853bfb6001db4
Author: Campbell Barton
Date: Mon Sep 6 20:04:25 2021 +1000
Branches: master
https://developer.blender.org/rBa0912ff5663b950222ef00485a3853bfb6001db4
Cleanup: support passing in arbitrary buffers to IMB_allocFromBuffer
Also remove IB_metadata flag from the resulting imbuf as this image
has no meta-data.
===================================================================
M source/blender/blenkernel/intern/main.c
M source/blender/imbuf/intern/allocimbuf.c
===================================================================
diff --git a/source/blender/blenkernel/intern/main.c
b/source/blender/blenkernel/intern/main.c
index bb33f5f9f87..981f1d4a623 100644
--- a/source/blender/blenkernel/intern/main.c
+++ b/source/blender/blenkernel/intern/main.c
@@ -405,11 +405,8 @@ ImBuf *BKE_main_thumbnail_to_imbuf(Main *bmain,
BlendThumbnail *data)
}
if (data) {
- /* NOTE: we cannot use IMB_allocFromBuffer(), since it tries to dupalloc
passed buffer,
- * which will fail here (we do not want to pass the first two
ints!). */
- img = IMB_allocImBuf(
- (unsigned int)data->width, (unsigned int)data->height, 32, IB_rect |
IB_metadata);
- memcpy(img->rect, data->rect, BLEN_THUMB_MEMSIZE(data->width,
data->height) - sizeof(*data));
+ img = IMB_allocFromBuffer(
+ (const uint *)data->rect, NULL, (uint)data->width, (uint)data->height,
4);
}
return img;
diff --git a/source/blender/imbuf/intern/allocimbuf.c
b/source/blender/imbuf/intern/allocimbuf.c
index 90c863878ff..d327981f583 100644
--- a/source/blender/imbuf/intern/allocimbuf.c
+++ b/source/blender/imbuf/intern/allocimbuf.c
@@ -445,13 +445,21 @@ struct ImBuf *IMB_allocFromBuffer(const unsigned int
*rect,
ibuf = IMB_allocImBuf(w, h, 32, 0);
ibuf->channels = channels;
+
+ /* Avoid #MEM_dupallocN since the buffers might not be allocated using
guarded-allocation. */
if (rectf) {
- ibuf->rect_float = MEM_dupallocN(rectf);
+ const size_t size = sizeof(float[4]) * w * h;
+ ibuf->rect_float = MEM_mallocN(sizeof(float[4]) * w * h, __func__);
+ memcpy(ibuf->rect_float, rectf, size);
+
ibuf->flags |= IB_rectfloat;
ibuf->mall |= IB_rectfloat;
}
if (rect) {
- ibuf->rect = MEM_dupallocN(rect);
+ const size_t size = sizeof(uchar[4]) * w * h;
+ ibuf->rect = MEM_mallocN(size, __func__);
+ memcpy(ibuf->rect, rect, size);
+
ibuf->flags |= IB_rect;
ibuf->mall |= IB_rect;
}
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs