also use libexif for sorting a directory according to EXIF date, makes operation...
authorgc <gc>
Sun, 17 Jun 2007 17:34:11 +0000 (17:34 +0000)
committergc <gc>
Sun, 17 Jun 2007 17:34:11 +0000 (17:34 +0000)
bin/booh
ext/rbbooh.c

index 2ce0159..c9ac026 100755 (executable)
--- a/bin/booh
+++ b/bin/booh
@@ -2155,8 +2155,8 @@ def sort_by_exif_date
             pb.text = f
             pb.fraction = i.to_f / current_order.size
             Gtk.main_iteration while Gtk.events_pending?
             pb.text = f
             pb.fraction = i.to_f / current_order.size
             Gtk.main_iteration while Gtk.events_pending?
-            date_time = `identify -format "%[EXIF:DateTimeOriginal]" '#{from_utf8($current_path + "/" + f)}'`.chomp
-            if $? == 0 && date_time != ''
+            date_time = Exif.datetimeoriginal(from_utf8($current_path + "/" + f))
+            if ! date_time.nil?
                 dates[f] = date_time
             end
         end
                 dates[f] = date_time
             end
         end
index 9f76c1c..d9bc20b 100644 (file)
@@ -91,36 +91,68 @@ gammacorrect(self, level)
         return self;
 }
 
         return self;
 }
 
-static VALUE exif_orientation(VALUE module, VALUE filename) {
-        VALUE ret = Qnil;
-        ExifData* data;
+static ExifEntry* exif_entry(VALUE filename, ExifTag tag, ExifData** data) {
         unsigned int i;
 
         unsigned int i;
 
-        data = exif_data_new_from_file(StringValuePtr(filename));
-        if (data == NULL) {
+        *data = exif_data_new_from_file(StringValuePtr(filename));
+        if (*data == NULL) {
                 fprintf(stderr, "libexif failed loading file '%s'\n", StringValuePtr(filename));
                 fprintf(stderr, "libexif failed loading file '%s'\n", StringValuePtr(filename));
-                return Qnil;
+                return NULL;
         }
 
        for (i = 0; i < EXIF_IFD_COUNT; i++) {
         }
 
        for (i = 0; i < EXIF_IFD_COUNT; i++) {
-                ExifEntry* entry = exif_content_get_entry(data->ifd[i], EXIF_TAG_ORIENTATION);
+                ExifEntry* entry = exif_content_get_entry((*data)->ifd[i], tag);
                if (entry) {
                if (entry) {
-                        ExifByteOrder o;
-                        ExifShort v_short;
-                        if (!entry || !entry->parent || !entry->parent->parent)
-                                break;
-                        o = exif_data_get_byte_order(entry->parent->parent);
-                        v_short = exif_get_short(entry->data, o);
-                        ret = INT2NUM(v_short);
-                        break;
+                        return entry;
                 }
                 }
+        }
+
+        return NULL;
+}
+
+static VALUE exif_orientation(VALUE module, VALUE filename) {
+        ExifData* data = NULL;
+        ExifEntry* entry;
+
+        entry = exif_entry(filename, EXIF_TAG_ORIENTATION, &data);
+
+        if (entry != NULL) {
+                VALUE ret;
+                ExifByteOrder o;
+                ExifShort v_short;
+                if (!entry || !entry->parent || !entry->parent->parent)
+                        return Qnil;
+                o = exif_data_get_byte_order(entry->parent->parent);
+                v_short = exif_get_short(entry->data, o);
+                ret = INT2NUM(v_short);
+                exif_data_free(data);
+                return ret;
        }
        }
+        
+        if (data)
+                exif_data_free(data);
+        return Qnil;
+}
+
+static VALUE exif_datetimeoriginal(VALUE module, VALUE filename) {
+        ExifData* data = NULL;
+        ExifEntry* entry;
+
+        entry = exif_entry(filename, EXIF_TAG_DATE_TIME_ORIGINAL, &data);
 
 
-        exif_data_free(data);
-        return ret;
+        if (entry != NULL) {
+                VALUE ret = rb_str_new((const char*) entry->data, entry->size);
+                exif_data_free(data);
+                return ret;
+       }
+
+        if (data)
+                exif_data_free(data);
+        return Qnil;
 }
 
 
 }
 
 
+
 void 
 Init_libadds()
 {
 void 
 Init_libadds()
 {
@@ -130,4 +162,5 @@ Init_libadds()
 
     VALUE exif = rb_define_module("Exif");
     rb_define_module_function(exif, "orientation", exif_orientation, 1);
 
     VALUE exif = rb_define_module("Exif");
     rb_define_module_function(exif, "orientation", exif_orientation, 1);
+    rb_define_module_function(exif, "datetimeoriginal", exif_datetimeoriginal, 1);
 }
 }