diff src/format_raw.c @ 51:276ea4c98d33

Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net> * exif.[ch]: Use glib provided data types and byte order functions for consistency with rest of application. Made several more functions available in the header. Use MakerNote parsing from format_raw.c. * format_canon.[ch]: Changes to match exif.h and format_raw.h. * format_fuji.[ch]: Add support for Fuji EXIF MakerNote. * format_nikon.[ch]: New files, add support for Nikon EXIF MakerNote. * format_raw.[ch]: Add EXIF MakerNote parser functions to gather all camera formats here (similar to existing raw format list). * src/Makefile.am: Add format_nikon.[ch]. ##### Note: GQview CVS on sourceforge is not always up to date, please use ##### ##### an offical release when making enhancements and translation updates. #####
author gqview
date Sun, 05 Jun 2005 02:48:54 +0000
parents aa4c0e1b54b0
children 00843150f7c8
line wrap: on
line diff
--- a/src/format_raw.c	Sat Jun 04 08:06:47 2005 +0000
+++ b/src/format_raw.c	Sun Jun 05 02:48:54 2005 +0000
@@ -30,35 +30,51 @@
 
 #include "format_canon.h"
 #include "format_fuji.h"
+#include "format_nikon.h"
 
 
-typedef struct _FormatEntry FormatEntry;
-struct _FormatEntry {
+typedef struct _FormatRawEntry FormatRawEntry;
+struct _FormatRawEntry {
 	const void *header_pattern;
 	const guint header_length;
 	const gchar *description;
 	FormatRawParseFunc func_parse;
 };
 
-
-static FormatEntry format_list[] = {
+static FormatRawEntry format_raw_list[] = {
 	FORMAT_RAW_CANON,
 	FORMAT_RAW_FUJI,
 	{ NULL, 0, NULL, NULL }
 };
 
 
-static FormatEntry *format_raw_find(const void *data, const guint len)
+typedef struct _FormatExifEntry FormatExifEntry;
+struct _FormatExifEntry {
+	FormatExifMatchType header_type;
+	const void *header_pattern;
+	const guint header_length;
+	FormatExifParseFunc func_parse;
+};
+
+static FormatExifEntry format_exif_list[] = {
+	FORMAT_EXIF_CANON,
+	FORMAT_EXIF_FUJI,
+	FORMAT_EXIF_NIKON,
+	{ 0, NULL, 0, NULL }
+};
+
+
+static FormatRawEntry *format_raw_find(const void *data, const guint len)
 {
 	gint n;
 
 	n = 0;
-	while (format_list[n].header_pattern)
+	while (format_raw_list[n].header_pattern)
 		{
-		if (format_list[n].header_length <= len &&
-		    memcmp(data, format_list[n].header_pattern, format_list[n].header_length) == 0)
+		if (format_raw_list[n].header_length <= len &&
+		    memcmp(data, format_raw_list[n].header_pattern, format_raw_list[n].header_length) == 0)
 			{
-			return &format_list[n];
+			return &format_raw_list[n];
 			}
 		n++;
 		}
@@ -66,7 +82,7 @@
 	return NULL;
 }
 
-static gint format_raw_parse(FormatEntry *entry,
+static gint format_raw_parse(FormatRawEntry *entry,
 			     const void *data, const guint len,
 			     guint *image_offset, guint *exif_offset)
 {
@@ -94,7 +110,7 @@
 gint format_raw_img_exif_offsets(const void *data, const guint len,
 				 guint *image_offset, guint *exif_offset)
 {
-	FormatEntry *entry;
+	FormatRawEntry *entry;
 
 	if (!data || len < 1) return FALSE;
 
@@ -109,7 +125,7 @@
 gint format_raw_img_exif_offsets_fd(int fd, const void *header_data, const guint header_len,
 				    guint *image_offset, guint *exif_offset)
 {
-	FormatEntry *entry;
+	FormatRawEntry *entry;
 	void *map_data = NULL;
 	size_t map_len = 0;
 	struct stat st;
@@ -157,3 +173,53 @@
 }
 
 
+static FormatExifEntry *format_exif_makernote_find(ExifData *exif, unsigned char *tiff,
+						   guint offset, guint size)
+{
+	ExifItem *make;
+	gint n;
+
+	make = exif_get_item(exif, "Make");
+
+	n = 0;
+	while (format_exif_list[n].header_pattern)
+		{
+		switch (format_exif_list[n].header_type)
+			{
+			case FORMAT_EXIF_MATCH_MAKERNOTE:
+				if (format_exif_list[n].header_length + offset < size &&
+				    memcmp(tiff + offset, format_exif_list[n].header_pattern,
+							  format_exif_list[n].header_length) == 0)
+					{
+					return &format_exif_list[n];
+					}
+				break;
+			case FORMAT_EXIF_MATCH_MAKE:
+				if (make &&
+				    make->data_len >= format_exif_list[n].header_length &&
+				    memcmp(make->data, format_exif_list[n].header_pattern,
+						       format_exif_list[n].header_length) == 0)
+					{
+					return &format_exif_list[n];
+					}
+				break;
+			}
+		n++;
+		}
+
+	return FALSE;
+}
+
+gint format_exif_makernote_parse(ExifData *exif, unsigned char *tiff, guint offset,
+				 guint size, ExifByteOrder byte_order)
+{
+	FormatExifEntry *entry;
+
+	entry = format_exif_makernote_find(exif, tiff, offset, size);
+
+	if (!entry || !entry->func_parse) return FALSE;
+
+	return entry->func_parse(exif, tiff, offset, size, byte_order);
+}
+
+