Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
dev_history.h
Go to the documentation of this file.
1/*
2 This file is part of the Ansel project.
3 Copyright (C) 2025 Alynx Zhou.
4 Copyright (C) 2025-2026 Aurélien PIERRE.
5
6 Ansel is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 Ansel is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Ansel. If not, see <http://www.gnu.org/licenses/>.
18*/
19#include "system/atomic.h"
20#include "history/history.h"
22
23#include <glib.h>
24
25#ifndef DT_DEVELOP_DEV_HISTORY_H
26#define DT_DEVELOP_DEV_HISTORY_H
27
37#ifdef __cplusplus
38extern "C" {
39#endif
40
41#ifndef DT_IOP_PARAMS_T
42#define DT_IOP_PARAMS_T
43typedef void dt_iop_params_t;
44#endif
45
46struct dt_iop_module_t;
48struct dt_develop_t;
49
51{
52 struct dt_iop_module_t *module; // pointer to image operation module
53 gboolean enabled; // switched respective module on/off
54 dt_iop_params_t *params; // parameters for this operation
55 int params_size; // serialized params size
56 int module_version; // serialized module version
58 int blendop_params_size; // serialized blend params size
59 int blendop_version; // serialized blend version
60 char op_name[32];
63 char multi_name[128];
64 GList *forms; // snapshot of dt_develop_t->forms
65 int num; // num of history on database
66
67 uint64_t hash; // module params hash.
68
69 // Refcount, mirroring dt_masks_form_t: dev->history holds one reference per element. See
70 // dt_dev_history_cow_touch(): before mutating an item in place (the "reuse previous entry"
71 // path), check refcount -- if shared with something else holding a reference, clone first
72 // and mutate the clone instead.
75
76
85
94
103void dt_dev_free_history_item(gpointer data);
104
109
121
143{
144 GList *items; // dt_dev_history_item_t*, one reference each, same order as dev->history
145 int32_t history_end; // dt_dev_get_history_end_ext() at snapshot time
146 uint64_t history_hash; // dt_dev_get_history_hash() at snapshot time
148
153
158
199 struct dt_iop_module_t *module, gboolean enabled,
200 const void *params, const int32_t params_size,
201 const struct dt_develop_blend_params_t *blend_params, GList *forms);
202
210int dt_dev_next_multi_priority_for_op(struct dt_develop_t *dev, const char *op);
211
223struct dt_iop_module_t *dt_dev_get_module_instance(struct dt_develop_t *dev, const char *op, const char *multi_name,
224 const int multi_priority);
225
236struct dt_iop_module_t *dt_dev_create_module_instance(struct dt_develop_t *dev, const char *op, const char *multi_name,
237 const int multi_priority, gboolean use_next_priority);
250int dt_dev_copy_module_contents(struct dt_develop_t *dev_dest, struct dt_develop_t *dev_src,
251 struct dt_iop_module_t *mod_dest, const struct dt_iop_module_t *mod_src);
252
267 const struct dt_dev_history_item_t *hist_src,
268 struct dt_iop_module_t *mod_dest,
269 struct dt_dev_history_item_t **out_hist);
270
283int dt_dev_merge_history_into_image(struct dt_develop_t *dev_src, int32_t dest_imgid, const GList *mod_list,
284 gboolean merge_iop_order, const dt_history_merge_strategy_t mode,
285 const gboolean paste_instances, const char *source_label,
286 dt_hm_batch_state_t *batch);
299int dt_dev_replace_history_on_image(struct dt_develop_t *dev_src, const int32_t dest_imgid,
300 const gboolean reload_defaults, const char *msg);
301
316gboolean dt_dev_add_history_item_ext(struct dt_develop_t *dev, struct dt_iop_module_t *module, gboolean enable,
317 gboolean force_new_item);
318
330void dt_dev_add_history_item_real(struct dt_develop_t *dev, struct dt_iop_module_t *module, gboolean enable, gboolean redraw);
331
332// Debug helper to follow calls to `dt_dev_add_history_item_real()`, but mostly to follow useless pipe recomputations.
333#define dt_dev_add_history_item(dev, module, enable, redraw) DT_DEBUG_TRACE_WRAPPER(DT_DEBUG_DEV, dt_dev_add_history_item_real, (dev), (module), (enable), (redraw))
334
350
360
361
370void dt_dev_write_history_ext(struct dt_develop_t *dev, const int32_t imgid);
371
379void dt_dev_write_history(struct dt_develop_t *dev, gboolean async);
380
388/* Implemented in dev_history_gui.c: attaches missing expanders and refreshes every module
389 * widget after a backend history reload. Declared here because its callers are the ones
390 * already driving the engine, and the signature carries no GTK type. */
392
401void dt_dev_history_commit_item_now(struct dt_develop_t *dev, struct dt_iop_module_t *module, gboolean enable);
402
415 int mask_edit_mode,
416 int request_mask_display);
418
424
431void dt_dev_history_pixelpipe_update(struct dt_develop_t *dev, gboolean rebuild);
432
439gboolean dt_dev_history_is_image_in_dev(GList *imgs);
440
447
456void dt_dev_history_notify_change(struct dt_develop_t *dev, const int32_t imgid);
457
496
508gboolean dt_dev_read_history_ext(struct dt_develop_t *dev, const int32_t imgid);
509
518
525
526
537gboolean dt_dev_reload_history_items(struct dt_develop_t *dev, const int32_t imgid);
538
539
548void dt_dev_invalidate_history_module(GList *list, struct dt_iop_module_t *module);
549
558
569
579void dt_dev_set_history_end_ext(struct dt_develop_t *dev, const uint32_t index);
580
589gboolean dt_history_module_skip_copy(const int flags);
590
603int dt_history_merge_module_into_history(struct dt_develop_t *dev_dest, struct dt_develop_t *dev_src,
604 struct dt_iop_module_t *mod_src);
605
620void dt_dev_history_compress_ext(struct dt_develop_t *dev, gboolean write_history);
630void dt_dev_history_cleanup(void);
631
644gboolean dt_dev_init_default_history(struct dt_develop_t *dev, const int32_t imgid, gboolean apply_auto_presets);
645
654
663dt_dev_history_item_t *dt_dev_history_get_last_item_by_module(GList *history_list, struct dt_iop_module_t *module, int history_end);
664
681int dt_dev_history_refresh_nodes_ext(struct dt_develop_t *dev, GList **iop, GList *history,
682 GList **removed_gui_modules);
683
685void dt_dev_history_truncate(struct dt_develop_t *dev, const int32_t imgid);
686
710void dt_dev_transient_params_set(struct dt_iop_module_t *module, const void *params, size_t params_size,
711 const void *blend_params, size_t blend_size);
712
720
730gboolean dt_dev_transient_params_get(struct dt_develop_t *dev, const struct dt_iop_module_t *module,
731 void *out_params, size_t out_params_size,
732 void *out_blend, size_t out_blend_size, gboolean *out_has_blend);
733
735gboolean dt_dev_transient_params_active(struct dt_develop_t *dev, const struct dt_iop_module_t *module);
736
740GList *dt_history_duplicate(GList *hist);
741
742#ifdef __cplusplus
743}
744#endif
745
746#endif // DT_DEVELOP_DEV_HISTORY_H
void reload_defaults(dt_iop_module_t *module)
Definition ashift.c:5828
atomic_int dt_atomic_int
Definition atomic.h:68
size_t params_size(dt_imageio_module_format_t *self)
Definition avif.c:571
typedef void((*dt_cache_allocate_t)(void *userdata, dt_cache_entry_t *entry))
void dt_dev_transient_params_set(struct dt_iop_module_t *module, const void *params, size_t params_size, const void *blend_params, size_t blend_size)
Out-of-history transient param channel.
void dt_dev_history_compress_ext(struct dt_develop_t *dev, gboolean write_history)
Variant of history compression that optionally skips DB writeback.
void dt_dev_history_set_commit_gui_handler(dt_dev_history_commit_gui_handler_t handler)
gboolean dt_dev_history_item_update_from_params(struct dt_develop_t *dev, dt_dev_history_item_t *hist, struct dt_iop_module_t *module, gboolean enabled, const void *params, const int32_t params_size, const struct dt_develop_blend_params_t *blend_params, GList *forms)
Fill/refresh a history item from explicit params and apply them to the module.
int dt_history_merge_module_into_history(struct dt_develop_t *dev_dest, struct dt_develop_t *dev_src, struct dt_iop_module_t *mod_src)
Merge a single module instance into a destination history.
void(* dt_dev_history_commit_gui_handler_t)(struct dt_develop_t *dev, struct dt_iop_module_t *module)
Post-commit presentation work: viewport-size refresh for geometry-changing modules,...
dt_dev_history_item_t * dt_dev_history_get_last_item_by_module(GList *history_list, struct dt_iop_module_t *module, int history_end)
Find the last history item referencing a module up to history_end.
void dt_dev_history_snapshot_release(dt_dev_history_snapshot_t *snapshot)
Release every reference a snapshot holds and reset it. Needs no lock.
void dt_dev_history_free_history(struct dt_develop_t *dev)
Free the whole history list attached to dev->history.
void dt_dev_history_set_undo_restore_gui_handler(dt_dev_history_undo_restore_gui_handler_t handler)
void dt_apply_dev_history_update(struct dt_develop_t *dev)
Reload the current darkroom history and refresh every dependent GUI.
void dt_dev_history_undo_end_record(struct dt_develop_t *dev)
Finish an undo record for history changes.
struct dt_iop_module_t * dt_dev_get_module_instance(struct dt_develop_t *dev, const char *op, const char *multi_name, const int multi_priority)
Find a module instance by op name and instance metadata.
int dt_dev_history_item_from_source_history_item(struct dt_develop_t *dev_dest, struct dt_develop_t *dev_src, const struct dt_dev_history_item_t *hist_src, struct dt_iop_module_t *mod_dest, struct dt_dev_history_item_t **out_hist)
Create a history item from another history item, using a destination module.
void dt_dev_history_commit_item_now(struct dt_develop_t *dev, struct dt_iop_module_t *module, gboolean enable)
Commit one history item immediately – record undo, take history_mutex as writer, write through,...
gboolean dt_dev_transient_params_get(struct dt_develop_t *dev, const struct dt_iop_module_t *module, void *out_params, size_t out_params_size, void *out_blend, size_t out_blend_size, gboolean *out_has_blend)
Copy the active transient params for module into caller buffers (pipeline thread).
dt_dev_history_item_t * dt_dev_history_item_create(void)
Allocate a fresh, blank history item with refcount 1.
int dt_dev_merge_history_into_image(struct dt_develop_t *dev_src, int32_t dest_imgid, const GList *mod_list, gboolean merge_iop_order, const dt_history_merge_strategy_t mode, const gboolean paste_instances, const char *source_label, dt_hm_batch_state_t *batch)
Merge a list of modules into a destination image history via dt_history_merge().
void dt_dev_set_history_end_ext(struct dt_develop_t *dev, const uint32_t index)
Set the history end index (GUI perspective).
Definition develop.c:1905
void dt_dev_history_undo_invalidate_module(struct dt_iop_module_t *module)
Invalidate a module pointer inside undo snapshots.
gboolean dt_dev_reload_history_items(struct dt_develop_t *dev, const int32_t imgid)
Reload history from DB and rebuild pipelines/GUI state.
void dt_dev_history_cleanup(void)
Cleanup cached statements or state used by history I/O.
void dt_dev_pop_history_items(struct dt_develop_t *dev)
Thread-safe wrapper around dt_dev_pop_history_items_ext(), then update GUI.
void dt_dev_free_history_item(gpointer data)
Release a reference to a history item (used as GList free callback).
void dt_dev_history_pixelpipe_update(struct dt_develop_t *dev, gboolean rebuild)
Rebuild or resync pixelpipes after backend history changes.
GList * dt_history_duplicate(GList *hist)
Deep-copy a history list.
int dt_dev_replace_history_on_image(struct dt_develop_t *dev_src, const int32_t dest_imgid, const gboolean reload_defaults, const char *msg)
Replace an image history with the content of dev_src.
void dt_dev_transient_params_clear(struct dt_iop_module_t *module)
Drop the transient slot if it belongs to module.
gboolean dt_dev_init_default_history(struct dt_develop_t *dev, const int32_t imgid, gboolean apply_auto_presets)
Initialize module defaults and insert required default modules.
uint64_t dt_dev_history_compute_hash(struct dt_develop_t *dev)
Get the integrity checksum of the whole history stack. This should be done ONLY when history is chang...
gboolean dt_dev_transient_params_active(struct dt_develop_t *dev, const struct dt_iop_module_t *module)
Whether a transient slot is currently active for module (cheap, locked read).
void dt_dev_history_undo_start_record_locked(struct dt_develop_t *dev)
Start an undo record with history_mutex already locked.
dt_dev_history_item_t * dt_dev_history_item_ref(dt_dev_history_item_t *item)
Take a reference on a history item. Pair with dt_dev_free_history_item().
void dt_dev_history_drop_pending_commits(struct dt_develop_t *dev)
Discard every history commit still queued for dev, without running it.
gboolean dt_dev_history_is_image_in_dev(GList *imgs)
Check whether any image of the list is the one currently loaded in the darkroom.
void dt_dev_pop_history_items_ext(struct dt_develop_t *dev)
Apply history items to module params up to dev->history_end.
void dt_dev_history_truncate(struct dt_develop_t *dev, const int32_t imgid)
void dt_dev_history_undo_start_record(struct dt_develop_t *dev)
Start an undo record for history changes.
void dt_dev_history_compress_or_truncate(struct dt_develop_t *dev)
Compress history if history_end is at top, otherwise truncate.
void dt_dev_write_history_ext(struct dt_develop_t *dev, const int32_t imgid)
Write dev->history to DB and XMP for a given image id.
gboolean dt_dev_read_history_ext(struct dt_develop_t *dev, const int32_t imgid)
Read history and masks from DB and populate dev->history.
void dt_dev_history_gui_update(struct dt_develop_t *dev)
Apply history-loaded params to module GUIs.
int32_t dt_dev_get_history_end_ext(struct dt_develop_t *dev)
Get the current history end index (GUI perspective).
Definition develop.c:1899
int dt_dev_copy_module_contents(struct dt_develop_t *dev_dest, struct dt_develop_t *dev_src, struct dt_iop_module_t *mod_dest, const struct dt_iop_module_t *mod_src)
Copy params/blend params from one module instance to another.
void dt_dev_history_snapshot_take(struct dt_develop_t *dev, dt_dev_history_snapshot_t *snapshot)
Take a snapshot of dev->history. Caller holds history_mutex (reader suffices).
void(* dt_dev_history_undo_restore_gui_handler_t)(struct dt_develop_t *dev, int mask_edit_mode, int request_mask_display)
Restores the presentation half of an undo record: the blending panel's mask toggles for the focused m...
gboolean dt_history_module_skip_copy(const int flags)
Determine whether a module should be skipped during history copy.
void dt_dev_history_undo_end_record_locked(struct dt_develop_t *dev)
Finish an undo record with history_mutex already locked.
void dt_iop_params_t
Definition dev_history.h:43
dt_dev_history_item_t * dt_dev_history_cow_touch(struct dt_develop_t *dev, dt_dev_history_item_t *hist)
Copy-on-write gate for mutating a history item in place.
void dt_dev_history_flush_pending_commits(struct dt_develop_t *dev)
Run every history commit still queued for dev, now.
void dt_dev_invalidate_history_module(GList *list, struct dt_iop_module_t *module)
Remove a module pointer from a history list.
gboolean dt_dev_add_history_item_ext(struct dt_develop_t *dev, struct dt_iop_module_t *module, gboolean enable, gboolean force_new_item)
Append or update a history item for a module.
void dt_dev_history_notify_change(struct dt_develop_t *dev, const int32_t imgid)
Notify the rest of the app that history changes were written.
void dt_dev_write_history(struct dt_develop_t *dev, gboolean async)
Thread-safe wrapper around dt_dev_write_history_ext() for dev->image_storage.id.
void dt_dev_history_compress(struct dt_develop_t *dev)
Compress an history from a loaded pipeline, aka simply take a snapshot of all modules parameters....
void dt_dev_add_history_item_real(struct dt_develop_t *dev, struct dt_iop_module_t *module, gboolean enable, gboolean redraw)
Thread-safe wrapper around dt_dev_add_history_item_ext().
struct dt_iop_module_t * dt_dev_create_module_instance(struct dt_develop_t *dev, const char *op, const char *multi_name, const int multi_priority, gboolean use_next_priority)
Create a new module instance from an existing base .so.
int dt_dev_history_refresh_nodes_ext(struct dt_develop_t *dev, GList **iop, GList *history, GList **removed_gui_modules)
Refresh GUI module nodes to match history state.
int dt_dev_next_multi_priority_for_op(struct dt_develop_t *dev, const char *op)
Return the next available multi_priority for an operation.
dt_dev_history_item_t * dt_dev_history_get_first_item_by_module(GList *history_list, struct dt_iop_module_t *module)
Find the first history item referencing a module.
gboolean enabled
–doc was passed on the command line
static gboolean enable(const dt_image_t *image)
Definition highlights.c:879
dt_history_merge_strategy_t
dt_mipmap_buffer_dsc_flags flags
Definition mipmap_cache.c:4
unsigned __int64 uint64_t
Definition strptime.c:75
dt_iop_params_t * params
Definition dev_history.h:54
dt_atomic_int refcount
Definition dev_history.h:73
struct dt_develop_blend_params_t * blend_params
Definition dev_history.h:57
struct dt_iop_module_t *gboolean enabled
Definition dev_history.h:52
A reference-sharing snapshot of dev->history, for readers that outlive a lock.
struct dt_develop_blend_params_t * blend_params
Definition imageop.h:349
char multi_name[128]
Definition imageop.h:387
struct dt_develop_t * dev
Definition imageop.h:311
dt_dev_operation_t op
Definition imageop.h:259
dt_iop_params_t * params
Definition imageop.h:333