simplified exif.h, moved implementation-specific stuff to exif-int.h
authorVladimir Nadvornik <nadvornik@suse.cz>
Wed, 13 Feb 2008 13:57:31 +0000 (13:57 +0000)
committerVladimir Nadvornik <nadvornik@suse.cz>
Wed, 13 Feb 2008 13:57:31 +0000 (13:57 +0000)
src/bar_exif.c
src/exif-int.h [new file with mode: 0644]
src/exif.c
src/exif.h
src/format_canon.h
src/format_fuji.h
src/format_nikon.h
src/format_olympus.h
src/format_raw.h
src/image-load.c
src/image.c

index 086579c..f25ef4b 100644 (file)
@@ -241,14 +241,14 @@ static void bar_exif_update(ExifBar *eb)
                GtkListStore *store;
                GtkTreeIter iter;
                GList *work;
+               ExifItem *item;
                
                store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(eb->listview)));
                gtk_list_store_clear(store);
 
-               work = exif->items;
-               while (work)
+               item = exif_get_first_item(exif);
+               while (item)
                        {
-                       ExifItem *item;
                        gchar *tag;
                        const gchar *tag_name;
                        gchar *text;
@@ -256,15 +256,12 @@ static void bar_exif_update(ExifBar *eb)
                        gchar *elements;
                        const gchar *description;
 
-                       item = work->data;
-                       work = work->next;
-
-                       tag = g_strdup_printf("0x%04x", item->tag);
+                       tag = g_strdup_printf("0x%04x", exif_item_get_tag_id(item));
                        tag_name = exif_item_get_tag_name(item);
                        format = exif_item_get_format_name(item, TRUE);
                        text = exif_item_get_data_as_text(item);
                        text = bar_exif_validate_text(text);
-                       elements = g_strdup_printf("%d", item->elements);
+                       elements = g_strdup_printf("%d", exif_item_get_elements(item));
                        description = exif_item_get_description(item);
                        if (!description) description = "";
                        gtk_list_store_append(store, &iter);
@@ -279,6 +276,7 @@ static void bar_exif_update(ExifBar *eb)
                        g_free(tag);
                        g_free(text);
                        g_free(elements);
+                       item = exif_get_next_item(exif);
                        }
                }
 
diff --git a/src/exif-int.h b/src/exif-int.h
new file mode 100644 (file)
index 0000000..fc45e42
--- /dev/null
@@ -0,0 +1,175 @@
+/*
+ *  GQView
+ *  (C) 2006 John Ellis
+ *
+ *  Authors:
+ *    Support for Exif file format, originally written by Eric Swalens.    
+ *    Modified by Quy Tonthat
+ *    Reimplemented with generic data storage by John Ellis
+ *
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program 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 General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#ifndef __EXIF_INT_H
+#define __EXIF_INT_H
+
+#include "exif.h"
+
+/*
+ *-----------------------------------------------------------------------------
+ * Tag formats
+ *-----------------------------------------------------------------------------
+ */
+
+typedef enum {
+       EXIF_BYTE_ORDER_INTEL,
+       EXIF_BYTE_ORDER_MOTOROLA
+} ExifByteOrder;
+
+typedef struct _ExifFormatAttrib ExifFormatAttrib;
+struct _ExifFormatAttrib
+{
+       ExifFormatType type;
+       guint size;
+       const gchar *short_name;
+       const gchar *description;
+};
+
+/* the list of known tag data formats */
+extern ExifFormatAttrib ExifFormatList[];
+
+
+/*
+ *-----------------------------------------------------------------------------
+ * Data storage
+ *-----------------------------------------------------------------------------
+ */
+
+typedef struct _ExifMarker ExifMarker;
+typedef struct _ExifTextList ExifTextList;
+
+struct _ExifData
+{
+       GList *items;   /* list of (ExifItem *) */
+       GList *current; /* for exif_get_next_item */
+};
+
+
+struct _ExifItem
+{
+       ExifFormatType format;
+       guint tag;
+       const ExifMarker *marker;
+       guint elements;
+       gpointer data;
+       guint data_len;
+};
+
+struct _ExifMarker
+{
+       guint           tag;
+       ExifFormatType  format;
+       gint            components;
+       gchar           *key;
+       gchar           *description;
+       ExifTextList    *list;
+};
+
+#define EXIF_MARKER_LIST_END { 0x0000, EXIF_FORMAT_UNKNOWN, 0, NULL, NULL, NULL }
+
+struct _ExifTextList
+{
+       gint value;
+       const gchar* description;
+};
+
+#define EXIF_TEXT_LIST_END { -1, NULL }
+
+
+typedef struct _ExifFormattedText ExifFormattedText;
+struct _ExifFormattedText
+{
+       const gchar *key;
+       const gchar *description;
+};
+
+
+/*
+ *-----------------------------------------------------------------------------
+ * Data
+ *-----------------------------------------------------------------------------
+ */
+
+
+
+/* the known exif tags list */
+extern ExifMarker ExifKnownMarkersList[];
+
+/* the unknown tags utilize this generic list */
+extern ExifMarker ExifUnknownMarkersList[];
+
+/* the list of specially formatted keys, for human readable output */
+extern ExifFormattedText ExifFormattedList[];
+
+
+/*
+ *-----------------------------------------------------------------------------
+ * functions
+ *-----------------------------------------------------------------------------
+ */
+
+
+/* usually for debugging to stdout */
+void exif_write_data_list(ExifData *exif, FILE *f, gint human_readable_list);
+
+
+
+/* These funcs for use by makernote/tiff parsers only */
+
+#define EXIF_TIFF_MAX_LEVELS 4
+
+#define EXIF_TIFD_OFFSET_TAG 0
+#define EXIF_TIFD_OFFSET_FORMAT 2
+#define EXIF_TIFD_OFFSET_COUNT 4
+#define EXIF_TIFD_OFFSET_DATA 8
+#define EXIF_TIFD_SIZE 12
+
+
+guint16 exif_byte_get_int16(unsigned char *f, ExifByteOrder bo);
+guint32 exif_byte_get_int32(unsigned char *f, ExifByteOrder bo);
+void exif_byte_put_int16(unsigned char *f, guint16 n, ExifByteOrder bo);
+void exif_byte_put_int32(unsigned char *f, guint32 n, ExifByteOrder bo);
+
+ExifItem *exif_item_new(ExifFormatType format, guint tag,
+                       guint elements, const ExifMarker *marker);
+void exif_item_copy_data(ExifItem *item, void *src, guint len,
+                        ExifFormatType src_format, ExifByteOrder bo);
+
+gint exif_parse_IFD_table(ExifData *exif,
+                         unsigned char *tiff, guint offset,
+                         guint size, ExifByteOrder bo,
+                         gint level,
+                         const ExifMarker *list);
+
+gint exif_tiff_directory_offset(unsigned char *data, const guint len,
+                               guint *offset, ExifByteOrder *bo);
+gint exif_tiff_parse(ExifData *exif, unsigned char *tiff, guint size, ExifMarker *list);
+
+gchar *exif_text_list_find_value(ExifTextList *list, guint value);
+
+
+#endif
+
index 16a3363..908fcfb 100644 (file)
@@ -68,7 +68,7 @@
 #include "intl.h"
 
 #include "gqview.h"
-#include "exif.h"
+#include "exif-int.h"
 
 #include "format_raw.h"
 #include "ui_fileops.h"
@@ -512,6 +512,29 @@ const char *exif_item_get_tag_name(ExifItem *item)
        return item->marker->key;
 }
 
+guint exif_item_get_tag_id(ExifItem *item)
+{
+       return item->tag;
+}
+
+guint exif_item_get_elements(ExifItem *item)
+{
+       return item->elements;
+}
+
+char *exif_item_get_data(ExifItem *item, guint *data_len)
+{
+       if (data_len)
+               *data_len = item->data_len;
+       return item->data;
+}
+
+guint exif_item_get_format_id(ExifItem *item)
+{
+       return item->format;
+}
+
+
 const char *exif_item_get_description(ExifItem *item)
 {
        if (!item || !item->marker) return NULL;
@@ -575,6 +598,7 @@ gchar *exif_text_list_find_value(ExifTextList *list, guint value)
        return result;
 }
 
+
 /*
  *-------------------------------------------------------------------
  * byte order utils
@@ -1122,6 +1146,32 @@ static gint exif_jpeg_parse(ExifData *exif,
  *-------------------------------------------------------------------
  */
 
+
+ExifItem *exif_get_first_item(ExifData *exif)
+{
+       if (exif->items) 
+               {
+               ExifItem *ret = (ExifItem *)exif->items->data;
+               exif->current = exif->items->next;
+               return ret;
+               }
+       exif->current = NULL;
+       return NULL;
+}
+
+ExifItem *exif_get_next_item(ExifData *exif)
+{
+       if (exif->current) 
+               {
+               ExifItem *ret = (ExifItem *)exif->current->data;
+               exif->current = exif->current->next;
+               return ret;
+               }
+       return NULL;
+}
+
+
+
 static gint map_file(const gchar *path, void **mapping, int *size)
 {
        int fd;
@@ -1201,6 +1251,7 @@ ExifData *exif_read(FileData *fd, gint parse_color_profile)
 
        exif = g_new0(ExifData, 1);
        exif->items = NULL;
+       exif->current = NULL;
 
        if ((res = exif_jpeg_parse(exif, (unsigned char *)f, size,
                                   ExifKnownMarkersList,
index 205bcfa..c2c07d7 100644 (file)
@@ -51,35 +51,15 @@ typedef enum {
        EXIF_FORMAT_DOUBLE              = 12
 } ExifFormatType;
 
-typedef enum {
-       EXIF_BYTE_ORDER_INTEL,
-       EXIF_BYTE_ORDER_MOTOROLA
-} ExifByteOrder;
-
-typedef struct _ExifFormatAttrib ExifFormatAttrib;
-struct _ExifFormatAttrib
-{
-       ExifFormatType type;
-       guint size;
-       const gchar *short_name;
-       const gchar *description;
-};
-
-/* the list of known tag data formats */
-extern ExifFormatAttrib ExifFormatList[];
-
-
 /*
  *-----------------------------------------------------------------------------
  * Data storage
  *-----------------------------------------------------------------------------
  */
 
+typedef struct _ExifItem ExifItem;
+
 typedef struct _ExifData ExifData;
-struct _ExifData
-{
-       GList *items;   /* list of (ExifItem *) */
-};
 
 typedef struct _ExifRational ExifRational;
 struct _ExifRational
@@ -89,55 +69,6 @@ struct _ExifRational
 };
 
 
-typedef struct _ExifItem ExifItem;
-typedef struct _ExifMarker ExifMarker;
-typedef struct _ExifTextList ExifTextList;
-
-struct _ExifItem
-{
-       ExifFormatType format;
-       guint tag;
-       const ExifMarker *marker;
-       guint elements;
-       gpointer data;
-       guint data_len;
-};
-
-struct _ExifMarker
-{
-       guint           tag;
-       ExifFormatType  format;
-       gint            components;
-       gchar           *key;
-       gchar           *description;
-       ExifTextList    *list;
-};
-
-#define EXIF_MARKER_LIST_END { 0x0000, EXIF_FORMAT_UNKNOWN, 0, NULL, NULL, NULL }
-
-struct _ExifTextList
-{
-       gint value;
-       const gchar* description;
-};
-
-#define EXIF_TEXT_LIST_END { -1, NULL }
-
-
-typedef struct _ExifFormattedText ExifFormattedText;
-struct _ExifFormattedText
-{
-       const gchar *key;
-       const gchar *description;
-};
-
-
-/*
- *-----------------------------------------------------------------------------
- * Data
- *-----------------------------------------------------------------------------
- */
-
 /* enums useful for image manipulation */
 
 typedef enum {
@@ -160,16 +91,6 @@ typedef enum {
 } ExifUnitType;
 
 
-/* the known exif tags list */
-extern ExifMarker ExifKnownMarkersList[];
-
-/* the unknown tags utilize this generic list */
-extern ExifMarker ExifUnknownMarkersList[];
-
-/* the list of specially formatted keys, for human readable output */
-extern ExifFormattedText ExifFormattedList[];
-
-
 /*
  *-----------------------------------------------------------------------------
  * functions
@@ -185,9 +106,15 @@ ExifRational *exif_get_rational(ExifData *exif, const gchar *key, gint *sign);
 double exif_rational_to_double(ExifRational *r, gint sign);
 
 ExifItem *exif_get_item(ExifData *exif, const gchar *key);
+ExifItem *exif_get_first_item(ExifData *exif);
+ExifItem *exif_get_next_item(ExifData *exif);
 
 const char *exif_item_get_tag_name(ExifItem *item);
+guint exif_item_get_tag_id(ExifItem *item);
+guint exif_item_get_elements(ExifItem *item);
+char *exif_item_get_data(ExifItem *item, guint *data_len);
 const char *exif_item_get_description(ExifItem *item);
+guint exif_item_get_format_id(ExifItem *item);
 const char *exif_item_get_format_name(ExifItem *item, gint brief);
 gchar *exif_item_get_data_as_text(ExifItem *item);
 gint exif_item_get_integer(ExifItem *item, gint *value);
@@ -195,43 +122,9 @@ ExifRational *exif_item_get_rational(ExifItem *item, gint *sign);
 
 const gchar *exif_get_description_by_key(const gchar *key);
 
-/* usually for debugging to stdout */
-void exif_write_data_list(ExifData *exif, FILE *f, gint human_readable_list);
-
-
-
-/* These funcs for use by makernote/tiff parsers only */
-
-#define EXIF_TIFF_MAX_LEVELS 4
-
-#define EXIF_TIFD_OFFSET_TAG 0
-#define EXIF_TIFD_OFFSET_FORMAT 2
-#define EXIF_TIFD_OFFSET_COUNT 4
-#define EXIF_TIFD_OFFSET_DATA 8
-#define EXIF_TIFD_SIZE 12
-
-
-guint16 exif_byte_get_int16(unsigned char *f, ExifByteOrder bo);
-guint32 exif_byte_get_int32(unsigned char *f, ExifByteOrder bo);
-void exif_byte_put_int16(unsigned char *f, guint16 n, ExifByteOrder bo);
-void exif_byte_put_int32(unsigned char *f, guint32 n, ExifByteOrder bo);
-
-ExifItem *exif_item_new(ExifFormatType format, guint tag,
-                       guint elements, const ExifMarker *marker);
-void exif_item_copy_data(ExifItem *item, void *src, guint len,
-                        ExifFormatType src_format, ExifByteOrder bo);
-
-gint exif_parse_IFD_table(ExifData *exif,
-                         unsigned char *tiff, guint offset,
-                         guint size, ExifByteOrder bo,
-                         gint level,
-                         const ExifMarker *list);
-
-gint exif_tiff_directory_offset(unsigned char *data, const guint len,
-                               guint *offset, ExifByteOrder *bo);
-gint exif_tiff_parse(ExifData *exif, unsigned char *tiff, guint size, ExifMarker *list);
-
-gchar *exif_text_list_find_value(ExifTextList *list, guint value);
+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);
 
 
 #endif
index b2422b4..ba5241a 100644 (file)
@@ -19,7 +19,7 @@
 #define __FORMAT_CANON_H
 
 
-#include "exif.h"
+#include "exif-int.h"
 
 
 gint format_canon_raw_crw(unsigned char *data, const guint len,
index fc28362..16af3c0 100644 (file)
@@ -14,7 +14,7 @@
 #define __FORMAT_FUJI_H
 
 
-#include "exif.h"
+#include "exif-int.h"
 
 
 gint format_fuji_raw(unsigned char *data, const guint len,
index 5c2cd77..0ae249a 100644 (file)
@@ -11,7 +11,7 @@
 #define __FORMAT_NIKON_H
 
 
-#include "exif.h"
+#include "exif-int.h"
 
 gint format_nikon_raw(unsigned char *data, const guint len,
                      guint *image_offset, guint *exif_offset);
index edb7061..b55143b 100644 (file)
@@ -11,7 +11,7 @@
 #define __FORMAT_OLYMPUS_H
 
 
-#include "exif.h"
+#include "exif-int.h"
 
 
 gint format_olympus_raw(unsigned char *data, const guint len,
index 1133c7c..3e34017 100644 (file)
@@ -13,7 +13,7 @@
 #ifndef __FORMAT_RAW_H
 #define __FORMAT_RAW_H
 
-#include "exif.h"
+#include "exif-int.h"
 
 
 typedef enum {
index 7231f99..69f341e 100644 (file)
@@ -14,7 +14,7 @@
 #include "image-load.h"
 #include "filelist.h"
 
-#include "format_raw.h"
+#include "exif.h"
 #include "ui_fileops.h"
 
 #include <fcntl.h>
index e197d72..e9b67b8 100644 (file)
@@ -379,16 +379,21 @@ static gint image_post_process_color(ImageWindow *imd, gint start_row, ExifData
                                }
                        }
                }
-       if (item && item->format == EXIF_FORMAT_UNDEFINED)
+
+       if (item && exif_item_get_format_id(item) == EXIF_FORMAT_UNDEFINED)
                {
+               char *data;
+               guint data_len;
                if (debug) printf("Found embedded color profile\n");
+               
+               data = exif_item_get_data(item, &data_len);
 
                cm = color_man_new_embedded(imd, NULL,
-                                           item->data, item->data_len,
+                                           data, data_len,
                                            screen_type, screen_file,
                                            image_post_process_color_cb, imd);
                }
-       else
+       else 
                {
                cm = color_man_new(imd, NULL,
                                   input_type, input_file,