From 151cc02b6f8234c94a65618ae0437403e1aba689 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 2 Oct 2019 00:07:06 +1000 Subject: Image: support storing full image buffers for each undo step Update image undo to store buffers for each step: - Undo buffers share tiles to avoid using too much memory. - Undo support for different sized buffers allowing operations such as crop or resize. - Paint tiles have been split into separate API/storage. - Painting speed wont be impacted significantly since storing the extra tiles is done after the stroke & only for the first undo step. Resolves T61263, see D5939 for details. --- source/blender/imbuf/IMB_imbuf.h | 2 ++ source/blender/imbuf/intern/rectop.c | 39 ++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) (limited to 'source/blender/imbuf') diff --git a/source/blender/imbuf/IMB_imbuf.h b/source/blender/imbuf/IMB_imbuf.h index 6e49630dc46..9e9c47194e1 100644 --- a/source/blender/imbuf/IMB_imbuf.h +++ b/source/blender/imbuf/IMB_imbuf.h @@ -228,6 +228,8 @@ void IMB_blend_color_float(float dst[4], void IMB_rect_crop(struct ImBuf *ibuf, const struct rcti *crop); +void IMB_rect_size_set(struct ImBuf *ibuf, const uint size[2]); + void IMB_rectclip(struct ImBuf *dbuf, const struct ImBuf *sbuf, int *destx, diff --git a/source/blender/imbuf/intern/rectop.c b/source/blender/imbuf/intern/rectop.c index b8ea6c2ea03..3163a960892 100644 --- a/source/blender/imbuf/intern/rectop.c +++ b/source/blender/imbuf/intern/rectop.c @@ -279,6 +279,45 @@ void IMB_rect_crop(ImBuf *ibuf, const rcti *crop) ibuf->y = size_dst[1]; } +/** Re-alloc buffers at a new size */ + +static void rect_realloc_4bytes(void **buf_p, const uint size[2]) +{ + if (*buf_p == NULL) { + return; + } + MEM_freeN(*buf_p); + *buf_p = MEM_mallocN(sizeof(uint) * size[0] * size[1], __func__); +} + +static void rect_realloc_16bytes(void **buf_p, const uint size[2]) +{ + if (*buf_p == NULL) { + return; + } + MEM_freeN(*buf_p); + *buf_p = MEM_mallocN(sizeof(uint[4]) * size[0] * size[1], __func__); +} + +/** + * In-place size setting (caller must fill in buffer contents). + */ +void IMB_rect_size_set(ImBuf *ibuf, const uint size[2]) +{ + BLI_assert(size[0] > 0 && size[0] > 0); + if ((size[0] == ibuf->x) && (size[1] == ibuf->y)) { + return; + } + + rect_realloc_4bytes((void **)&ibuf->rect, size); + rect_realloc_4bytes((void **)&ibuf->zbuf, size); + rect_realloc_4bytes((void **)&ibuf->zbuf_float, size); + rect_realloc_16bytes((void **)&ibuf->rect_float, size); + + ibuf->x = size[0]; + ibuf->y = size[1]; +} + /* clipping */ void IMB_rectclip(ImBuf *dbuf, -- cgit v1.2.3