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:
authorCampbell Barton <ideasman42@gmail.com>2021-09-06 13:04:26 +0300
committerCampbell Barton <ideasman42@gmail.com>2021-09-06 13:05:58 +0300
commit687f70ceca88324fb8f376e086a55b341dd34e6f (patch)
tree1d9b467aecc63dbb78c77d67d046e3a86527cef1 /source/blender/imbuf
parenta0912ff5663b950222ef00485a3853bfb6001db4 (diff)
ImBuf: add IMB_allocFromBufferOwn that takes ownership of the buffer
Avoids duplicating the image buffer when saving thumbnails.
Diffstat (limited to 'source/blender/imbuf')
-rw-r--r--source/blender/imbuf/IMB_imbuf.h8
-rw-r--r--source/blender/imbuf/intern/allocimbuf.c35
2 files changed, 43 insertions, 0 deletions
diff --git a/source/blender/imbuf/IMB_imbuf.h b/source/blender/imbuf/IMB_imbuf.h
index 4ad7aa98484..dd8e6549e24 100644
--- a/source/blender/imbuf/IMB_imbuf.h
+++ b/source/blender/imbuf/IMB_imbuf.h
@@ -150,6 +150,14 @@ bool IMB_initImBuf(
/**
* Create a copy of a pixel buffer and wrap it to a new ImBuf
+ * (transferring ownership to the in imbuf).
+ * \attention Defined in allocimbuf.c
+ */
+struct ImBuf *IMB_allocFromBufferOwn(
+ unsigned int *rect, float *rectf, unsigned int w, unsigned int h, unsigned int channels);
+
+/**
+ * Create a copy of a pixel buffer and wrap it to a new ImBuf
* \attention Defined in allocimbuf.c
*/
struct ImBuf *IMB_allocFromBuffer(const unsigned int *rect,
diff --git a/source/blender/imbuf/intern/allocimbuf.c b/source/blender/imbuf/intern/allocimbuf.c
index d327981f583..c2bff9ddc51 100644
--- a/source/blender/imbuf/intern/allocimbuf.c
+++ b/source/blender/imbuf/intern/allocimbuf.c
@@ -430,6 +430,41 @@ bool imb_addrectImBuf(ImBuf *ibuf)
return false;
}
+/**
+ * \param take_ownership: When true, the buffers become owned by the resulting image.
+ */
+struct ImBuf *IMB_allocFromBufferOwn(
+ unsigned int *rect, float *rectf, unsigned int w, unsigned int h, unsigned int channels)
+{
+ ImBuf *ibuf = NULL;
+
+ if (!(rect || rectf)) {
+ return NULL;
+ }
+
+ 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) {
+ BLI_assert(MEM_allocN_len(rectf) == sizeof(float[4]) * w * h);
+ ibuf->rect_float = rectf;
+
+ ibuf->flags |= IB_rectfloat;
+ ibuf->mall |= IB_rectfloat;
+ }
+ if (rect) {
+ BLI_assert(MEM_allocN_len(rect) == sizeof(uchar[4]) * w * h);
+ ibuf->rect = rect;
+
+ ibuf->flags |= IB_rect;
+ ibuf->mall |= IB_rect;
+ }
+
+ return ibuf;
+}
+
struct ImBuf *IMB_allocFromBuffer(const unsigned int *rect,
const float *rectf,
unsigned int w,