use libexif for getting the EXIF orientation tag, it is so much faster than identify...
authorgc <gc>
Sat, 16 Jun 2007 17:48:51 +0000 (17:48 +0000)
committergc <gc>
Sat, 16 Jun 2007 17:48:51 +0000 (17:48 +0000)
INSTALL
bin/booh
bin/booh-fix-whitebalance
bin/booh-gamma-correction
ext/extconf.rb
ext/rbbooh.c
lib/booh/booh-lib.rb

diff --git a/INSTALL b/INSTALL
index e02958fc3086f7945d3ea31db9b929fce1ae04bd..56c28ed320569c07bbdd48fbc0b58f9cab58b986 100644 (file)
--- a/INSTALL
+++ b/INSTALL
@@ -5,6 +5,7 @@ This software requires for compiling:
 - ruby-gettext >= 0.8.0
 - ruby-gtk2 >= 0.12
 - devel of ruby-gnome2 (mkmf-gnome2.rb, rbgobject.h)
+- libexif
 
     Note: theoretically, gtk and ruby-gtk2 are not needed if
     you're gonna use only the backend script (the only lost
@@ -18,7 +19,6 @@ And for runtime:
 
 For runtime, not strictly needed but nice to have:
 
-- identify (from ImageMagick)
 - transcode and mencoder (not strictly needed if you won't manipulate any video)
 
 
index e93253006f205a7dd9ef2eedde496686158f42d7..fe733775dae6ce44a9e42eb563e9ddd34c30fb0a 100755 (executable)
--- a/bin/booh
+++ b/bin/booh
@@ -24,7 +24,7 @@ require 'tempfile'
 require 'thread'
 
 require 'gtk2'
-require 'booh/gtkadds'
+require 'booh/libadds'
 require 'booh/GtkAutoTable'
 
 require 'gettext'
index 1e7b66f1321808c69a7ca393672f6bd235e16aac..2cd9af9fb2d898c84381dc9dd4eadddb1f146569 100644 (file)
@@ -20,7 +20,7 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
 require 'gtk2'
-require 'booh/gtkadds'
+require 'booh/libadds'
 
 if ARGV.size != 3
     puts "Usage: %s orig_file dest_file_jpeg level" % File.basename($0)
index 531d2479d336992c9a7cf6cb26cdbc82d3bf5e6a..d9428a46c652113f4c0e90788024df62b815d759 100755 (executable)
@@ -20,7 +20,7 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
 require 'gtk2'
-require 'booh/gtkadds'
+require 'booh/libadds'
 
 if ARGV.size != 3
     puts "Usage: %s orig_file dest_file_jpeg level" % File.basename($0)
index 9463aa244cbef7848bc585daed86b7cb6dc63aa0..4cfdc37d41df06791c282811a431c03a2ebfbcdf 100644 (file)
@@ -1,16 +1,19 @@
 =begin
-extconf.rb for booh additions to Ruby/GdkPixbuf
+extconf.rb for booh lib additions
 =end
 
-PACKAGE_NAME = "booh/gtkadds"
+PACKAGE_NAME = "booh/libadds"
 
+#- some adds to Gdk::Pixbuf
 require 'mkmf-gnome2'
-
 PKGConfig.have_package('gdk-pixbuf-2.0') or exit 1
-
-setup_win32(PACKAGE_NAME)
-
 have_func("gdk_pixbuf_set_option")
 have_header("gdk-pixbuf/gdk-pixbuf-io.h")
 
+#- directo libexif access for image orientation
+PKGConfig.have_package('libexif') or exit 1
+
+#- does it do something good, actually?
+setup_win32(PACKAGE_NAME)
+
 create_makefile_at_srcdir(PACKAGE_NAME, '.')
index 2d886888f2ab7b1449518472414486c5afe09b4c..9f76c1c81787105562dc0a03049644ae62a14314 100644 (file)
@@ -29,6 +29,8 @@
 
 #define _SELF(s) GDK_PIXBUF(RVAL2GOBJ(s)) 
 
+#include <libexif/exif-data.h>
+
 static VALUE
 whitebalance(self, level)
     VALUE self, level; 
@@ -89,10 +91,43 @@ gammacorrect(self, level)
         return self;
 }
 
+static VALUE exif_orientation(VALUE module, VALUE filename) {
+        VALUE ret = Qnil;
+        ExifData* data;
+        unsigned int i;
+
+        data = exif_data_new_from_file(StringValuePtr(filename));
+        if (data == NULL) {
+                fprintf(stderr, "libexif failed loading file '%s'\n", StringValuePtr(filename));
+                return Qnil;
+        }
+
+       for (i = 0; i < EXIF_IFD_COUNT; i++) {
+                ExifEntry* entry = exif_content_get_entry(data->ifd[i], EXIF_TAG_ORIENTATION);
+               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;
+                }
+       }
+
+        exif_data_free(data);
+        return ret;
+}
+
+
 void 
-Init_gtkadds()
+Init_libadds()
 {
     RGObjClassInfo* cinfo = (RGObjClassInfo*)rbgobj_lookup_class_by_gtype(GDK_TYPE_PIXBUF, Qnil);
     rb_define_method(cinfo->klass, "whitebalance!", whitebalance, 1); 
     rb_define_method(cinfo->klass, "gammacorrect!", gammacorrect, 1); 
+
+    VALUE exif = rb_define_module("Exif");
+    rb_define_module_function(exif, "orientation", exif_orientation, 1);
 }
index b659d63573ea1297e5007296dcf83336d51e9ea3..77e2c6652eab600c2932fd98122d75f1657f0c19 100644 (file)
@@ -33,6 +33,11 @@ begin
 rescue LoadError
     $no_gtk2 = true
 end
+begin
+    require 'booh/libadds'
+rescue LoadError
+    $no_libadds = true
+end
 
 module Booh
     $verbose_level = 2
@@ -249,14 +254,19 @@ module Booh
     end
 
     def guess_rotate(filename)
-        if $no_identify
-            return 0
+        #- identify is slow, try with libexif if available (4ms vs 35ms)
+        if $no_libadds
+            if $no_identify
+                return 0
+            end
+            orientation = `identify -format "%[EXIF:orientation]" '#{filename}'`.chomp.to_i
+        else
+            orientation = Exif.orientation(filename)
         end
 
-        orientation = `identify -format "%[EXIF:orientation]" '#{filename}'`.chomp
-        if orientation == '6'
+        if orientation == 6
             angle = 90
-        elsif orientation == '8'
+        elsif orientation == 8
             angle = -90
         else
             return 0