images: extend pixel-at/set-pixel-at with versions that select/replace rows of pixels
parent
36618bc46e
commit
54e0221de5
|
@ -1,6 +1,6 @@
|
||||||
! Copyright (C) 2009 Doug Coleman, Daniel Ehrenberg.
|
! Copyright (C) 2009 Doug Coleman, Daniel Ehrenberg.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: combinators kernel accessors sequences math arrays ;
|
USING: combinators kernel locals accessors sequences math arrays ;
|
||||||
IN: images
|
IN: images
|
||||||
|
|
||||||
SINGLETONS:
|
SINGLETONS:
|
||||||
|
@ -128,18 +128,31 @@ TUPLE: image dim component-order component-type upside-down? bitmap ;
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
: pixel@ ( x y image -- start end bitmap )
|
:: pixel@ ( x y w image -- start end bitmap )
|
||||||
[ dim>> first * + ]
|
image dim>> first y * x + :> start
|
||||||
[ bytes-per-pixel [ * dup ] keep + ]
|
start w [ image bytes-per-pixel * ] bi@ :> ( start' w' )
|
||||||
[ bitmap>> ] tri ;
|
start' start' w' + image bitmap>> ; inline
|
||||||
|
|
||||||
: set-subseq ( new-value from to victim -- )
|
: set-subseq ( new-value from to victim -- )
|
||||||
<slice> 0 swap copy ; inline
|
<slice> 0 swap copy ; inline
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
|
: pixel-row-at ( x y w image -- pixels )
|
||||||
|
pixel@ subseq ; inline
|
||||||
|
|
||||||
|
: pixel-row-slice-at ( x y w image -- pixels )
|
||||||
|
pixel@ <slice> ; inline
|
||||||
|
|
||||||
|
: set-pixel-row-at ( pixel x y w image -- )
|
||||||
|
pixel@ set-subseq ; inline
|
||||||
|
|
||||||
: pixel-at ( x y image -- pixel )
|
: pixel-at ( x y image -- pixel )
|
||||||
pixel@ subseq ;
|
[ 1 ] dip pixel-row-at ; inline
|
||||||
|
|
||||||
|
: pixel-slice-at ( x y image -- pixels )
|
||||||
|
[ 1 ] dip pixel-row-slice-at ; inline
|
||||||
|
|
||||||
: set-pixel-at ( pixel x y image -- )
|
: set-pixel-at ( pixel x y image -- )
|
||||||
pixel@ set-subseq ;
|
[ 1 ] dip set-pixel-row-at ; inline
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue