Show lens ID data via a lua script
authorColin Clark <colin.clark@cclark.uk>
Mon, 7 Oct 2019 16:46:37 +0000 (17:46 +0100)
committerColin Clark <colin.clark@cclark.uk>
Mon, 7 Oct 2019 16:46:37 +0000 (17:46 +0100)
Lens ID can be shown in the Overlay Screen Display or the Info sidebar
with the pre-formatted tag lua.lensID.

Requires lua and exiftool.

It is not included in the defaults because it runs rather slowly.

configure.ac
doc/docbook/GuideSidebarsInfo.xml
plugins/Makefile.am
plugins/lens/Makefile.am [new file with mode: 0644]
plugins/lens/lensID [new file with mode: 0644]
src/exif-common.c
src/lua.c
src/osd.c
src/search.c

index 0da02fd..29f54ae 100644 (file)
@@ -752,6 +752,7 @@ AC_CONFIG_FILES([
     plugins/camera-import/Makefile
     plugins/image-crop/Makefile
     plugins/random-image/Makefile
+    plugins/lens/Makefile
     geeqie.spec
 ])
 
index f9c6fc4..09a4122 100644 (file)
             <entry>file.page_no</entry>\r
             <entry>if the file is a multi-page file, e.g. .tiff, the current page number and page total is displayed (e.g. [2/10])</entry>\r
           </row>\r
+          <row>\r
+            <entry>lua.lensID</entry>\r
+            <entry>\r
+              lens identification data\r
+              <footnote id='lensid'>\r
+                Requires lua and exiftool.\r
+                <note>This function may be slow.</note>\r
+              </footnote>\r
+            </entry>\r
+          </row>\r
           <row>\r
             <entry>lua.&lt;lua script&gt;</entry>\r
             <entry>\r
index fa75238..5b63d6c 100644 (file)
@@ -1,5 +1,5 @@
 
-SUBDIRS = rotate symlink ufraw geocode-parameters export-jpeg tethered-photography camera-import image-crop random-image
+SUBDIRS = rotate symlink ufraw geocode-parameters export-jpeg tethered-photography camera-import image-crop random-image lens
 qq_desktoptemplatedir = $(appdir)
 qq_desktoptemplate_in_files = template.desktop.in
 qq_desktoptemplate_DATA = $(qq_desktoptemplate_in_files:.desktop.in=.desktop)
diff --git a/plugins/lens/Makefile.am b/plugins/lens/Makefile.am
new file mode 100644 (file)
index 0000000..4447d44
--- /dev/null
@@ -0,0 +1 @@
+dist_gq_bin_SCRIPTS = lensID
diff --git a/plugins/lens/lensID b/plugins/lens/lensID
new file mode 100644 (file)
index 0000000..5b4d28f
--- /dev/null
@@ -0,0 +1,34 @@
+-- Retrieve the lens ID data
+-- Called from the pre-formatted tag lua.lensID
+-- Requires lua and extftool
+-- Runs rather slow
+
+n = 0
+m = 0
+lensID = ""
+lensIDstring = ""
+
+path = Image:get_path()
+
+lensIDfile = io.popen("exiftool -Composite:LensID \"" .. path .. "\" 2>/dev/null ")
+lensID = lensIDfile:read("*a")
+
+if lensID ~= ""
+then
+       n = string.find(lensID, ":")
+       if n > 2
+       then
+               n = n + 2
+               lensIDstring = string.sub(lensID, n)
+               m = string.find(lensIDstring, "Unknown")
+               if m ~= nil
+               then
+                       lensIDstring = ""
+               else
+                       lensIDstring = string.gsub(lensIDstring, "\n", "")
+               end
+       end
+end
+
+lensIDfile:close()
+return (lensIDstring)
index 8cc7c2d..ea561f4 100644 (file)
@@ -945,6 +945,7 @@ ExifFormattedText ExifFormattedList[] = {
        {"file.link",                           N_("File link"),        NULL},
        {"file.class",                          N_("File class"),       NULL},
        {"file.page_no",                        N_("Page no."),         NULL},
+       {"lua.lensID",                          N_("Lens"),             NULL},
        { NULL, NULL, NULL }
 };
 
@@ -970,8 +971,7 @@ gchar *exif_get_description_by_key(const gchar *key)
 {
        if (!key) return NULL;
 
-       if (strncmp(key, EXIF_FORMATTED(), EXIF_FORMATTED_LEN) == 0 ||
-           strncmp(key, "file.", 5) == 0)
+       if (strncmp(key, EXIF_FORMATTED(), EXIF_FORMATTED_LEN) == 0 || strncmp(key, "file.", 5) == 0 || strncmp(key, "lua.", 4) == 0)
                {
                gint i;
 
index 7859162..6851926 100644 (file)
--- a/src/lua.c
+++ b/src/lua.c
@@ -272,6 +272,26 @@ gchar *lua_callvalue(FileData *fd, const gchar *file, const gchar *function)
        FileData **image_data;
        gchar *tmp;
        GError *error = NULL;
+       gboolean ok;
+
+       ok = access(g_build_filename(get_rc_dir(), "lua", file, NULL), R_OK);
+       if (ok == 0)
+               {
+               path = g_build_filename(get_rc_dir(), "lua", file, NULL);
+               }
+       else
+               {
+               /* FIXME: what is the correct way to find the scripts folder? */
+               ok = access(g_build_filename("/usr/local/lib", GQ_APPNAME_LC, file, NULL), R_OK);
+               if (ok == 0)
+                       {
+                       path = g_build_filename("/usr/local/lib", GQ_APPNAME_LC, file, NULL);
+                       }
+               else
+                       {
+                       return g_strdup("");
+                       }
+               }
 
        /* Collection Table (Dummy at the moment) */
        lua_newtable(L);
@@ -290,8 +310,6 @@ gchar *lua_callvalue(FileData *fd, const gchar *file, const gchar *function)
                }
        else
                {
-               dir = g_build_filename(get_rc_dir(), "lua", NULL);
-               path = g_build_filename(dir, file, NULL);
                result = luaL_dofile(L, path);
                g_free(path);
                g_free(dir);
index a32c837..7e1f6fd 100644 (file)
--- a/src/osd.c
+++ b/src/osd.c
@@ -60,6 +60,7 @@ static const gchar *predefined_tags[][2] = {
        {"%formatted.ExposureBias%",            N_("Exposure bias")},
        {"%formatted.Resolution%",                      N_("Resolution")},
        {"%formatted.Camera%",                          N_("Camera")},
+       {"%lua.lensID%",                                        N_("Lens")},
        {"%formatted.ISOSpeedRating%",          N_("ISO")},
        {"%formatted.FocalLength%",                     N_("Focal length")},
        {"%formatted.FocalLength35mmFilm%",     N_("Focal len. 35mm")},
index 00a5790..aa904db 100644 (file)
@@ -736,7 +736,6 @@ static void search_result_collection_from_selection(SearchData *sd)
 {
        CollectWindow *w;
        GList *list;
-DEBUG_0(" ");
 
        list = search_result_selection_list(sd);
        w = collection_window_new(NULL);