clang-tidy: modernize-use-auto
[geeqie.git] / src / exif-common.cc
index 6d04644..1fcfb6a 100644 (file)
 
 #include <config.h>
 
+#ifdef __linux__
 #define _XOPEN_SOURCE
+#endif
 
-#include <string.h>
-#include <math.h>
+#include <cmath>
+#include <cstdlib>
+#include <cstring>
 
 #ifdef HAVE_LCMS
 /*** color support enabled ***/
@@ -114,12 +117,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)
@@ -399,7 +401,6 @@ static gchar *exif_build_formatted_Flash(ExifData *exif)
 {
        /* grr, flash is a bitmask... */
        GString *string;
-       gchar *text;
        gint n;
        gint v;
 
@@ -440,9 +441,7 @@ 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)
@@ -511,7 +510,7 @@ static gchar *exif_build_formatted_ColorProfile(ExifData *exif)
 #ifdef HAVE_LCMS2
                                profileID[16] = '\0';
                                cmsGetHeaderProfileID(profile, profileID);
-                               name = (gchar *) profileID;
+                               name = reinterpret_cast<gchar *>(profileID);
 #else
                                name = (gchar *) cmsTakeProductName(profile);
 #endif
@@ -528,7 +527,7 @@ 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;
@@ -573,10 +572,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)
@@ -994,7 +990,7 @@ gchar *exif_get_data_as_text(ExifData *exif, const gchar *key)
        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 nullptr;
 }
@@ -1174,7 +1170,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;
 
@@ -1226,7 +1222,7 @@ gchar *metadata_file_info(FileData *fd, const gchar *key, MetadataFormat UNUSED(
 }
 
 #ifdef HAVE_LUA
-gchar *metadata_lua_info(FileData *fd, const gchar *key, MetadataFormat UNUSED(format))
+gchar *metadata_lua_info(FileData *fd, const gchar *key, MetadataFormat)
 {
        gchar *script_name;
        gchar *script_name_utf8;
@@ -1237,7 +1233,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);