factor/basis/images/bitmap/bitmap.factor

58 lines
1.5 KiB
Factor
Raw Normal View History

! Copyright (C) 2007, 2009 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien alien.c-types arrays byte-arrays columns
2009-06-03 00:29:04 -04:00
combinators compression.run-length endian fry grouping images
images.bitmap.loading images.loader io
io.encodings.string io.files io.streams.limited kernel locals
macros math math.bitwise math.functions namespaces sequences
specialized-arrays.uint specialized-arrays.ushort strings
summary ;
QUALIFIED-WITH: bitstreams b
IN: images.bitmap
: write2 ( n -- ) 2 >le write ;
: write4 ( n -- ) 4 >le write ;
: save-bitmap ( image path -- )
binary [
B{ CHAR: B CHAR: M } write
[
bitmap>> length 14 + 40 + write4
0 write4
54 write4
40 write4
] [
{
2009-03-14 16:08:50 -04:00
! width height
[ dim>> first2 [ write4 ] bi@ ]
2009-03-14 16:08:50 -04:00
! planes
[ drop 1 write2 ]
2009-03-14 16:08:50 -04:00
! bit-count
[ drop 24 write2 ]
2009-03-14 16:08:50 -04:00
! compression
[ drop 0 write4 ]
2009-03-14 16:08:50 -04:00
! image-size
[ bitmap>> length write4 ]
2009-03-14 16:08:50 -04:00
! x-pels
[ drop 0 write4 ]
2009-03-14 16:08:50 -04:00
! y-pels
[ drop 0 write4 ]
2009-03-14 16:08:50 -04:00
! color-used
[ drop 0 write4 ]
2009-03-14 16:08:50 -04:00
! color-important
[ drop 0 write4 ]
2009-03-14 16:08:50 -04:00
2009-06-03 00:20:07 -04:00
! color-palette
[ bitmap>> write ]
} cleave
] bi
] with-file-writer ;