Skip to content

Commit

Permalink
Styles/History: completely remove the overwrite mode
Browse files Browse the repository at this point in the history
Users have an explicit way of deleting an history on an image before applying styles & copy-pasting. The overwrite mode is misleading in its name, because people believe it will overwrite modules content, while it overwrites the history as a whole.
  • Loading branch information
aurelienpierre committed Feb 4, 2025
1 parent e41a24b commit 84816d5
Show file tree
Hide file tree
Showing 24 changed files with 42 additions and 450 deletions.
7 changes: 0 additions & 7 deletions data/anselconfig.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -1207,13 +1207,6 @@
<shortdescription/>
<longdescription/>
</dtconfig>
<dtconfig>
<name>plugins/lighttable/copy_history/pastemode</name>
<type>int</type>
<default>0</default>
<shortdescription>append or replace history stack if pasted</shortdescription>
<longdescription>0 -- append on top of stack, 1 -- replace it.</longdescription>
</dtconfig>
<dtconfig>
<name>plugins/lighttable/collect/num_rules</name>
<type>int</type>
Expand Down
11 changes: 1 addition & 10 deletions src/cli/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ static void usage(const char *progname)
fprintf(stderr, " --bpp <bpp>, unsupported\n");
fprintf(stderr, " --export_masks <0|1|false|true>, default: false\n");
fprintf(stderr, " --style <style name>\n");
fprintf(stderr, " --style-overwrite\n");
fprintf(stderr, " --apply-custom-presets <0|1|false|true>, default: true\n");
fprintf(stderr, " disable for multiple instances\n");
fprintf(stderr, " --out-ext <extension>, default from output destination or '.jpg'\n");
Expand Down Expand Up @@ -196,8 +195,7 @@ int main(int argc, char *arg[])
char *style = NULL;
int file_counter = 0;
int width = 0, height = 0, bpp = 0;
gboolean verbose = FALSE,
style_overwrite = FALSE, custom_presets = TRUE, export_masks = FALSE,
gboolean verbose = FALSE, custom_presets = TRUE, export_masks = FALSE,
output_to_dir = FALSE;

GList* inputs = NULL;
Expand Down Expand Up @@ -265,10 +263,6 @@ int main(int argc, char *arg[])
k++;
style = arg[k];
}
else if(!strcmp(arg[k], "--style-overwrite"))
{
style_overwrite = TRUE;
}
else if(!strcmp(arg[k], "--apply-custom-presets") && argc > k + 1)
{
k++;
Expand Down Expand Up @@ -688,14 +682,11 @@ int main(int argc, char *arg[])
fdata->max_width = (w != 0 && fdata->max_width > w) ? w : fdata->max_width;
fdata->max_height = (h != 0 && fdata->max_height > h) ? h : fdata->max_height;
fdata->style[0] = '\0';
fdata->style_append = 1; // make append the default and override with --style-overwrite

if(style)
{
g_strlcpy((char *)fdata->style, style, DT_MAX_STYLE_NAME_LENGTH);
fdata->style[127] = '\0';
if(style_overwrite)
fdata->style_append = 0;
}

if(storage->initialize_store)
Expand Down
10 changes: 3 additions & 7 deletions src/common/history.c
Original file line number Diff line number Diff line change
Expand Up @@ -995,19 +995,17 @@ gboolean dt_history_paste_on_list(const GList *list, gboolean undo)
if(!list) // do we have any images to receive the pasted history?
return FALSE;

const gboolean merge = dt_conf_get_bool("plugins/lighttable/copy_history/pastemode");

if(undo) dt_undo_start_group(darktable.undo, DT_UNDO_LT_HISTORY);
for(GList *l = (GList *)list; l; l = g_list_next(l))
{
const int dest = GPOINTER_TO_INT(l->data);
dt_history_copy_and_paste_on_image(darktable.view_manager->copy_paste.copied_imageid,
dest, merge,
dest,
darktable.view_manager->copy_paste.selops,
darktable.view_manager->copy_paste.copy_iop_order,
darktable.view_manager->copy_paste.full_copy);
}

if(undo) dt_undo_end_group(darktable.undo);

return TRUE;
Expand All @@ -1034,14 +1032,12 @@ gboolean dt_history_paste_parts_on_list(const GList *list, gboolean undo)
return FALSE;
}

const gboolean merge = dt_conf_get_bool("plugins/lighttable/copy_history/pastemode");

if(undo) dt_undo_start_group(darktable.undo, DT_UNDO_LT_HISTORY);
for (const GList *l = l_copy; l; l = g_list_next(l))
{
const int dest = GPOINTER_TO_INT(l->data);
dt_history_copy_and_paste_on_image(darktable.view_manager->copy_paste.copied_imageid,
dest, merge,
dest,
darktable.view_manager->copy_paste.selops,
darktable.view_manager->copy_paste.copy_iop_order,
darktable.view_manager->copy_paste.full_copy);
Expand Down
2 changes: 1 addition & 1 deletion src/common/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -2317,7 +2317,7 @@ int32_t dt_image_copy_rename(const int32_t imgid, const int32_t filmid, const gc
sqlite3_step(stmt);
sqlite3_finalize(stmt);

dt_history_copy_and_paste_on_image(imgid, newid, FALSE, NULL, TRUE, TRUE);
dt_history_copy_and_paste_on_image(imgid, newid, NULL, TRUE, TRUE);

// write xmp file
dt_control_save_xmp(newid);
Expand Down
18 changes: 8 additions & 10 deletions src/common/imageio.c
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ int dt_imageio_export(const int32_t imgid, const char *filename, dt_imageio_modu
}
}

gboolean _apply_style_before_export(dt_develop_t *dev, dt_imageio_module_data_t *format_params, const uint32_t imgid, const gboolean appending)
gboolean _apply_style_before_export(dt_develop_t *dev, dt_imageio_module_data_t *format_params, const uint32_t imgid)
{
GList *style_items = dt_styles_get_item_list(format_params->style, TRUE, -1);
if(!style_items)
Expand All @@ -685,13 +685,13 @@ gboolean _apply_style_before_export(dt_develop_t *dev, dt_imageio_module_data_t
GList *modules_used = NULL;

dt_ioppr_check_iop_order(dev, imgid, "dt_imageio_export_with_flags");
dt_dev_pop_history_items_ext(dev, appending ? dt_dev_get_history_end(dev) : 0);
dt_ioppr_update_for_style_items(dev, style_items, appending);
dt_dev_pop_history_items_ext(dev, dt_dev_get_history_end(dev));
dt_ioppr_update_for_style_items(dev, style_items, TRUE);

for(GList *st_items = style_items; st_items; st_items = g_list_next(st_items))
{
dt_style_item_t *st_item = (dt_style_item_t *)st_items->data;
dt_styles_apply_style_item(dev, st_item, &modules_used, appending);
dt_styles_apply_style_item(dev, st_item, &modules_used);
}

g_list_free(modules_used);
Expand All @@ -700,15 +700,14 @@ gboolean _apply_style_before_export(dt_develop_t *dev, dt_imageio_module_data_t
return FALSE;
}

void _print_export_debug(dt_dev_pixelpipe_t *pipe, dt_imageio_module_data_t *format_params, const gboolean appending, const gboolean use_style)
void _print_export_debug(dt_dev_pixelpipe_t *pipe, dt_imageio_module_data_t *format_params, const gboolean use_style)
{
if(darktable.unmuted & DT_DEBUG_IMAGEIO)
{
fprintf(stderr,"[dt_imageio_export_with_flags] ");
if(use_style)
{
if(appending) fprintf(stderr,"appending style `%s'\n", format_params->style);
else fprintf(stderr,"overwrite style `%s'\n", format_params->style);
fprintf(stderr,"appending style `%s'\n", format_params->style);
}
else fprintf(stderr,"\n");
int cnt = 0;
Expand Down Expand Up @@ -1027,9 +1026,8 @@ int dt_imageio_export_with_flags(const int32_t imgid, const char *filename,
}

const gboolean use_style = !thumbnail_export && format_params->style[0] != '\0';
const gboolean appending = format_params->style_append != FALSE;
// If a style is to be applied during export, add the iop params into the history
if(use_style && _apply_style_before_export(&dev, format_params, imgid, appending))
if(use_style && _apply_style_before_export(&dev, format_params, imgid))
goto error;

dt_ioppr_resync_modules_order(&dev);
Expand All @@ -1042,7 +1040,7 @@ int dt_imageio_export_with_flags(const int32_t imgid, const char *filename,
dt_dev_pixelpipe_synch_all(&pipe, &dev);

// Write debug info to stdout
_print_export_debug(&pipe, format_params, appending, use_style);
_print_export_debug(&pipe, format_params, use_style);

// Remove modules past or prior a certain one.
// Useful for partial exports, for technical purposes (HDR merge)
Expand Down
2 changes: 0 additions & 2 deletions src/common/imageio_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ typedef struct dt_imageio_module_data_t
int max_width, max_height;
int width, height;
char style[128];
gboolean style_append;
} dt_imageio_module_data_t;

struct dt_imageio_module_format_t;
Expand Down Expand Up @@ -152,4 +151,3 @@ gchar *dt_imageio_resizing_factor_get_and_parsing(double *num, double *denum);
// vim: shiftwidth=2 expandtab tabstop=2 cindent
// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
// clang-format on

48 changes: 7 additions & 41 deletions src/common/styles.c
Original file line number Diff line number Diff line change
Expand Up @@ -558,36 +558,13 @@ void dt_styles_apply_to_list(const char *name, const GList *list, gboolean dupli
const dt_view_t *cv = dt_view_manager_get_current_view(darktable.view_manager);
if(cv->view(cv) == DT_VIEW_DARKROOM) dt_dev_write_history(darktable.develop);

const int mode = dt_conf_get_int("plugins/lighttable/style/applymode");
const gboolean is_overwrite = (mode == DT_STYLE_HISTORY_OVERWRITE);

/* for each selected image apply style */
dt_undo_start_group(darktable.undo, DT_UNDO_LT_HISTORY);

dt_undo_lt_history_t *hist = NULL;

for(const GList *l = list; l; l = g_list_next(l))
{
const int32_t imgid = GPOINTER_TO_INT(l->data);
if(is_overwrite)
{
hist = dt_history_snapshot_item_init();
hist->imgid = imgid;
dt_history_snapshot_undo_create(hist->imgid, &hist->before, &hist->before_history_end);

dt_undo_disable_next(darktable.undo);
if(!duplicate) dt_history_delete_on_image_ext(imgid, FALSE);
}

dt_styles_apply_to_image(name, duplicate, is_overwrite, imgid);

if(is_overwrite)
{
dt_history_snapshot_undo_create(hist->imgid, &hist->after, &hist->after_history_end);
dt_undo_record(darktable.undo, NULL, DT_UNDO_LT_HISTORY, (dt_undo_data_t)hist,
dt_history_snapshot_undo_pop, dt_history_snapshot_undo_lt_history_data_free);
}

dt_styles_apply_to_image(name, duplicate, imgid);
selected = TRUE;
}

Expand Down Expand Up @@ -629,20 +606,14 @@ void dt_multiple_styles_apply_to_list(GList *styles, const GList *list, gboolean
return;
}

const int mode = dt_conf_get_int("plugins/lighttable/style/applymode");
const gboolean is_overwrite = (mode == DT_STYLE_HISTORY_OVERWRITE);

/* for each selected image apply style */
dt_undo_start_group(darktable.undo, DT_UNDO_LT_HISTORY);
for(const GList *l = list; l; l = g_list_next(l))
{
const int32_t imgid = GPOINTER_TO_INT(l->data);
if(is_overwrite && !duplicate)
dt_history_delete_on_image_ext(imgid, FALSE);

for (GList *style = styles; style; style = g_list_next(style))
{
dt_styles_apply_to_image((char*)style->data, duplicate, is_overwrite, imgid);
dt_styles_apply_to_image((char*)style->data, duplicate, imgid);
}
}
dt_undo_end_group(darktable.undo);
Expand All @@ -667,7 +638,7 @@ void dt_styles_create_from_list(const GList *list)
if(!selected) dt_control_log(_("no image selected!"));
}

void dt_styles_apply_style_item(dt_develop_t *dev, dt_style_item_t *style_item, GList **modules_used, const gboolean append)
void dt_styles_apply_style_item(dt_develop_t *dev, dt_style_item_t *style_item, GList **modules_used)
{
dt_pthread_mutex_lock(&dev->history_mutex);

Expand Down Expand Up @@ -758,7 +729,7 @@ void dt_styles_apply_style_item(dt_develop_t *dev, dt_style_item_t *style_item,
}

if(do_merge)
dt_history_merge_module_into_history(dev, NULL, module, modules_used, append);
dt_history_merge_module_into_history(dev, NULL, module, modules_used);
}

if(module)
Expand All @@ -770,7 +741,7 @@ void dt_styles_apply_style_item(dt_develop_t *dev, dt_style_item_t *style_item,
dt_pthread_mutex_unlock(&dev->history_mutex);
}

void dt_styles_apply_to_image(const char *name, const gboolean duplicate, const gboolean overwrite, const int32_t imgid)
void dt_styles_apply_to_image(const char *name, const gboolean duplicate, const int32_t imgid)
{
int id = 0;
sqlite3_stmt *stmt;
Expand All @@ -783,12 +754,7 @@ void dt_styles_apply_to_image(const char *name, const gboolean duplicate, const
{
newimgid = dt_image_duplicate(imgid);
if(newimgid != -1)
{
if(overwrite)
dt_history_delete_on_image_ext(newimgid, FALSE);
else
dt_history_copy_and_paste_on_image(imgid, newimgid, FALSE, NULL, TRUE, TRUE);
}
dt_history_copy_and_paste_on_image(imgid, newimgid, NULL, TRUE, TRUE);
}
else
newimgid = imgid;
Expand Down Expand Up @@ -875,7 +841,7 @@ void dt_styles_apply_to_image(const char *name, const gboolean duplicate, const
for(GList *l = si_list; l; l = g_list_next(l))
{
dt_style_item_t *style_item = (dt_style_item_t *)l->data;
dt_styles_apply_style_item(dev_dest, style_item, &modules_used, FALSE);
dt_styles_apply_style_item(dev_dest, style_item, &modules_used);
}

g_list_free_full(si_list, dt_style_item_free);
Expand Down
5 changes: 2 additions & 3 deletions src/common/styles.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ void dt_styles_apply_to_list(const char *name, const GList *list, gboolean dupli
void dt_multiple_styles_apply_to_list(GList *styles, const GList *list, gboolean duplicate);

/** applies the item style to dev->history */
void dt_styles_apply_style_item(dt_develop_t *dev, dt_style_item_t *style_item, GList **modules_used, const gboolean append);
void dt_styles_apply_style_item(dt_develop_t *dev, dt_style_item_t *style_item, GList **modules_used);

/** applies the style to image by imgid, takes care of overwrite and duplicate modes */
void dt_styles_apply_to_image(const char *name, const gboolean duplicate, const gboolean overwrite, const int32_t imgid);
void dt_styles_apply_to_image(const char *name, const gboolean duplicate, const int32_t imgid);

/** delete a style by name */
void dt_styles_delete_by_name_adv(const char *name, const gboolean raise);
Expand Down Expand Up @@ -132,4 +132,3 @@ void dt_init_styles_actions();
// vim: shiftwidth=2 expandtab tabstop=2 cindent
// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
// clang-format on

7 changes: 2 additions & 5 deletions src/control/jobs/control_jobs.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ typedef struct dt_control_export_t
// is dispatched, but we have to keep that information
gboolean export_masks;
char style[128];
gboolean style_append;
dt_colorspaces_color_profile_type_t icc_type;
gchar *icc_filename;
dt_iop_color_intent_t icc_intent;
Expand Down Expand Up @@ -592,7 +591,7 @@ static int32_t dt_control_duplicate_images_job_run(dt_job_t *job)
if(GPOINTER_TO_INT(params->data))
dt_history_delete_on_image(newimgid);
else
dt_history_copy_and_paste_on_image(imgid, newimgid, FALSE, NULL, TRUE, TRUE);
dt_history_copy_and_paste_on_image(imgid, newimgid, NULL, TRUE, TRUE);

// a duplicate should keep the change time stamp of the original
dt_image_cache_set_change_timestamp_from_image(darktable.image_cache, newimgid, imgid);
Expand Down Expand Up @@ -1369,7 +1368,6 @@ static int32_t dt_control_export_job_run(dt_job_t *job)
fdata->max_width = (settings->max_width != 0 && w != 0) ? MIN(w, settings->max_width) : MAX(w, settings->max_width);
fdata->max_height = (settings->max_height != 0 && h != 0) ? MIN(h, settings->max_height) : MAX(h, settings->max_height);
g_strlcpy(fdata->style, settings->style, sizeof(fdata->style));
fdata->style_append = settings->style_append;
// Invariant: the tagid for 'darktable|changed' will not change while this function runs. Is this a
// sensible assumption?
guint tagid = 0, etagid = 0;
Expand Down Expand Up @@ -1849,7 +1847,7 @@ static void dt_control_export_cleanup(void *p)
}

void dt_control_export(GList *imgid_list, int max_width, int max_height, int format_index, int storage_index,
gboolean high_quality, gboolean export_masks, char *style, gboolean style_append,
gboolean high_quality, gboolean export_masks, char *style,
dt_colorspaces_color_profile_type_t icc_type, const gchar *icc_filename,
dt_iop_color_intent_t icc_intent, const gchar *metadata_export)
{
Expand Down Expand Up @@ -1884,7 +1882,6 @@ void dt_control_export(GList *imgid_list, int max_width, int max_height, int for
data->sdata = sdata;
data->export_masks = export_masks;
g_strlcpy(data->style, style, sizeof(data->style));
data->style_append = style_append;
data->icc_type = icc_type;
data->icc_filename = g_strdup(icc_filename);
data->icc_intent = icc_intent;
Expand Down
2 changes: 1 addition & 1 deletion src/control/jobs/control_jobs.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void dt_control_set_local_copy_images();
void dt_control_reset_local_copy_images();
void dt_control_export(GList *imgid_list, int max_width, int max_height, int format_index, int storage_index,
gboolean high_quality, gboolean export_masks,
char *style, gboolean style_append,
char *style,
dt_colorspaces_color_profile_type_t icc_type, const gchar *icc_filename,
dt_iop_color_intent_t icc_intent, const gchar *metadata_export);
void dt_control_merge_hdr();
Expand Down
Loading

0 comments on commit 84816d5

Please sign in to comment.