images: adding an "each-pixel" that iterates over pixels by row.

db4
John Benediktsson 2015-07-14 17:19:04 -07:00
parent f8bf42bce8
commit 04c0fdc39e
1 changed files with 10 additions and 0 deletions

View File

@ -167,3 +167,13 @@ PRIVATE>
: set-pixel-at ( pixel x y image -- ) : set-pixel-at ( pixel x y image -- )
[ 1 ] dip set-pixel-row-at ; inline [ 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