]> gitweb.factorcode.org Git - factor.git/commitdiff
images.gtk: update to new with-out-parameters, small speedup when loading aligned...
authorPhilipp Brüschweiler <blei42@gmail.com>
Sat, 17 Jul 2010 09:47:31 +0000 (11:47 +0200)
committerPhilipp Brüschweiler <blei42@gmail.com>
Sat, 17 Jul 2010 09:47:31 +0000 (11:47 +0200)
basis/images/gtk/gtk.factor

index 6f6921d21fd115c842f69cafeb0d3de1c245ab21..9b50bf6a62b723ed27747d37f744052e138f4ca9 100644 (file)
@@ -39,27 +39,30 @@ ERROR: g-error domain code message ;
         throw
     ] when* ;
 
-STRUCT: GErrorPointer { to pointer: GError } ;
-
 : GInputStream>GdkPixbuf ( GInputStream -- GdkPixbuf )
-    f GErrorPointer malloc-struct &free
-    [ gdk_pixbuf_new_from_stream ] keep
-    to>> handle-GError &g_object_unref ;
+    f { { pointer: GError initial: f } }
+    [ gdk_pixbuf_new_from_stream ] with-out-parameters
+    handle-GError &g_object_unref ;
 
 : image-data ( GdkPixbuf -- data )
-    [let
-        {
-            [ gdk_pixbuf_get_pixels ]
-            [ gdk_pixbuf_get_width ]
-            [ gdk_pixbuf_get_height ]
-            [ gdk_pixbuf_get_rowstride ]
-            [ gdk_pixbuf_get_n_channels ]
-            [ gdk_pixbuf_get_bits_per_sample ]
-        } cleave :> ( pixels w h rowstride channels bps )
+    {
+        [ gdk_pixbuf_get_pixels ]
+        [ gdk_pixbuf_get_width ]
+        [ gdk_pixbuf_get_height ]
+        [ gdk_pixbuf_get_rowstride ]
+        [ gdk_pixbuf_get_n_channels ]
+        [ gdk_pixbuf_get_bits_per_sample ]
+    } cleave
+    [let :> ( pixels w h rowstride channels bps )
         bps channels * 7 + 8 /i w * :> bytes-per-row
-        pixels rowstride h * <direct-uchar-array>
-        rowstride <sliced-groups>
-        [ bytes-per-row head-slice ] map concat
+
+        bytes-per-row rowstride =
+        [ pixels h rowstride * memory>byte-array ]
+        [
+            pixels rowstride h * <direct-uchar-array>
+            rowstride <sliced-groups>
+            [ bytes-per-row head-slice ] map concat
+        ] if
     ] ;
 
 : component-type ( GdkPixbuf -- component-type )