tag: exiftag: don't try to convert utf-8 to latin1 if string is ASCII already
authorTim-Philipp Müller <tim@centricular.com>
Fri, 3 Apr 2015 20:00:53 +0000 (21:00 +0100)
committerTim-Philipp Müller <tim@centricular.com>
Fri, 3 Apr 2015 20:03:50 +0000 (21:03 +0100)
Bypass g_convert/iconv if there's nothing to convert. That way,
conversion won't fail on systems where iconv doesn't support
converting utf-8 to latin1 and there's nothing to convert.

https://bugzilla.gnome.org/show_bug.cgi?id=723252

gst-libs/gst/tag/gstexiftag.c

index 8200a9f..1f0528e 100644 (file)
@@ -801,6 +801,20 @@ write_exif_undefined_tag (GstExifWriter * writer, guint16 tag,
   }
 }
 
+static inline gboolean
+gst_exif_tag_str_is_ascii (const gchar * str, gsize * length)
+{
+  gsize len = 0;
+
+  while (*str) {
+    if (*str++ & 0x80)
+      return FALSE;
+    ++len;
+  }
+  *length = len;
+  return TRUE;
+}
+
 static void
 write_exif_ascii_tag (GstExifWriter * writer, guint16 tag, const gchar * str)
 {
@@ -809,7 +823,11 @@ write_exif_ascii_tag (GstExifWriter * writer, guint16 tag, const gchar * str)
   gsize ascii_size;
   GError *error = NULL;
 
-  ascii_str = g_convert (str, -1, "latin1", "utf8", NULL, &ascii_size, &error);
+  if (gst_exif_tag_str_is_ascii (str, &ascii_size))
+    ascii_str = g_strndup (str, ascii_size);
+  else
+    ascii_str =
+        g_convert (str, -1, "latin1", "utf8", NULL, &ascii_size, &error);
 
   if (error) {
     GST_WARNING ("Failed to convert exif tag to ascii: 0x%x - %s. Error: %s",