-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stable gimp-darktable calling interface
As we want to support darktable as a gimp plugin in the best possible way we put the burden of "how to do so" on the dt dev team instead of having that on the gimp side as we likely know better to achieve this. Summary of currently implemented darktable features - always use default resources - don't print any logs - while being in darkroom ignore any requests to change view ************************************************************************************** The GIMP support cli API Added --gimp <mode> option to the cli interface. <mode> is always a string, can be "version" "file" "thumb" Whenever we call 'darktable --gimp' the result is a string <res> written to stdout. Also the returncode is 0. In case of errors <res> is "error" and returncode will be 1 As darktable makes use of external libraries <ret> might be preceeded by other text, the <res> is always the last written line string (eol before and after) version Returns the current API version (for initial commit will be 1) file <path> Starts darktable in darkroom mode using image defined by <path>. When closing the darkroom window the file is exported as an xcf file to a temporary location. The full path of the exported file is returned as <res> thumb <path> <dim> Write a thumbnail jpg file to a temporary location. <path> is the image file <dim> (in pixels) is used for the greater of width/height and ratio is kept. The returned <res> has the following format: * The full path of the exported file on the first line * The width and height as space-separated integers on the second line. These dimensions are informational and may not be accurate. For raw files this is sensor size containing valid data.
- Loading branch information
1 parent
ced8a13
commit a5a3680
Showing
9 changed files
with
272 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
This file is part of darktable, | ||
Copyright (C) 2024 darktable developers. | ||
darktable is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
darktable is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with darktable. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "common/image.h" | ||
#include "common/image_cache.h" | ||
#include "control/control.h" | ||
#include <glib.h> | ||
|
||
void dt_gimp_init_settings(void) | ||
{ | ||
darktable.unmuted_signal_dbg_acts = 0; | ||
darktable.unmuted = 0; | ||
} | ||
|
||
gboolean dt_export_gimp_file(const dt_imgid_t id) | ||
{ | ||
const gboolean thumb = dt_check_gimpmode("thumb"); | ||
char *tmp_directory = g_dir_make_tmp("darktable_XXXXXX", NULL); | ||
char path[PATH_MAX]= { 0 }; | ||
|
||
snprintf(path, sizeof(path), "%s/%s", tmp_directory, thumb ? "thumb" : "image"); | ||
g_free(tmp_directory); | ||
|
||
// init the export data structures | ||
dt_imageio_module_storage_t *storage = dt_imageio_get_storage_by_name("disk"); | ||
if(storage == NULL) return FALSE; | ||
|
||
dt_imageio_module_data_t *sdata = storage->get_params(storage); | ||
if(sdata == NULL) return FALSE; | ||
|
||
// and now for the really ugly hacks. don't tell your children about this one or they won't sleep at night | ||
// any longer ... | ||
g_strlcpy((char *)sdata, path, DT_MAX_PATH_FOR_PARAMS); | ||
|
||
dt_imageio_module_format_t *format = dt_imageio_get_format_by_name(thumb ? "jpeg" : "xcf"); | ||
if(format == NULL) return FALSE; | ||
|
||
dt_imageio_module_data_t *fdata = format->get_params(format); | ||
if(fdata == NULL) return FALSE; | ||
|
||
// For disk exporting and used formats we dont have to check dimensions | ||
const size_t dim = MIN(MAX(darktable.gimp.size, 32), 1024); | ||
|
||
fdata->max_width = thumb ? dim : 0; | ||
fdata->max_height = thumb ? dim : 0; | ||
fdata->style[0] = '\0'; | ||
fdata->style_append = FALSE; | ||
|
||
storage->store(storage, sdata, id, format, fdata, 1, 1, | ||
thumb ? FALSE : TRUE, // high_quality, | ||
FALSE, // never upscale | ||
thumb ? FALSE : TRUE, // export_masks | ||
DT_COLORSPACE_SRGB, // for xcf it's irrelevant, for jpeg we want it | ||
NULL, // icc_filename | ||
DT_INTENT_PERCEPTUAL, // for xcf it's irrelevant, for jpeg we want it | ||
NULL); // &metadata | ||
fprintf(stdout, "\n%s%s\n", path, thumb ? ".jpg" : ".xcf"); | ||
if(thumb) | ||
{ | ||
dt_image_t *image = dt_image_cache_get(darktable.image_cache, id, 'r'); | ||
fprintf(stdout, "%i %i\n", image->width, image->height); | ||
dt_image_cache_read_release(darktable.image_cache, image); | ||
} | ||
return TRUE; | ||
} | ||
|
||
dt_imgid_t dt_gimp_load_image(const char *file) | ||
{ | ||
char *filename = dt_util_normalize_path(file); | ||
if(filename == NULL) | ||
return NO_IMGID; | ||
|
||
gchar *directory = g_path_get_dirname((const gchar *)filename); | ||
dt_film_t film; | ||
const dt_filmid_t filmid = dt_film_new(&film, directory); | ||
g_free(directory); | ||
if(!dt_is_valid_filmid(filmid)) | ||
{ | ||
g_free(filename); | ||
return NO_IMGID; | ||
} | ||
|
||
const dt_imgid_t id = dt_image_import(filmid, filename, TRUE, TRUE); | ||
g_free(filename); | ||
|
||
darktable.gimp.imgid = id; | ||
return id; | ||
} | ||
|
||
dt_imgid_t dt_gimp_load_darkroom(const char *file) | ||
{ | ||
const dt_imgid_t id = dt_gimp_load_image(file); | ||
if(dt_is_valid_imgid(id)) | ||
{ | ||
dt_control_set_mouse_over_id(id); | ||
dt_ctl_switch_mode_to("darkroom"); | ||
} | ||
return id; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
This file is part of darktable, | ||
Copyright (C) 2024 darktable developers. | ||
darktable is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
darktable is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with darktable. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#define DT_GIMP_VERSION 1 | ||
|
||
void dt_gimp_init_settings(void); | ||
gboolean dt_export_gimp_file(const dt_imgid_t id); | ||
|
||
dt_imgid_t dt_gimp_load_darkroom(const char *file); | ||
dt_imgid_t dt_gimp_load_image(const char *file); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters