 
 : read-graphic-control-extension ( -- graphic-control-extension )
     \ graphics-control-extension new
-        1 read le> [ >>block-size ] [ read ] bi
-        >>raw-data
-        1 read le> >>block-terminator ;
+        1 read le> graphic-control-extension-block-size assert=
+        1 read le> >>flags
+        2 read le> >>delay-time
+        1 read le> >>transparent-color-index
+        1 read le> block-terminator assert= ;
 
 : read-plain-text-extension ( -- plain-text-extension )
     \ plain-text-extension new

    [ compressed-bytes>> ] bi
    lzw-uncompress ;

: apply-palette ( indexes palette -- bitmap )
    [ nth 255 suffix ] curry V{ } map-as concat ;

: dimensions ( loading-gif -- dim )
    [ image-descriptor>> width>> ] [ image-descriptor>> height>> ] bi 2array ;

: loading-gif>image ( loading-gif -- image )
    [ <image> ] dip
    [ dimensions >>dim ]
    [ drop RGBA >>component-order ubyte-components >>component-type ]
    [
        [ decompress ] [ global-color-table>> ] bi
        apply-palette >>bitmap
    ] tri ;


CONSTANT: comment-extension HEX: fe
CONSTANT: application-extension HEX: ff
CONSTANT: trailer HEX: 3b
CONSTANT: graphic-control-extension-block-size HEX: 04
CONSTANT: block-terminator HEX: 00

: <loading-gif> ( -- loading-gif )
    \ loading-gif new
