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 "common/darktable.h"
31#include "common/debug.h"
32#include "common/exif.h"
33#include "common/image_cache.h"
35#include "common/utility.h"
37#include "gui/gtk.h"
38#include <glib/gstdio.h>
39#include <inttypes.h>
40#include <stdio.h>
41#include <stdlib.h>
42
43DT_MODULE(1)
44
45// FIXME: we can't rely on darktable to avoid file overwriting -- it doesn't know the filename (extension).
46int write_image(dt_imageio_module_data_t *data, const char *filename, const void *in,
47 dt_colorspaces_color_profile_type_t over_type, const char *over_filename,
48 void *exif, int exif_len, int32_t imgid, int num, int total, struct dt_dev_pixelpipe_t *pipe,
49 const gboolean export_masks)
50{
51 int status = 1;
52 gboolean from_cache = TRUE;
53 char sourcefile[PATH_MAX];
54 char *targetfile = NULL;
55 char *xmpfile = NULL;
56
57 dt_image_full_path(imgid, sourcefile, sizeof(sourcefile), &from_cache, __FUNCTION__);
58
59 char *extension = g_strrstr(sourcefile, ".");
60 if(IS_NULL_PTR(extension)) goto END;
61 targetfile = g_strconcat(filename, ++extension, NULL);
62
63 if(!strcmp(sourcefile, targetfile)) goto END;
64
65 dt_copy_file(sourcefile, targetfile);
66
67 // we got a copy of the file, now write the xmp data
68 xmpfile = g_strconcat(targetfile, ".xmp", NULL);
70 if(IS_NULL_PTR(img) || dt_exif_xmp_write_with_imgpath(img, xmpfile, sourcefile) != 0)
71 {
73 // something went wrong, unlink the copied image.
74 g_unlink(targetfile);
75 goto END;
76 }
78
79 status = 0;
80END:
81 dt_free(targetfile);
82 dt_free(xmpfile);
83 return status;
84}
85
87{
88 return sizeof(dt_imageio_module_data_t);
89}
90
96
101
102int set_params(dt_imageio_module_format_t *self, const void *params, const int size)
103{
104 if(size != self->params_size(self)) return 1;
105 return 0;
106}
107
109{
110 return 0;
111}
112
114{
115 return "x-copy";
116}
117
119{
120 return "";
121}
122
123const char *name()
124{
125 return _("copy");
126}
127
129{
130}
134
136{
137 self->widget = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, DT_GUI_BOX_SPACING);
138
139 gtk_container_add(GTK_CONTAINER(self->widget),
140 dt_ui_label_new(_("do a 1:1 copy of the selected files.\nthe global options below do not apply!")));
141}
148
149// clang-format off
150// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
151// vim: shiftwidth=2 expandtab tabstop=2 cindent
152// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
153// clang-format on
#define TRUE
Definition ashift_lsd.c:162
static const dt_aligned_pixel_simd_t const dt_adaptation_t const float p
dt_colorspaces_color_profile_type_t
Definition colorspaces.h:81
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:113
size_t params_size(dt_imageio_module_format_t *self)
Definition copy.c:86
void gui_reset(dt_imageio_module_format_t *self)
Definition copy.c:145
void gui_init(dt_imageio_module_format_t *self)
Definition copy.c:135
const char * extension(dt_imageio_module_data_t *data)
Definition copy.c:118
int set_params(dt_imageio_module_format_t *self, const void *params, const int size)
Definition copy.c:102
const char * name()
Definition copy.c:123
void cleanup(dt_imageio_module_format_t *self)
Definition copy.c:131
void free_params(dt_imageio_module_format_t *self, dt_imageio_module_data_t *params)
Definition copy.c:97
void init(dt_imageio_module_format_t *self)
Definition copy.c:128
void * get_params(dt_imageio_module_format_t *self)
Definition copy.c:91
void gui_cleanup(dt_imageio_module_format_t *self)
Definition copy.c:142
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:46
darktable_t darktable
Definition darktable.c:181
#define DT_MODULE(MODVER)
Definition darktable.h:140
#define dt_free(ptr)
Definition darktable.h:456
#define PATH_MAX
Definition darktable.h:1062
#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 darktable.h:281
int dt_exif_xmp_write_with_imgpath(const dt_image_t *image, const char *filename, const char *imgpath)
Definition exif.cc:4486
#define DT_GUI_BOX_SPACING
Definition gtk.h:109
static GtkWidget * dt_ui_label_new(const gchar *str)
Definition gtk.h:461
dt_image_t * dt_image_cache_get(dt_image_cache_t *cache, const int32_t imgid, char mode)
void dt_image_cache_write_release(dt_image_cache_t *cache, dt_image_t *img, dt_image_cache_write_mode_t mode)
@ DT_IMAGE_CACHE_MINIMAL
Definition image_cache.h:54
int bpp
size_t size
Definition mipmap_cache.c:3
struct dt_image_cache_t * image_cache
Definition darktable.h:777
GModule *GtkWidget * widget
void dt_copy_file(const char *const sourcefile, const char *dst)
Definition utility.c:917