drawing video borders in ruby is too slow, do it in extension
authorgc <gc>
Sat, 21 Jul 2007 17:00:55 +0000 (17:00 +0000)
committergc <gc>
Sat, 21 Jul 2007 17:00:55 +0000 (17:00 +0000)
INSTALL
bin/booh-classifier
ext/extconf.rb
ext/rbbooh.c

diff --git a/INSTALL b/INSTALL
index 361c852..ebd874a 100644 (file)
--- a/INSTALL
+++ b/INSTALL
@@ -1,11 +1,12 @@
 This software requires for compiling:
 
 - gtk >= 2.6
+- devel of gtk
 - ruby
 - ruby-gettext >= 0.8.0
 - ruby-gtk2 >= 0.12
 - devel of ruby-gnome2 (mkmf-gnome2.rb, rbgobject.h)
-- libexif
+- devel of libexif
 
     Note: theoretically, gtk and ruby-gtk2 are not needed if
     you're gonna use only the backend script (the only lost
index c7c6efe..5d02353 100644 (file)
@@ -490,13 +490,7 @@ class MainView < Gtk::DrawingArea
         if @pixbuf
             window.draw_pixbuf(nil, @pixbuf, 0, 0, @xpos, @ypos, -1, -1, Gdk::RGB::DITHER_NONE, -1, -1)
             if @entry && @entry.type == 'video'
-                y = @ypos
-                while y < @ypos + @pixbuf.height
-                    render_height = [ @pixbuf.height, @ypos + @pixbuf.height - y ].min
-                    window.draw_pixbuf(nil, $videoborder_pixbuf, 0, 0, @xpos - $videoborder_pixbuf.width, y, -1, render_height, Gdk::RGB::DITHER_NONE, -1, -1)
-                    window.draw_pixbuf(nil, $videoborder_pixbuf, 0, 0, @xpos + @pixbuf.width, y, -1, render_height, Gdk::RGB::DITHER_NONE, -1, -1)
-                    y += $videoborder_pixbuf.height
-                end
+                window.draw_borders($videoborder_pixbuf, @xpos - $videoborder_pixbuf.width, @xpos + @pixbuf.width, @ypos, @ypos + @pixbuf.height)
             end
         end
     end
index 4cfdc37..09c9b51 100644 (file)
@@ -6,7 +6,7 @@ PACKAGE_NAME = "booh/libadds"
 
 #- some adds to Gdk::Pixbuf
 require 'mkmf-gnome2'
-PKGConfig.have_package('gdk-pixbuf-2.0') or exit 1
+PKGConfig.have_package('gtk+-2.0') or exit 1
 have_func("gdk_pixbuf_set_option")
 have_header("gdk-pixbuf/gdk-pixbuf-io.h")
 
index 963a30c..56b101f 100644 (file)
@@ -23,8 +23,7 @@
 #include <math.h>
 
 #define GDK_PIXBUF_ENABLE_BACKEND
-#include <gdk-pixbuf/gdk-pixbuf.h>
-#include <gdk-pixbuf/gdk-pixdata.h>
+#include <gtk/gtk.h>
 #include "rbgobject.h"
 
 #define _SELF(s) GDK_PIXBUF(RVAL2GOBJ(s)) 
@@ -150,6 +149,20 @@ static VALUE exif_datetimeoriginal(VALUE module, VALUE filename) {
         return Qnil;
 }
 
+static VALUE draw_borders(VALUE self, VALUE pixbuf, VALUE x1, VALUE x2, VALUE ystart, VALUE yend) {
+        GdkDrawable* drawable = GDK_DRAWABLE(RVAL2GOBJ(self));
+        int y = NUM2INT(ystart);
+        int yend_ = NUM2INT(yend);
+        GdkPixbuf* pb = GDK_PIXBUF(RVAL2GOBJ(pixbuf));
+        int height = gdk_pixbuf_get_height(pb);
+        while (y < yend_) {
+                int render_height = MIN(height, yend_ - y);
+                gdk_draw_pixbuf(drawable, NULL, pb, 0, 0, NUM2INT(x1), y, -1, render_height, GDK_RGB_DITHER_NONE, -1, -1);
+                gdk_draw_pixbuf(drawable, NULL, pb, 0, 0, NUM2INT(x2), y, -1, render_height, GDK_RGB_DITHER_NONE, -1, -1);
+                y += height;
+        }
+        return self;
+}
 
 
 void 
@@ -159,6 +172,9 @@ Init_libadds()
     rb_define_method(cinfo->klass, "whitebalance!", whitebalance, 1); 
     rb_define_method(cinfo->klass, "gammacorrect!", gammacorrect, 1); 
 
+    cinfo = (RGObjClassInfo*)rbgobj_lookup_class_by_gtype(GDK_TYPE_DRAWABLE, Qnil);
+    rb_define_method(cinfo->klass, "draw_borders", draw_borders, 5);
+
     VALUE exif = rb_define_module("Exif");
     rb_define_module_function(exif, "orientation", exif_orientation, 1);
     rb_define_module_function(exif, "datetimeoriginal", exif_datetimeoriginal, 1);