gint byte_order;
};
+static void serialize_orientation (GstExifWriter * writer,
+ const GstTagList * taglist, const GstExifTagMatch * exiftag);
+static gint deserialize_orientation (GstExifReader * exif_reader,
+ GstByteReader * reader, const GstExifTagMatch * exiftag,
+ GstExifTagData * tagdata);
+
static void serialize_geo_coordinate (GstExifWriter * writer,
const GstTagList * taglist, const GstExifTagMatch * exiftag);
static gint deserialize_geo_coordinate (GstExifReader * exif_reader,
{GST_TAG_DESCRIPTION, 0x10E, EXIF_TYPE_ASCII, 0, NULL, NULL},
{GST_TAG_DEVICE_MANUFACTURER, 0x10F, EXIF_TYPE_ASCII, 0, NULL, NULL},
{GST_TAG_DEVICE_MODEL, 0x110, EXIF_TYPE_ASCII, 0, NULL, NULL},
+ {GST_TAG_IMAGE_ORIENTATION, 0x112, EXIF_TYPE_SHORT, 0, serialize_orientation,
+ deserialize_orientation},
{GST_TAG_ARTIST, 0x13B, EXIF_TYPE_ASCII, 0, NULL, NULL},
{GST_TAG_COPYRIGHT, 0x8298, EXIF_TYPE_ASCII, 0, NULL, NULL},
{NULL, EXIF_GPS_IFD_TAG, EXIF_TYPE_LONG, 0, NULL, NULL},
}
static void
+gst_exif_writer_write_short_tag (GstExifWriter * writer, guint16 tag,
+ guint16 value)
+{
+ guint32 offset = 0;
+
+ if (writer->byte_order == G_LITTLE_ENDIAN) {
+ GST_WRITE_UINT16_LE ((guint8 *) & offset, value);
+ } else {
+ GST_WRITE_UINT16_BE ((guint8 *) & offset, value);
+ }
+
+ gst_exif_writer_write_tag_header (writer, tag, EXIF_TYPE_SHORT,
+ 1, offset, TRUE);
+}
+
+static void
write_exif_ascii_tag (GstExifWriter * writer, guint16 tag, const gchar * str)
{
gint size;
/* special serialization functions */
static void
+serialize_orientation (GstExifWriter * writer, const GstTagList * taglist,
+ const GstExifTagMatch * exiftag)
+{
+ gchar *str = NULL;
+ gint exif_value;
+
+ if (!gst_tag_list_get_string_index (taglist, GST_TAG_IMAGE_ORIENTATION, 0,
+ &str)) {
+ GST_WARNING ("No image orientation tag present in taglist");
+ return;
+ }
+
+ exif_value = gst_tag_image_orientation_to_exif_value (str);
+ if (exif_value == -1) {
+ GST_WARNING ("Invalid image orientation value: %s", str);
+ g_free (str);
+ return;
+ }
+ g_free (str);
+
+ gst_exif_writer_write_short_tag (writer, exiftag->exif_tag, exif_value);
+}
+
+static gint
+deserialize_orientation (GstExifReader * exif_reader,
+ GstByteReader * reader, const GstExifTagMatch * exiftag,
+ GstExifTagData * tagdata)
+{
+ gint ret = 1;
+ const gchar *str = NULL;
+ gint value;
+
+ GST_LOG ("Starting to parse %s tag in exif 0x%x", exiftag->gst_tag,
+ exiftag->exif_tag);
+
+ /* validate tag */
+ if (tagdata->tag_type != EXIF_TYPE_SHORT || tagdata->count != 1) {
+ GST_WARNING ("Orientation tag has unexpected type/count");
+ return ret;
+ }
+
+ if (exif_reader->byte_order == G_LITTLE_ENDIAN) {
+ value = GST_READ_UINT16_LE (tagdata->offset_as_data);
+ } else {
+ value = GST_READ_UINT16_BE (tagdata->offset_as_data);
+ }
+
+ str = gst_tag_image_orientation_from_exif_value (value);
+ if (str == NULL) {
+ GST_WARNING ("Invalid value for exif orientation tag: %d", value);
+ return ret;
+ }
+ gst_tag_list_add (exif_reader->taglist, GST_TAG_MERGE_REPLACE,
+ exiftag->gst_tag, str, NULL);
+
+ return ret;
+}
+
+static void
serialize_geo_coordinate (GstExifWriter * writer, const GstTagList * taglist,
const GstExifTagMatch * exiftag)
{
--- /dev/null
+/* GStreamer
+ * Copyright (C) 2010 Thiago Santos <thiago.sousa.santos@collabora.co.uk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "gsttageditingprivate.h"
+
+#include <string.h>
+
+gint
+gst_tag_image_orientation_to_exif_value (const gchar * str)
+{
+ if (str == NULL)
+ goto end;
+
+ if (strcmp (str, "rotate-0") == 0)
+ return 1;
+ else if (strcmp (str, "flip-rotate-0") == 0)
+ return 2;
+ else if (strcmp (str, "rotate-180") == 0)
+ return 3;
+ else if (strcmp (str, "flip-rotate-180") == 0)
+ return 4;
+ else if (strcmp (str, "flip-rotate-270") == 0)
+ return 5;
+ else if (strcmp (str, "rotate-90") == 0)
+ return 6;
+ else if (strcmp (str, "flip-rotate-90") == 0)
+ return 7;
+ else if (strcmp (str, "rotate-270") == 0)
+ return 8;
+
+end:
+ GST_WARNING ("Invalid image orientation tag: %d", str);
+ return -1;
+}
+
+const gchar *
+gst_tag_image_orientation_from_exif_value (gint value)
+{
+ switch (value) {
+ case 1:
+ return "rotate-0";
+ case 2:
+ return "flip-rotate-0";
+ case 3:
+ return "rotate-180";
+ case 4:
+ return "flip-rotate-180";
+ case 5:
+ return "flip-rotate-270";
+ case 6:
+ return "rotate-90";
+ case 7:
+ return "flip-rotate-90";
+ case 8:
+ return "rotate-270";
+ default:
+ GST_WARNING ("Invalid tiff orientation tag value: %d", value);
+ return NULL;
+ }
+}
do_exif_tag_serialization_deserialization (GST_TAG_COPYRIGHT, &value);
g_value_set_static_string (&value, "ty");
do_exif_tag_serialization_deserialization (GST_TAG_ARTIST, &value);
+
+ /* image orientation tests */
+ g_value_set_static_string (&value, "rotate-0");
+ do_exif_tag_serialization_deserialization (GST_TAG_IMAGE_ORIENTATION, &value);
+ g_value_set_static_string (&value, "flip-rotate-0");
+ do_exif_tag_serialization_deserialization (GST_TAG_IMAGE_ORIENTATION, &value);
+ g_value_set_static_string (&value, "rotate-180");
+ do_exif_tag_serialization_deserialization (GST_TAG_IMAGE_ORIENTATION, &value);
+ g_value_set_static_string (&value, "flip-rotate-180");
+ do_exif_tag_serialization_deserialization (GST_TAG_IMAGE_ORIENTATION, &value);
+ g_value_set_static_string (&value, "flip-rotate-270");
+ do_exif_tag_serialization_deserialization (GST_TAG_IMAGE_ORIENTATION, &value);
+ g_value_set_static_string (&value, "rotate-90");
+ do_exif_tag_serialization_deserialization (GST_TAG_IMAGE_ORIENTATION, &value);
+ g_value_set_static_string (&value, "flip-rotate-90");
+ do_exif_tag_serialization_deserialization (GST_TAG_IMAGE_ORIENTATION, &value);
+ g_value_set_static_string (&value, "rotate-270");
+ do_exif_tag_serialization_deserialization (GST_TAG_IMAGE_ORIENTATION, &value);
g_value_unset (&value);
g_value_init (&value, G_TYPE_DOUBLE);