Remove commented out code.
[geeqie.git] / src / format_olympus.c
index b0fa572..e943ada 100644 (file)
@@ -1,6 +1,7 @@
 /*
- *  GQView
- *  (C) 2005 John Ellis
+ * Geeqie
+ * (C) 2005 John Ellis
+ * Copyright (C) 2008 - 2012 The Geeqie Team
  *
  * This software is released under the GNU General Public License (GNU GPL).
  * Please read the included file COPYING for more information.
@@ -11,6 +12,7 @@
 #  include "config.h"
 #endif
 
+#ifndef HAVE_EXIV2
 
 #include <stdio.h>
 #include <string.h>
 
 #include "intl.h"
 
+#include "main.h"
 #include "format_olympus.h"
 #include "format_raw.h"
 
 #include "exif.h"
 
 
+/*
+ *-----------------------------------------------------------------------------
+ * Raw ORF embedded jpeg extraction for Olympus
+ *-----------------------------------------------------------------------------
+ */
+
+static guint olympus_tiff_table(guchar *data, const guint len, guint offset, ExifByteOrder bo,
+                               gint level,
+                               guint *image_offset, guint *exif_offset);
+
+
+static void olympus_tiff_entry(guchar *data, const guint len, guint offset, ExifByteOrder bo,
+                              gint level,
+                              guint *image_offset, guint *exif_offset)
+{
+       guint tag;
+       guint type;
+       guint count;
+       guint segment;
+       guint seg_len;
+
+       tag = exif_byte_get_int16(data + offset + EXIF_TIFD_OFFSET_TAG, bo);
+       type = exif_byte_get_int16(data + offset + EXIF_TIFD_OFFSET_FORMAT, bo);
+       count = exif_byte_get_int32(data + offset + EXIF_TIFD_OFFSET_COUNT, bo);
+
+       /* so far, we only care about tags with type long */
+       if (type != EXIF_FORMAT_LONG_UNSIGNED && type != EXIF_FORMAT_LONG) return;
+
+       seg_len = ExifFormatList[type].size * count;
+       if (seg_len > 4)
+               {
+               segment = exif_byte_get_int32(data + offset + EXIF_TIFD_OFFSET_DATA, bo);
+               if (segment + seg_len > len) return;
+               }
+       else
+               {
+               segment = offset + EXIF_TIFD_OFFSET_DATA;
+               }
+
+       if (tag == 0x201)
+               {
+               /* start of embedded jpeg, not all olympus cameras embed a jpeg */
+               *image_offset = exif_byte_get_int32(data + segment, bo);
+               }
+
+       if (tag == 0x8769)
+               {
+               /* This is the Exif info */
+               *exif_offset = exif_byte_get_int32(data + segment, bo);
+               }
+}
+
+static guint olympus_tiff_table(guchar *data, const guint len, guint offset, ExifByteOrder bo,
+                               gint level,
+                               guint *image_offset, guint *exif_offset)
+{
+       guint count;
+       guint i;
+
+       if (level > EXIF_TIFF_MAX_LEVELS) return 0;
+
+       if (len < offset + 2) return FALSE;
+
+       count = exif_byte_get_int16(data + offset, bo);
+       offset += 2;
+       if (len < offset + count * EXIF_TIFD_SIZE + 4) return 0;
+
+       for (i = 0; i < count; i++)
+               {
+               olympus_tiff_entry(data, len, offset + i * EXIF_TIFD_SIZE, bo, level,
+                                  image_offset, exif_offset);
+               }
+
+       return exif_byte_get_int32(data + offset + count * EXIF_TIFD_SIZE, bo);
+}
+
+gboolean format_olympus_raw(guchar *data, const guint len,
+                           guint *image_offset, guint *exif_offset)
+{
+       guint i_off = 0;
+       guint e_off = 0;
+       guint offset;
+       gint level;
+
+       if (len < 8) return FALSE;
+
+       /* these are in tiff file format with a different magick header */
+       if (memcmp(data, "IIR", 3) != 0) return FALSE;
+
+       offset = exif_byte_get_int32(data + 4, EXIF_BYTE_ORDER_INTEL);
+
+       level = 0;
+       while (offset && level < EXIF_TIFF_MAX_LEVELS)
+               {
+               offset = olympus_tiff_table(data, len, offset, EXIF_BYTE_ORDER_INTEL, 0, &i_off, &e_off);
+               level++;
+               }
+
+       if (i_off != 0 || e_off != 0)
+               {
+               if (image_offset) *image_offset = i_off;
+               if (exif_offset) *exif_offset = e_off;
+               return TRUE;
+               }
+
+       return FALSE;
+}
+
+
 /*
  *-----------------------------------------------------------------------------
  * EXIF Makernote for Olympus
@@ -93,14 +205,6 @@ static ExifTextList OlympusTagContrast[]= {
        EXIF_TEXT_LIST_END
 };
 
-#if 0
-static ExifTextList OlympusTag[]= {
-       { ,     "" },
-       { ,     "" },
-       EXIF_TEXT_LIST_END
-};
-#endif
-
 
 static ExifMarker OlympusExifMarkersList[] = {
 { 0x0001, EXIF_FORMAT_LONG_UNSIGNED, -1, "Konica/MinoltaSettings", "Konica / Minolta settings", NULL },
@@ -124,9 +228,9 @@ static ExifMarker OlympusExifMarkersList[] = {
 { 0x020d, EXIF_FORMAT_STRING, -1,       "Epson.Manufacturer",  "Manufacturer",         NULL },
 { 0x0e00, EXIF_FORMAT_BYTE, -1,                 "Olympus.PrintImageMatching", "Print image matching", NULL },
 { 0x1004, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Olympus.FlashMode",  "Flash mode",           OlympusTagFlashMode },
-{ 0x1006, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Olympus.Bracket",    "Bracket",              NULL },
+{ 0x1006, EXIF_FORMAT_RATIONAL, 1,      "Olympus.Bracket",     "Bracket",              NULL },
 { 0x100b, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Olympus.FocusMode",  "Focus mode",           OlympusTagFocusMode },
-{ 0x100c, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Olympus.FocusDistance", "Focus distance",    NULL },
+{ 0x100c, EXIF_FORMAT_RATIONAL_UNSIGNED, 1, "Olympus.FocusDistance", "Focus distance", NULL },
 { 0x100d, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Olympus.Zoom",       "Zoom",                 NULL },
 { 0x1006, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Olympus.MacroFocus", "Macro focus",          NULL },
 { 0x100f, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Olympus.Sharpness",  "Sharpness",            OlympusTagSharpness },
@@ -135,8 +239,8 @@ static ExifMarker OlympusExifMarkersList[] = {
 { 0x1015, EXIF_FORMAT_SHORT_UNSIGNED, 2, "Olympus.WhiteBalance", "White balance",      NULL },
 { 0x1017, EXIF_FORMAT_SHORT_UNSIGNED, 2, "Olympus.RedBias",    "Red bias",             NULL },
 { 0x1018, EXIF_FORMAT_SHORT_UNSIGNED, 2, "Olympus.BlueBias",   "Blue bias",            NULL },
-{ 0x101a, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Olympus.SerialNumber", "Serial number",      NULL },
-{ 0x1023, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Olympus.FlashBias",  "Flash bias",           NULL },
+{ 0x101a, EXIF_FORMAT_STRING, -1,       "Olympus.SerialNumber", "Serial number",       NULL },
+{ 0x1023, EXIF_FORMAT_RATIONAL, 1,      "Olympus.FlashBias",   "Flash bias",           NULL },
 { 0x1029, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Olympus.Contrast",   "Contrast",             OlympusTagContrast },
 { 0x102a, EXIF_FORMAT_SHORT_UNSIGNED, 1, "Olympus.SharpnessFactor", "Sharpness factor",        NULL },
 { 0x102b, EXIF_FORMAT_SHORT_UNSIGNED, 6, "Olympus.ColorControl", "Color control",      NULL },
@@ -182,10 +286,10 @@ static ExifTextList OlympusWBColorTemp[]= {
        EXIF_TEXT_LIST_END
 };
 
-gint format_olympus_makernote(ExifData *exif, unsigned char *tiff, guint offset,
-                             guint size, ExifByteOrder bo)
+gboolean format_olympus_makernote(ExifData *exif, guchar *tiff, guint offset,
+                                 guint size, ExifByteOrder bo)
 {
-       unsigned char *data;
+       guchar *data;
        ExifItem *item;
 
        if (offset + 8 + 4 >= size) return FALSE;
@@ -211,8 +315,8 @@ gint format_olympus_makernote(ExifData *exif, unsigned char *tiff, guint offset,
                static ExifMarker marker = { 0x0200, EXIF_FORMAT_STRING, -1,
                                             "Olympus.ShootingMode", "Shooting mode", NULL };
                guint32 *array = item->data;
-               const gchar *mode;
-               const gchar *pdir = NULL;
+               gchar *mode;
+               gchar *pdir = NULL;
                gchar *text;
                gint l;
 
@@ -222,13 +326,16 @@ gint format_olympus_makernote(ExifData *exif, unsigned char *tiff, guint offset,
                        pdir = exif_text_list_find_value(OlympusPanoramaDirection, array[2]);
                        }
 
-               text = g_strdup_printf("%s%s%s, seq %d", (mode) ? mode : "unknown",
+               text = g_strdup_printf("%s%s%s, seq %d", mode,
                                       (pdir) ? " " : "", (pdir) ? pdir : "",
                                       array[1] + 1);
                l = strlen(text) + 1;
                item = exif_item_new(marker.format, marker.tag, l, &marker);
                memcpy(item->data, text, l);
+
                g_free(text);
+               g_free(pdir);
+               g_free(mode);
 
                exif->items = g_list_prepend(exif->items, item);
                }
@@ -239,8 +346,8 @@ gint format_olympus_makernote(ExifData *exif, unsigned char *tiff, guint offset,
                static ExifMarker marker = { 0x1015, EXIF_FORMAT_STRING, -1,
                                             "Olympus.WhiteBalance", "White balance", NULL };
                guint16 *array = item->data;
-               const gchar *mode;
-               const gchar *color = NULL;
+               gchar *mode;
+               gchar *color = NULL;
                gchar *text;
                gint l;
 
@@ -250,12 +357,15 @@ gint format_olympus_makernote(ExifData *exif, unsigned char *tiff, guint offset,
                        color = exif_text_list_find_value(OlympusWBColorTemp, array[1]);
                        }
 
-               text = g_strdup_printf("%s%s%s", (mode) ? mode : "unknown",
+               text = g_strdup_printf("%s%s%s", mode,
                                       (color) ? " " : "", (color) ? color : "");
                l = strlen(text) + 1;
                item = exif_item_new(marker.format, marker.tag, l, &marker);
                memcpy(item->data, text, l);
+
                g_free(text);
+               g_free(color);
+               g_free(mode);
 
                exif->items = g_list_prepend(exif->items, item);
                }
@@ -264,3 +374,6 @@ gint format_olympus_makernote(ExifData *exif, unsigned char *tiff, guint offset,
 }
 
 
+#endif
+/* not HAVE_EXIV2 */
+/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */