- 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
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)
require 'thread'
require 'gtk2'
-require 'booh/gtkadds'
+require 'booh/libadds'
require 'booh/GtkAutoTable'
require 'gettext'
# 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)
# 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)
=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, '.')
#define _SELF(s) GDK_PIXBUF(RVAL2GOBJ(s))
+#include <libexif/exif-data.h>
+
static VALUE
whitebalance(self, level)
VALUE 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);
}
rescue LoadError
$no_gtk2 = true
end
+begin
+ require 'booh/libadds'
+rescue LoadError
+ $no_libadds = true
+end
module Booh
$verbose_level = 2
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