Blender  V2.93
Classes | Variables
image_undo.c File Reference
#include "CLG_log.h"
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
#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  PaintTile
 
struct  UndoImageTile
 
struct  UndoImageBuf
 
struct  UndoImageHandle
 
struct  ImageUndoStep
 

Functions

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)
 
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.
ListBaseED_image_paint_tile_list_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"}
 

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.

typedef struct PaintTile PaintTile
 
static ImBufimbuf_alloc_temp_tile (void)
 
static void ptile_free (PaintTile *ptile)
 
static void ptile_free_list (ListBase *paint_tiles)
 
static void ptile_invalidate_list (ListBase *paint_tiles)
 
void * ED_image_paint_tile_find (ListBase *paint_tiles, Image *image, ImBuf *ibuf, ImageUser *iuser, int x_tile, int y_tile, ushort **r_mask, bool validate)
 
void * ED_image_paint_tile_push (ListBase *paint_tiles, 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_list (ListBase *paint_tiles)
 

Image Undo Tile

typedef struct UndoImageTile UndoImageTile
 
static uint index_from_xy (uint tile_x, uint tile_y, const uint tiles_dims[2])
 
static UndoImageTileutile_alloc (bool has_float)
 
static void utile_init_from_imbuf (UndoImageTile *utile, const uint x, const uint 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 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)
 

Implements ED Undo System

typedef struct ImageUndoStep ImageUndoStep
 
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)
 

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.c.

Typedef Documentation

◆ ImageUndoStep

typedef struct ImageUndoStep ImageUndoStep

◆ PaintTile

typedef struct PaintTile PaintTile

◆ UndoImageBuf

typedef struct UndoImageBuf UndoImageBuf

◆ UndoImageHandle

◆ UndoImageTile

typedef struct UndoImageTile UndoImageTile

Function Documentation

◆ ED_image_paint_tile_find()

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

◆ ED_image_paint_tile_list_get()

ListBase* ED_image_paint_tile_list_get ( void  )

◆ ED_image_paint_tile_lock_end()

void ED_image_paint_tile_lock_end ( void  )

Definition at line 81 of file image_undo.c.

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 76 of file image_undo.c.

References BLI_spin_init(), and paint_tiles_lock.

Referenced by proj_paint_state_thread_init().

◆ ED_image_paint_tile_push()

void* ED_image_paint_tile_push ( ListBase paint_tiles,
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 1066 of file image_undo.c.

References image_undo_push_begin().

Referenced by ED_imapaint_bucket_fill(), texture_paint_camera_project_exec(), and 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 ( UndoStep us)

Definition at line 1044 of file image_undo.c.

References ptile_invalidate_list(), and ptile_restore_runtime_list().

Referenced by paint_stroke_update_step().

◆ ED_image_undosys_type()

void ED_image_undosys_type ( 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 ( void  )
static

◆ index_from_xy()

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

Definition at line 318 of file image_undo.c.

References BLI_assert.

Referenced by image_undosys_step_encode().

◆ ptile_free()

static void ptile_free ( PaintTile ptile)
static

Definition at line 124 of file image_undo.c.

References PaintTile::mask, MEM_freeN, PaintTile::pt, and PaintTile::rect.

Referenced by image_undosys_step_encode(), and ptile_free_list().

◆ ptile_free_list()

static void ptile_free_list ( ListBase paint_tiles)
static

Definition at line 135 of file image_undo.c.

References BLI_listbase_clear(), ListBase::first, and ptile_free().

Referenced by image_undosys_step_free().

◆ ptile_invalidate_list()

static void ptile_invalidate_list ( ListBase paint_tiles)
static

Definition at line 144 of file image_undo.c.

References LISTBASE_FOREACH.

Referenced by ED_image_undo_restore().

◆ ptile_restore_runtime_list()

static void ptile_restore_runtime_list ( ListBase paint_tiles)
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 711 of file image_undo.c.

References ImageUndoStep::handles, UndoImageBuf::ibuf_name, UndoImageBuf::image_dims, NULL, 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 590 of file image_undo.c.

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 387 of file image_undo.c.

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 uint  x,
const uint  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 65 of file image_undo.c.

Referenced by uhandle_restore_list().

◆ paint_tiles_lock

SpinLock paint_tiles_lock
static