2009-05-14 16:46:10 -04:00
|
|
|
! Copyright (C) 2009 Marc Fauconneau.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
|
|
|
USING: accessors arrays byte-arrays combinators grouping images
|
2009-05-15 00:33:00 -04:00
|
|
|
kernel locals math math.order
|
2009-05-14 16:46:10 -04:00
|
|
|
math.ranges math.vectors sequences sequences.deep fry ;
|
|
|
|
IN: images.processing
|
|
|
|
|
|
|
|
: coord-matrix ( dim -- m )
|
2010-02-25 02:54:41 -05:00
|
|
|
[ iota ] map first2 cartesian-product ;
|
2009-05-14 16:46:10 -04:00
|
|
|
|
|
|
|
: map^2 ( m quot -- m' ) '[ _ map ] map ; inline
|
|
|
|
: each^2 ( m quot -- m' ) '[ _ each ] each ; inline
|
|
|
|
|
|
|
|
: matrix-dim ( m -- dim ) [ length ] [ first length ] bi 2array ;
|
|
|
|
|
|
|
|
: matrix>image ( m -- image )
|
|
|
|
<image> over matrix-dim >>dim
|
|
|
|
swap flip flatten
|
2010-01-14 12:18:10 -05:00
|
|
|
[ 128 * 128 + 0 255 clamp >fixnum ] map
|
2009-06-22 12:20:54 -04:00
|
|
|
>byte-array >>bitmap L >>component-order ubyte-components >>component-type ;
|
2009-05-14 16:46:10 -04:00
|
|
|
|
|
|
|
:: matrix-zoom ( m f -- m' )
|
|
|
|
m matrix-dim f v*n coord-matrix
|
|
|
|
[ [ f /i ] map first2 swap m nth nth ] map^2 ;
|
|
|
|
|
|
|
|
:: image-offset ( x,y image -- xy )
|
|
|
|
image dim>> first
|
|
|
|
x,y second * x,y first + ;
|
|
|
|
|
|
|
|
:: draw-grey ( value x,y image -- )
|
|
|
|
x,y image image-offset 3 * { 0 1 2 }
|
|
|
|
[
|
2010-01-14 12:18:10 -05:00
|
|
|
+ value 128 + >fixnum 0 255 clamp swap image bitmap>> set-nth
|
2009-05-14 16:46:10 -04:00
|
|
|
] with each ;
|
|
|
|
|
|
|
|
:: draw-color ( value x,y color-id image -- )
|
|
|
|
x,y image image-offset 3 * color-id + value >fixnum
|
|
|
|
swap image bitmap>> set-nth ;
|
|
|
|
|
|
|
|
! : matrix. ( m -- ) 10 matrix-zoom matrix>image image. ;
|