drawing video borders in ruby is too slow, do it in extension
[booh] / ext / rbbooh.c
index 963a30c53813d5fd50cdfe2e6f22ea3b923d797d..56b101f0dfd3d4b09e119d342f529609b5467023 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);