USING: io.pathnames sequences locals kernel prettyprint accessors math math.functions io.encodings.binary io.files images images.bitmap images.loader ; IN: bitmaps ! Set the working directory : 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 ; ! two separate image tuples on the stack ! Horizontal (row) 50% split : image-resize50%h ( image -- ) (clone-image) (top-bitmap) "out1.bmp" (write-bitmap) ! write the top half (bottom-bitmap) "out2.bmp" (write-bitmap) ; ! write the bottom half : resize50% ( bitmap-filename -- ) image-file load-image image-resize50%h ;