#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 ***/
{
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)
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)
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)
{
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);
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)
{
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);
{
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)
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);
}
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);
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);
}
}
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);
}
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");
{
/* 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");
/* 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)
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);
#ifdef HAVE_LCMS2
profileID[16] = '\0';
cmsGetHeaderProfileID(profile, profileID);
- name = (gchar *) profileID;
+ name = reinterpret_cast<gchar *>(profileID);
#else
name = (gchar *) cmsTakeProductName(profile);
#endif
}
#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;
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);
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)
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);
*/
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)
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;
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;
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);
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))
{
time_zone_image = g_strconcat("TZ=", timezone, NULL);
time_zone_org = g_strconcat("TZ=", getenv("TZ"), NULL);
- putenv("TZ=UTC");
+ setenv("TZ", "UTC", TRUE);
memset(&tm_utc, 0, sizeof(tm_utc));
if (exif_date_time && strptime(exif_date_time, "%Y:%m:%d:%H:%M:%S", &tm_utc))
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);
*/
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);
*/
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);
*/
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);
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)
}
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)
{
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;
}
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);
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
/* we are not able to handle XMP sidecars without exiv2 */
{
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;
}
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)
{
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))
+gchar *metadata_lua_info(FileData *fd, const gchar *key, MetadataFormat)
{
gchar *script_name;
gchar *script_name_utf8;
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);