Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
authorJohn Ellis <johne@verizon.net>
Mon, 16 May 2005 01:49:51 +0000 (01:49 +0000)
committerJohn Ellis <johne@verizon.net>
Mon, 16 May 2005 01:49:51 +0000 (01:49 +0000)
        * format_raw.[ch]: New files to parse image data and exif offsets for
        the raw camera formats.
        * exif.c, image-load.c: Add support calls to format_raw.c functions
        above.
        * filelist.c: Add Fujifilm raw file extension to known formats.
        * thumb_standard.c (thumb_loader_std_start): Check for existing
        thumbnail file before checking for a failure mark.
        * src/Makefile.am: Add format_raw.[ch].

##### Note: GQview CVS on sourceforge is not always up to date, please use #####
##### an offical release when making enhancements and translation updates. #####

ChangeLog
src/Makefile.am
src/exif.c
src/filelist.c
src/format_raw.c [new file with mode: 0644]
src/format_raw.h [new file with mode: 0644]
src/image-load.c
src/thumb_standard.c

index d0034a4..56e78d6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+Sun May 15 21:40:26 2005  John Ellis  <johne@verizon.net>
+
+       * format_raw.[ch]: New files to parse image data and exif offsets for
+       the raw camera formats.
+       * exif.c, image-load.c: Add support calls to format_raw.c functions
+       above.
+       * filelist.c: Add Fujifilm raw file extension to known formats.
+       * thumb_standard.c (thumb_loader_std_start): Check for existing
+       thumbnail file before checking for a failure mark.
+       * src/Makefile.am: Add format_raw.[ch].
+
 Sat May 14 13:04:23 2005  John Ellis  <johne@verizon.net>
 
        * po/cs.po: Update Czech translation,
index e33c1f7..54e03d4 100644 (file)
@@ -84,6 +84,8 @@ gqview_SOURCES = \
        exif.h          \
        filelist.c      \
        filelist.h      \
+       format_raw.c    \
+       format_raw.h    \
        fullscreen.c    \
        fullscreen.h    \
        globals.c       \
index 82f43ea..4642127 100644 (file)
@@ -70,6 +70,7 @@
 
 #include "exif.h"
 
+#include "format_raw.h"
 #include "ui_fileops.h"
 
 
@@ -437,18 +438,22 @@ ExifFormattedText ExifFormattedList[] = {
 
 #define BYTE_ORDER_INTEL       1
 #define BYTE_ORDER_MOTOROLA    2
-                                                                                                                          
+
+
 #define MARKER_UNKNOWN         0x00
 #define MARKER_SOI             0xD8
 #define MARKER_APP1            0xE1
 
-typedef struct {
+/* These data structs are packed to make sure the
+ * byte alignment matches the on-disk data format.
+ */
+typedef struct __attribute__((packed)) {
        char            byte_order[2];
        uint16_t        magic;
        uint32_t        IFD_offset;
 } TIFFHeader;
  
-typedef struct {
+typedef struct __attribute__((packed)) {
        uint16_t        tag;
        uint16_t        format;
        uint32_t        nb;
@@ -1079,6 +1084,16 @@ ExifData *exif_read(const gchar *path)
                res = parse_TIFF(exif, (unsigned char *)f, size);
                }
 
+       if (res != 0)
+               {
+               guint32 offset = 0;
+               
+               if (format_raw_img_exif_offsets(-1, f, size, NULL, &offset))
+                       {
+                       res = parse_TIFF(exif, (unsigned char*)f + offset, size - offset);
+                       }
+               }
+
        if (res != 0)
                {
                exif_free(exif);
index 88c0114..714a2f5 100644 (file)
@@ -207,6 +207,11 @@ void filter_add_defaults(void)
        filter_add_if_missing("ico", "Icon file", ".ico;.cur", FALSE);
        filter_add_if_missing("ras", "Raster", ".ras", FALSE);
        filter_add_if_missing("svg", "Scalable Vector Graphics", ".svg", FALSE);
+
+       /* These are the raw camera formats with embedded jpeg/exif.
+        * (see format_raw.c)
+        */
+       filter_add_if_missing("raf", "Fujifilm raw camera format", ".raf", TRUE);
 }
 
 static GList *filter_to_list(const gchar *extensions)
diff --git a/src/format_raw.c b/src/format_raw.c
new file mode 100644 (file)
index 0000000..c805f19
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ *  GQView
+ *  (C) 2005 John Ellis
+ *
+ *  Authors:
+ *    Original version 2005 Lars Ellenberg, base on dcraw by David coffin.
+ *
+ * This software is released under the GNU General Public License (GNU GPL).
+ * Please read the included file COPYING for more information.
+ * This software comes with no warranty of any kind, use at your own risk!
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <glib.h>
+
+#include "intl.h"
+
+#include "format_raw.h"
+
+static gint format_raw_test_canon(int fd, const void *data, const guint len,
+                                 guint *image_offset, guint *exif_offset)
+{
+       return FALSE;
+}
+
+static gint format_raw_test_fuji(int fd, const void *data, const guint len,
+                                 guint *image_offset, guint *exif_offset)
+{
+       if (len < 128 ||
+           memcmp(data, "FUJIFILM", 8) != 0)
+               {
+               return FALSE;
+               }
+
+       *image_offset = GUINT32_FROM_BE(*(guint32*)(data + 84));
+       *exif_offset = *image_offset + 12;
+printf("found a raw fuji file!\n");
+       return TRUE;
+}
+
+static gint format_raw_test_nikon(int fd, const void *data, const guint len,
+                                 guint *image_offset, guint *exif_offset)
+{
+       return FALSE;
+}
+
+
+gint format_raw_img_exif_offsets(int fd, const void *data, const guint len,
+                                guint *image_offset, guint *exif_offset)
+{
+       guint32 io = 0;
+       guint32 eo = 0;
+       gint found;
+
+       if (fd < 0 && !data) return FALSE;
+#if 0
+       if (len < 512) return FALSE;
+#endif
+
+       found = format_raw_test_canon(fd, data, len, &io, &eo) ||
+               format_raw_test_fuji (fd, data, len, &io, &eo) ||
+               format_raw_test_nikon(fd, data, len, &io, &eo);
+
+       if (!found ||
+           io >= len - 4 ||
+           eo >= len ||
+           memcmp(data + io, "\xff\xd8\xff\xe1", 4) != 0)      /* jpeg marker */
+               {
+               return FALSE;
+               }
+
+       if (image_offset) *image_offset = io;
+       if (exif_offset) *exif_offset = eo;
+
+       return TRUE;
+}
+
+
+
diff --git a/src/format_raw.h b/src/format_raw.h
new file mode 100644 (file)
index 0000000..d76b4ee
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ *  GQView
+ *  (C) 2005 John Ellis
+ *
+ *  Authors:
+ *    Original version 2005 Lars Ellenberg, base on dcraw by David coffin.
+ *
+ * This software is released under the GNU General Public License (GNU GPL).
+ * Please read the included file COPYING for more information.
+ * This software comes with no warranty of any kind, use at your own risk!
+ */
+
+#ifndef __FORMAT_RAW_H
+#define __FORMAT_RAW_H
+
+gint format_raw_img_exif_offsets(int fd, const void *data, const guint len,
+                                guint *image_offset, guint *exif_offset);
+
+#endif
+
index fb8066b..1daf78b 100644 (file)
@@ -13,6 +13,7 @@
 #include "gqview.h"
 #include "image-load.h"
 
+#include "format_raw.h"
 #include "ui_fileops.h"
 
 #include <fcntl.h>
@@ -210,6 +211,7 @@ static gint image_loader_begin(ImageLoader *il)
 {
        guchar buf[IMAGE_LOADER_BUFFER_SIZE];
        int b;
+       unsigned int offset = 0;
 
        if (!il->loader || il->pixbuf) return FALSE;
 
@@ -221,7 +223,9 @@ static gint image_loader_begin(ImageLoader *il)
                return FALSE;
                }
 
-       if (gdk_pixbuf_loader_write(il->loader, buf, b, NULL))
+       format_raw_img_exif_offsets(il->load_fd, buf, b, &offset, NULL);
+
+       if (gdk_pixbuf_loader_write(il->loader, buf + offset, b - offset, NULL))
                {
                il->bytes_read += b;
 
index 887a27b..a4711a7 100644 (file)
@@ -715,14 +715,14 @@ gint thumb_loader_std_start(ThumbLoaderStd *tl, const gchar *path)
                {
                gint found;
 
-               if (thumb_loader_std_fail_check(tl)) return FALSE;
-
                tl->thumb_path = thumb_loader_std_cache_path(tl, FALSE, NULL, FALSE);
                tl->thumb_path_local = FALSE;
 
                found = isfile(tl->thumb_path);
                if (found && thumb_loader_std_setup(tl, tl->thumb_path)) return TRUE;
 
+               if (thumb_loader_std_fail_check(tl)) return FALSE;
+
                return thumb_loader_std_next_source(tl, found);
                }