Remove commented out code.
[geeqie.git] / src / format_raw.c
index 3a369fe..cc5b719 100644 (file)
@@ -1,6 +1,7 @@
 /*
- *  GQView
- *  (C) 2006 John Ellis
+ * Geeqie
+ * (C) 2006 John Ellis
+ * Copyright (C) 2008 - 2012 The Geeqie Team
  *
  *  Authors:
  *    Original version 2005 Lars Ellenberg, base on dcraw by David coffin.
@@ -27,7 +28,7 @@
 
 #include "intl.h"
 
-#include "gqview.h"
+#include "main.h"
 #include "format_raw.h"
 
 #include "format_canon.h"
 #include "format_olympus.h"
 
 
-/* so that debugging is honored */
-extern gint debug;
-
-
 typedef struct _FormatRawEntry FormatRawEntry;
 struct _FormatRawEntry {
        const gchar *extension;
        FormatRawMatchType magic_type;
        const guint magic_offset;
-       const void *magic_pattern;
+       gconstpointer magic_pattern;
        const guint magic_length;
        const FormatRawExifType exif_type;
        FormatRawExifParseFunc exif_func;
@@ -62,6 +59,7 @@ static FormatRawEntry format_raw_list[] = {
        FORMAT_RAW_NIKON,
        FORMAT_RAW_OLYMPUS,
        FORMAT_RAW_PENTAX,
+       FORMAT_RAW_SAMSUNG,
        { NULL, 0, 0, NULL, 0, 0, NULL, NULL, NULL }
 };
 
@@ -69,7 +67,7 @@ static FormatRawEntry format_raw_list[] = {
 typedef struct _FormatExifEntry FormatExifEntry;
 struct _FormatExifEntry {
        FormatExifMatchType header_type;
-       const void *header_pattern;
+       gconstpointer header_pattern;
        const guint header_length;
        const gchar *description;
        FormatExifParseFunc func_parse;
@@ -80,11 +78,11 @@ static FormatExifEntry format_exif_list[] = {
        FORMAT_EXIF_FUJI,
        FORMAT_EXIF_NIKON,
        FORMAT_EXIF_OLYMPUS,
-       { 0, NULL, 0, NULL }
+       { 0, NULL, 0, NULL, NULL }
 };
 
 
-static guint tiff_table(unsigned char *data, const guint len, guint offset, ExifByteOrder bo,
+static guint tiff_table(guchar *data, const guint len, guint offset, ExifByteOrder bo,
                        guint tag, ExifFormatType type,
                        guint *result_offset, guint *result_count)
 {
@@ -92,7 +90,7 @@ static guint tiff_table(unsigned char *data, const guint len, guint offset, Exif
        guint i;
 
        if (len < offset + 2) return 0;
-       if (type < 0 || type > EXIF_FORMAT_COUNT) return 0;
+       if (type > EXIF_FORMAT_COUNT) return 0;
 
        count = exif_byte_get_int16(data + offset, bo);
        offset += 2;
@@ -135,9 +133,9 @@ static guint tiff_table(unsigned char *data, const guint len, guint offset, Exif
        return exif_byte_get_int32(data + offset + count * 12, bo);
 }
 
-static gint format_tiff_find_tag_data(unsigned char *data, const guint len,
-                                     guint tag, ExifFormatType type,
-                                     guint *result_offset, guint *result_count)
+static gboolean format_tiff_find_tag_data(guchar *data, const guint len,
+                                         guint tag, ExifFormatType type,
+                                         guint *result_offset, guint *result_count)
 {
        ExifByteOrder bo;
        guint offset;
@@ -181,10 +179,10 @@ static gint format_tiff_find_tag_data(unsigned char *data, const guint len,
        return FALSE;
 }
 
-static FormatRawEntry *format_raw_find(unsigned char *data, const guint len)
+static FormatRawEntry *format_raw_find(guchar *data, const guint len)
 {
        gint n;
-       gint tiff;
+       gboolean tiff;
        guint make_count = 0;
        guint make_offset = 0;
 
@@ -232,17 +230,17 @@ static FormatRawEntry *format_raw_find(unsigned char *data, const guint len)
        return NULL;
 }
 
-static gint format_raw_parse(FormatRawEntry *entry,
-                            unsigned char *data, const guint len,
-                            guint *image_offset, guint *exif_offset)
+static gboolean format_raw_parse(FormatRawEntry *entry,
+                                guchar *data, const guint len,
+                                guint *image_offset, guint *exif_offset)
 {
        guint io = 0;
        guint eo = 0;
-       gint found;
+       gboolean found;
 
        if (!entry || !entry->func_parse) return FALSE;
 
-       if (debug) printf("RAW using file parser for %s\n", entry->description);
+       DEBUG_1("RAW using file parser for %s", entry->description);
 
        found = entry->func_parse(data, len, &io, &eo);
 
@@ -259,8 +257,8 @@ static gint format_raw_parse(FormatRawEntry *entry,
        return TRUE;
 }
 
-gint format_raw_img_exif_offsets(unsigned char *data, const guint len,
-                                guint *image_offset, guint *exif_offset)
+gboolean format_raw_img_exif_offsets(guchar *data, const guint len,
+                                    guint *image_offset, guint *exif_offset)
 {
        FormatRawEntry *entry;
 
@@ -274,7 +272,7 @@ gint format_raw_img_exif_offsets(unsigned char *data, const guint len,
 }
 
 
-FormatRawExifType format_raw_exif_offset(unsigned char *data, const guint len, guint *exif_offset,
+FormatRawExifType format_raw_exif_offset(guchar *data, const guint len, guint *exif_offset,
                                         FormatRawExifParseFunc *exif_parse_func)
 {
        FormatRawEntry *entry;
@@ -296,15 +294,15 @@ FormatRawExifType format_raw_exif_offset(unsigned char *data, const guint len, g
 }
 
 
-gint format_raw_img_exif_offsets_fd(int fd, const gchar *path,
-                                   unsigned char *header_data, const guint header_len,
-                                   guint *image_offset, guint *exif_offset)
+gboolean format_raw_img_exif_offsets_fd(gint fd, const gchar *path,
+                                       guchar *header_data, const guint header_len,
+                                       guint *image_offset, guint *exif_offset)
 {
        FormatRawEntry *entry;
-       void *map_data = NULL;
+       gpointer map_data = NULL;
        size_t map_len = 0;
        struct stat st;
-       gint success;
+       gboolean success;
 
        if (!header_data || fd < 0) return FALSE;
 
@@ -312,7 +310,7 @@ gint format_raw_img_exif_offsets_fd(int fd, const gchar *path,
        if (path)
                {
                const gchar *ext;
-               gint match = FALSE;
+               gboolean match = FALSE;
                gint i;
 
                ext = strrchr(path, '.');
@@ -323,7 +321,7 @@ gint format_raw_img_exif_offsets_fd(int fd, const gchar *path,
                while (!match && format_raw_list[i].magic_pattern)
                        {
                        if (format_raw_list[i].extension &&
-                           strcasecmp(format_raw_list[i].extension, ext) == 0)
+                           g_ascii_strcasecmp(format_raw_list[i].extension, ext) == 0)
                                {
                                match = TRUE;
                                }
@@ -332,27 +330,27 @@ gint format_raw_img_exif_offsets_fd(int fd, const gchar *path,
 
                if (!match) return FALSE;
 
-               if (debug) printf("RAW file parser extension match\n");
+               DEBUG_1("RAW file parser extension match");
                }
 
        /* FIXME:
         * when the target is a tiff file it should be mmaped prior to format_raw_find as
         * the make field data may not always be within header_data + header_len
-        */ 
+        */
        entry = format_raw_find(header_data, header_len);
 
        if (!entry || !entry->func_parse) return FALSE;
 
        if (fstat(fd, &st) == -1)
                {
-               printf("Failed to stat file %d\n", fd);
+               log_printf("Failed to stat file %d\n", fd);
                return FALSE;
                }
        map_len = st.st_size;
        map_data = mmap(0, map_len, PROT_READ, MAP_PRIVATE, fd, 0);
        if (map_data == MAP_FAILED)
                {
-               printf("Failed to mmap file %d\n", fd);
+               log_printf("Failed to mmap file %d\n", fd);
                return FALSE;
                }
 
@@ -360,14 +358,14 @@ gint format_raw_img_exif_offsets_fd(int fd, const gchar *path,
 
        if (munmap(map_data, map_len) == -1)
                {
-               printf("Failed to unmap file %d\n", fd);
+               log_printf("Failed to unmap file %d\n", fd);
                }
 
        if (success && image_offset)
                {
-               if (lseek(fd, *image_offset, SEEK_SET) != *image_offset)
+               if (lseek(fd, *image_offset, SEEK_SET) != (off_t) *image_offset)
                        {
-                       printf("Failed to seek to embedded image\n");
+                       log_printf("Failed to seek to embedded image\n");
 
                        *image_offset = 0;
                        if (*exif_offset) *exif_offset = 0;
@@ -379,13 +377,13 @@ gint format_raw_img_exif_offsets_fd(int fd, const gchar *path,
 }
 
 
-static FormatExifEntry *format_exif_makernote_find(ExifData *exif, unsigned char *tiff,
+static FormatExifEntry *format_exif_makernote_find(ExifData *exif, guchar *tiff,
                                                   guint offset, guint size)
 {
        ExifItem *make;
        gint n;
 
-       make = exif_get_item(exif, "Make");
+       make = exif_get_item(exif, "Exif.Image.Make");
 
        n = 0;
        while (format_exif_list[n].header_pattern)
@@ -416,8 +414,8 @@ static FormatExifEntry *format_exif_makernote_find(ExifData *exif, unsigned char
        return FALSE;
 }
 
-gint format_exif_makernote_parse(ExifData *exif, unsigned char *tiff, guint offset,
-                                guint size, ExifByteOrder bo)
+gboolean format_exif_makernote_parse(ExifData *exif, guchar *tiff, guint offset,
+                                    guint size, ExifByteOrder bo)
 {
        FormatExifEntry *entry;
 
@@ -425,7 +423,7 @@ gint format_exif_makernote_parse(ExifData *exif, unsigned char *tiff, guint offs
 
        if (!entry || !entry->func_parse) return FALSE;
 
-       if (debug) printf("EXIF using makernote parser for %s\n", entry->description);
+       DEBUG_1("EXIF using makernote parser for %s", entry->description);
 
        return entry->func_parse(exif, tiff, offset, size, bo);
 }
@@ -437,10 +435,10 @@ gint format_exif_makernote_parse(ExifData *exif, unsigned char *tiff, guint offs
  */
 #if DEBUG_RAW_TIFF
 
-static guint format_debug_tiff_table(unsigned char *data, const guint len, guint offset,
+static guint format_debug_tiff_table(guchar *data, const guint len, guint offset,
                                     ExifByteOrder bo, gint level);
 
-static void format_debug_tiff_entry(unsigned char *data, const guint len, guint offset,
+static void format_debug_tiff_entry(guchar *data, const guint len, guint offset,
                                    ExifByteOrder bo, gint level)
 {
        guint tag;
@@ -464,7 +462,7 @@ static void format_debug_tiff_entry(unsigned char *data, const guint len, guint
                segment = offset + EXIF_TIFD_OFFSET_DATA;
                }
 
-       printf("%*stag:0x%04X (%05d), type:%2d %9s, len:%6d [%02X %02X %02X %02X] @ offset:%d\n",
+       log_printf("%*stag:0x%04X (%05d), type:%2d %9s, len:%6d [%02X %02X %02X %02X] @ offset:%d\n",
                level, "", tag, tag, type,
                (type < EXIF_FORMAT_COUNT) ? ExifFormatList[type].short_name : "???", count,
                data[segment], data[segment + 1], data[segment + 2], data[segment + 3], segment);
@@ -473,7 +471,7 @@ static void format_debug_tiff_entry(unsigned char *data, const guint len, guint
                {
                gint i;
 
-               printf("%*s~~~ found %s table\n", level, "", (tag == 0x14a) ? "subIFD" : "EXIF" );
+               log_printf("%*s~~~ found %s table\n", level, "", (tag == 0x14a) ? "subIFD" : "EXIF" );
 
                for (i = 0; i < count; i++)
                        {
@@ -485,21 +483,21 @@ static void format_debug_tiff_entry(unsigned char *data, const guint len, guint
                }
        else if (tag == 0x8773 && type == EXIF_FORMAT_UNDEFINED)
                {
-               printf("%*s~~~ found ICC color profile at offset %d, length %d\n", level, "", segment, seg_len);
+               log_printf("%*s~~~ found ICC color profile at offset %d, length %d\n", level, "", segment, seg_len);
                }
        else if (tag == 0x201 && (type == EXIF_FORMAT_LONG_UNSIGNED || type == EXIF_FORMAT_LONG))
                {
                guint subset = exif_byte_get_int32(data + segment, bo);
-               printf("%*s~~~ found jpeg data at offset %d\n", level, "", subset);
+               log_printf("%*s~~~ found jpeg data at offset %d\n", level, "", subset);
                }
        else if (tag == 0x202 && (type == EXIF_FORMAT_LONG_UNSIGNED || type == EXIF_FORMAT_LONG))
                {
                guint subset = exif_byte_get_int32(data + segment, bo);
-               printf("%*s~~~ found jpeg data length of %d\n", level, "", subset);
+               log_printf("%*s~~~ found jpeg data length of %d\n", level, "", subset);
                }
 }
 
-static guint format_debug_tiff_table(unsigned char *data, const guint len, guint offset,
+static guint format_debug_tiff_table(guchar *data, const guint len, guint offset,
                                     ExifByteOrder bo, gint level)
 {
        guint count;
@@ -513,20 +511,20 @@ static guint format_debug_tiff_table(unsigned char *data, const guint len, guint
        offset += 2;
        if (len < offset + count * EXIF_TIFD_SIZE + 4) return 0;
 
-       printf("%*s== tiff table #%d has %d entries ==\n", level, "", level, count);
+       log_printf("%*s== tiff table #%d has %d entries ==\n", level, "", level, count);
 
        for (i = 0; i < count; i++)
                {
                format_debug_tiff_entry(data, len, offset + i * EXIF_TIFD_SIZE, bo, level);
                }
 
-       printf("%*s----------- end of #%d ------------\n", level, "", level);
+       log_printf("%*s----------- end of #%d ------------\n", level, "", level);
 
        return exif_byte_get_int32(data + offset + count * EXIF_TIFD_SIZE, bo);
 }
 
-gint format_debug_tiff_raw(unsigned char *data, const guint len,
-                          guint *image_offset, guint *exif_offset)
+gboolean format_debug_tiff_raw(guchar *data, const guint len,
+                              guint *image_offset, guint *exif_offset)
 {
        ExifByteOrder bo;
        gint level;
@@ -548,7 +546,7 @@ gint format_debug_tiff_raw(unsigned char *data, const guint len,
                return FALSE;
                }
 
-       printf("*** debug parsing tiff\n");
+       log_printf("*** debug parsing tiff\n");
 
        offset = exif_byte_get_int32(data + 4, bo);
        level = 0;
@@ -558,13 +556,13 @@ gint format_debug_tiff_raw(unsigned char *data, const guint len,
                level++;
                }
 
-       printf("*** end\n");
+       log_printf("*** end\n");
 
        /* we are debugging, not trying to return any data */
        return FALSE;
 }
 #endif
 
-#endif 
+#endif
 /* not HAVE_EXIV2 */
-
+/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */