 
 : read2 ( -- n ) 2 read le> ;
 : read4 ( -- n ) 4 read le> ;
+: write2 ( n -- ) 2 >le write ;
+: write4 ( n -- ) 4 >le write ;
 
 TUPLE: bitmap-image < image ;
 


ERROR: bmp-not-supported n ;

: raw-bitmap>seq ( bitmap -- array )
    dup bit-count>>
    {
        { 32 [ color-index>> ] }
        { 24 [ color-index>> ] }
        { 8 [ 8bit>buffer ] }
        [ bmp-not-supported ]
    } case >byte-array ;

: parse-file-header ( bitmap -- bitmap )
    2 read "BM" assert-sequence=
    read4 >>size
    read4 >>reserved
    read4 >>offset ;

: parse-bitmap-header ( bitmap -- bitmap )
    read4 >>header-length
    read4 >>width
    read4 >>height


M: bitmap-image load-image* ( path loading-bitmap -- bitmap )
    drop loading-bitmap new
    load-bitmap-data
    loading-bitmap>bitmap-image ;

PRIVATE>

