From 19e15950dc3df7ba27241b594f68e1743f2f2552 Mon Sep 17 00:00:00 2001 From: Colin Clark Date: Mon, 7 Oct 2019 17:46:37 +0100 Subject: [PATCH] Show lens ID data via a lua script 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 | 1 + doc/docbook/GuideSidebarsInfo.xml | 10 +++++++++ plugins/Makefile.am | 2 +- plugins/lens/Makefile.am | 1 + plugins/lens/lensID | 34 +++++++++++++++++++++++++++++++ src/exif-common.c | 4 ++-- src/lua.c | 22 ++++++++++++++++++-- src/osd.c | 1 + src/search.c | 1 - 9 files changed, 70 insertions(+), 6 deletions(-) create mode 100644 plugins/lens/Makefile.am create mode 100644 plugins/lens/lensID diff --git a/configure.ac b/configure.ac index 0da02fda..29f54ae7 100644 --- a/configure.ac +++ b/configure.ac @@ -752,6 +752,7 @@ AC_CONFIG_FILES([ plugins/camera-import/Makefile plugins/image-crop/Makefile plugins/random-image/Makefile + plugins/lens/Makefile geeqie.spec ]) diff --git a/doc/docbook/GuideSidebarsInfo.xml b/doc/docbook/GuideSidebarsInfo.xml index f9c6fc4e..09a4122f 100644 --- a/doc/docbook/GuideSidebarsInfo.xml +++ b/doc/docbook/GuideSidebarsInfo.xml @@ -344,6 +344,16 @@ file.page_no if the file is a multi-page file, e.g. .tiff, the current page number and page total is displayed (e.g. [2/10]) + + lua.lensID + + lens identification data + + Requires lua and exiftool. + This function may be slow. + + + lua.<lua script> diff --git a/plugins/Makefile.am b/plugins/Makefile.am index fa752389..5b63d6c9 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -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 index 00000000..4447d440 --- /dev/null +++ b/plugins/lens/Makefile.am @@ -0,0 +1 @@ +dist_gq_bin_SCRIPTS = lensID diff --git a/plugins/lens/lensID b/plugins/lens/lensID new file mode 100644 index 00000000..5b4d28f2 --- /dev/null +++ b/plugins/lens/lensID @@ -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) diff --git a/src/exif-common.c b/src/exif-common.c index 8cc7c2d4..ea561f4e 100644 --- a/src/exif-common.c +++ b/src/exif-common.c @@ -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; diff --git a/src/lua.c b/src/lua.c index 7859162a..6851926f 100644 --- 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); diff --git a/src/osd.c b/src/osd.c index a32c8377..7e1f6fda 100644 --- 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")}, diff --git a/src/search.c b/src/search.c index 00a57900..aa904db9 100644 --- a/src/search.c +++ b/src/search.c @@ -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); -- 2.20.1