 
 : load-bitmap ( path -- bitmap )
     normalize-path binary [
-        T{ bitmap } clone
-        dup parse-file-header
-        dup parse-bitmap-header
-        dup parse-bitmap
+        bitmap new
+            dup parse-file-header
+            dup parse-bitmap-header
+            dup parse-bitmap
     ] with-file-reader
-    dup color-index>> over bit-count>>
-    raw-bitmap>string >byte-array >>array ;
+    dup raw-bitmap>array >>array ;
 
 : save-bitmap ( bitmap path -- )
     binary [

        bit-count>> {
            ! { 32 [ GL_BGRA GL_UNSIGNED_INT_8_8_8_8 ] } ! broken
            { 24 [ GL_BGR GL_UNSIGNED_BYTE ] }
        } case
    ] keep array>> glDrawPixels ;


        swap [ >>array ] [ >>color-index ] bi
        24 >>bit-count ;

: 8bit>array ( bitmap -- array )
    [ rgb-quads>> 4 <sliced-groups> [ 3 head-slice ] map ]
    [ color-index>> >array ] bi [ swap nth ] with map concat ;

: 4bit>array ( bitmap -- array )
    [ rgb-quads>> 4 <sliced-groups> [ 3 head-slice ] map ]
    [ color-index>> >array ] bi [ swap nth ] with map concat ;

: raw-bitmap>array ( bitmap -- array )
    dup bit-count>>
    {
        { 32 [ "32bit" throw ] }
        { 24 [ color-index>> ] }
        { 16 [ "16bit" throw ] }
        { 8 [ 8bit>array ] }
        { 4 [ 4bit>array ] }
        { 2 [ "2bit" throw ] }
        { 1 [ "1bit" throw ] }
    } case >byte-array ;

ERROR: bitmap-magic ;

