]> gitweb.factorcode.org Git - factor.git/commitdiff
images: adding an "each-pixel" that iterates over pixels by row.
authorJohn Benediktsson <mrjbq7@gmail.com>
Wed, 15 Jul 2015 00:19:04 +0000 (17:19 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Wed, 15 Jul 2015 00:19:04 +0000 (17:19 -0700)
basis/images/images.factor

index 359a19cae979d46e83ab055fc0d7612b4c8b64d9..a8439e5113aca3eb251c8bac17b221395fc9ed47 100644 (file)
@@ -167,3 +167,13 @@ PRIVATE>
 
 : set-pixel-at ( pixel x y image -- )
     [ 1 ] dip set-pixel-row-at ; inline
+
+:: each-pixel ( ... image quot: ( ... x y pixel -- ... ) -- ... )
+    image dim>> first2 :> ( width height )
+    image bytes-per-pixel :> n
+    height width [ iota ] bi@ [| y x |
+        y width * x + :> start
+        start n * :> from
+        from n + :> to
+        x y from to image bitmap>> <slice> quot call
+    ] cartesian-each ; inline