[gimp] plug-ins: Get an image size when creating thumbs with darktable



commit 68b91cc9f6db83c958454918fd83f62ba37b84d8
Author: Tobias Ellinghaus <me houz org>
Date:   Tue Apr 26 13:38:33 2016 +0200

    plug-ins: Get an image size when creating thumbs with darktable
    
    The reported size isn't very precise but close enough to get an idea of
    what you will get. The problem is that raw files always have some unused
    regions that get cropped away later.
    Another source of discrepancy can be manual cropping by the user in
    darktable, but there isn't much we can do about that.

 plug-ins/file-darktable/Makefile.am        |    3 +-
 plug-ins/file-darktable/export-on-exit.lua |   24 +++++++++---------
 plug-ins/file-darktable/file-darktable.c   |   35 +++++++++++++++++++++++----
 plug-ins/file-darktable/get-size.lua       |   21 ++++++++++++++++
 4 files changed, 64 insertions(+), 19 deletions(-)
---
diff --git a/plug-ins/file-darktable/Makefile.am b/plug-ins/file-darktable/Makefile.am
index e3de447..5856463 100644
--- a/plug-ins/file-darktable/Makefile.am
+++ b/plug-ins/file-darktable/Makefile.am
@@ -39,6 +39,7 @@ file_darktable_LDADD = \
        $(file_darktable_RC)
 
 filedarktabledata_DATA = \
-       export-on-exit.lua
+       export-on-exit.lua      \
+       get-size.lua
 
 EXTRA_DIST = $(filedarktabledata_DATA)
diff --git a/plug-ins/file-darktable/export-on-exit.lua b/plug-ins/file-darktable/export-on-exit.lua
index 66066e4..35f457f 100644
--- a/plug-ins/file-darktable/export-on-exit.lua
+++ b/plug-ins/file-darktable/export-on-exit.lua
@@ -1,19 +1,19 @@
 --[[
-    This file is part of GIMP,
-    copyright (c) 2015-2016 Tobias Ellinghaus
+  This file is part of GIMP,
+  copyright (c) 2015-2016 Tobias Ellinghaus
 
-    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.
+  GIMP 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.
+  GIMP 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/>.
+  You should have received a copy of the GNU General Public License
+  along with GIMP.  If not, see <http://www.gnu.org/licenses/>.
 ]]
 
 --[[
diff --git a/plug-ins/file-darktable/file-darktable.c b/plug-ins/file-darktable/file-darktable.c
index ae71e4f..d81031e 100644
--- a/plug-ins/file-darktable/file-darktable.c
+++ b/plug-ins/file-darktable/file-darktable.c
@@ -386,9 +386,16 @@ load_thumbnail_image (const gchar   *filename,
                       gint          *height,
                       GError       **error)
 {
-  gint32  image_ID     = -1;
-  gchar  *filename_out = gimp_temp_name ("jpg");
-  gchar  *size         = g_strdup_printf ("%d", thumb_size);
+  gint32  image_ID         = -1;
+  gchar  *filename_out     = gimp_temp_name ("jpg");
+  gchar  *size             = g_strdup_printf ("%d", thumb_size);
+  GFile  *lua_file         = gimp_data_directory_file ("file-darktable",
+                                                       "get-size.lua",
+                                                       NULL);
+  gchar  *lua_script       = g_file_get_path (lua_file);
+  gchar  *lua_quoted       = g_shell_quote (lua_script);
+  gchar  *lua_cmd          = g_strdup_printf ("dofile(%s)", lua_quoted);
+  gchar  *darktable_stdout = NULL;
 
   gchar *argv[] =
     {
@@ -399,21 +406,27 @@ load_thumbnail_image (const gchar   *filename,
       "--hq",             "false",
       "--core",
       "--conf",           "plugins/lighttable/export/icctype=3",
+      "--luacmd",         lua_cmd,
       NULL
     };
 
+  g_object_unref (lua_file);
+  g_free (lua_script);
+  g_free (lua_quoted);
+
   gimp_progress_init_printf (_("Opening thumbnail for '%s'"),
                              gimp_filename_to_utf8 (filename));
 
+  *width = *height = thumb_size;
+
   if (g_spawn_sync (NULL,
                     argv,
                     NULL,
-                    G_SPAWN_STDOUT_TO_DEV_NULL |
                     G_SPAWN_STDERR_TO_DEV_NULL |
                     G_SPAWN_SEARCH_PATH,
                     NULL,
                     NULL,
-                    NULL,
+                    &darktable_stdout,
                     NULL,
                     NULL,
                     error))
@@ -425,9 +438,17 @@ load_thumbnail_image (const gchar   *filename,
                                  filename_out);
       if (image_ID != -1)
         {
+          /* 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);
+
           /* is this needed for thumbnails? */
           gimp_image_set_filename (image_ID, filename);
-          *width = *height = thumb_size; // TODO
         }
     }
 
@@ -436,6 +457,8 @@ load_thumbnail_image (const gchar   *filename,
   g_unlink (filename_out);
   g_free (filename_out);
   g_free (size);
+  g_free (lua_cmd);
+  g_free (darktable_stdout);
 
   return image_ID;
 }
diff --git a/plug-ins/file-darktable/get-size.lua b/plug-ins/file-darktable/get-size.lua
new file mode 100644
index 0000000..b37811b
--- /dev/null
+++ b/plug-ins/file-darktable/get-size.lua
@@ -0,0 +1,21 @@
+--[[
+  This file is part of GIMP,
+  copyright (c) 2016 Tobias Ellinghaus
+
+  GIMP 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.
+
+  GIMP 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 GIMP.  If not, see <http://www.gnu.org/licenses/>.
+]]
+
+local dt = require "darktable"
+
+print("[dt4gimp] " .. (dt.database[1].width) .. " " .. (dt.database[1].height))


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]