factor/basis/images/bitmap/bitmap.factor

59 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
2009-06-11 15:35:55 -04:00
images.bitmap.loading images.loader io io.binary
io.encodings.binary io.encodings.string io.files
io.streams.limited kernel locals macros math math.bitwise
math.functions namespaces sequences specialized-arrays
strings summary ;
SPECIALIZED-ARRAY: uint
SPECIALIZED-ARRAY: ushort
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 ;