]> git.datanom.net - lensdb.git/commitdiff
Implement Exif scanner
authorMichael Rasmussen <mir@datanom.net>
Thu, 24 Oct 2024 00:25:00 +0000 (02:25 +0200)
committerMichael Rasmussen <mir@datanom.net>
Thu, 24 Oct 2024 00:25:00 +0000 (02:25 +0200)
Signed-off-by: Michael Rasmussen <mir@datanom.net>
12 files changed:
Makefile.am
configure.ac
lib/Makefile.am
lib/exiftool/ExifTool.h [new file with mode: 0644]
lib/exiftool/ExifToolPipe.h [new file with mode: 0644]
lib/exiftool/TagInfo.h [new file with mode: 0644]
lib/main.cpp
lib/main.hpp [new file with mode: 0644]
lib/scanner.cpp [new file with mode: 0644]
lib/scanner.h [new file with mode: 0644]
src/Makefile.am
src/main.c

index 420aa244d03c5fa945f3370264d2083111ead7b2..401c4a6603deeeab748e434e1bdd025b8e583e38 100644 (file)
@@ -3,8 +3,8 @@ AUTOMAKE_OPTIONS = gnu
 ACLOCAL_AMFLAGS = -I m4
 
 SUBDIRS = \
 ACLOCAL_AMFLAGS = -I m4
 
 SUBDIRS = \
-         src \
-         lib
+         lib \
+         src
 
 EXTRA_DIST = \
             AUTHORS \
 
 EXTRA_DIST = \
             AUTHORS \
index 42454960412b5530b5d74c2a1389ad05bc2a7248..f628fb89706a9660f0d3a362b36a2d40cc387e5d 100644 (file)
@@ -25,11 +25,13 @@ GLIB_REQUIRED=2.50.0
 GOBJECT_REQUIRED=2.50.0
 GTK_REQUIRED=3.24
 SQLITE3_REQUIRED=3.40
 GOBJECT_REQUIRED=2.50.0
 GTK_REQUIRED=3.24
 SQLITE3_REQUIRED=3.40
+EXIV2_REQUIRED=0.28
 
 AC_SUBST(GLIB_REQUIRED)
 AC_SUBST(GOBJECT_REQUIRED)
 AC_SUBST(GTK_REQUIRED)
 AC_SUBST(SQLITE3_REQUIRED)
 
 AC_SUBST(GLIB_REQUIRED)
 AC_SUBST(GOBJECT_REQUIRED)
 AC_SUBST(GTK_REQUIRED)
 AC_SUBST(SQLITE3_REQUIRED)
+AC_SUBST(EXIV2_REQUIRED)
 
 AC_CONFIG_HEADERS(config.h)
 
 
 AC_CONFIG_HEADERS(config.h)
 
@@ -41,6 +43,7 @@ AC_PROG_LN_S
 AC_PROG_MAKE_SET
 AC_PROG_CPP
 LT_INIT
 AC_PROG_MAKE_SET
 AC_PROG_CPP
 LT_INIT
+
 if test -n "$lt_prog_compiler_pic"; then
     CFLAGS="$CFLAGS $lt_prog_compiler_pic"
 fi
 if test -n "$lt_prog_compiler_pic"; then
     CFLAGS="$CFLAGS $lt_prog_compiler_pic"
 fi
@@ -58,9 +61,10 @@ enable_exif_scanner=yes
 AC_MSG_CHECKING([whether to build EXIF scanner])
 if test x"$HAVE_CXX" = xno; then
        AC_MSG_RESULT(no)
 AC_MSG_CHECKING([whether to build EXIF scanner])
 if test x"$HAVE_CXX" = xno; then
        AC_MSG_RESULT(no)
-       AC_MSG_ERROR("Auto read EXIF cannot be built; missing $dependencies_missing")
+       AC_MSG_WARN("Auto read EXIF cannot be built; missing dependencies")
        enable_exif_scanner=no
 else
        enable_exif_scanner=no
 else
+       LIBS+="-lstdc++"
        AC_MSG_RESULT(yes)
 fi
 
        AC_MSG_RESULT(yes)
 fi
 
@@ -86,6 +90,10 @@ PKG_CHECK_MODULES([SQLITE3], [sqlite3 >= $SQLITE3_REQUIRED])
 AC_SUBST(SQLITE3_LIBS)
 AC_SUBST(SQLITE3_CFLAGS)
 
 AC_SUBST(SQLITE3_LIBS)
 AC_SUBST(SQLITE3_CFLAGS)
 
+PKG_CHECK_MODULES([EXIV2], [exiv2 >= $EXIV2_REQUIRED])
+AC_SUBST(EXIV2_LIBS)
+AC_SUBST(EXIV2_CFLAGS)
+
 # Checks for header files.
 AC_CHECK_HEADER([assert.h],
                AC_DEFINE([HAVE_ASSERT_H], [1], [Define to 1 if you have the <assert.h> header file.]))
 # Checks for header files.
 AC_CHECK_HEADER([assert.h],
                AC_DEFINE([HAVE_ASSERT_H], [1], [Define to 1 if you have the <assert.h> header file.]))
index bb28425df32a913310d7813b840e5ace66c97f0c..0082fae3697a415c62886864c538a13fc7367fe9 100644 (file)
@@ -1,17 +1,22 @@
 AUTOMAKE_OPTIONS = gnu
 
 AUTOMAKE_OPTIONS = gnu
 
-IFLAGS = \
+AM_CPPFLAGS = \
         -I${top_srcdir} \
         -I${top_srcdir} \
-        -I${top_builddir}
+        -I${top_builddir} \
+        @EXIV2_CFLAGS@
 
 if BUILD_EXIF_SCANNER
 noinst_LIBRARIES = libscanner.a 
 
 libscanner_a_SOURCES = \
 
 if BUILD_EXIF_SCANNER
 noinst_LIBRARIES = libscanner.a 
 
 libscanner_a_SOURCES = \
-                      main.cpp
+                      main.cpp \
+                      main.hpp \
+                      scanner.h \
+                      scanner.cpp
 
 libscanner_a_LIBADD = \
                      $(LIBOBJS) \
 
 libscanner_a_LIBADD = \
                      $(LIBOBJS) \
-                     $(ALLOCA)
+                     $(ALLOCA) \
+                     @EXIV2_LIBS@
 
 endif
 
 endif
diff --git a/lib/exiftool/ExifTool.h b/lib/exiftool/ExifTool.h
new file mode 100644 (file)
index 0000000..247ef1b
--- /dev/null
@@ -0,0 +1,93 @@
+//------------------------------------------------------------------------------
+// File:        ExifTool.h
+//
+// Description: C++ library interface to Perl exiftool application script
+//
+// License:     Copyright 2013-2019, Phil Harvey (philharvey66 at gmail.com)
+//
+//              This is software, in whole or part, is free for use in
+//              non-commercial applications, provided that this copyright notice
+//              is retained.  A licensing fee may be required for use in a
+//              commercial application.
+//
+// Created:     2013-11-23 - Phil Harvey
+//------------------------------------------------------------------------------
+#ifndef __EXIFTOOL_H__
+#define __EXIFTOOL_H__
+
+#include "ExifToolPipe.h"
+#include "TagInfo.h"
+
+#define NOW     0
+#define NEVER   1e9
+
+#define SUMMARY_DIRECTORIES_SCANNED     "directories scanned"
+#define SUMMARY_DIRECTORIES_CREATED     "directories created"
+#define SUMMARY_FILES_FAILED_CONDITION  "files failed condition"
+#define SUMMARY_IMAGE_FILES_CREATED     "image files created"
+#define SUMMARY_IMAGE_FILES_UPDATED     "image files updated"
+#define SUMMARY_IMAGE_FILES_UNCHANGED   "image files unchanged"
+#define SUMMARY_IMAGE_FILES_MOVED       "image files moved"
+#define SUMMARY_IMAGE_FILES_COPIED      "image files copied"
+#define SUMMARY_FILE_UPDATE_ERRORS      "files weren't updated due to errors"
+#define SUMMARY_FILE_CREATE_ERRORS      "files weren't created due to errors"
+#define SUMMARY_IMAGE_FILES_READ        "image files read"
+#define SUMMARY_IMAGE_FILE_ERRORS       "files could not be read"
+#define SUMMARY_OUTPUT_FILES_CREATED    "output files created"
+#define SUMMARY_OUTPUT_FILES_APPENDED   "output files appended"
+#define SUMMARY_HARD_LINKS_CREATED      "hard links created"
+#define SUMMARY_HARD_LINK_ERRORS        "hard links could not be created"
+#define SUMMARY_SYMBOLIC_LINKS_CREATED  "symbolic links created"
+#define SUMMARY_SYMBOLIC_LINK_ERRORS    "symbolic links could not be created"
+
+class ExifTool
+{
+public:
+            ExifTool(const char *exec=NULL, const char *arg1=NULL);
+    virtual ~ExifTool();
+
+    TagInfo *ImageInfo(const char *file, const char *opts=NULL, double timeout=NEVER);
+
+    int     ExtractInfo(const char *file, const char *opts=NULL);
+    TagInfo *GetInfo(int cmdNum=0, double timeout=NEVER);
+
+    int     SetNewValue(const char *tag=NULL, const char *value=NULL, int len=-1);
+    int     WriteInfo(const char *file, const char *opts=NULL, TagInfo *info=NULL);
+
+    int     Command(const char *cmd=NULL);
+    int     Complete(double timeout=NEVER);
+
+    int     IsRunning();
+    int     LastComplete()  { return mLastComplete; }
+    int     LastCommand()   { return mCmdNum; } // (undocumented)
+    void    SetLastComplete(int lastComplete) { mLastComplete = lastComplete; }
+    void    SetWaitTime(int waitTime) { mWaitTime = waitTime; }
+
+    char *  GetOutput()     { return mLastComplete > 0 ? mStdout.GetString() : NULL; }
+    int     GetOutputLen()  { return mLastComplete > 0 ? mStdout.GetStringLen() : 0; }
+    char *  GetError()      { return mLastComplete > 0 ? mStderr.GetString() : NULL; }
+    int     GetErrorLen()   { return mLastComplete > 0 ? mStderr.GetStringLen() : 0; } // (undocumented)
+
+    int     GetSummary(const char *msg);
+
+    // flags to allow some ExifTool features to be disabled
+    // (must be set before creating ExifTool object)
+    static int  sNoSigPipe;     // set to disable SIGPIPE handler
+    static int  sNoWatchdog;    // set to disable watchdog process
+
+private:
+    ExifToolPipe  mStdout;      // buffer for exiftool stdout read pipe
+    ExifToolPipe  mStderr;      // buffer for exiftool stderr read pipe
+    int           mTo;          // write pipe for exiftool stdin
+    int           mPid;         // exiftool application process ID
+    int           mWatchdog;    // watchdog process ID
+    TagInfo     * mWriteInfo;   // tag information to write
+    char        * mCmdQueue;    // queued command arguments (NULL if nothing queued)
+    int           mCmdQueueLen; // length of data in command queue
+    int           mCmdQueueSize;// size of command queue
+    int           mLastComplete;// result of last Complete() call
+    int           mCmdNum;      // last command number
+    int           mWaitTime;    // time to wait (microsec) if no commands in queue
+};
+
+#endif // __EXIFTOOL_H__
diff --git a/lib/exiftool/ExifToolPipe.h b/lib/exiftool/ExifToolPipe.h
new file mode 100644 (file)
index 0000000..8b65cd5
--- /dev/null
@@ -0,0 +1,43 @@
+//------------------------------------------------------------------------------
+// File:        ExifToolPipe.h
+//
+// Description: Piped output from exiftool application
+//
+// License:     Copyright 2013-2019, Phil Harvey (philharvey66 at gmail.com)
+//
+//              This is software, in whole or part, is free for use in
+//              non-commercial applications, provided that this copyright notice
+//              is retained.  A licensing fee may be required for use in a
+//              commercial application.
+//
+// Created:     2013-11-23 - Phil Harvey
+//------------------------------------------------------------------------------
+#ifndef __EXIFTOOLPIPE_H__
+#define __EXIFTOOLPIPE_H__
+
+class ExifToolPipe
+{
+public:
+    ExifToolPipe();
+    ~ExifToolPipe();
+    void    Init(int fd, int pid, int initialSize);
+    int     Read();     // read exiftool response
+    void    Free();     // free buffer memory
+    void    Flush();    // remove previous response from buffer
+    char  * GetString() { return (mString && mString[0]) ? mString : (char *)0; }
+    int     GetStringLen() { return mStringLen; }
+
+private:
+    int     mFile;      // read file descriptor
+    char  * mBuff;      // buffer pointer
+    int     mSize;      // buffer size
+    int     mLen;       // length of data in buffer
+    int     mPos;       // current read position in buffer
+    int     mSearchPos; // current search position in buffer
+    int     mBlockSize; // initial buffer size
+    char  * mString;    // returned string from last Read()
+    int     mStringLen; // length of returned string
+    int     mPid;       // process id for other side of the pipe
+};
+
+#endif // __EXIFTOOLPIPE_H__
diff --git a/lib/exiftool/TagInfo.h b/lib/exiftool/TagInfo.h
new file mode 100644 (file)
index 0000000..57d3f45
--- /dev/null
@@ -0,0 +1,35 @@
+//------------------------------------------------------------------------------
+// File:        TagInfo.h
+//
+// Description: Tag information object
+//
+// License:     Copyright 2013-2019, Phil Harvey (philharvey66 at gmail.com)
+//
+//              This is software, in whole or part, is free for use in
+//              non-commercial applications, provided that this copyright notice
+//              is retained.  A licensing fee may be required for use in a
+//              commercial application.
+//
+// Created:     2013-11-23 - Phil Harvey
+//------------------------------------------------------------------------------
+#ifndef __TAGINFO_H__
+#define __TAGINFO_H__
+
+struct TagInfo
+{
+    TagInfo();
+    virtual ~TagInfo();
+
+    char    *group[3];  // family 0-2 group names
+    char    *name;      // tag name
+    char    *desc;      // tag description
+    char    *id;        // tag ID
+    char    *value;     // converted value
+    int     valueLen;   // length of value in bytes (not including null terminator)
+    char    *num;       // "numerical" value
+    int     numLen;     // length of numerical value
+    int     copyNum;    // copy number for this tag name
+    TagInfo *next;      // next TagInfo in linked list
+};
+
+#endif // __TAGINFO_H__
index ad1d7048115b92e36978ce819ecf16788cc01926..27efeaab0ea2c49417c7233bd68511745eadb77c 100644 (file)
@@ -1,3 +1,39 @@
- int main(int argc, char** argv) {
-        return 0;
- }
+#include "main.hpp"
+
+using namespace std;
+
+
+ExifScanner::ExifScanner(const char* file): file(file) {
+
+}
+
+ExifScanner::~ExifScanner() {
+
+}
+
+void ExifScanner::scanner_do_work() {
+       if (file == NULL){
+        cout << "Example1: Read metadata from an image." << endl;
+        cout << "Please specify input file name" << endl;
+        return;
+    }
+
+    // create our ExifTool object
+    ExifTool *et = new ExifTool();
+    // read metadata from the image
+    TagInfo *info = et->ImageInfo(file);
+    if (info) {
+        // print returned information
+        for (TagInfo *i=info; i; i=i->next) {
+            cout << i->name << " = " << i->value << endl;
+        }
+        // we are responsible for deleting the information when done
+        delete info;
+    } else if (et->LastComplete() <= 0) {
+        cerr << "Error executing exiftool!" << endl;
+    }
+    // print exiftool stderr messages
+    char *err = et->GetError();
+    if (err) cout << err;
+    delete et;      // delete our ExifTool object              
+}
diff --git a/lib/main.hpp b/lib/main.hpp
new file mode 100644 (file)
index 0000000..b828632
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * main.hpp
+ * 
+ * Copyright 2024 Michael Rasmussen <mir@datanom.net>
+ * 
+ * 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 2 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
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ * 
+ * 
+ */
+
+
+#ifndef _MAIN_HPP_
+#define _MAIN_HPP_
+
+#include <iostream>
+#include "exiftool/ExifTool.h"
+
+class ExifScanner {
+public:
+    ExifScanner(const char* file);
+    ~ExifScanner();
+
+    void scanner_do_work();
+
+private:
+    const char* file;
+    
+};
+
+#endif /* _MAIN_HPP_ */
diff --git a/lib/scanner.cpp b/lib/scanner.cpp
new file mode 100644 (file)
index 0000000..961f64d
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * scanner.cpp
+ * 
+ * Copyright 2024 Michael Rasmussen <mir@datanom.net>
+ * 
+ * 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 2 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
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ * 
+ * 
+ */
+
+#include <stdlib.h> 
+#include "main.hpp"
+#include "scanner.h"
+
+struct Scanner {
+       void* obj;
+};
+
+Scanner_t* scanner_create(const char* file) {
+       Scanner_t* s;
+       ExifScanner* obj;
+       
+       s = (typeof(s))malloc(sizeof(*s));
+       obj = new ExifScanner(file);
+       s->obj = obj;
+       
+       return s;
+}
+
+void scanner_destroy(Scanner_t* s) {
+       if (s == NULL)
+               return;
+
+       delete static_cast<ExifScanner *>(s->obj);
+       free(s);
+}
+
+void scanner_do_work(Scanner_t* s) {
+       ExifScanner* obj;
+
+       if (s == NULL)
+               return;
+
+       obj = static_cast<ExifScanner *>(s->obj);
+       obj->scanner_do_work();
+}
diff --git a/lib/scanner.h b/lib/scanner.h
new file mode 100644 (file)
index 0000000..555ac99
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * scanner.h
+ * 
+ * Copyright 2024 Michael Rasmussen <mir@datanom.net>
+ * 
+ * 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
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ * 
+ * 
+ */
+
+#ifndef _SCANNER_H_
+#define _SCANNER_H_
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+struct Scanner;
+typedef struct Scanner Scanner_t;
+
+Scanner_t* scanner_create(const char* file);
+
+void scanner_destroy(Scanner_t* s);
+
+void scanner_do_work(Scanner_t* s);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* _SCANNER_H_ */
index 65006d6cbd51e7edbbf4726c9b27728a46d53707..90d919b0e718651c6817ea2dc9b3e6f855b67d03 100644 (file)
@@ -1,8 +1,17 @@
 AUTOMAKE_OPTIONS = gnu
 
 AUTOMAKE_OPTIONS = gnu
 
+extra =
+
+if BUILD_EXIF_SCANNER
+extra += \
+               ${top_builddir}/lib/libscanner.a  \
+               ${top_builddir}/lib/exiftool/exiftool.a
+endif
+
 AM_CPPFLAGS = \
            -I${top_srcdir} \
            -I${top_builddir} \
 AM_CPPFLAGS = \
            -I${top_srcdir} \
            -I${top_builddir} \
+           -I${top_srcdir}/lib \
            @GLIB_CFLAGS@ \
            @GTK_CFLAGS@ \
            @SQLITE3_CFLAGS@
            @GLIB_CFLAGS@ \
            @GTK_CFLAGS@ \
            @SQLITE3_CFLAGS@
@@ -22,7 +31,10 @@ lensdb_SOURCES = \
 lensdb_LDADD = \
                @GLIB_LIBS@ \
                @GTK_LIBS@ \
 lensdb_LDADD = \
                @GLIB_LIBS@ \
                @GTK_LIBS@ \
-               @SQLITE3_LIBS@
+               @SQLITE3_LIBS@ \
+               ${extra} \
+               @LIBS@
+               
 
 lensdb_LDFLAGS =
 
 
 lensdb_LDFLAGS =
 
index 9ad343a582736aecc8c55d5677623d61d74781d8..351c627b259d2b3bf1362f0384976a77a0506047 100644 (file)
 #include <stdio.h>
 #include "sqlite-storage.h"
 #include "gui.h"
 #include <stdio.h>
 #include "sqlite-storage.h"
 #include "gui.h"
-
+#include "lib/scanner.h"
 
 gint main(gint argc, gchar** argv) {
        gint status = 0;
 
 
 gint main(gint argc, gchar** argv) {
        gint status = 0;
 
+//     Scanner_t* sc = scanner_create("/home/mir/Pictures/Pictures/20211019_0012.jpg");
+//     Scanner_t* sc = scanner_create("/home/mir/Pictures/Pictures/2024/09/14/Lndskrona Foto Festival/Lndskrona Foto Festival-8.ORF");
+       Scanner_t* sc = scanner_create("/home/mir/Pictures/Pictures/2024/08/21/Fototur til Hejresøen/Fototur til Hejresøen-6.NEF");
+       scanner_do_work(sc);
+       scanner_destroy(sc);
+       
        gchar* path = g_path_get_dirname(argv[0]);
        if ((status = init_storage(path)) > 0) {
                fprintf(stderr, "%s: Failed to open DB\n", path);
        gchar* path = g_path_get_dirname(argv[0]);
        if ((status = init_storage(path)) > 0) {
                fprintf(stderr, "%s: Failed to open DB\n", path);
This page took 0.362126 seconds and 5 git commands to generate.