Paste: rotate image
Author: | randy7 |
Mode: | factor |
Date: | Wed, 6 May 2009 20:28:19 |
Plain Text |
USING: images.loader grouping colors images.bitmap sequences accessors kernel math
combinators fry ;
IN: image-rotate
: (rotate-90) ( seq^3 -- seq^3 )
flip [ reverse ] map ;
: (rotate-180) ( seq^3 -- seq^3 )
reverse [ reverse ] map ;
: (rotate-270) ( seq^3 -- seq^3 )
flip reverse ;
: pixel-list ( image length -- seq )
[ bitmap>> ] dip group ;
: image>rows ( image component-length -- rows )
[ pixel-list ]
[ drop dim>> first ] 2bi group ;
: (n-rotate) ( seq n -- image )
360 mod
{
{ 0 [ ] }
{ 90 [ (rotate-90) ] }
{ 180 [ (rotate-180) ] }
{ 270 [ (rotate-270) ] }
[ "unsupported rotation" throw ]
} case ;
: rotate ( image rgba n -- image )
[ dupd length image>rows ] dip (n-rotate)
concat concat >>bitmap ;
: rotate-90 ( image rgba -- image )
90 rotate ;
Author: | randy |
Mode: | factor |
Date: | Wed, 6 May 2009 20:29:43 |
Plain Text |
use like
Author: | r |
Mode: | factor |
Date: | Wed, 6 May 2009 21:14:04 |
Plain Text |
"row length" length 4 mod 4 swap -
New Annotation