diff options
author | Campbell Barton <ideasman42@gmail.com> | 2021-09-06 13:04:25 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2021-09-06 13:04:25 +0300 |
commit | a0912ff5663b950222ef00485a3853bfb6001db4 (patch) | |
tree | 86d109d8543ae752e802af6d7f4998d3be218741 /source/blender/imbuf/intern | |
parent | 49f1695ed06792ea1f4d1a43d30170c407f227f8 (diff) |
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.
Diffstat (limited to 'source/blender/imbuf/intern')
-rw-r--r-- | source/blender/imbuf/intern/allocimbuf.c | 12 |
1 files changed, 10 insertions, 2 deletions
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; } |