2016-04-19 07:18:05 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* file-darktable.c -- raw file format plug-in that uses darktable
|
|
|
|
* Copyright (C) 2012 Simon Budig <simon@gimp.org>
|
|
|
|
* Copyright (C) 2016 Tobias Ellinghaus <me@houz.org>
|
|
|
|
*
|
|
|
|
* This program 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.
|
|
|
|
*
|
|
|
|
* This program 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
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2016-04-19 07:18:05 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <glib/gstdio.h>
|
|
|
|
|
|
|
|
#include <libgimp/gimp.h>
|
|
|
|
|
|
|
|
#include "libgimp/stdplugins-intl.h"
|
|
|
|
|
2017-07-31 00:35:20 +08:00
|
|
|
#include "file-raw-formats.h"
|
2017-07-29 07:15:28 +08:00
|
|
|
#include "file-raw-utils.h"
|
2016-04-19 07:18:05 +08:00
|
|
|
|
2017-07-05 06:50:54 +08:00
|
|
|
|
2018-01-05 21:31:40 +08:00
|
|
|
#define LOAD_THUMB_PROC "file-darktable-load-thumb"
|
2017-07-29 07:15:28 +08:00
|
|
|
#define REGISTRY_KEY_BASE "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\darktable"
|
2016-05-03 21:10:32 +08:00
|
|
|
|
2018-01-05 21:31:40 +08:00
|
|
|
|
2019-08-14 07:34:11 +08:00
|
|
|
typedef struct _Darktable Darktable;
|
|
|
|
typedef struct _DarktableClass DarktableClass;
|
|
|
|
|
|
|
|
struct _Darktable
|
2016-04-19 07:18:05 +08:00
|
|
|
{
|
2019-08-14 07:34:11 +08:00
|
|
|
GimpPlugIn parent_instance;
|
2016-04-19 07:18:05 +08:00
|
|
|
};
|
|
|
|
|
2019-08-14 07:34:11 +08:00
|
|
|
struct _DarktableClass
|
|
|
|
{
|
|
|
|
GimpPlugInClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#define DARKTABLE_TYPE (darktable_get_type ())
|
|
|
|
#define DARKTABLE (obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DARKTABLE_TYPE, Darktable))
|
|
|
|
|
|
|
|
GType darktable_get_type (void) G_GNUC_CONST;
|
|
|
|
|
|
|
|
static GList * darktable_init_procedures (GimpPlugIn *plug_in);
|
|
|
|
static GimpProcedure * darktable_create_procedure (GimpPlugIn *plug_in,
|
|
|
|
const gchar *name);
|
|
|
|
|
|
|
|
static GimpValueArray * darktable_load (GimpProcedure *procedure,
|
|
|
|
GimpRunMode run_mode,
|
|
|
|
GFile *file,
|
|
|
|
const GimpValueArray *args,
|
|
|
|
gpointer run_data);
|
|
|
|
static GimpValueArray * darktable_load_thumb (GimpProcedure *procedure,
|
2019-08-19 20:04:00 +08:00
|
|
|
GFile *file,
|
|
|
|
gint size,
|
2019-08-14 07:34:11 +08:00
|
|
|
const GimpValueArray *args,
|
|
|
|
gpointer run_data);
|
|
|
|
|
2019-09-12 03:48:34 +08:00
|
|
|
static GimpImage * load_image (GFile *file,
|
2019-08-14 07:34:11 +08:00
|
|
|
GimpRunMode run_mode,
|
|
|
|
GError **error);
|
2019-09-12 03:48:34 +08:00
|
|
|
static GimpImage * load_thumbnail_image (GFile *file,
|
2019-08-14 07:34:11 +08:00
|
|
|
gint thumb_size,
|
|
|
|
gint *width,
|
|
|
|
gint *height,
|
|
|
|
GError **error);
|
|
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (Darktable, darktable, GIMP_TYPE_PLUG_IN)
|
|
|
|
|
|
|
|
GIMP_MAIN (DARKTABLE_TYPE)
|
2022-05-26 06:59:36 +08:00
|
|
|
DEFINE_STD_SET_I18N
|
2019-08-14 07:34:11 +08:00
|
|
|
|
2016-04-19 07:18:05 +08:00
|
|
|
|
|
|
|
static void
|
2019-08-14 07:34:11 +08:00
|
|
|
darktable_class_init (DarktableClass *klass)
|
2016-04-19 07:18:05 +08:00
|
|
|
{
|
2019-08-14 07:34:11 +08:00
|
|
|
GimpPlugInClass *plug_in_class = GIMP_PLUG_IN_CLASS (klass);
|
|
|
|
|
|
|
|
plug_in_class->init_procedures = darktable_init_procedures;
|
|
|
|
plug_in_class->create_procedure = darktable_create_procedure;
|
2022-05-26 06:59:36 +08:00
|
|
|
plug_in_class->set_i18n = STD_SET_I18N;
|
2019-08-14 07:34:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
darktable_init (Darktable *darktable)
|
|
|
|
{
|
|
|
|
}
|
2016-04-26 07:03:35 +08:00
|
|
|
|
2019-08-14 07:34:11 +08:00
|
|
|
static GList *
|
|
|
|
darktable_init_procedures (GimpPlugIn *plug_in)
|
|
|
|
{
|
2016-04-25 05:30:25 +08:00
|
|
|
/* check if darktable is installed
|
|
|
|
*/
|
2017-05-15 18:26:51 +08:00
|
|
|
gboolean search_path = FALSE;
|
2017-07-29 07:15:28 +08:00
|
|
|
gchar *exec_path = file_raw_get_executable_path ("darktable", NULL,
|
|
|
|
"DARKTABLE_EXECUTABLE",
|
|
|
|
"org.darktable",
|
|
|
|
REGISTRY_KEY_BASE,
|
|
|
|
&search_path);
|
2017-05-15 18:26:51 +08:00
|
|
|
gchar *argv[] = { exec_path, "--version", NULL };
|
2016-04-25 05:30:25 +08:00
|
|
|
gchar *darktable_stdout = NULL;
|
2017-07-05 06:50:54 +08:00
|
|
|
gchar *darktable_stderr = NULL;
|
2016-04-25 05:30:25 +08:00
|
|
|
gboolean have_darktable = FALSE;
|
2017-07-05 06:50:54 +08:00
|
|
|
GError *error = NULL;
|
2016-04-25 05:30:25 +08:00
|
|
|
gint i;
|
2016-04-21 17:40:45 +08:00
|
|
|
|
2017-11-20 19:48:47 +08:00
|
|
|
/* allow the user to have some insight into why darktable may fail. */
|
|
|
|
gboolean debug_prints = g_getenv ("DARKTABLE_DEBUG") != NULL;
|
|
|
|
|
|
|
|
if (debug_prints)
|
2018-01-05 21:31:40 +08:00
|
|
|
g_printf ("[%s] trying to call '%s'\n", __FILE__, exec_path);
|
2017-07-05 06:50:54 +08:00
|
|
|
|
2016-04-21 17:40:45 +08:00
|
|
|
if (g_spawn_sync (NULL,
|
|
|
|
argv,
|
|
|
|
NULL,
|
2017-05-15 18:26:51 +08:00
|
|
|
(search_path ? G_SPAWN_SEARCH_PATH : 0),
|
2016-04-21 17:40:45 +08:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
&darktable_stdout,
|
2017-07-05 06:50:54 +08:00
|
|
|
&darktable_stderr,
|
2016-04-21 17:40:45 +08:00
|
|
|
NULL,
|
2017-07-05 06:50:54 +08:00
|
|
|
&error))
|
2016-04-21 17:40:45 +08:00
|
|
|
{
|
2017-11-26 10:45:45 +08:00
|
|
|
GRegex *regex;
|
|
|
|
GMatchInfo *matches;
|
|
|
|
gint major;
|
|
|
|
gint minor;
|
|
|
|
|
|
|
|
/* A default darktable would apparently output something like
|
|
|
|
* "this is darktable 2.2.5", but this version string is
|
|
|
|
* customizable. In the official Fedora package for instance, I
|
|
|
|
* encountered a "this is darktable darktable-2.2.5-4.fc27".
|
|
|
|
* Therefore make the version recognition a bit more flexible.
|
|
|
|
*/
|
|
|
|
regex = g_regex_new ("this is darktable [^0-9]*([0-9]+)\\.([0-9]+)\\.([0-9]+)",
|
|
|
|
0, 0, NULL);
|
|
|
|
if (g_regex_match (regex, darktable_stdout, 0, &matches))
|
2016-04-25 05:30:25 +08:00
|
|
|
{
|
2017-11-26 10:45:45 +08:00
|
|
|
gchar *match;
|
|
|
|
|
|
|
|
match = g_match_info_fetch (matches, 1);
|
|
|
|
major = g_ascii_strtoll (match, NULL, 10);
|
|
|
|
g_free (match);
|
|
|
|
|
|
|
|
match = g_match_info_fetch (matches, 2);
|
|
|
|
minor = g_ascii_strtoll (match, NULL, 10);
|
|
|
|
g_free (match);
|
|
|
|
|
2016-04-25 05:30:25 +08:00
|
|
|
if (((major == 1 && minor >= 7) || major >= 2))
|
|
|
|
{
|
|
|
|
if (g_strstr_len (darktable_stdout, -1,
|
|
|
|
"Lua support enabled"))
|
|
|
|
{
|
|
|
|
have_darktable = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-01-05 21:31:40 +08:00
|
|
|
|
2017-11-26 10:45:45 +08:00
|
|
|
g_match_info_free (matches);
|
|
|
|
g_regex_unref (regex);
|
2016-04-21 17:40:45 +08:00
|
|
|
}
|
2017-11-20 19:48:47 +08:00
|
|
|
else if (debug_prints)
|
2018-01-05 21:31:40 +08:00
|
|
|
{
|
|
|
|
g_printf ("[%s] g_spawn_sync failed\n", __FILE__);
|
|
|
|
}
|
2016-04-21 17:40:45 +08:00
|
|
|
|
2017-11-20 19:48:47 +08:00
|
|
|
if (debug_prints)
|
2017-07-05 06:50:54 +08:00
|
|
|
{
|
2017-11-20 19:48:47 +08:00
|
|
|
if (error)
|
2018-01-05 21:31:40 +08:00
|
|
|
g_printf ("[%s] error: %s\n", __FILE__, error->message);
|
|
|
|
|
2017-11-20 19:48:47 +08:00
|
|
|
if (darktable_stdout && *darktable_stdout)
|
2018-01-05 21:31:40 +08:00
|
|
|
g_printf ("[%s] stdout:\n%s\n", __FILE__, darktable_stdout);
|
|
|
|
|
2017-11-20 19:48:47 +08:00
|
|
|
if (darktable_stderr && *darktable_stderr)
|
2018-01-05 21:31:40 +08:00
|
|
|
g_printf ("[%s] stderr:\n%s\n", __FILE__, darktable_stderr);
|
|
|
|
|
|
|
|
g_printf ("[%s] have_darktable: %d\n", __FILE__, have_darktable);
|
2017-07-05 06:50:54 +08:00
|
|
|
}
|
|
|
|
|
2018-01-05 21:31:40 +08:00
|
|
|
g_clear_error (&error);
|
|
|
|
|
2017-07-05 06:50:54 +08:00
|
|
|
g_free (darktable_stdout);
|
|
|
|
g_free (darktable_stderr);
|
2017-05-15 18:26:51 +08:00
|
|
|
g_free (exec_path);
|
|
|
|
|
2019-08-14 07:34:11 +08:00
|
|
|
if (have_darktable)
|
2016-04-19 07:18:05 +08:00
|
|
|
{
|
2019-08-14 07:34:11 +08:00
|
|
|
GList *list = NULL;
|
2016-04-19 07:18:05 +08:00
|
|
|
|
2019-08-14 07:34:11 +08:00
|
|
|
list = g_list_append (list, g_strdup (LOAD_THUMB_PROC));
|
2017-06-28 04:45:31 +08:00
|
|
|
|
2019-08-14 07:34:11 +08:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (file_formats); i++)
|
|
|
|
{
|
|
|
|
const FileFormat *format = &file_formats[i];
|
|
|
|
gchar *load_proc;
|
2016-04-19 07:18:05 +08:00
|
|
|
|
2019-08-14 07:34:11 +08:00
|
|
|
load_proc = g_strdup_printf (format->load_proc_format, "darktable");
|
2016-04-19 07:18:05 +08:00
|
|
|
|
2019-08-14 07:34:11 +08:00
|
|
|
list = g_list_append (list, load_proc);
|
|
|
|
}
|
2016-04-19 07:18:05 +08:00
|
|
|
|
2019-08-14 07:34:11 +08:00
|
|
|
return list;
|
|
|
|
}
|
2016-04-19 07:18:05 +08:00
|
|
|
|
2019-08-14 07:34:11 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2016-04-19 07:18:05 +08:00
|
|
|
|
2019-08-14 07:34:11 +08:00
|
|
|
static GimpProcedure *
|
|
|
|
darktable_create_procedure (GimpPlugIn *plug_in,
|
|
|
|
const gchar *name)
|
|
|
|
{
|
|
|
|
GimpProcedure *procedure = NULL;
|
2017-07-25 02:41:41 +08:00
|
|
|
|
2019-08-14 07:34:11 +08:00
|
|
|
if (! strcmp (name, LOAD_THUMB_PROC))
|
|
|
|
{
|
2019-08-30 18:52:28 +08:00
|
|
|
procedure = gimp_thumbnail_procedure_new (plug_in, name,
|
|
|
|
GIMP_PDB_PROC_TYPE_PLUGIN,
|
2019-08-19 20:04:00 +08:00
|
|
|
darktable_load_thumb, NULL, NULL);
|
2019-08-14 07:34:11 +08:00
|
|
|
|
|
|
|
gimp_procedure_set_documentation (procedure,
|
|
|
|
"Load thumbnail from a raw image "
|
|
|
|
"via darktable",
|
|
|
|
"This plug-in loads a thumbnail "
|
|
|
|
"from a raw image by calling "
|
|
|
|
"darktable-cli.",
|
|
|
|
name);
|
|
|
|
gimp_procedure_set_attribution (procedure,
|
|
|
|
"Tobias Ellinghaus",
|
|
|
|
"Tobias Ellinghaus",
|
|
|
|
"2016");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gint i;
|
2016-04-19 07:18:05 +08:00
|
|
|
|
2019-08-14 07:34:11 +08:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (file_formats); i++)
|
2016-04-19 07:18:05 +08:00
|
|
|
{
|
2019-08-14 07:34:11 +08:00
|
|
|
const FileFormat *format = &file_formats[i];
|
|
|
|
gchar *load_proc;
|
|
|
|
gchar *load_blurb;
|
|
|
|
gchar *load_help;
|
2016-04-19 07:18:05 +08:00
|
|
|
|
2019-08-14 07:34:11 +08:00
|
|
|
load_proc = g_strdup_printf (format->load_proc_format, "darktable");
|
|
|
|
|
|
|
|
if (strcmp (name, load_proc))
|
2016-04-19 07:18:05 +08:00
|
|
|
{
|
2019-08-14 07:34:11 +08:00
|
|
|
g_free (load_proc);
|
|
|
|
continue;
|
2016-04-19 07:18:05 +08:00
|
|
|
}
|
|
|
|
|
2019-08-14 07:34:11 +08:00
|
|
|
load_blurb = g_strdup_printf (format->load_blurb_format, "darktable");
|
|
|
|
load_help = g_strdup_printf (format->load_help_format, "darktable");
|
2016-04-26 07:03:35 +08:00
|
|
|
|
2019-08-30 18:52:28 +08:00
|
|
|
procedure = gimp_load_procedure_new (plug_in, name,
|
|
|
|
GIMP_PDB_PROC_TYPE_PLUGIN,
|
2019-08-14 07:34:11 +08:00
|
|
|
darktable_load,
|
|
|
|
(gpointer) format, NULL);
|
2016-04-26 07:03:35 +08:00
|
|
|
|
2019-08-14 07:34:11 +08:00
|
|
|
gimp_procedure_set_documentation (procedure,
|
|
|
|
load_blurb, load_help, name);
|
|
|
|
gimp_procedure_set_attribution (procedure,
|
|
|
|
"Tobias Ellinghaus",
|
|
|
|
"Tobias Ellinghaus",
|
|
|
|
"2016");
|
|
|
|
|
|
|
|
gimp_file_procedure_set_mime_types (GIMP_FILE_PROCEDURE (procedure),
|
|
|
|
format->mime_type);
|
|
|
|
gimp_file_procedure_set_extensions (GIMP_FILE_PROCEDURE (procedure),
|
|
|
|
format->extensions);
|
|
|
|
gimp_file_procedure_set_magics (GIMP_FILE_PROCEDURE (procedure),
|
|
|
|
format->magic);
|
|
|
|
|
|
|
|
gimp_load_procedure_set_handles_raw (GIMP_LOAD_PROCEDURE (procedure),
|
|
|
|
TRUE);
|
|
|
|
gimp_load_procedure_set_thumbnail_loader (GIMP_LOAD_PROCEDURE (procedure),
|
|
|
|
LOAD_THUMB_PROC);
|
|
|
|
|
|
|
|
g_free (load_proc);
|
|
|
|
g_free (load_blurb);
|
|
|
|
g_free (load_help);
|
2016-04-26 07:03:35 +08:00
|
|
|
|
2016-04-19 07:18:05 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-14 07:34:11 +08:00
|
|
|
return procedure;
|
|
|
|
}
|
2016-04-19 07:18:05 +08:00
|
|
|
|
2019-08-14 07:34:11 +08:00
|
|
|
static GimpValueArray *
|
|
|
|
darktable_load (GimpProcedure *procedure,
|
|
|
|
GimpRunMode run_mode,
|
|
|
|
GFile *file,
|
|
|
|
const GimpValueArray *args,
|
|
|
|
gpointer run_data)
|
|
|
|
{
|
|
|
|
GimpValueArray *return_vals;
|
2019-08-14 22:51:03 +08:00
|
|
|
GimpImage *image;
|
2019-08-14 07:34:11 +08:00
|
|
|
GError *error = NULL;
|
|
|
|
|
2019-09-12 03:48:34 +08:00
|
|
|
image = load_image (file, run_mode, &error);
|
2019-08-14 07:34:11 +08:00
|
|
|
|
2019-08-14 22:51:03 +08:00
|
|
|
if (! image)
|
2019-08-14 07:34:11 +08:00
|
|
|
return gimp_procedure_new_return_values (procedure,
|
|
|
|
GIMP_PDB_EXECUTION_ERROR,
|
|
|
|
error);
|
|
|
|
|
|
|
|
return_vals = gimp_procedure_new_return_values (procedure,
|
|
|
|
GIMP_PDB_SUCCESS,
|
|
|
|
NULL);
|
|
|
|
|
2019-08-14 22:51:03 +08:00
|
|
|
GIMP_VALUES_SET_IMAGE (return_vals, 1, image);
|
2019-08-14 07:34:11 +08:00
|
|
|
|
|
|
|
return return_vals;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GimpValueArray *
|
|
|
|
darktable_load_thumb (GimpProcedure *procedure,
|
2019-08-19 20:04:00 +08:00
|
|
|
GFile *file,
|
|
|
|
gint size,
|
2019-08-14 07:34:11 +08:00
|
|
|
const GimpValueArray *args,
|
|
|
|
gpointer run_data)
|
|
|
|
{
|
|
|
|
GimpValueArray *return_vals;
|
|
|
|
gint width;
|
|
|
|
gint height;
|
2019-08-14 22:51:03 +08:00
|
|
|
GimpImage *image = NULL;
|
2019-08-14 07:34:11 +08:00
|
|
|
GError *error = NULL;
|
|
|
|
|
2019-08-19 20:04:00 +08:00
|
|
|
width = size;
|
|
|
|
height = size;
|
2019-08-19 18:54:52 +08:00
|
|
|
|
2019-09-12 03:48:34 +08:00
|
|
|
image = load_thumbnail_image (file, width, &width, &height, &error);
|
2019-08-14 07:34:11 +08:00
|
|
|
|
2019-08-14 22:51:03 +08:00
|
|
|
if (! image)
|
2019-08-14 07:34:11 +08:00
|
|
|
return gimp_procedure_new_return_values (procedure,
|
|
|
|
GIMP_PDB_EXECUTION_ERROR,
|
|
|
|
error);
|
|
|
|
|
|
|
|
return_vals = gimp_procedure_new_return_values (procedure,
|
|
|
|
GIMP_PDB_SUCCESS,
|
|
|
|
NULL);
|
|
|
|
|
2019-08-14 22:51:03 +08:00
|
|
|
GIMP_VALUES_SET_IMAGE (return_vals, 1, image);
|
2019-08-20 07:03:38 +08:00
|
|
|
GIMP_VALUES_SET_INT (return_vals, 2, width);
|
|
|
|
GIMP_VALUES_SET_INT (return_vals, 3, height);
|
|
|
|
GIMP_VALUES_SET_ENUM (return_vals, 4, GIMP_RGB_IMAGE);
|
|
|
|
GIMP_VALUES_SET_INT (return_vals, 5, 1);
|
2019-08-14 07:34:11 +08:00
|
|
|
|
2019-08-19 20:04:00 +08:00
|
|
|
gimp_value_array_truncate (return_vals, 6);
|
2016-04-19 07:18:05 +08:00
|
|
|
|
2019-08-14 07:34:11 +08:00
|
|
|
return return_vals;
|
2016-04-19 07:18:05 +08:00
|
|
|
}
|
|
|
|
|
2019-08-14 22:51:03 +08:00
|
|
|
static GimpImage *
|
2019-09-12 03:48:34 +08:00
|
|
|
load_image (GFile *file,
|
2016-04-19 07:18:05 +08:00
|
|
|
GimpRunMode run_mode,
|
|
|
|
GError **error)
|
|
|
|
{
|
2019-08-14 22:51:03 +08:00
|
|
|
GimpImage *image = NULL;
|
|
|
|
GFile *lua_file = gimp_data_directory_file ("file-raw",
|
|
|
|
"file-darktable-export-on-exit.lua",
|
|
|
|
NULL);
|
2021-10-02 04:58:14 +08:00
|
|
|
gchar *lua_script_escaped = g_strescape (g_file_peek_path (lua_file), "");
|
2019-08-14 22:51:03 +08:00
|
|
|
gchar *lua_quoted = g_shell_quote (lua_script_escaped);
|
|
|
|
gchar *lua_cmd = g_strdup_printf ("dofile(%s)", lua_quoted);
|
2019-09-12 04:32:44 +08:00
|
|
|
GFile *file_out = gimp_temp_file ("exr");
|
2019-08-14 22:51:03 +08:00
|
|
|
gchar *export_filename = g_strdup_printf ("lua/export_on_exit/export_filename=%s",
|
2021-10-02 04:58:14 +08:00
|
|
|
g_file_peek_path (file_out));
|
2017-09-04 18:56:34 +08:00
|
|
|
|
|
|
|
gchar *darktable_stdout = NULL;
|
2018-01-05 21:21:59 +08:00
|
|
|
gchar *darktable_stderr = NULL;
|
2016-05-03 21:10:32 +08:00
|
|
|
|
2017-11-20 19:48:47 +08:00
|
|
|
/* allow the user to have some insight into why darktable may fail. */
|
|
|
|
gboolean debug_prints = g_getenv ("DARKTABLE_DEBUG") != NULL;
|
|
|
|
|
2016-04-19 07:18:05 +08:00
|
|
|
/* linear sRGB for now as GIMP uses that internally in many places anyway */
|
2017-05-15 18:26:51 +08:00
|
|
|
gboolean search_path = FALSE;
|
2017-07-29 07:15:28 +08:00
|
|
|
gchar *exec_path = file_raw_get_executable_path ("darktable", NULL,
|
|
|
|
"DARKTABLE_EXECUTABLE",
|
|
|
|
"org.darktable",
|
|
|
|
REGISTRY_KEY_BASE,
|
|
|
|
&search_path);
|
2017-07-29 06:15:45 +08:00
|
|
|
gchar *argv[] =
|
2016-04-19 07:18:05 +08:00
|
|
|
{
|
2017-05-15 18:26:51 +08:00
|
|
|
exec_path,
|
2016-04-19 07:18:05 +08:00
|
|
|
"--library", ":memory:",
|
|
|
|
"--luacmd", lua_cmd,
|
2016-04-19 09:29:29 +08:00
|
|
|
"--conf", "plugins/lighttable/export/icctype=3",
|
2016-04-19 09:19:39 +08:00
|
|
|
"--conf", export_filename,
|
2021-10-02 04:58:14 +08:00
|
|
|
(gchar *) g_file_peek_path (file),
|
2016-04-19 07:18:05 +08:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
g_object_unref (lua_file);
|
2017-09-04 18:56:34 +08:00
|
|
|
g_free (lua_script_escaped);
|
2016-04-19 09:28:24 +08:00
|
|
|
g_free (lua_quoted);
|
2016-04-19 07:18:05 +08:00
|
|
|
|
|
|
|
gimp_progress_init_printf (_("Opening '%s'"),
|
2019-09-12 03:48:34 +08:00
|
|
|
gimp_file_get_utf8_name (file));
|
2016-04-19 07:18:05 +08:00
|
|
|
|
2018-01-05 21:21:59 +08:00
|
|
|
if (debug_prints)
|
|
|
|
{
|
2022-05-18 04:58:22 +08:00
|
|
|
gchar **environ_ = g_get_environ ();
|
2021-01-18 21:37:02 +08:00
|
|
|
gint i;
|
|
|
|
|
2018-08-13 01:21:44 +08:00
|
|
|
g_printf ("[%s] trying to call\n", __FILE__);
|
2018-01-05 21:21:59 +08:00
|
|
|
for (gchar **iter = argv; *iter; iter++)
|
2018-08-13 01:21:44 +08:00
|
|
|
g_printf (" %s\n", *iter);
|
|
|
|
g_printf ("\n");
|
2021-01-18 21:37:02 +08:00
|
|
|
|
|
|
|
g_printf ("## Environment ##\n");
|
2022-05-18 04:58:22 +08:00
|
|
|
for (i = 0; environ_[i]; i++)
|
|
|
|
g_printf ("- %s\n", environ_[i]);
|
|
|
|
g_strfreev (environ_) ;
|
2018-01-05 21:21:59 +08:00
|
|
|
}
|
|
|
|
|
2016-04-19 09:19:39 +08:00
|
|
|
if (g_spawn_sync (NULL,
|
2016-04-19 07:18:05 +08:00
|
|
|
argv,
|
|
|
|
NULL,
|
2017-06-28 02:05:52 +08:00
|
|
|
/*G_SPAWN_STDOUT_TO_DEV_NULL |*/
|
2018-01-05 21:21:59 +08:00
|
|
|
/*G_SPAWN_STDERR_TO_DEV_NULL |*/
|
2017-05-15 18:26:51 +08:00
|
|
|
(search_path ? G_SPAWN_SEARCH_PATH : 0),
|
2016-04-19 07:18:05 +08:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2016-05-03 21:10:32 +08:00
|
|
|
&darktable_stdout,
|
2018-01-05 21:21:59 +08:00
|
|
|
&darktable_stderr,
|
2016-04-19 07:18:05 +08:00
|
|
|
NULL,
|
|
|
|
error))
|
|
|
|
{
|
2019-09-12 04:32:44 +08:00
|
|
|
image = gimp_file_load (run_mode, file_out);
|
2016-04-19 07:18:05 +08:00
|
|
|
}
|
|
|
|
|
2018-01-05 21:21:59 +08:00
|
|
|
if (debug_prints)
|
|
|
|
{
|
|
|
|
if (darktable_stdout && *darktable_stdout)
|
2021-01-18 21:37:02 +08:00
|
|
|
g_printf ("\n## stdout ##\n%s\n", darktable_stdout);
|
2018-01-05 21:31:40 +08:00
|
|
|
|
2018-01-05 21:21:59 +08:00
|
|
|
if (darktable_stderr && *darktable_stderr)
|
2021-01-18 21:37:02 +08:00
|
|
|
g_printf ("\n## stderr ##\n%s\n", darktable_stderr);
|
2018-01-05 21:21:59 +08:00
|
|
|
}
|
2018-01-05 21:31:40 +08:00
|
|
|
|
2017-12-20 22:12:10 +08:00
|
|
|
g_free (darktable_stdout);
|
2018-01-05 21:21:59 +08:00
|
|
|
g_free (darktable_stderr);
|
2016-05-03 21:10:32 +08:00
|
|
|
|
2021-10-02 04:58:14 +08:00
|
|
|
g_file_delete (file_out, NULL, NULL);
|
2016-04-19 07:18:05 +08:00
|
|
|
g_free (lua_cmd);
|
2016-04-19 09:19:39 +08:00
|
|
|
g_free (export_filename);
|
2017-05-15 18:26:51 +08:00
|
|
|
g_free (exec_path);
|
2016-04-19 07:18:05 +08:00
|
|
|
|
|
|
|
gimp_progress_update (1.0);
|
|
|
|
|
2019-08-14 22:51:03 +08:00
|
|
|
return image;
|
2016-04-19 07:18:05 +08:00
|
|
|
}
|
2016-04-26 07:03:35 +08:00
|
|
|
|
2019-08-14 22:51:03 +08:00
|
|
|
static GimpImage *
|
2019-09-12 03:48:34 +08:00
|
|
|
load_thumbnail_image (GFile *file,
|
|
|
|
gint thumb_size,
|
|
|
|
gint *width,
|
|
|
|
gint *height,
|
|
|
|
GError **error)
|
2016-04-26 07:03:35 +08:00
|
|
|
{
|
2019-08-14 22:51:03 +08:00
|
|
|
GimpImage *image = NULL;
|
|
|
|
|
2019-09-12 04:32:44 +08:00
|
|
|
GFile *file_out = gimp_temp_file ("jpg");
|
2017-09-04 18:56:34 +08:00
|
|
|
gchar *size = g_strdup_printf ("%d", thumb_size);
|
|
|
|
GFile *lua_file = gimp_data_directory_file ("file-raw",
|
|
|
|
"file-darktable-get-size.lua",
|
|
|
|
NULL);
|
2021-10-02 04:58:14 +08:00
|
|
|
gchar *lua_script_escaped = g_strescape (g_file_peek_path (lua_file), "");
|
2017-09-04 20:08:31 +08:00
|
|
|
gchar *lua_quoted = g_shell_quote (lua_script_escaped);
|
2017-09-04 18:56:34 +08:00
|
|
|
gchar *lua_cmd = g_strdup_printf ("dofile(%s)", lua_quoted);
|
|
|
|
gchar *darktable_stdout = NULL;
|
2016-04-26 07:03:35 +08:00
|
|
|
|
2017-05-15 18:26:51 +08:00
|
|
|
gboolean search_path = FALSE;
|
2017-07-29 07:15:28 +08:00
|
|
|
gchar *exec_path = file_raw_get_executable_path ("darktable", "-cli",
|
|
|
|
"DARKTABLE_EXECUTABLE",
|
|
|
|
"org.darktable",
|
|
|
|
REGISTRY_KEY_BASE,
|
|
|
|
&search_path);
|
2017-07-29 06:15:45 +08:00
|
|
|
gchar *argv[] =
|
2016-04-26 07:03:35 +08:00
|
|
|
{
|
2017-05-15 18:26:51 +08:00
|
|
|
exec_path,
|
2021-10-02 04:58:14 +08:00
|
|
|
(gchar *) g_file_peek_path (file),
|
|
|
|
(gchar *) g_file_peek_path (file_out),
|
2016-04-26 07:03:35 +08:00
|
|
|
"--width", size,
|
|
|
|
"--height", size,
|
|
|
|
"--hq", "false",
|
|
|
|
"--core",
|
|
|
|
"--conf", "plugins/lighttable/export/icctype=3",
|
2016-04-26 19:38:33 +08:00
|
|
|
"--luacmd", lua_cmd,
|
2016-04-26 07:03:35 +08:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2016-04-26 19:38:33 +08:00
|
|
|
g_object_unref (lua_file);
|
2017-09-04 18:56:34 +08:00
|
|
|
g_free (lua_script_escaped);
|
2016-04-26 19:38:33 +08:00
|
|
|
g_free (lua_quoted);
|
|
|
|
|
2016-04-26 07:03:35 +08:00
|
|
|
gimp_progress_init_printf (_("Opening thumbnail for '%s'"),
|
2019-09-12 03:48:34 +08:00
|
|
|
gimp_file_get_utf8_name (file));
|
2016-04-26 07:03:35 +08:00
|
|
|
|
2016-04-26 19:38:33 +08:00
|
|
|
*width = *height = thumb_size;
|
|
|
|
|
2016-04-26 07:03:35 +08:00
|
|
|
if (g_spawn_sync (NULL,
|
|
|
|
argv,
|
|
|
|
NULL,
|
|
|
|
G_SPAWN_STDERR_TO_DEV_NULL |
|
2017-05-15 18:26:51 +08:00
|
|
|
(search_path ? G_SPAWN_SEARCH_PATH : 0),
|
2016-04-26 07:03:35 +08:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2016-04-26 19:38:33 +08:00
|
|
|
&darktable_stdout,
|
2016-04-26 07:03:35 +08:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
error))
|
|
|
|
{
|
|
|
|
gimp_progress_update (0.5);
|
|
|
|
|
2019-09-12 04:32:44 +08:00
|
|
|
image = gimp_file_load (GIMP_RUN_NONINTERACTIVE, file_out);
|
2019-08-14 22:51:03 +08:00
|
|
|
if (image)
|
2016-04-26 07:03:35 +08:00
|
|
|
{
|
2016-04-26 19:38:33 +08:00
|
|
|
/* the size reported by raw files isn't precise,
|
|
|
|
* but it should be close enough to get an idea.
|
|
|
|
*/
|
|
|
|
gchar *start_of_size = g_strstr_len (darktable_stdout,
|
|
|
|
-1,
|
|
|
|
"[dt4gimp]");
|
|
|
|
if (start_of_size)
|
|
|
|
sscanf (start_of_size, "[dt4gimp] %d %d", width, height);
|
2016-04-26 07:03:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_progress_update (1.0);
|
|
|
|
|
2021-10-02 04:58:14 +08:00
|
|
|
g_file_delete (file_out, NULL, NULL);
|
2016-04-26 07:03:35 +08:00
|
|
|
g_free (size);
|
2016-04-26 19:38:33 +08:00
|
|
|
g_free (lua_cmd);
|
|
|
|
g_free (darktable_stdout);
|
2017-05-15 18:26:51 +08:00
|
|
|
g_free (exec_path);
|
2016-04-26 07:03:35 +08:00
|
|
|
|
2019-08-14 22:51:03 +08:00
|
|
|
return image;
|
2016-04-26 07:03:35 +08:00
|
|
|
}
|