Paste: example of using the images vocabulary
Author: | _phred |
Mode: | factor |
Date: | Mon, 17 Jan 2011 21:10:08 |
Plain Text |
USING: images sequences byte-arrays images.viewer ;
<image>
16 16 2array >>dim
ubyte-components >>component-type
RGB >>component-order
16 16 3 * * iota >byte-array
dup image-window
Author: | otoburb |
Mode: | factor |
Date: | Mon, 17 Jan 2011 22:23:43 |
Plain Text |
USING: io.pathnames sequences locals kernel prettyprint accessors math math.functions io.encodings.binary io.files images images.bitmap images.loader ;
IN: bitmaps
: image-directory ( -- string )
home "/Downloads/factor/work/bitmaps/" append ;
:: image-file ( filename -- filename-path )
image-directory filename append ;
:: (bottom-bitmap) ( image -- image' )
image [ dup 1 swap [ 2 / round ] change-nth ] change-dim
dup dim>> dup first [ 3 * ] [ 4 mod ] bi + swap 1 swap ?nth * :> top-length
[ top-length head ] change-bitmap ;
:: (top-bitmap) ( image -- image' )
image [ dup 1 swap [ 2 / floor ] change-nth ] change-dim
dup dim>> dup first [ 3 * ] [ 4 mod ] bi + swap 1 swap ?nth * :> bottom-length
[ dup length bottom-length - tail ] change-bitmap ;
: (write-bitmap) ( image filename -- )
image-file binary [ output-bmp ] with-file-writer ;
: (clone-image) ( image -- image image' )
dup clone [ clone ] change-bitmap [ clone ] change-dim ;
: image-resize50%h ( image -- )
(clone-image)
(top-bitmap) "out1.bmp" (write-bitmap)
(bottom-bitmap) "out2.bmp" (write-bitmap) ;
: resize50% ( bitmap-filename -- )
image-file load-image image-resize50%h ;
New Annotation