diff options
Diffstat (limited to 'source/blender/editors/space_image/image_undo.c')
-rw-r--r-- | source/blender/editors/space_image/image_undo.c | 63 |
1 files changed, 33 insertions, 30 deletions
diff --git a/source/blender/editors/space_image/image_undo.c b/source/blender/editors/space_image/image_undo.c index 79aa4d2ed7f..1394c05d7bc 100644 --- a/source/blender/editors/space_image/image_undo.c +++ b/source/blender/editors/space_image/image_undo.c @@ -34,16 +34,16 @@ #include "MEM_guardedalloc.h" -#include "BLI_math.h" #include "BLI_blenlib.h" -#include "BLI_utildefines.h" +#include "BLI_math.h" #include "BLI_threads.h" +#include "BLI_utildefines.h" #include "DNA_image_types.h" -#include "DNA_windowmanager_types.h" #include "DNA_object_types.h" #include "DNA_screen_types.h" #include "DNA_space_types.h" +#include "DNA_windowmanager_types.h" #include "IMB_imbuf.h" #include "IMB_imbuf_types.h" @@ -55,10 +55,10 @@ #include "DEG_depsgraph.h" +#include "ED_object.h" #include "ED_paint.h" #include "ED_undo.h" #include "ED_util.h" -#include "ED_object.h" #include "GPU_draw.h" @@ -107,7 +107,11 @@ typedef struct PaintTile { struct PaintTile *next, *prev; Image *image; ImBuf *ibuf; - int tile_number; + /* For 2D image painting the ImageUser uses most of the values. + * Even though views and passes are stored they are currently not supported for painting. + * For 3D projection painting this only uses a tile & frame number. + * The scene pointer must be cleared (or temporarily set it as needed, but leave cleared). */ + ImageUser iuser; union { float *fp; uint *uint; @@ -149,7 +153,7 @@ static void ptile_invalidate_list(ListBase *paint_tiles) void *ED_image_paint_tile_find(ListBase *paint_tiles, Image *image, ImBuf *ibuf, - int tile_number, + ImageUser *iuser, int x_tile, int y_tile, ushort **r_mask, @@ -157,11 +161,11 @@ void *ED_image_paint_tile_find(ListBase *paint_tiles, { for (PaintTile *ptile = paint_tiles->first; ptile; ptile = ptile->next) { if (ptile->x_tile == x_tile && ptile->y_tile == y_tile) { - if (ptile->image == image && ptile->ibuf == ibuf && ptile->tile_number == tile_number) { + if (ptile->image == image && ptile->ibuf == ibuf && ptile->iuser.tile == iuser->tile) { if (r_mask) { /* allocate mask if requested. */ if (!ptile->mask) { - ptile->mask = MEM_callocN(sizeof(ushort) * SQUARE(ED_IMAGE_UNDO_TILE_SIZE), + ptile->mask = MEM_callocN(sizeof(ushort) * square_i(ED_IMAGE_UNDO_TILE_SIZE), "UndoImageTile.mask"); } *r_mask = ptile->mask; @@ -180,7 +184,7 @@ void *ED_image_paint_tile_push(ListBase *paint_tiles, Image *image, ImBuf *ibuf, ImBuf **tmpibuf, - int tile_number, + ImageUser *iuser, int x_tile, int y_tile, ushort **r_mask, @@ -195,7 +199,7 @@ void *ED_image_paint_tile_push(ListBase *paint_tiles, /* in projective painting we keep accounting of tiles, so if we need one pushed, just push! */ if (find_prev) { void *data = ED_image_paint_tile_find( - paint_tiles, image, ibuf, tile_number, x_tile, y_tile, r_mask, true); + paint_tiles, image, ibuf, iuser, x_tile, y_tile, r_mask, true); if (data) { return data; } @@ -209,19 +213,20 @@ void *ED_image_paint_tile_push(ListBase *paint_tiles, ptile->image = image; ptile->ibuf = ibuf; - ptile->tile_number = tile_number; + ptile->iuser = *iuser; + ptile->iuser.scene = NULL; ptile->x_tile = x_tile; ptile->y_tile = y_tile; /* add mask explicitly here */ if (r_mask) { - *r_mask = ptile->mask = MEM_callocN(sizeof(ushort) * SQUARE(ED_IMAGE_UNDO_TILE_SIZE), + *r_mask = ptile->mask = MEM_callocN(sizeof(ushort) * square_i(ED_IMAGE_UNDO_TILE_SIZE), "PaintTile.mask"); } ptile->rect.pt = MEM_mapallocN((ibuf->rect_float ? sizeof(float[4]) : sizeof(char[4])) * - SQUARE(ED_IMAGE_UNDO_TILE_SIZE), + square_i(ED_IMAGE_UNDO_TILE_SIZE), "PaintTile.rect"); ptile->use_float = has_float; @@ -264,10 +269,7 @@ static void ptile_restore_runtime_list(ListBase *paint_tiles) for (PaintTile *ptile = paint_tiles->first; ptile; ptile = ptile->next) { Image *image = ptile->image; - ImageUser iuser; - BKE_imageuser_default(&iuser); - iuser.tile = ptile->tile_number; - ImBuf *ibuf = BKE_image_acquire_ibuf(image, &iuser, NULL); + ImBuf *ibuf = BKE_image_acquire_ibuf(image, &ptile->iuser, NULL); const bool has_float = (ibuf->rect_float != NULL); if (has_float) { @@ -333,10 +335,10 @@ static UndoImageTile *utile_alloc(bool has_float) { UndoImageTile *utile = MEM_callocN(sizeof(*utile), "ImageUndoTile"); if (has_float) { - utile->rect.fp = MEM_mallocN(sizeof(float[4]) * SQUARE(ED_IMAGE_UNDO_TILE_SIZE), __func__); + utile->rect.fp = MEM_mallocN(sizeof(float[4]) * square_i(ED_IMAGE_UNDO_TILE_SIZE), __func__); } else { - utile->rect.uint = MEM_mallocN(sizeof(uint) * SQUARE(ED_IMAGE_UNDO_TILE_SIZE), __func__); + utile->rect.uint = MEM_mallocN(sizeof(uint) * square_i(ED_IMAGE_UNDO_TILE_SIZE), __func__); } return utile; } @@ -659,22 +661,23 @@ static UndoImageHandle *uhandle_lookup(ListBase *undo_handles, const Image *imag return NULL; } -static UndoImageHandle *uhandle_add(ListBase *undo_handles, Image *image, int tile_number) +static UndoImageHandle *uhandle_add(ListBase *undo_handles, Image *image, ImageUser *iuser) { - BLI_assert(uhandle_lookup(undo_handles, image, tile_number) == NULL); + BLI_assert(uhandle_lookup(undo_handles, image, iuser->tile) == NULL); UndoImageHandle *uh = MEM_callocN(sizeof(*uh), __func__); uh->image_ref.ptr = image; + uh->iuser = *iuser; + BLI_assert(uh->iuser.scene == NULL); uh->iuser.ok = 1; - uh->iuser.tile = tile_number; BLI_addtail(undo_handles, uh); return uh; } -static UndoImageHandle *uhandle_ensure(ListBase *undo_handles, Image *image, int tile_number) +static UndoImageHandle *uhandle_ensure(ListBase *undo_handles, Image *image, ImageUser *iuser) { - UndoImageHandle *uh = uhandle_lookup(undo_handles, image, tile_number); + UndoImageHandle *uh = uhandle_lookup(undo_handles, image, iuser->tile); if (uh == NULL) { - uh = uhandle_add(undo_handles, image, tile_number); + uh = uhandle_add(undo_handles, image, iuser); } return uh; } @@ -779,7 +782,7 @@ static bool image_undosys_step_encode(struct bContext *C, /* Initialize undo tiles from ptiles (if they exist). */ for (PaintTile *ptile = us->paint_tiles.first, *ptile_next; ptile; ptile = ptile_next) { if (ptile->valid) { - UndoImageHandle *uh = uhandle_ensure(&us->handles, ptile->image, ptile->tile_number); + UndoImageHandle *uh = uhandle_ensure(&us->handles, ptile->image, &ptile->iuser); UndoImageBuf *ubuf_pre = uhandle_ensure_ubuf(uh, ptile->image, ptile->ibuf); UndoImageTile *utile = MEM_callocN(sizeof(*utile), "UndoImageTile"); @@ -1047,12 +1050,12 @@ void ED_image_undo_push_begin(const char *name, int paint_mode) void ED_image_undo_push_begin_with_image(const char *name, Image *image, ImBuf *ibuf, - int tile_number) + ImageUser *iuser) { ImageUndoStep *us = image_undo_push_begin(name, PAINT_MODE_TEXTURE_2D); - BLI_assert(BKE_image_get_tile(image, tile_number)); - UndoImageHandle *uh = uhandle_ensure(&us->handles, image, tile_number); + BLI_assert(BKE_image_get_tile(image, iuser->tile)); + UndoImageHandle *uh = uhandle_ensure(&us->handles, image, iuser); UndoImageBuf *ubuf_pre = uhandle_ensure_ubuf(uh, image, ibuf); BLI_assert(ubuf_pre->post == NULL); @@ -1061,7 +1064,7 @@ void ED_image_undo_push_begin_with_image(const char *name, us_reference = (ImageUndoStep *)us_reference->step.prev; } UndoImageBuf *ubuf_reference = (us_reference ? ubuf_lookup_from_reference( - us_reference, image, tile_number, ubuf_pre) : + us_reference, image, iuser->tile, ubuf_pre) : NULL); if (ubuf_reference) { |