Move third-party sources to separate sub-directory
[geeqie.git] / src / exif-common.cc
index 8c87be4..4dcdc4b 100644 (file)
 
 #include <config.h>
 
+#ifdef __linux__
 #define _XOPEN_SOURCE
+#endif
+
+#include <sys/stat.h>
 
 #include <cmath>
 #include <cstdlib>
 #include <cstring>
+#include <ctime>
 
-#ifdef HAVE_LCMS
-/*** color support enabled ***/
+#include <glib.h>
 
-#ifdef HAVE_LCMS2
-#include <lcms2.h>
-#else
-#include <lcms.h>
-#endif
+#if HAVE_LCMS
+/*** color support enabled ***/
+#  if HAVE_LCMS2
+#    include <lcms2.h>
+#  else
+#    include <lcms.h>
+#  endif
 #endif
 
-#include "main.h"
+#include "cache.h"
+#include "debug.h"
 #include "exif.h"
-
 #include "filecache.h"
+#include "filedata.h"
 #include "glua.h"
-#include "ui-fileops.h"
-#include "cache.h"
+#include "intl.h"
 #include "jpeg-parser.h"
+#include "main-defines.h"
 #include "misc.h"
-#include "zonedetect.h"
+#include "third-party/zonedetect.h"
+#include "typedefs.h"
+#include "ui-fileops.h"
+struct ExifData;
+struct ExifItem;
+struct FileCacheData;
+struct ZoneDetect;
 
 
 static gdouble exif_rational_to_double(ExifRational *r, gint sign)
@@ -97,8 +110,12 @@ static gdouble get_crop_factor(ExifData *exif)
        gdouble xres = exif_get_rational_as_double(exif, "Exif.Photo.FocalPlaneXResolution");
        gdouble yres = exif_get_rational_as_double(exif, "Exif.Photo.FocalPlaneYResolution");
        gint res_unit;
-       gint w, h;
-       gdouble xsize, ysize, size, ratio;
+       gint w;
+       gint h;
+       gdouble xsize;
+       gdouble ysize;
+       gdouble size;
+       gdouble ratio;
 
        if (xres == 0.0 || yres == 0.0) return 0.0;
 
@@ -115,12 +132,11 @@ static gdouble get_crop_factor(ExifData *exif)
 
        if (ratio < 0.5 || ratio > 2.0) return 0.0; /* reasonable ratio */
 
-       size = sqrt(xsize * xsize + ysize * ysize);
+       size = hypot(xsize, ysize);
 
        if (size < 1.0 || size > 100.0) return 0.0; /* reasonable sensor size in mm */
 
-       return sqrt(36*36+24*24) / size;
-
+       return hypot(36, 24) / size;
 }
 
 static gboolean remove_suffix(gchar *str, const gchar *suffix, gint suffix_len)
@@ -159,7 +175,8 @@ static gchar *exif_build_formatted_Camera(ExifData *exif)
 
        if (software)
                {
-               gint i, j;
+               gint i;
+               gint j;
 
                g_strstrip(software);
 
@@ -351,7 +368,8 @@ static gchar *exif_build_formatted_FocalLength(ExifData *exif)
 static gchar *exif_build_formatted_FocalLength35mmFilm(ExifData *exif)
 {
        gint n;
-       gdouble f, c;
+       gdouble f;
+       gdouble c;
 
        if (exif_get_integer(exif, "Exif.Photo.FocalLengthIn35mmFilm", &n) && n != 0)
                {
@@ -400,7 +418,6 @@ static gchar *exif_build_formatted_Flash(ExifData *exif)
 {
        /* grr, flash is a bitmask... */
        GString *string;
-       gchar *text;
        gint n;
        gint v;
 
@@ -441,14 +458,13 @@ static gchar *exif_build_formatted_Flash(ExifData *exif)
        /* red-eye (bit 6) */
        if ((n >> 5) & 0x01) string = append_comma_text(string, _("red-eye reduction"));
 
-       text = string->str;
-       g_string_free(string, FALSE);
-       return text;
+       return g_string_free(string, FALSE);
 }
 
 static gchar *exif_build_formatted_Resolution(ExifData *exif)
 {
-       ExifRational *rx, *ry;
+       ExifRational *rx;
+       ExifRational *ry;
        gchar *units;
        gchar *text;
 
@@ -467,7 +483,7 @@ static gchar *exif_build_formatted_Resolution(ExifData *exif)
 
 static gchar *exif_build_formatted_ColorProfile(ExifData *exif)
 {
-#ifdef HAVE_LCMS2
+#if HAVE_LCMS2
        cmsUInt8Number profileID[17];
 #endif
        const gchar *name = "";
@@ -501,7 +517,7 @@ static gchar *exif_build_formatted_ColorProfile(ExifData *exif)
        else
                {
                source = _("embedded");
-#ifdef HAVE_LCMS
+#if HAVE_LCMS
 
                        {
                        cmsHPROFILE profile;
@@ -509,7 +525,7 @@ static gchar *exif_build_formatted_ColorProfile(ExifData *exif)
                        profile = cmsOpenProfileFromMem(profile_data, profile_len);
                        if (profile)
                                {
-#ifdef HAVE_LCMS2
+#if HAVE_LCMS2
                                profileID[16] = '\0';
                                cmsGetHeaderProfileID(profile, profileID);
                                name = reinterpret_cast<gchar *>(profileID);
@@ -529,12 +545,14 @@ static gchar *exif_build_formatted_ColorProfile(ExifData *exif)
 static gchar *exif_build_formatted_GPSPosition(ExifData *exif)
 {
        GString *string;
-       gchar *text, *ref;
+       gchar *ref;
        ExifRational *value;
        ExifItem *item;
        guint i;
-       gdouble p, p3;
-       gulong p1, p2;
+       gdouble p;
+       gdouble p3;
+       gulong p1;
+       gulong p2;
 
        string = g_string_new("");
 
@@ -574,10 +592,7 @@ static gchar *exif_build_formatted_GPSPosition(ExifData *exif)
                g_string_append_printf(string, ", %0lu° %0lu' %0.2f\" %.1s", p1, p2, p3, ref);
                } // if (item && ref)
 
-       text = string->str;
-       g_string_free(string, FALSE);
-
-       return text;
+       return g_string_free(string, FALSE);
 } // static gchar *exif_build_forma...
 
 static gchar *exif_build_formatted_GPSAltitude(ExifData *exif)
@@ -1030,7 +1045,7 @@ ExifData *exif_read_fd(FileData *fd)
         * not writable directly, thus it should contain the most up-to-date version */
        sidecar_path = nullptr;
 
-#ifdef HAVE_EXIV2
+#if HAVE_EXIV2
        /* we are not able to handle XMP sidecars without exiv2 */
        sidecar_path = cache_find_location(CACHE_TYPE_XMP_METADATA, fd->path);
 
@@ -1140,7 +1155,10 @@ gboolean exif_jpeg_parse_color(ExifData *exif, guchar *data, guint size)
 
 static gchar *mode_number(mode_t m)
 {
-       gint mb, mu, mg, mo;
+       gint mb;
+       gint mu;
+       gint mg;
+       gint mo;
        gchar pbuf[12];
 
        mb = mu = mg = mo = 0;
@@ -1175,7 +1193,7 @@ static gchar *mode_number(mode_t m)
        return g_strdup_printf("%s (%d%d%d%d)", pbuf, mb, mu, mg, mo);
 }
 
-gchar *metadata_file_info(FileData *fd, const gchar *key, MetadataFormat UNUSED(format))
+gchar *metadata_file_info(FileData *fd, const gchar *key, MetadataFormat)
 {
        gchar *page_n_of_m;
 
@@ -1218,16 +1236,14 @@ gchar *metadata_file_info(FileData *fd, const gchar *key, MetadataFormat UNUSED(
                        page_n_of_m = g_strdup_printf("[%d/%d]", fd->page_num + 1, fd->page_total);
                        return page_n_of_m;
                        }
-               else
-                       {
-                       return nullptr;
-                       }
+
+               return nullptr;
                }
        return g_strdup("");
 }
 
-#ifdef HAVE_LUA
-gchar *metadata_lua_info(FileData *fd, const gchar *key, MetadataFormat UNUSED(format))
+#if HAVE_LUA
+gchar *metadata_lua_info(FileData *fd, const gchar *key, MetadataFormat)
 {
        gchar *script_name;
        gchar *script_name_utf8;