Blender  V3.3
Classes | Variables
image_undo.cc File Reference
#include "CLG_log.h"
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
#include "BLI_map.hh"
#include "BLI_math.h"
#include "BLI_threads.h"
#include "BLI_utildefines.h"
#include "DNA_image_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"
#include "BKE_context.h"
#include "BKE_image.h"
#include "BKE_paint.h"
#include "BKE_undo_system.h"
#include "DEG_depsgraph.h"
#include "ED_object.h"
#include "ED_paint.h"
#include "ED_undo.h"
#include "ED_util.h"
#include "WM_api.h"

Go to the source code of this file.

Classes

struct  PaintTileKey
 
struct  PaintTile
 
struct  PaintTileMap
 
struct  UndoImageTile
 
struct  UndoImageBuf
 
struct  UndoImageHandle
 
struct  ImageUndoStep
 

Functions

Paint Tiles

Created on demand while painting, use to access the previous state for some paint operations.

These buffers are also used for undo when available.

static ImBufimbuf_alloc_temp_tile ()
 
static void ptile_free (PaintTile *ptile)
 
static void ptile_invalidate_map (PaintTileMap *paint_tile_map)
 
voidED_image_paint_tile_find (PaintTileMap *paint_tile_map, Image *image, ImBuf *ibuf, ImageUser *iuser, int x_tile, int y_tile, ushort **r_mask, bool validate)
 
voidED_image_paint_tile_push (PaintTileMap *paint_tile_map, Image *image, ImBuf *ibuf, ImBuf **tmpibuf, ImageUser *iuser, int x_tile, int y_tile, ushort **r_mask, bool **r_valid, bool use_thread_lock, bool find_prev)
 
static void ptile_restore_runtime_map (PaintTileMap *paint_tile_map)
 
Image Undo Tile
static uint32_t index_from_xy (uint32_t tile_x, uint32_t tile_y, const uint32_t tiles_dims[2])
 
static UndoImageTileutile_alloc (bool has_float)
 
static void utile_init_from_imbuf (UndoImageTile *utile, const uint32_t x, const uint32_t y, const ImBuf *ibuf, ImBuf *tmpibuf)
 
static void utile_restore (const UndoImageTile *utile, const uint x, const uint y, ImBuf *ibuf, ImBuf *tmpibuf)
 
static void utile_decref (UndoImageTile *utile)
 
Image Undo Internal Utilities
static UndoImageBufuhandle_lookup_ubuf (UndoImageHandle *uh, const Image *UNUSED(image), const char *ibuf_name)
 
static UndoImageBufuhandle_add_ubuf (UndoImageHandle *uh, Image *image, ImBuf *ibuf)
 
static UndoImageBufuhandle_ensure_ubuf (UndoImageHandle *uh, Image *image, ImBuf *ibuf)
 
static UndoImageHandleuhandle_lookup_by_name (ListBase *undo_handles, const Image *image, int tile_number)
 
static UndoImageHandleuhandle_lookup (ListBase *undo_handles, const Image *image, int tile_number)
 
static UndoImageHandleuhandle_add (ListBase *undo_handles, Image *image, ImageUser *iuser)
 
static UndoImageHandleuhandle_ensure (ListBase *undo_handles, Image *image, ImageUser *iuser)
 
Implements ED Undo System
static UndoImageBufubuf_lookup_from_reference (ImageUndoStep *us_prev, const Image *image, int tile_number, const UndoImageBuf *ubuf)
 
static bool image_undosys_poll (bContext *C)
 
static void image_undosys_step_encode_init (struct bContext *UNUSED(C), UndoStep *us_p)
 
static bool image_undosys_step_encode (struct bContext *C, struct Main *UNUSED(bmain), UndoStep *us_p)
 
static void image_undosys_step_decode_undo_impl (ImageUndoStep *us, bool is_final)
 
static void image_undosys_step_decode_redo_impl (ImageUndoStep *us)
 
static void image_undosys_step_decode_undo (ImageUndoStep *us, bool is_final)
 
static void image_undosys_step_decode_redo (ImageUndoStep *us)
 
static void image_undosys_step_decode (struct bContext *C, struct Main *bmain, UndoStep *us_p, const eUndoStepDir dir, bool is_final)
 
static void image_undosys_step_free (UndoStep *us_p)
 
static void image_undosys_foreach_ID_ref (UndoStep *us_p, UndoTypeForEachIDRefFn foreach_ID_ref_fn, void *user_data)
 
void ED_image_undosys_type (UndoType *ut)
 
Utilities
Note
image undo exposes ED_image_undo_push_begin, ED_image_undo_push_end which must be called by the operator directly.

Unlike most other undo stacks this is needed:

  • So we can always access the state before the image was painted onto, which is needed if previous undo states aren't image-type.
  • So operators can access the pixel-data before the stroke was applied, at run-time.
PaintTileMapED_image_paint_tile_map_get (void)
 
void ED_image_undo_restore (UndoStep *us)
 
static ImageUndoStepimage_undo_push_begin (const char *name, int paint_mode)
 
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, ImageUser *iuser)
 
void ED_image_undo_push_end (void)
 

Variables

static CLG_LogRef LOG = {"ed.image.undo"}
 

Image Undo Buffer

typedef struct UndoImageBuf UndoImageBuf
 
static UndoImageBufubuf_from_image_no_tiles (Image *image, const ImBuf *ibuf)
 
static void ubuf_from_image_all_tiles (UndoImageBuf *ubuf, const ImBuf *ibuf)
 
static void ubuf_ensure_compat_ibuf (const UndoImageBuf *ubuf, ImBuf *ibuf)
 
static void ubuf_free (UndoImageBuf *ubuf)
 

Image Undo Handle

typedef struct UndoImageHandle UndoImageHandle
 
static void uhandle_restore_list (ListBase *undo_handles, bool use_init)
 
static void uhandle_free_list (ListBase *undo_handles)
 

Thread Locking

static SpinLock paint_tiles_lock
 
void ED_image_paint_tile_lock_init (void)
 
void ED_image_paint_tile_lock_end (void)
 

Detailed Description

Overview

When the undo system manages an image, there will always be a full copy (as a UndoImageBuf) each new undo step only stores modified tiles.

Definition in file image_undo.cc.

Typedef Documentation

◆ UndoImageBuf

typedef struct UndoImageBuf UndoImageBuf

◆ UndoImageHandle

Function Documentation

◆ ED_image_paint_tile_find()

void* ED_image_paint_tile_find ( PaintTileMap paint_tile_map,
Image image,
ImBuf ibuf,
ImageUser iuser,
int  x_tile,
int  y_tile,
ushort **  r_mask,
bool  validate 
)

◆ ED_image_paint_tile_lock_end()

void ED_image_paint_tile_lock_end ( void  )

Definition at line 69 of file image_undo.cc.

References BLI_spin_end(), and paint_tiles_lock.

Referenced by project_paint_end().

◆ ED_image_paint_tile_lock_init()

void ED_image_paint_tile_lock_init ( void  )

Definition at line 64 of file image_undo.cc.

References BLI_spin_init(), and paint_tiles_lock.

Referenced by proj_paint_state_thread_init().

◆ ED_image_paint_tile_map_get()

PaintTileMap* ED_image_paint_tile_map_get ( void  )

◆ ED_image_paint_tile_push()

void* ED_image_paint_tile_push ( PaintTileMap paint_tile_map,
Image image,
ImBuf ibuf,
ImBuf **  tmpibuf,
ImageUser iuser,
int  x_tile,
int  y_tile,
ushort **  r_mask,
bool **  r_valid,
bool  use_thread_lock,
bool  find_prev 
)

◆ ED_image_undo_push_begin()

void ED_image_undo_push_begin ( const char *  name,
int  paint_mode 
)

The caller is responsible for running ED_image_undo_push_end, failure to do so causes an invalid state for the undo system.

Definition at line 1095 of file image_undo.cc.

References image_undo_push_begin().

Referenced by ED_imapaint_bucket_fill(), sculpt_stroke_test_start(), texture_paint_camera_project_exec(), and blender::ed::sculpt_paint::image::ops::paint::texture_paint_init().

◆ ED_image_undo_push_begin_with_image()

void ED_image_undo_push_begin_with_image ( const char *  name,
Image image,
ImBuf ibuf,
ImageUser iuser 
)

◆ ED_image_undo_push_end()

void ED_image_undo_push_end ( void  )

◆ ED_image_undo_restore()

void ED_image_undo_restore ( struct UndoStep us)

Restore painting image to previous state. Used for anchored and drag-dot style brushes.

Definition at line 1077 of file image_undo.cc.

References ptile_invalidate_map(), and ptile_restore_runtime_map().

Referenced by blender::ed::sculpt_paint::image::ops::paint::paint_stroke_update_step().

◆ ED_image_undosys_type()

void ED_image_undosys_type ( struct UndoType ut)

◆ image_undo_push_begin()

static ImageUndoStep* image_undo_push_begin ( const char *  name,
int  paint_mode 
)
static

◆ image_undosys_foreach_ID_ref()

static void image_undosys_foreach_ID_ref ( UndoStep us_p,
UndoTypeForEachIDRefFn  foreach_ID_ref_fn,
void user_data 
)
static

◆ image_undosys_poll()

static bool image_undosys_poll ( bContext C)
static

◆ image_undosys_step_decode()

static void image_undosys_step_decode ( struct bContext C,
struct Main bmain,
UndoStep us_p,
const eUndoStepDir  dir,
bool  is_final 
)
static

◆ image_undosys_step_decode_redo()

static void image_undosys_step_decode_redo ( ImageUndoStep us)
static

◆ image_undosys_step_decode_redo_impl()

static void image_undosys_step_decode_redo_impl ( ImageUndoStep us)
static

◆ image_undosys_step_decode_undo()

static void image_undosys_step_decode_undo ( ImageUndoStep us,
bool  is_final 
)
static

◆ image_undosys_step_decode_undo_impl()

static void image_undosys_step_decode_undo_impl ( ImageUndoStep us,
bool  is_final 
)
static

◆ image_undosys_step_encode()

static bool image_undosys_step_encode ( struct bContext C,
struct Main UNUSEDbmain,
UndoStep us_p 
)
static

◆ image_undosys_step_encode_init()

static void image_undosys_step_encode_init ( struct bContext UNUSEDC,
UndoStep us_p 
)
static

◆ image_undosys_step_free()

static void image_undosys_step_free ( UndoStep us_p)
static

◆ imbuf_alloc_temp_tile()

static ImBuf* imbuf_alloc_temp_tile ( )
static

◆ index_from_xy()

static uint32_t index_from_xy ( uint32_t  tile_x,
uint32_t  tile_y,
const uint32_t  tiles_dims[2] 
)
static

Definition at line 347 of file image_undo.cc.

References BLI_assert.

Referenced by image_undosys_step_encode().

◆ ptile_free()

static void ptile_free ( PaintTile ptile)
static

◆ ptile_invalidate_map()

static void ptile_invalidate_map ( PaintTileMap paint_tile_map)
static

◆ ptile_restore_runtime_map()

static void ptile_restore_runtime_map ( PaintTileMap paint_tile_map)
static

◆ ubuf_ensure_compat_ibuf()

static void ubuf_ensure_compat_ibuf ( const UndoImageBuf ubuf,
ImBuf ibuf 
)
static

◆ ubuf_free()

static void ubuf_free ( UndoImageBuf ubuf)
static

◆ ubuf_from_image_all_tiles()

static void ubuf_from_image_all_tiles ( UndoImageBuf ubuf,
const ImBuf ibuf 
)
static

◆ ubuf_from_image_no_tiles()

static UndoImageBuf* ubuf_from_image_no_tiles ( Image image,
const ImBuf ibuf 
)
static

◆ ubuf_lookup_from_reference()

static UndoImageBuf* ubuf_lookup_from_reference ( ImageUndoStep us_prev,
const Image image,
int  tile_number,
const UndoImageBuf ubuf 
)
static

Find the previous undo buffer from this one.

Note
We could look into undo steps even further back.

Definition at line 743 of file image_undo.cc.

References ImageUndoStep::handles, UndoImageBuf::ibuf_name, image(), UndoImageBuf::image_dims, UndoImageBuf::post, uhandle_lookup_by_name(), and uhandle_lookup_ubuf().

Referenced by ED_image_undo_push_begin_with_image(), and image_undosys_step_encode().

◆ uhandle_add()

static UndoImageHandle* uhandle_add ( ListBase undo_handles,
Image image,
ImageUser iuser 
)
static

◆ uhandle_add_ubuf()

static UndoImageBuf* uhandle_add_ubuf ( UndoImageHandle uh,
Image image,
ImBuf ibuf 
)
static

◆ uhandle_ensure()

static UndoImageHandle* uhandle_ensure ( ListBase undo_handles,
Image image,
ImageUser iuser 
)
static

◆ uhandle_ensure_ubuf()

static UndoImageBuf* uhandle_ensure_ubuf ( UndoImageHandle uh,
Image image,
ImBuf ibuf 
)
static

◆ uhandle_free_list()

static void uhandle_free_list ( ListBase undo_handles)
static

Definition at line 624 of file image_undo.cc.

References BLI_listbase_clear(), LISTBASE_FOREACH_MUTABLE, MEM_freeN, and ubuf_free().

Referenced by image_undosys_step_free().

◆ uhandle_lookup()

static UndoImageHandle* uhandle_lookup ( ListBase undo_handles,
const Image image,
int  tile_number 
)
static

◆ uhandle_lookup_by_name()

static UndoImageHandle* uhandle_lookup_by_name ( ListBase undo_handles,
const Image image,
int  tile_number 
)
static

◆ uhandle_lookup_ubuf()

static UndoImageBuf* uhandle_lookup_ubuf ( UndoImageHandle uh,
const Image UNUSEDimage,
const char *  ibuf_name 
)
static

◆ uhandle_restore_list()

static void uhandle_restore_list ( ListBase undo_handles,
bool  use_init 
)
static

◆ utile_alloc()

static UndoImageTile* utile_alloc ( bool  has_float)
static

◆ utile_decref()

static void utile_decref ( UndoImageTile utile)
static

Definition at line 419 of file image_undo.cc.

References BLI_assert, MEM_freeN, UndoImageTile::pt, UndoImageTile::rect, and UndoImageTile::users.

Referenced by ubuf_free().

◆ utile_init_from_imbuf()

static void utile_init_from_imbuf ( UndoImageTile utile,
const uint32_t  x,
const uint32_t  y,
const ImBuf ibuf,
ImBuf tmpibuf 
)
static

◆ utile_restore()

static void utile_restore ( const UndoImageTile utile,
const uint  x,
const uint  y,
ImBuf ibuf,
ImBuf tmpibuf 
)
static

Variable Documentation

◆ LOG

CLG_LogRef LOG = {"ed.image.undo"}
static

Definition at line 53 of file image_undo.cc.

Referenced by uhandle_restore_list().

◆ paint_tiles_lock

SpinLock paint_tiles_lock
static