gthumb r2224 - in trunk: . libgthumb src



Author: mjc
Date: Sat Jan 26 19:08:58 2008
New Revision: 2224
URL: http://svn.gnome.org/viewvc/gthumb?rev=2224&view=rev

Log:
2008-01-26  Michael J. Chudobiak  <mjc svn gnome org>

        * AUTHORS:
        * libgthumb/gth-exif-utils.c: (get_metadata_time_from_fd),
        (get_metadata_string_from_fd):
        * libgthumb/gth-exif-utils.h:
        * src/catalog-web-exporter.c: (gth_parsed_doc_print):
        * src/gth-fullscreen.c: (get_file_info):
        Purged get_exif_tag, get_exif_entry_value, get_exif_aperture_value,
        as part of the project to remove the libexif requirement.
        Tweaked version of David Turner's <cillian64 googlemail com> ghop patch.
        http://code.google.com/p/google-highly-open-participation-gnome/issues/detail?id=110



Modified:
   trunk/ChangeLog
   trunk/libgthumb/gth-exif-utils.c
   trunk/libgthumb/gth-exif-utils.h
   trunk/src/catalog-web-exporter.c
   trunk/src/gth-fullscreen.c

Modified: trunk/libgthumb/gth-exif-utils.c
==============================================================================
--- trunk/libgthumb/gth-exif-utils.c	(original)
+++ trunk/libgthumb/gth-exif-utils.c	Sat Jan 26 19:08:58 2008
@@ -35,14 +35,83 @@
 #include "gth-gstreamer-utils.h"
 
 
-const char *DATE_TAG_NAMES[] = {
-	"Exif.Photo.DateTimeOriginal",
-	"Xmp.exif.DateTimeOriginal",
-	"Exif.Photo.DateTimeDigitized",
-	"Xmp.exif.DateTimeDigitized",
-	"Exif.Image.DateTime",
-	"Xmp.exif.DateTime",
-	"Xmp.photoshop.DateCreated" };
+/* Some bits of information may be contained in more than one metadata tag.
+   The arrays below define the valid tags for a particular piece of 
+   information, in decreasing order of preference (best one first) */
+
+const char *_DATE_TAG_NAMES[] = {
+        "Exif.Photo.DateTimeOriginal",
+        "Xmp.exif.DateTimeOriginal",
+        "Exif.Photo.DateTimeDigitized",
+        "Xmp.exif.DateTimeDigitized",
+        "Exif.Image.DateTime",
+        "Xmp.exif.DateTime",
+        "Xmp.photoshop.DateCreated",
+	NULL };
+
+const char *_EXPTIME_TAG_NAMES[] = {
+        "Exif.Photo.ExposureTime",
+	"Xmp.exif.ExposureTime",
+	"Exif.Photo.ShutterSpeedValue",
+	"Xmp.exif.ShutterSpeedValue",
+	NULL };
+
+const char *_EXPMODE_TAG_NAMES[] = {
+	"Exif.Photo.ExposureMode",
+	"Xmp.exif.ExposureMode",
+	NULL };
+
+const char *_ISOSPEED_TAG_NAMES[] = {
+        "Exif.Photo.ISOSpeedRatings",
+	"Xmp.exif.ISOSpeedRatings", 
+	NULL };
+
+const char *_APERTURE_TAG_NAMES[] = {
+        "Exif.Photo.ApertureValue",
+	"Xmp.exif.ApertureValue", 
+	"Exif.Photo.FNumber", 
+	"Xmp.exif.FNumber",
+	NULL };
+
+const char *_FOCAL_TAG_NAMES[] = {
+        "Exif.Photo.FocalLength",
+	"Xmp.exif.FocalLength",
+	NULL };
+
+const char *_SHUTTERSPEED_TAG_NAMES[] = {
+	"Exif.Photo.ShutterSpeedValue",
+	"Xmp.exif.ShutterSpeedValue",
+	NULL };
+
+const char *_MAKE_TAG_NAMES[] = {
+	"Exif.Image.Make",
+	"Xmp.exif.Make",
+	NULL };
+
+const char *_MODEL_TAG_NAMES[] = {
+	"Exif.Image.Model",
+	"Xmp.exif.Model", 
+	NULL };
+
+const char *_FLASH_TAG_NAMES[] = {
+	"Exif.Photo.Flash",
+	"Xmp.exif.Flash", 
+	NULL };
+
+
+/* if you add something here, also update the matching enum in gth-exif-utils.h */
+const char **TAG_NAME_SETS[] = {
+        _DATE_TAG_NAMES,
+        _EXPTIME_TAG_NAMES,
+	_EXPMODE_TAG_NAMES,
+        _ISOSPEED_TAG_NAMES,
+        _APERTURE_TAG_NAMES,
+        _FOCAL_TAG_NAMES,
+	_SHUTTERSPEED_TAG_NAMES,
+	_MAKE_TAG_NAMES,
+	_MODEL_TAG_NAMES,
+	_FLASH_TAG_NAMES
+};
 
 
 ExifData *
@@ -61,55 +130,6 @@
 	return new_exif_data;
 }
 
-
-char *
-get_exif_tag (const char *uri,
-	      ExifTag     etag)
-{
-	ExifData     *edata;
-	unsigned int  i, j;
-
-	if (uri == NULL)
-		return g_strdup ("-");
-
-	edata = gth_exif_data_new_from_uri (uri);
-	if (edata == NULL) 
-		return g_strdup ("-");
-
-	for (i = 0; i < EXIF_IFD_COUNT; i++) {
-		ExifContent *content = edata->ifd[i];
-
-		if (! edata->ifd[i] || ! edata->ifd[i]->count) 
-			continue;
-
-		for (j = 0; j < content->count; j++) {
-			ExifEntry *e = content->entries[j];
-
-			if (! content->entries[j]) 
-				continue;
-
-			if (e->tag == etag) {
-				const char *value;
-				char *retval = NULL;
-
-				value = get_exif_entry_value (e);
-				if (value != NULL)
-					retval = g_locale_to_utf8 (value, -1, 0, 0, 0);
-				else
-					retval = g_strdup ("-");
-				exif_data_unref (edata);
-
-				return retval;
-			}
-		}
-	}
-
-	exif_data_unref (edata);
-
-	return g_strdup ("-");
-}
-
-
 time_t
 exif_string_to_time_t (char *string) 
 {
@@ -158,82 +178,36 @@
 time_t
 get_metadata_time_from_fd (FileData *fd)
 {
-	int     i;
 	char   *date = NULL;
 	time_t  result = 0;
 
-	for (i = 0; (i < G_N_ELEMENTS (DATE_TAG_NAMES)) && (date == NULL); i++) {			
-		GList *search_result = g_list_find_custom (fd->metadata, DATE_TAG_NAMES[i], (GCompareFunc) metadata_search);
-		if (search_result != NULL) {
-			GthMetadata *md_entry = search_result->data;
-			date = g_strdup (md_entry->value);
-		}
-	}
-		
+	date = get_metadata_string_from_fd (fd, TAG_NAME_SETS[DATE_TAG_NAMES]);
 	if (date != NULL)
 		result = exif_string_to_time_t (date);
-
+	
 	g_free (date);
 	return result;
 }
 
 
 char *
-get_exif_aperture_value (const char *uri)
+get_metadata_string_from_fd (FileData *fd, const char *tagnames[])
 {
-	ExifData     *edata;
-	unsigned int  i, j;
-
-	if (uri == NULL)
-		return g_strdup ("-");
-
-	edata = gth_exif_data_new_from_uri (uri);
-	if (edata == NULL) 
-		return g_strdup ("-");
-
-	for (i = 0; i < EXIF_IFD_COUNT; i++) {
-		ExifContent *content = edata->ifd[i];
-
-		if (! edata->ifd[i] || ! edata->ifd[i]->count) 
-			continue;
-
-		for (j = 0; j < content->count; j++) {
-			ExifEntry   *e = content->entries[j];
-			const char  *value = NULL;
-			char        *retval = NULL;
-
-			if (! content->entries[j]) 
-				continue;
-
-			if ((e->tag != EXIF_TAG_APERTURE_VALUE) &&
-			    (e->tag != EXIF_TAG_FNUMBER))
-				continue;
-
-			value = get_exif_entry_value (e);
-			if (value)
-				retval = g_locale_to_utf8 (value, -1, 0, 0, 0);
-			else
-				retval = g_strdup ("-");
-			exif_data_unref (edata);
+	int     i;
+	char   *string = NULL;
 
-			return retval;
+	for (i = 0; (tagnames[i] != NULL) && (string == NULL); i++) {
+		GList *search_result = g_list_find_custom (fd->metadata, tagnames[i], (GCompareFunc) metadata_search);
+		if (search_result != NULL) {
+			GthMetadata *md_entry = search_result->data;
+			g_free (string);
+			string = g_strdup (md_entry->value);
 		}
 	}
-
-	exif_data_unref (edata);
-
-	return g_strdup ("-");
-}
-
-
-#define VALUE_LEN 1024
-
-
-const char *
-get_exif_entry_value (ExifEntry *entry)
-{
-	char value[VALUE_LEN + 1];
-	return exif_entry_get_value (entry, value, VALUE_LEN);
+		
+	/* Assuming the string will be freed when the caller is
+	 * done with it */
+	return string;
 }
 
 

Modified: trunk/libgthumb/gth-exif-utils.h
==============================================================================
--- trunk/libgthumb/gth-exif-utils.h	(original)
+++ trunk/libgthumb/gth-exif-utils.h	Sat Jan 26 19:08:58 2008
@@ -74,15 +74,29 @@
 } GthMetadata;
 
 
+extern const char **TAG_NAME_SETS[];
+
+enum {
+	DATE_TAG_NAMES,
+	EXPTIME_TAG_NAMES,
+	EXPMODE_TAG_NAMES,
+	ISOSPEED_TAG_NAMES,
+	APERTURE_TAG_NAMES,
+	FOCAL_TAG_NAMES,
+	SHUTTERSPEED_TAG_NAMES,
+	MAKE_TAG_NAMES,
+	MODEL_TAG_NAMES,
+	FLASH_TAG_NAMES
+};
+
+
 ExifData     *gth_exif_data_new_from_uri  (const char   *path);
-char *        get_exif_tag                (const char   *filename,
-				           ExifTag       etag);
 time_t        get_metadata_time_from_fd   (FileData     *fd);
-time_t        get_metadata_time           (const char *mime_type,
-					   const char *uri,
-					   GList *md);
-char *        get_exif_aperture_value     (const char   *filename);
-const char   *get_exif_entry_value        (ExifEntry    *entry);
+time_t        get_metadata_time           (const char   *mime_type,
+					   const char   *uri,
+					   GList        *md);
+char *	      get_metadata_string_from_fd (FileData	*fd,
+					   const char   *tagnames[]);
 void          save_exif_data_to_uri       (const char   *filename,
 				           ExifData     *edata);
 void          copy_exif_data              (const char   *src,

Modified: trunk/src/catalog-web-exporter.c
==============================================================================
--- trunk/src/catalog-web-exporter.c	(original)
+++ trunk/src/catalog-web-exporter.c	Sat Jan 26 19:08:58 2008
@@ -1751,47 +1751,54 @@
 		case GTH_TAG_EXIF_EXPOSURE_TIME:
 			idx = get_image_idx (tag, ce);
 			idata = g_list_nth (ce->file_list, idx)->data;
-			line = get_exif_tag (idata->src_file->path,
-					     EXIF_TAG_EXPOSURE_TIME);
+			file_data_insert_metadata (idata->src_file);
+			line = get_metadata_string_from_fd (idata->src_file, 
+							    TAG_NAME_SETS[EXPTIME_TAG_NAMES]);
 			write_markup_escape_line (line, fout);
 			break;
 
 		case GTH_TAG_EXIF_EXPOSURE_MODE:
 			idx = get_image_idx (tag, ce);
 			idata = g_list_nth (ce->file_list, idx)->data;
-			line = get_exif_tag (idata->src_file->path,
-					     EXIF_TAG_EXPOSURE_MODE);
+			file_data_insert_metadata (idata->src_file);
+			line = get_metadata_string_from_fd (idata->src_file,
+							    TAG_NAME_SETS[EXPMODE_TAG_NAMES]);
 			write_markup_escape_line (line, fout);
 			break;
 
 		case GTH_TAG_EXIF_FLASH:
 			idx = get_image_idx (tag, ce);
 			idata = g_list_nth (ce->file_list, idx)->data;
-			line = get_exif_tag (idata->src_file->path, 
-					     EXIF_TAG_FLASH);
+			file_data_insert_metadata (idata->src_file);
+			line = get_metadata_string_from_fd (idata->src_file,
+					     		    TAG_NAME_SETS[FLASH_TAG_NAMES]);
 			write_markup_escape_line (line, fout);
 			break;
 
 		case GTH_TAG_EXIF_SHUTTER_SPEED:
 			idx = get_image_idx (tag, ce);
 			idata = g_list_nth (ce->file_list, idx)->data;
-			line = get_exif_tag (idata->src_file->path,
-					     EXIF_TAG_SHUTTER_SPEED_VALUE);
+			file_data_insert_metadata (idata->src_file);
+			line = get_metadata_string_from_fd (idata->src_file,
+							    TAG_NAME_SETS[SHUTTERSPEED_TAG_NAMES]);
 			write_markup_escape_line (line, fout);
 			break;
 
 		case GTH_TAG_EXIF_APERTURE_VALUE:
 			idx = get_image_idx (tag, ce);
 			idata = g_list_nth (ce->file_list, idx)->data;
-			line = get_exif_aperture_value (idata->src_file->path);
+			file_data_insert_metadata (idata->src_file);
+			line = get_metadata_string_from_fd (idata->src_file,
+							    TAG_NAME_SETS[APERTURE_TAG_NAMES]); 
 			write_markup_escape_line (line, fout);
 			break;
 
 		case GTH_TAG_EXIF_FOCAL_LENGTH:
 			idx = get_image_idx (tag, ce);
 			idata = g_list_nth (ce->file_list, idx)->data;
-			line = get_exif_tag (idata->src_file->path,
-					     EXIF_TAG_FOCAL_LENGTH);
+			file_data_insert_metadata (idata->src_file);
+			line = get_metadata_string_from_fd (idata->src_file,
+					     		    TAG_NAME_SETS[FOCAL_TAG_NAMES]);
 			write_markup_escape_line (line, fout);
 			break;
 
@@ -1820,15 +1827,16 @@
 		case GTH_TAG_EXIF_CAMERA_MODEL:
 			idx = get_image_idx (tag, ce);
 			idata = g_list_nth (ce->file_list, idx)->data;
-			line = get_exif_tag (idata->src_file->path,
-					     EXIF_TAG_MAKE);
+			file_data_insert_metadata (idata->src_file);
+			line = get_metadata_string_from_fd (idata->src_file,
+							    TAG_NAME_SETS[MAKE_TAG_NAMES]);
 			write_markup_escape_line (line, fout);
 			g_free (line);
 
 			write_line (" &nbsp; ", fout);
 
-			line = get_exif_tag (idata->src_file->path,
-					     EXIF_TAG_MODEL);
+			line = get_metadata_string_from_fd (idata->src_file,
+					    		    TAG_NAME_SETS[MODEL_TAG_NAMES]);
 			write_markup_escape_line (line, fout);
 			break;
 

Modified: trunk/src/gth-fullscreen.c
==============================================================================
--- trunk/src/gth-fullscreen.c	(original)
+++ trunk/src/gth-fullscreen.c	Sat Jan 26 19:08:58 2008
@@ -897,27 +897,28 @@
                 );
 
         /* load exif data */
-        exif_exposure_time   = get_exif_tag (image_filename, EXIF_TAG_EXPOSURE_TIME);
-        exif_ISOSpeed_rating = get_exif_tag (image_filename, EXIF_TAG_ISO_SPEED_RATINGS);
-        exif_aperture_value  = get_exif_aperture_value (image_filename);
-        exif_focal_length    = get_exif_tag (image_filename, EXIF_TAG_FOCAL_LENGTH);
+	exif_exposure_time   = get_metadata_string_from_fd (current_file, TAG_NAME_SETS[EXPTIME_TAG_NAMES]);
+	exif_ISOSpeed_rating = get_metadata_string_from_fd (current_file, TAG_NAME_SETS[ISOSPEED_TAG_NAMES]);
+	exif_aperture_value =  get_metadata_string_from_fd (current_file, TAG_NAME_SETS[APERTURE_TAG_NAMES]);
+	exif_focal_length =    get_metadata_string_from_fd (current_file, TAG_NAME_SETS[FOCAL_TAG_NAMES]);
+
         
         /* build exif info string */
         exif_file_info = g_strdup("\n<small>");
 
-        if (strcmp (exif_exposure_time, "-") != 0) {
+        if (exif_exposure_time != NULL) {
             exif_file_info = str_concat_with_free (exif_file_info, exif_exposure_time);
             has_exif_info = TRUE;
         }
 
-        if (strcmp (exif_aperture_value, "-") != 0) {
+        if (exif_aperture_value != NULL) {
             if (has_exif_info == TRUE)
                 exif_file_info = str_concat_with_free (exif_file_info, ", ");
             exif_file_info = str_concat_with_free (exif_file_info, exif_aperture_value);
             has_exif_info = TRUE;
         }
 
-        if (strcmp (exif_ISOSpeed_rating, "-") != 0) {
+        if (exif_ISOSpeed_rating != NULL) {
             if (has_exif_info == TRUE)
                 exif_file_info = str_concat_with_free (exif_file_info, ", ISO ");
             else
@@ -926,7 +927,7 @@
             has_exif_info = TRUE;
         }
 
-        if (strcmp(exif_focal_length, "-") !=0) {
+        if (exif_focal_length != NULL) {
             if (has_exif_info == TRUE)
                 exif_file_info = str_concat_with_free (exif_file_info,", ");
             exif_file_info = str_concat_with_free (exif_file_info, exif_focal_length);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]