1 /*
2 This file is part of darktable,
3 Copyright (C) 2010-2020 darktable developers.
4
5 darktable is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 darktable is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with darktable. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #pragma once
20
21 #include <gtk/gtk.h>
22 #include <inttypes.h>
23 #include <sqlite3.h>
24 #include "develop/imageop.h"
25
26 struct dt_develop_t;
27 struct dt_iop_module_t;
28
29 // history hash is designed to detect any change made on the image
30 // if current = basic the image has only the mandatory modules with their original settings
31 // if current = auto the image has the mandatory and auto applied modules with their original settings
32 // else the image has been changed in some way
33 // note that if an image has no history (and no history hash) it is considered as basic
34 typedef enum dt_history_hash_t
35 {
36 DT_HISTORY_HASH_BASIC = 1 << 0, // only mandatory modules
37 DT_HISTORY_HASH_AUTO = 1 << 1, // mandatory modules plus the auto applied ones
38 DT_HISTORY_HASH_CURRENT = 1 << 2, // current state, with or without change
39 DT_HISTORY_HASH_MIPMAP = 1 << 3, // last mipmap hash
40 } dt_history_hash_t;
41
42 typedef struct dt_history_hash_values_t
43 {
44 guint8 *basic;
45 int basic_len;
46 guint8 *auto_apply;
47 int auto_apply_len;
48 guint8 *current;
49 int current_len;
50 } dt_history_hash_values_t;
51
52 typedef struct dt_history_copy_item_t
53 {
54 GList *selops;
55 GtkTreeView *items;
56 int copied_imageid;
57 gboolean full_copy;
58 gboolean copy_iop_order;
59 } dt_history_copy_item_t;
60
61 /** helper function to free a GList of dt_history_item_t */
62 void dt_history_item_free(gpointer data);
63
64 /** adds to dev_dest module mod_src */
65 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, GList **_modules_used, const int append);
66
67 /** copy history from imgid and pasts on dest_imgid, merge or overwrite... */
68 int dt_history_copy_and_paste_on_image(int32_t imgid, int32_t dest_imgid, gboolean merge, GList *ops, gboolean copy_iop_order, const gboolean copy_full);
69
70 /** delete all history for the given image */
71 void dt_history_delete_on_image(int32_t imgid);
72
73 /** as above but control whether to record undo/redo */
74 void dt_history_delete_on_image_ext(int32_t imgid, gboolean undo);
75
76 /** copy history from imgid and pasts on selected images, merge or overwrite... */
77 gboolean dt_history_copy(int imgid);
78 gboolean dt_history_copy_parts(int imgid);
79 gboolean dt_history_paste_on_list(const GList *list, gboolean undo);
80 gboolean dt_history_paste_parts_on_list(const GList *list, gboolean undo);
81
dt_history_module_skip_copy(const int flags)82 static inline gboolean dt_history_module_skip_copy(const int flags)
83 {
84 return flags & (IOP_FLAGS_DEPRECATED | IOP_FLAGS_UNSAFE_COPY | IOP_FLAGS_HIDDEN);
85 }
86
87 /** load a dt file and applies to selected images */
88 int dt_history_load_and_apply_on_list(gchar *filename, const GList *list);
89
90 /** load a dt file and applies to specified image */
91 int dt_history_load_and_apply(int imgid, gchar *filename, int history_only);
92
93 /** delete historystack of selected images */
94 gboolean dt_history_delete_on_list(const GList *list, gboolean undo);
95
96 /** compress history stack */
97 int dt_history_compress_on_list(const GList *imgs);
98 void dt_history_compress_on_image(const int32_t imgid);
99
100 /** truncate history stack */
101 void dt_history_truncate_on_image(const int32_t imgid, const int32_t history_end);
102
103 /* set or clear a tag representing an error state while compressing history */
104 void dt_history_set_compress_problem(const int32_t imgid, const gboolean set);
105 /* duplicate an history list */
106 GList *dt_history_duplicate(GList *hist);
107
108
109
110 typedef struct dt_history_item_t
111 {
112 guint num;
113 gchar *op;
114 gchar *name;
115 } dt_history_item_t;
116
117 /** get list of history items for image */
118 GList *dt_history_get_items(int32_t imgid, gboolean enabled);
119
120 /** get list of history items for image as a nice string */
121 char *dt_history_get_items_as_string(int32_t imgid);
122
123 /* check if a module exists in the history of corresponding image */
124 gboolean dt_history_check_module_exists(int32_t imgid, const char *operation);
125
126 /** calculate history hash and save it to database*/
127 void dt_history_hash_write_from_history(const int32_t imgid, const dt_history_hash_t type);
128
129 /** return the hash history status */
130 dt_history_hash_t dt_history_hash_get_status(const int32_t imgid);
131
132 /** return true if mipmap_hash = current_hash */
133 gboolean dt_history_hash_is_mipmap_synced(const int32_t imgid);
134
135 /** update mipmap hash to db (= current_hash) */
136 void dt_history_hash_set_mipmap(const int32_t imgid);
137
138 /** write hash values to db */
139 void dt_history_hash_write(const int32_t imgid, dt_history_hash_values_t *hash);
140
141 /** read hash values from db */
142 void dt_history_hash_read(const int32_t imgid, dt_history_hash_values_t *hash);
143
144 // modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh
145 // vim: shiftwidth=2 expandtab tabstop=2 cindent
146 // kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
147