             40 write4
         ] [
             {
+                ! width height
                 [ dim>> first2 [ write4 ] bi@ ]
+
+                ! planes
                 [ drop 1 write2 ]
+
+                ! bit-count
                 [ drop 24 write2 ]
+
+                ! compression
                 [ drop 0 write4 ]
+
+                ! size-image
                 [ bitmap>> bitmap>color-index length write4 ]
+
+                ! x-pels
                 [ drop 0 write4 ]
+
+                ! y-pels
                 [ drop 0 write4 ]
+
+                ! color-used
                 [ drop 0 write4 ]
+
+                ! color-important
                 [ drop 0 write4 ]
+
                 ! rgb-quads
                 [ bitmap>> bitmap>color-index write ]
             } cleave

        [ unknown-component-order ]
    } case ;

: fill-image-slots ( bitmap -- bitmap )
    dup {
        [ [ width>> ] [ height>> ] bi 2array >>dim ]
        [ bitmap>component-order >>component-order ]
        [ bitmap>> >>bitmap ]
    } cleave ;

M: bitmap-image load-image* ( path bitmap -- bitmap )
    load-bitmap-data process-bitmap-data
    fill-image-slots ;

MACRO: (nbits>bitmap) ( bits -- )
    [ -3 shift ] keep '[
        bitmap-image new
            2over * _ * >>size-image
            swap >>height
            swap >>width
            swap array-copy [ >>bitmap ] [ >>color-index ] bi
            _ >>bit-count fill-image-slots
            t >>upside-down?
    ] ;

: bgr>bitmap ( array height width -- bitmap )

    dup rgb-quads-length read >>rgb-quads
    dup color-index-length read >>color-index ;

: load-bitmap-data ( path loading-bitmap -- loading-bitmap )
    [ binary ] dip '[
        _ parse-file-header parse-bitmap-header parse-bitmap
    ] with-file-reader ;

ERROR: unknown-component-order bitmap ;

