Blender V4.3
image_undo.cc File Reference
#include "CLG_log.h"
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
#include "BLI_map.hh"
#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.hh"
#include "IMB_imbuf_types.hh"
#include "BKE_context.hh"
#include "BKE_image.hh"
#include "BKE_paint.hh"
#include "BKE_undo_system.hh"
#include "DEG_depsgraph.hh"
#include "ED_object.hh"
#include "ED_paint.hh"
#include "ED_undo.hh"
#include "ED_util.hh"
#include "WM_api.hh"

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)
 
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)
 
static uint8_timage_undo_steal_and_assign_byte_buffer (ImBuf *ibuf, uint8_t *new_buffer_data)
 
static floatimage_undo_steal_and_assign_float_buffer (ImBuf *ibuf, float *new_buffer_data)
 
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)
 
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 Buffer
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
static void uhandle_restore_list (ListBase *undo_handles, bool use_init)
 
static void uhandle_free_list (ListBase *undo_handles)
 
Image Undo Internal Utilities
static UndoImageBufuhandle_lookup_ubuf (UndoImageHandle *uh, const Image *, const char *ibuf_filepath)
 
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 (bContext *, UndoStep *us_p)
 
static bool image_undosys_step_encode (bContext *C, Main *, 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 (bContext *C, 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 ED_image_undo_restore (UndoStep *us)
 
static ImageUndoStepimage_undo_push_begin (const char *name, PaintMode paint_mode)
 
void ED_image_undo_push_begin (const char *name, PaintMode 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 ()
 

Variables

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

Thread Locking

static SpinLock paint_tiles_lock
 
void ED_image_paint_tile_lock_init ()
 
void ED_image_paint_tile_lock_end ()
 

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.

Function Documentation

◆ ED_image_paint_tile_find()

◆ ED_image_paint_tile_lock_end()

void ED_image_paint_tile_lock_end ( )

Definition at line 70 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 ( )

Definition at line 65 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()

◆ ED_image_paint_tile_push()

◆ ED_image_undo_push_begin()

void ED_image_undo_push_begin ( const char * name,
PaintMode 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 1119 of file image_undo.cc.

References image_undo_push_begin().

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

◆ ED_image_undo_push_begin_with_image()

◆ ED_image_undo_push_end()

◆ ED_image_undo_restore()

void ED_image_undo_restore ( UndoStep * us)

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

Definition at line 1101 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()

◆ image_undo_push_begin()

◆ image_undo_steal_and_assign_byte_buffer()

static uint8_t * image_undo_steal_and_assign_byte_buffer ( ImBuf * ibuf,
uint8_t * new_buffer_data )
static

◆ image_undo_steal_and_assign_float_buffer()

static float * image_undo_steal_and_assign_float_buffer ( ImBuf * ibuf,
float * new_buffer_data )
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

Definition at line 1041 of file image_undo.cc.

References ImageUndoStep::handles, and LISTBASE_FOREACH.

Referenced by ED_image_undosys_type().

◆ image_undosys_poll()

static bool image_undosys_poll ( bContext * C)
static

◆ image_undosys_step_decode()

◆ 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()

◆ image_undosys_step_encode_init()

static void image_undosys_step_encode_init ( bContext * ,
UndoStep * us_p )
static

◆ image_undosys_step_free()

static void image_undosys_step_free ( UndoStep * us_p)
static

◆ imbuf_alloc_temp_tile()

◆ 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 367 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()

◆ ubuf_ensure_compat_ibuf()

◆ ubuf_free()

static void ubuf_free ( UndoImageBuf * ubuf)
static

◆ ubuf_from_image_all_tiles()

◆ ubuf_from_image_no_tiles()

◆ 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 766 of file image_undo.cc.

References ImageUndoStep::handles, UndoImageBuf::ibuf_filepath, 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

◆ uhandle_lookup()

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

Definition at line 710 of file image_undo.cc.

References LISTBASE_FOREACH.

Referenced by uhandle_add(), and uhandle_ensure().

◆ uhandle_lookup_by_name()

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

Definition at line 698 of file image_undo.cc.

References LISTBASE_FOREACH, and STREQ.

Referenced by ubuf_lookup_from_reference().

◆ uhandle_lookup_ubuf()

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

◆ uhandle_restore_list()

◆ utile_alloc()

◆ utile_decref()

static void utile_decref ( UndoImageTile * utile)
static

Definition at line 443 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()

◆ 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 54 of file image_undo.cc.

Referenced by uhandle_restore_list().

◆ paint_tiles_lock

SpinLock paint_tiles_lock
static