Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
copy.c
Go to the documentation of this file.
1/*
2 This file is part of darktable,
3 Copyright (C) 2010-2011, 2014-2020 Tobias Ellinghaus.
4 Copyright (C) 2011-2012 Henrik Andersson.
5 Copyright (C) 2011 johannes hanika.
6 Copyright (C) 2012 Richard Wonka.
7 Copyright (C) 2013 Jérémy Rosen.
8 Copyright (C) 2013-2014, 2020-2021 Pascal Obry.
9 Copyright (C) 2014-2016 Roman Lebedev.
10 Copyright (C) 2014 Ulrich Pegelow.
11 Copyright (C) 2019, 2025 Aurélien PIERRE.
12 Copyright (C) 2020 Ralf Brown.
13 Copyright (C) 2021 Diederik Ter Rahe.
14 Copyright (C) 2022 Martin Bařinka.
15 Copyright (C) 2023 Ricky Moon.
16
17 darktable is free software: you can redistribute it and/or modify
18 it under the terms of the GNU General Public License as published by
19 the Free Software Foundation, either version 3 of the License, or
20 (at your option) any later version.
21
22 darktable is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 GNU General Public License for more details.
26
27 You should have received a copy of the GNU General Public License
28 along with darktable. If not, see <http://www.gnu.org/licenses/>.
29*/
30#include "system/macros.h"
31#include "common/paths.h" // DT_PATH_MAX
32#include "system/mem_alloc.h"
34#include "common/xmp_sidecar.h"
35#include "caches/image_cache.h"
37#include "common/utility.h"
39#include "widgets/label.h"
41#include <glib/gstdio.h>
42#include <inttypes.h>
43#include <stdio.h>
44#include <stdlib.h>
45
46DT_MODULE(1)
47
48// FIXME: we can't rely on darktable to avoid file overwriting -- it doesn't know the filename (extension).
49int write_image(dt_imageio_module_data_t *data, const char *filename, const void *in,
50 dt_colorspaces_color_profile_type_t over_type, const char *over_filename,
51 void *exif, int exif_len, int32_t imgid, int num, int total, struct dt_dev_pixelpipe_t *pipe,
52 const gboolean export_masks)
53{
54 int status = 1;
55 gboolean from_cache = TRUE;
56 char sourcefile[DT_PATH_MAX];
57 char *targetfile = NULL;
58 char *xmpfile = NULL;
59
60 dt_image_full_path(imgid, sourcefile, sizeof(sourcefile), &from_cache, __FUNCTION__);
61
62 char *extension = g_strrstr(sourcefile, ".");
63 if(IS_NULL_PTR(extension)) goto END;
64 targetfile = g_strconcat(filename, ++extension, NULL);
65
66 if(!strcmp(sourcefile, targetfile)) goto END;
67
68 dt_copy_file(sourcefile, targetfile);
69
70 // we got a copy of the file, now write the xmp data
71 xmpfile = g_strconcat(targetfile, ".xmp", NULL);
72 dt_image_t *img = dt_image_cache_get(imgid, 'w');
73 if(IS_NULL_PTR(img) || dt_exif_xmp_write_with_imgpath(img, xmpfile, sourcefile) != 0)
74 {
76 // something went wrong, unlink the copied image.
77 g_unlink(targetfile);
78 goto END;
79 }
81
82 status = 0;
83END:
84 dt_free(targetfile);
85 dt_free(xmpfile);
86 return status;
87}
88
90{
91 return sizeof(dt_imageio_module_data_t);
92}
93
99
101{
102 dt_free(params);
103}
104
105int set_params(dt_imageio_module_format_t *self, const void *params, const int size)
106{
107 if(size != self->params_size(self)) return 1;
108 return 0;
109}
110
112{
113 return 0;
114}
115
117{
118 return "x-copy";
119}
120
122{
123 return "";
124}
125
126const char *name()
127{
128 return _("copy");
129}
130
132{
133}
137
139{
140 self->widget = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, DT_GUI_BOX_SPACING);
141
142 gtk_container_add(GTK_CONTAINER(self->widget),
143 dt_ui_label_new(_("do a 1:1 copy of the selected files.\nthe global options below do not apply!")));
144}
151
152// clang-format off
153// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
154// vim: shiftwidth=2 expandtab tabstop=2 cindent
155// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
156// clang-format on
#define TRUE
Definition ashift_lsd.c:162
void dt_image_full_path(const int32_t imgid, char *pathname, size_t pathname_len, gboolean *from_cache, const char *calling_func)
Get the full path of an image out of the database.
const char * mime(dt_imageio_module_data_t *data)
Definition copy.c:116
size_t params_size(dt_imageio_module_format_t *self)
Definition copy.c:89
void gui_reset(dt_imageio_module_format_t *self)
Definition copy.c:148
void gui_init(dt_imageio_module_format_t *self)
Definition copy.c:138
const char * extension(dt_imageio_module_data_t *data)
Definition copy.c:121
int set_params(dt_imageio_module_format_t *self, const void *params, const int size)
Definition copy.c:105
const char * name()
Definition copy.c:126
void cleanup(dt_imageio_module_format_t *self)
Definition copy.c:134
void free_params(dt_imageio_module_format_t *self, dt_imageio_module_data_t *params)
Definition copy.c:100
void init(dt_imageio_module_format_t *self)
Definition copy.c:131
void * get_params(dt_imageio_module_format_t *self)
Definition copy.c:94
void gui_cleanup(dt_imageio_module_format_t *self)
Definition copy.c:145
int write_image(dt_imageio_module_data_t *data, const char *filename, const void *in, dt_colorspaces_color_profile_type_t over_type, const char *over_filename, void *exif, int exif_len, int32_t imgid, int num, int total, struct dt_dev_pixelpipe_t *pipe, const gboolean export_masks)
Definition copy.c:49
GtkWidget * status
result of the last capture
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_MINIMAL
Definition image_cache.h:53
int bpp
GtkWidget * dt_ui_label_new(const gchar *str)
Definition label.c:125
#define IS_NULL_PTR(p)
C is way too permissive with !=, == and if(var) checks, which can mean too many things depending on w...
Definition macros.h:96
#define dt_free(ptr)
g_free() ptr and set it to NULL, skipping both if it is already NULL.
Definition mem_alloc.h:171
size_t size
Definition mipmap_cache.c:3
#define DT_MODULE(MODVER)
Instantiate the version handshake every module must export. Use once, at file scope,...
#define DT_PATH_MAX
Buffer size for a filesystem path anywhere in Ansel.
Definition paths.h:57
dt_colorspaces_color_profile_type_t
GModule *GtkWidget * widget
void dt_copy_file(const char *const sourcefile, const char *dst)
Definition utility.c:920
#define DT_GUI_BOX_SPACING
int dt_exif_xmp_write_with_imgpath(const dt_image_t *image, const char *filename, const char *imgpath)
The XMP document that carries an image's development: history stack, mask shapes, module order,...