! Copyright (c) 2012 Anonymous
! See http://factorcode.org/license.txt for BSD license.
-USING: arrays fry kernel math.matrices sequences ;
+USING: arrays kernel math.matrices sequences ;
IN: rosetta-code.bitmap
! http://rosettacode.org/wiki/Basic_bitmap_storage
! Various utilities
: meach ( matrix quot -- ) [ each ] curry each ; inline
-: meach-index ( matrix quot -- )
+: meach-index ( matrix quot -- )
[ swap 2array ] prepose
[ curry each-index ] curry each-index ; inline
: mmap ( matrix quot -- matrix' ) [ map ] curry map ; inline
: mmap! ( matrix quot -- matrix' ) [ map! ] curry map! ; inline
-: mmap-index ( matrix quot -- matrix' )
+: mmap-index ( matrix quot -- matrix' )
[ swap 2array ] prepose
[ curry map-index ] curry map-index ; inline
: Mi,j ( {i,j} matrix -- elt ) [ first2 swap ] dip nth nth ;
! The storage functions
-: <raster-image> ( width height -- image )
- zero-matrix [ drop { 0 0 0 } ] mmap ;
-: fill-image ( {R,G,B} image -- image )
+: <raster-image> ( width height -- image )
+ <zero-matrix> [ drop { 0 0 0 } ] mmap ;
+: fill-image ( {R,G,B} image -- image )
swap '[ drop _ ] mmap! ;
: set-pixel ( {R,G,B} {i,j} image -- ) set-Mi,j ; inline
: get-pixel ( {i,j} image -- pixel ) Mi,j ; inline