Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
history_snapshot.c
Go to the documentation of this file.
1/*
2 This file is part of darktable,
3 Copyright (C) 2019 Hanno Schwalm.
4 Copyright (C) 2019 Heiko Bauke.
5 Copyright (C) 2019-2020, 2022 Pascal Obry.
6 Copyright (C) 2019 Philippe Weyland.
7 Copyright (C) 2020 Aldric Renaudin.
8 Copyright (C) 2020 Hubert Kowalski.
9 Copyright (C) 2022-2023 Aurélien PIERRE.
10 Copyright (C) 2022 Martin Bařinka.
11
12 darktable is free software: you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation, either version 3 of the License, or
15 (at your option) any later version.
16
17 darktable is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with darktable. If not, see <http://www.gnu.org/licenses/>.
24*/
25
26#include "database/database.h"
28#include "history/notify.h"
29#include "system/mem_alloc.h"
31#include "history/history.h"
33#include "caches/image_cache.h"
34
39
40void dt_history_snapshot_undo_create(const int32_t imgid, int *snap_id, int *history_end)
41{
42 // create history & mask snapshots for imgid, return the snapshot id
43 *history_end = dt_history_repository_get_end(imgid);
45
46 if(!dt_history_snapshot_repository_create(*snap_id, imgid, *history_end == 0))
47 fprintf(stderr, "[dt_history_snapshot_undo_create] fails to create a snapshot for %d\n", imgid);
48}
49
50static void _history_snapshot_undo_restore(const int32_t imgid, const int snap_id, const int history_end)
51{
52 // restore the given snapshot for imgid
53 gboolean all_ok = TRUE;
54
56
59
60 // if no history end it means the image history was discarded, nothing more to restore
61 if(history_end != 0)
62 all_ok = dt_history_snapshot_repository_restore(snap_id, imgid);
63
64 // set history end
65 all_ok &= dt_history_repository_set_end(imgid, history_end);
66
67 if(all_ok)
69 else
70 {
72 fprintf(stderr, "[_history_snapshot_undo_restore] fails to restore a snapshot for %d\n", imgid);
73 }
74
75 dt_image_t *image = dt_image_cache_get(imgid, 'w');
76 if(image)
77 {
78 // FIXME: this might be wrong or need more accurate handling
79 image->history_hash = UINT64_MAX;
81 }
82}
83
84static void _clear_undo_snapshot(const int32_t imgid, const int snap_id)
85{
87}
88
90{
92
93 _clear_undo_snapshot(hist->imgid, hist->after);
94
95 // this is the first element in for this image, it corresponds to the initial status, we can safely remove it now
96 if(hist->before == 0)
97 _clear_undo_snapshot(hist->imgid, hist->before);
98
99 dt_free(hist);
100}
101
102void dt_history_snapshot_undo_pop(gpointer user_data, dt_undo_type_t type, dt_undo_data_t data, dt_undo_action_t action, GList **imgs)
103{
105 {
107
108 if(action == DT_ACTION_UNDO)
109 {
111 }
112 else
113 {
115 }
116
117 *imgs = g_list_append(*imgs, GINT_TO_POINTER(hist->imgid));
118 }
119}
120// clang-format off
121// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
122// vim: shiftwidth=2 expandtab tabstop=2 cindent
123// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
124// clang-format on
#define TRUE
Definition ashift_lsd.c:162
#define FALSE
Definition ashift_lsd.c:158
void dt_database_rollback_transaction(void)
Definition database.c:4899
#define dt_database_start_transaction()
Definition database.h:290
#define dt_database_release_transaction()
Definition database.h:291
void dt_history_delete_on_image_ext(int32_t imgid, gboolean undo)
void dt_history_changed(const dt_history_change_t what)
Raise it. Internal to this code.
Everything the history, styles and presets code says to the outside world: messages for the user,...
@ DT_HISTORY_CHANGE_TAGS
gboolean dt_history_repository_set_end(const int32_t imgid, const int32_t history_end)
int32_t dt_history_repository_get_end(const int32_t imgid)
void dt_history_snapshot_undo_create(const int32_t imgid, int *snap_id, int *history_end)
void dt_history_snapshot_undo_lt_history_data_free(gpointer data)
static void _clear_undo_snapshot(const int32_t imgid, const int snap_id)
dt_undo_lt_history_t * dt_history_snapshot_item_init(void)
void dt_history_snapshot_undo_pop(gpointer user_data, dt_undo_type_t type, dt_undo_data_t data, dt_undo_action_t action, GList **imgs)
static void _history_snapshot_undo_restore(const int32_t imgid, const int snap_id, const int history_end)
gboolean dt_history_snapshot_repository_restore(const int snap_id, const int32_t imgid)
Copy snapshot snap_id of imgid back over the live history tables.
void dt_history_snapshot_repository_clear(const int snap_id, const int32_t imgid)
Drop snapshot snap_id of imgid from all three undo tables.
gboolean dt_history_snapshot_repository_create(const int snap_id, const int32_t imgid, const gboolean empty_history)
Copy imgid's history, masks history and module order into the undo tables.
int dt_history_snapshot_repository_next_id(const int32_t imgid)
The id the next snapshot of imgid should use: one past the highest taken.
memory.undo_history, memory.undo_masks_history, memory.undo_module_order.
void dt_image_cache_write_release(dt_image_t *img, dt_image_cache_write_mode_t mode)
dt_image_t * dt_image_cache_get(const int32_t imgid, char mode)
@ DT_IMAGE_CACHE_RELAXED
Definition image_cache.h:50
_lib_location_type_t type
Definition location.c:1
#define dt_free(ptr)
g_free() ptr and set it to NULL, skipping both if it is already NULL.
Definition mem_alloc.h:171
uint64_t history_hash
Definition image.h:404
dt_undo_type_t
Definition undo.h:40
@ DT_UNDO_LT_HISTORY
Definition undo.h:49
void * dt_undo_data_t
Definition undo.h:70
dt_undo_action_t
Definition undo.h:65
@ DT_ACTION_UNDO
Definition undo.h:66