Move third-party sources to separate sub-directory
[geeqie.git] / src / exif-common.cc
index 921d2b7..4dcdc4b 100644 (file)
 
 #include <config.h>
 
+#ifdef __linux__
 #define _XOPEN_SOURCE
+#endif
 
-#include <string.h>
-#include <math.h>
+#include <sys/stat.h>
 
-#ifdef HAVE_LCMS
-/*** color support enabled ***/
+#include <cmath>
+#include <cstdlib>
+#include <cstring>
+#include <ctime>
 
-#ifdef HAVE_LCMS2
-#include <lcms2.h>
-#else
-#include <lcms.h>
-#endif
+#include <glib.h>
+
+#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)
 {
        if (!r || r->den == 0.0) return 0.0;
 
-       if (sign) return (gdouble)((gint)r->num) / (gdouble)((gint)r->den);
-       return (gdouble)r->num / r->den;
+       if (sign) return static_cast<gdouble>(static_cast<gint>(r->num)) / static_cast<gdouble>(static_cast<gint>(r->den));
+       return static_cast<gdouble>(r->num) / r->den;
 }
 
 static gdouble exif_get_rational_as_double(ExifData *exif, const gchar *key)
@@ -96,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;
 
@@ -114,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)
@@ -158,7 +175,8 @@ static gchar *exif_build_formatted_Camera(ExifData *exif)
 
        if (software)
                {
-               gint i, j;
+               gint i;
+               gint j;
 
                g_strstrip(software);
 
@@ -190,12 +208,12 @@ static gchar *exif_build_formatted_Camera(ExifData *exif)
 static gchar *exif_build_formatted_DateTime(ExifData *exif)
 {
        gchar *text = exif_get_data_as_text(exif, "Exif.Photo.DateTimeOriginal");
-       gchar *subsec = NULL;
+       gchar *subsec = nullptr;
        gchar buf[128];
        gchar *tmp;
        gint buflen;
        struct tm tm;
-       GError *error = NULL;
+       GError *error = nullptr;
 
        if (text)
                {
@@ -214,7 +232,7 @@ static gchar *exif_build_formatted_DateTime(ExifData *exif)
                buflen = strftime(buf, sizeof(buf), "%x %X", &tm);
                if (buflen > 0)
                        {
-                       tmp = g_locale_to_utf8(buf, buflen, NULL, NULL, &error);
+                       tmp = g_locale_to_utf8(buf, buflen, nullptr, nullptr, &error);
                        if (error)
                                {
                                log_printf("Error converting locale strftime to UTF-8: %s\n", error->message);
@@ -241,12 +259,12 @@ static gchar *exif_build_formatted_DateTime(ExifData *exif)
 static gchar *exif_build_formatted_DateTimeDigitized(ExifData *exif)
 {
        gchar *text = exif_get_data_as_text(exif, "Exif.Photo.DateTimeDigitized");
-       gchar *subsec = NULL;
+       gchar *subsec = nullptr;
        gchar buf[128];
        gchar *tmp;
        gint buflen;
        struct tm tm;
-       GError *error = NULL;
+       GError *error = nullptr;
 
        if (text)
                {
@@ -265,7 +283,7 @@ static gchar *exif_build_formatted_DateTimeDigitized(ExifData *exif)
                buflen = strftime(buf, sizeof(buf), "%x %X", &tm);
                if (buflen > 0)
                        {
-                       tmp = g_locale_to_utf8(buf, buflen, NULL, NULL, &error);
+                       tmp = g_locale_to_utf8(buf, buflen, nullptr, nullptr, &error);
                        if (error)
                                {
                                log_printf("Error converting locale strftime to UTF-8: %s\n", error->message);
@@ -293,25 +311,25 @@ static gchar *exif_build_formatted_ShutterSpeed(ExifData *exif)
 {
        ExifRational *r;
 
-       r = exif_get_rational(exif, "Exif.Photo.ExposureTime", NULL);
+       r = exif_get_rational(exif, "Exif.Photo.ExposureTime", nullptr);
        if (r && r->num && r->den)
                {
-               gdouble n = (gdouble)r->den / (gdouble)r->num;
+               gdouble n = static_cast<gdouble>(r->den) / static_cast<gdouble>(r->num);
                return g_strdup_printf("%s%.0fs", n > 1.0 ? "1/" : "",
                                                  n > 1.0 ? n : 1.0 / n);
                }
-       r = exif_get_rational(exif, "Exif.Photo.ShutterSpeedValue", NULL);
+       r = exif_get_rational(exif, "Exif.Photo.ShutterSpeedValue", nullptr);
        if (r && r->num  && r->den)
                {
                gdouble n = pow(2.0, exif_rational_to_double(r, TRUE));
 
                /* Correct exposure time to avoid values like 1/91s (seen on Minolta DImage 7) */
-               if (n > 1.0 && (gint)n - ((gint)(n/10))*10 == 1) n--;
+               if (n > 1.0 && static_cast<gint>(n) - (static_cast<gint>(n/10))*10 == 1) n--;
 
                return g_strdup_printf("%s%.0fs", n > 1.0 ? "1/" : "",
                                                  n > 1.0 ? floor(n) : 1.0 / n);
                }
-       return NULL;
+       return nullptr;
 }
 
 static gchar *exif_build_formatted_Aperture(ExifData *exif)
@@ -320,7 +338,7 @@ static gchar *exif_build_formatted_Aperture(ExifData *exif)
 
        n = exif_get_rational_as_double(exif, "Exif.Photo.FNumber");
        if (n == 0.0) n = exif_get_rational_as_double(exif, "Exif.Photo.ApertureValue");
-       if (n == 0.0) return NULL;
+       if (n == 0.0) return nullptr;
 
        return g_strdup_printf("f/%.1f", n);
 }
@@ -332,7 +350,7 @@ static gchar *exif_build_formatted_ExposureBias(ExifData *exif)
        gdouble n;
 
        r = exif_get_rational(exif, "Exif.Photo.ExposureBiasValue", &sign);
-       if (!r) return NULL;
+       if (!r) return nullptr;
 
        n = exif_rational_to_double(r, sign);
        return g_strdup_printf("%+.1f", n);
@@ -343,14 +361,15 @@ static gchar *exif_build_formatted_FocalLength(ExifData *exif)
        gdouble n;
 
        n = exif_get_rational_as_double(exif, "Exif.Photo.FocalLength");
-       if (n == 0.0) return NULL;
+       if (n == 0.0) return nullptr;
        return g_strdup_printf("%.0f mm", n);
 }
 
 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)
                {
@@ -358,10 +377,10 @@ static gchar *exif_build_formatted_FocalLength35mmFilm(ExifData *exif)
                }
 
        f = exif_get_rational_as_double(exif, "Exif.Photo.FocalLength");
-       if (f == 0.0) return NULL;
+       if (f == 0.0) return nullptr;
 
        c = get_crop_factor(exif);
-       if (c == 0.0) return NULL;
+       if (c == 0.0) return nullptr;
 
        return g_strdup_printf("%.0f mm", f * c);
 }
@@ -385,10 +404,10 @@ static gchar *exif_build_formatted_SubjectDistance(ExifData *exif)
        gdouble n;
 
        r = exif_get_rational(exif, "Exif.Photo.SubjectDistance", &sign);
-       if (!r) return NULL;
+       if (!r) return nullptr;
 
-       if ((glong)r->num == (glong)0xffffffff) return g_strdup(_("infinity"));
-       if ((glong)r->num == 0) return g_strdup(_("unknown"));
+       if (static_cast<glong>(r->num) == static_cast<glong>(0xffffffff)) return g_strdup(_("infinity"));
+       if (static_cast<glong>(r->num) == 0) return g_strdup(_("unknown"));
 
        n = exif_rational_to_double(r, sign);
        if (n == 0.0) return _("unknown");
@@ -399,11 +418,10 @@ static gchar *exif_build_formatted_Flash(ExifData *exif)
 {
        /* grr, flash is a bitmask... */
        GString *string;
-       gchar *text;
        gint n;
        gint v;
 
-       if (!exif_get_integer(exif, "Exif.Photo.Flash", &n)) return NULL;
+       if (!exif_get_integer(exif, "Exif.Photo.Flash", &n)) return nullptr;
 
        /* Exif 2.1 only defines first 3 bits */
        if (n <= 0x07) return exif_get_data_as_text(exif, "Exif.Photo.Flash");
@@ -440,24 +458,23 @@ 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;
 
-       rx = exif_get_rational(exif, "Exif.Image.XResolution", NULL);
-       ry = exif_get_rational(exif, "Exif.Image.YResolution", NULL);
-       if (!rx || !ry) return NULL;
+       rx = exif_get_rational(exif, "Exif.Image.XResolution", nullptr);
+       ry = exif_get_rational(exif, "Exif.Image.YResolution", nullptr);
+       if (!rx || !ry) return nullptr;
 
        units = exif_get_data_as_text(exif, "Exif.Image.ResolutionUnit");
-       text = g_strdup_printf("%0.f x %0.f (%s/%s)", rx->den ? (gdouble)rx->num / rx->den : 1.0,
-                                                     ry->den ? (gdouble)ry->num / ry->den : 1.0,
+       text = g_strdup_printf("%0.f x %0.f (%s/%s)", rx->den ? static_cast<gdouble>(rx->num) / rx->den : 1.0,
+                                                     ry->den ? static_cast<gdouble>(ry->num) / ry->den : 1.0,
                                                      _("dot"), (units) ? units : _("unknown"));
 
        g_free(units);
@@ -466,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 = "";
@@ -500,7 +517,7 @@ static gchar *exif_build_formatted_ColorProfile(ExifData *exif)
        else
                {
                source = _("embedded");
-#ifdef HAVE_LCMS
+#if HAVE_LCMS
 
                        {
                        cmsHPROFILE profile;
@@ -508,10 +525,10 @@ 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 = (gchar *) profileID;
+                               name = reinterpret_cast<gchar *>(profileID);
 #else
                                name = (gchar *) cmsTakeProductName(profile);
 #endif
@@ -521,19 +538,21 @@ static gchar *exif_build_formatted_ColorProfile(ExifData *exif)
                        }
 #endif
                }
-       if (name[0] == 0 && source[0] == 0) return NULL;
+       if (name[0] == 0 && source[0] == 0) return nullptr;
        return g_strdup_printf("%s (%s)", name, source);
 }
 
 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("");
 
@@ -544,12 +563,12 @@ static gchar *exif_build_formatted_GPSPosition(ExifData *exif)
                p = 0;
                for (i = 0; i < exif_item_get_elements(item); i++)
                        {
-                       value = exif_item_get_rational(item, NULL, i);
+                       value = exif_item_get_rational(item, nullptr, i);
                        if (value && value->num && value->den)
-                               p += (gdouble)value->num / (gdouble)value->den / pow(60.0, (gdouble)i);
+                               p += static_cast<gdouble>(value->num) / static_cast<gdouble>(value->den) / pow(60.0, static_cast<gdouble>(i));
                        }
-               p1 = (gint)p;
-               p2 = (gint)((p - p1)*60);
+               p1 = static_cast<gint>(p);
+               p2 = static_cast<gint>((p - p1)*60);
                p3 = ((p - p1)*60 - p2)*60;
 
                g_string_append_printf(string, "%0lu° %0lu' %0.2f\" %.1s", p1, p2, p3, ref);
@@ -562,21 +581,18 @@ static gchar *exif_build_formatted_GPSPosition(ExifData *exif)
                p = 0;
                for (i = 0; i < exif_item_get_elements(item); i++)
                        {
-                       value = exif_item_get_rational(item, NULL, i);
+                       value = exif_item_get_rational(item, nullptr, i);
                        if (value && value->num && value->den)
-                       p += (gdouble)value->num / (gdouble)value->den / pow(60.0, (gdouble)i);
+                       p += static_cast<gdouble>(value->num) / static_cast<gdouble>(value->den) / pow(60.0, static_cast<gdouble>(i));
                        }
-               p1 = (gint)p;
-               p2 = (gint)((p - p1)*60);
+               p1 = static_cast<gint>(p);
+               p2 = static_cast<gint>((p - p1)*60);
                p3 = ((p - p1)*60 - p2)*60;
 
                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)
@@ -587,9 +603,9 @@ static gchar *exif_build_formatted_GPSAltitude(ExifData *exif)
        gint ref;
 
        item = exif_get_item(exif, "Exif.GPSInfo.GPSAltitudeRef");
-       r = exif_get_rational(exif, "Exif.GPSInfo.GPSAltitude", NULL);
+       r = exif_get_rational(exif, "Exif.GPSInfo.GPSAltitude", nullptr);
 
-       if (!r || !item) return NULL;
+       if (!r || !item) return nullptr;
 
        alt = exif_rational_to_double(r, 0);
        exif_item_get_integer(item, &ref);
@@ -609,8 +625,8 @@ static gchar *exif_build_formatted_GPSAltitude(ExifData *exif)
  */
 static void zd_tz(ZoneDetectResult *results, gchar **timezone, gchar **countryname, gchar **countryalpha2)
 {
-       gchar *timezone_pre = NULL;
-       gchar *timezone_id = NULL;
+       gchar *timezone_pre = nullptr;
+       gchar *timezone_id = nullptr;
        unsigned int index = 0;
 
        while(results[index].lookupResult != ZD_LOOKUP_END)
@@ -690,7 +706,7 @@ static gboolean exif_build_tz_data(ExifData *exif, gchar **exif_date_time, gchar
        if (text_latitude && text_longitude && text_latitude_ref && text_longitude_ref)
                {
                lat_deg = strtok(text_latitude, "deg'");
-               lat_min = strtok(NULL, "deg'");
+               lat_min = strtok(nullptr, "deg'");
                if (!lat_deg || !lat_min)
                        {
                        return FALSE;
@@ -701,7 +717,7 @@ static gboolean exif_build_tz_data(ExifData *exif, gchar **exif_date_time, gchar
                        latitude = -latitude;
                        }
                lon_deg = strtok(text_longitude, "deg'");
-               lon_min = strtok(NULL, "deg'");
+               lon_min = strtok(nullptr, "deg'");
                if (!lon_deg || !lon_min)
                        {
                        return FALSE;
@@ -719,7 +735,7 @@ static gboolean exif_build_tz_data(ExifData *exif, gchar **exif_date_time, gchar
                        cd = ZDOpenDatabase(timezone_path);
                        if (cd)
                                {
-                               results = ZDLookup(cd, latitude, longitude, NULL);
+                               results = ZDLookup(cd, latitude, longitude, nullptr);
                                if (results)
                                        {
                                        zd_tz(results, timezone, countryname, countryalpha2);
@@ -762,16 +778,16 @@ static gchar *exif_build_formatted_localtime(ExifData *exif)
        gchar buf[128];
        gchar *tmp;
        gint buflen;
-       GError *error = NULL;
+       GError *error = nullptr;
        gchar *time_zone_image;
        gchar *time_zone_org;
        struct tm *tm_local;
        struct tm tm_utc;
        time_t stamp;
-       gchar *exif_date_time = NULL;
-       gchar *timezone = NULL;
-       gchar *countryname = NULL;
-       gchar *countryalpha2 = NULL;
+       gchar *exif_date_time = nullptr;
+       gchar *timezone = nullptr;
+       gchar *countryname = nullptr;
+       gchar *countryalpha2 = nullptr;
 
        if (exif_build_tz_data(exif, &exif_date_time, &timezone, &countryname, &countryalpha2))
                {
@@ -791,7 +807,7 @@ static gchar *exif_build_formatted_localtime(ExifData *exif)
                        buflen = strftime(buf, sizeof(buf), "%x %X", tm_local);
                        if (buflen > 0)
                                {
-                               tmp = g_locale_to_utf8(buf, buflen, NULL, NULL, &error);
+                               tmp = g_locale_to_utf8(buf, buflen, nullptr, nullptr, &error);
                                if (error)
                                        {
                                        log_printf("Error converting locale strftime to UTF-8: %s\n", error->message);
@@ -826,10 +842,10 @@ static gchar *exif_build_formatted_localtime(ExifData *exif)
  */
 static gchar *exif_build_formatted_timezone(ExifData *exif)
 {
-       gchar *exif_date_time = NULL;
-       gchar *timezone = NULL;
-       gchar *countryname = NULL;
-       gchar *countryalpha2 = NULL;
+       gchar *exif_date_time = nullptr;
+       gchar *timezone = nullptr;
+       gchar *countryname = nullptr;
+       gchar *countryalpha2 = nullptr;
 
        exif_build_tz_data(exif, &exif_date_time, &timezone, &countryname, &countryalpha2);
 
@@ -849,10 +865,10 @@ static gchar *exif_build_formatted_timezone(ExifData *exif)
  */
 static gchar *exif_build_formatted_countryname(ExifData *exif)
 {
-       gchar *exif_date_time = NULL;
-       gchar *timezone = NULL;
-       gchar *countryname = NULL;
-       gchar *countryalpha2 = NULL;
+       gchar *exif_date_time = nullptr;
+       gchar *timezone = nullptr;
+       gchar *countryname = nullptr;
+       gchar *countryalpha2 = nullptr;
 
        exif_build_tz_data(exif, &exif_date_time, &timezone, &countryname, &countryalpha2);
 
@@ -872,10 +888,10 @@ static gchar *exif_build_formatted_countryname(ExifData *exif)
  */
 static gchar *exif_build_formatted_countrycode(ExifData *exif)
 {
-       gchar *exif_date_time = NULL;
-       gchar *timezone = NULL;
-       gchar *countryname = NULL;
-       gchar *countryalpha2 = NULL;
+       gchar *exif_date_time = nullptr;
+       gchar *timezone = nullptr;
+       gchar *countryname = nullptr;
+       gchar *countryalpha2 = nullptr;
 
        exif_build_tz_data(exif, &exif_date_time, &timezone, &countryname, &countryalpha2);
 
@@ -919,17 +935,17 @@ ExifFormattedText ExifFormattedList[] = {
        EXIF_FORMATTED_TAG(countryname,         N_("Country name")),
        EXIF_FORMATTED_TAG(countrycode,         N_("Country code")),
        EXIF_FORMATTED_TAG(star_rating,         N_("Star rating")),
-       {"file.size",                           N_("File size"),        NULL},
-       {"file.date",                           N_("File date"),        NULL},
-       {"file.mode",                           N_("File mode"),        NULL},
-       {"file.ctime",                          N_("File ctime"),       NULL},
-       {"file.owner",                          N_("File owner"),       NULL},
-       {"file.group",                          N_("File group"),       NULL},
-       {"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 }
+       {"file.size",                           N_("File size"),        nullptr},
+       {"file.date",                           N_("File date"),        nullptr},
+       {"file.mode",                           N_("File mode"),        nullptr},
+       {"file.ctime",                          N_("File ctime"),       nullptr},
+       {"file.owner",                          N_("File owner"),       nullptr},
+       {"file.group",                          N_("File group"),       nullptr},
+       {"file.link",                           N_("File link"),        nullptr},
+       {"file.class",                          N_("File class"),       nullptr},
+       {"file.page_no",                        N_("Page no."),         nullptr},
+       {"lua.lensID",                          N_("Lens"),             nullptr},
+       { nullptr, nullptr, nullptr }
 };
 
 gchar *exif_get_formatted_by_key(ExifData *exif, const gchar *key, gboolean *key_valid)
@@ -947,12 +963,12 @@ gchar *exif_get_formatted_by_key(ExifData *exif, const gchar *key, gboolean *key
                }
 
        if (key_valid) *key_valid = FALSE;
-       return NULL;
+       return nullptr;
 }
 
 gchar *exif_get_description_by_key(const gchar *key)
 {
-       if (!key) return NULL;
+       if (!key) return nullptr;
 
        if (strncmp(key, EXIF_FORMATTED(), EXIF_FORMATTED_LEN) == 0 || strncmp(key, "file.", 5) == 0 || strncmp(key, "lua.", 4) == 0)
                {
@@ -988,15 +1004,15 @@ gchar *exif_get_data_as_text(ExifData *exif, const gchar *key)
        gchar *text;
        gboolean key_valid;
 
-       if (!key) return NULL;
+       if (!key) return nullptr;
 
        text = exif_get_formatted_by_key(exif, key, &key_valid);
        if (key_valid) return text;
 
        item = exif_get_item(exif, key);
-       if (item) return exif_item_get_data_as_text(item);
+       if (item) return exif_item_get_data_as_text(item, exif);
 
-       return NULL;
+       return nullptr;
 }
 
 
@@ -1005,10 +1021,10 @@ static FileCacheData *exif_cache;
 void exif_release_cb(FileData *fd)
 {
        exif_free(fd->exif);
-       fd->exif = NULL;
+       fd->exif = nullptr;
 }
 
-void exif_init_cache(void)
+void exif_init_cache()
 {
        g_assert(!exif_cache);
        exif_cache = file_cache_new(exif_release_cb, 4);
@@ -1020,16 +1036,16 @@ ExifData *exif_read_fd(FileData *fd)
 
        if (!exif_cache) exif_init_cache();
 
-       if (!fd) return NULL;
+       if (!fd) return nullptr;
 
        if (file_cache_get(exif_cache, fd)) return fd->exif;
-       g_assert(fd->exif == NULL);
+       g_assert(fd->exif == nullptr);
 
        /* CACHE_TYPE_XMP_METADATA file should exist only if the metadata are
         * not writable directly, thus it should contain the most up-to-date version */
-       sidecar_path = NULL;
+       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);
 
@@ -1086,7 +1102,7 @@ gboolean exif_jpeg_parse_color(ExifData *exif, guchar *data, guint size)
                        {
                        guint i;
 
-                       chunk_count = (guint)chunk_tot;
+                       chunk_count = static_cast<guint>(chunk_tot);
                        for (i = 0; i < chunk_count; i++) chunk_offset[i] = 0;
                        for (i = 0; i < chunk_count; i++) chunk_length[i] = 0;
                        }
@@ -1139,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;
@@ -1174,13 +1193,13 @@ 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;
 
        if (strcmp(key, "file.size") == 0)
                {
-               return g_strdup_printf("%ld", (long)fd->size);
+               return g_strdup_printf("%ld", static_cast<long>(fd->size));
                }
        if (strcmp(key, "file.date") == 0)
                {
@@ -1217,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 NULL;
-                       }
+
+               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;
@@ -1237,7 +1254,7 @@ gchar *metadata_lua_info(FileData *fd, const gchar *key, MetadataFormat UNUSED(f
        script_name_utf8 = g_strdup(key + 4);
        script_name = path_from_utf8(script_name_utf8);
 
-       raw_data = lua_callvalue(fd, script_name, NULL);
+       raw_data = lua_callvalue(fd, script_name, nullptr);
        valid_data = g_utf8_make_valid(raw_data, -1);
        data = g_utf8_substring(valid_data, 0, 150);