]> gitweb.factorcode.org Git - factor.git/commitdiff
images: move rowstride to the images vocab because it will be used by
authorBjörn Lindqvist <bjourne@gmail.com>
Tue, 7 Oct 2014 15:33:30 +0000 (17:33 +0200)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 9 Oct 2014 21:37:58 +0000 (14:37 -0700)
gdi too

basis/images/images-docs.factor [new file with mode: 0644]
basis/images/images-tests.factor
basis/images/images.factor
basis/images/loader/gtk/gtk.factor

diff --git a/basis/images/images-docs.factor b/basis/images/images-docs.factor
new file mode 100644 (file)
index 0000000..236c3d9
--- /dev/null
@@ -0,0 +1,6 @@
+USING: help.markup help.syntax math ;
+IN: images
+
+HELP: rowstride
+{ $values { "image" image } { "n" integer } }
+{ $description "Returns an images rowstride metric." } ;
index 1fda9b3b813af067296c52279f3802ef2dd51b21..0c647c62086bb75fbe7e35bba518b5958d190c4d 100644 (file)
@@ -4,26 +4,31 @@ USING: images tools.test kernel accessors ;
 IN: images.tests
 
 [ B{ 57 57 57 255 } ] [ 1 1 T{ image f { 2 3 } RGBA ubyte-components f f B{
-    0 0 0 0 
-    0 0 0 0 
-    0 0 0 0 
+    0 0 0 0
+    0 0 0 0
+    0 0 0 0
     57 57 57 255
-    0 0 0 0 
-    0 0 0 0 
+    0 0 0 0
+    0 0 0 0
 } } pixel-at ] unit-test
 
 [ B{
-    0 0 0 0 
-    0 0 0 0 
-    0 0 0 0 
+    0 0 0 0
+    0 0 0 0
+    0 0 0 0
     57 57 57 255
-    0 0 0 0 
-    0 0 0 0 
+    0 0 0 0
+    0 0 0 0
 } ] [ B{ 57 57 57 255 } 1 1 T{ image f { 2 3 } RGBA ubyte-components f f B{
-    0 0 0 0 
-    0 0 0 0 
-    0 0 0 0 
-    0 0 0 0 
-    0 0 0 0 
-    0 0 0 0 
+    0 0 0 0
+    0 0 0 0
+    0 0 0 0
+    0 0 0 0
+    0 0 0 0
+    0 0 0 0
 } } [ set-pixel-at ] keep bitmap>> ] unit-test
+
+{ 40 30 } [
+    T{ image f { 10 3 } RGBA ubyte-components f f } rowstride
+    T{ image f { 10 3 } RGB ubyte-components f f } rowstride
+] unit-test
index 2d90faf9ada1b754258594d16de28e3e6229c6f1..ae608dd80f78c4786b9f0aff767b9f93cb152829 100644 (file)
@@ -18,7 +18,7 @@ SINGLETONS:
     u-9-9-9-e5-components
     float-11-11-10-components ;
 
-UNION: component-order 
+UNION: component-order
     A L LA BGR RGB BGRA RGBA ABGR ARGB RGBX XRGB BGRX XBGR
     INTENSITY DEPTH DEPTH-STENCIL R RG ;
 
@@ -41,8 +41,8 @@ UNION: unnormalized-integer-components
     int-integer-components uint-integer-components ;
 
 UNION: signed-unnormalized-integer-components
-    byte-integer-components 
-    short-integer-components 
+    byte-integer-components
+    short-integer-components
     int-integer-components ;
 
 UNION: unsigned-unnormalized-integer-components
@@ -131,10 +131,13 @@ TUPLE: image
 
 : bytes-per-pixel ( image -- n )
     [ component-order>> ] [ component-type>> ] bi (bytes-per-pixel) ;
-    
+
 : bytes-per-image ( image -- n )
     [ dim>> product ] [ bytes-per-pixel ] bi * ;
 
+: rowstride ( image -- n )
+    [ dim>> first ] [ bytes-per-pixel ] bi * ;
+
 <PRIVATE
 
 :: pixel@ ( x y w image -- start end bitmap )
@@ -164,4 +167,3 @@ PRIVATE>
 
 : set-pixel-at ( pixel x y image -- )
     [ 1 ] dip set-pixel-row-at ; inline
-
index 80cff3331cff2f297e345fbeea958e34af6445cc..3e020f18751453a55b92f66ebb0ad503a1032ae5 100644 (file)
@@ -60,18 +60,12 @@ CONSTANT: bits>components {
         f >>premultiplied-alpha?
         f >>upside-down? ;
 
-: bits-per-sample ( image -- bits )
-    component-type>> bits>components value-at ;
-
-: rowstride ( image -- rowstride )
-    [ dim>> first ] [ bits-per-sample 8 / ] [ has-alpha? 4 3 ? ] tri * * ;
-
 : image>GdkPixbuf ( image -- GdkPixbuf )
     {
         [ bitmap>> ]
         [ drop GDK_COLORSPACE_RGB ]
         [ has-alpha? ]
-        [ bits-per-sample ]
+        [ bytes-per-component 8 * ]
         [ dim>> first2 ]
         [ rowstride ]
     } cleave f f gdk_pixbuf_new_from_data ;