 CONSTANT: indexed-color 3
 CONSTANT: greyscale-alpha 4
 CONSTANT: truecolor-alpha 6
+
+CONSTANT: interlace-none 0
+CONSTANT: interlace-adam7 1
 
 : <loading-png> ( -- image )
     loading-png new

    lines dup first length 0 <array> prefix
    [ n 1 - 0 <array> prepend ] map
    2 clump [
        n swap first2 [ ] [ n 1 - swap nth ] [ [ 0 n 1 - ] dip set-nth ] tri
        png-unfilter-line
    ] map B{ } concat-as ;

: png-image-bytes ( loading-png -- byte-array )
    [ png-bytes-per-pixel ]
    [ inflate-data ]
    [ png-group-width ] tri group reverse-png-filter ;

: loading-png>image ( loading-png -- image )
    [ image new ] dip {
        [ png-image-bytes >>bitmap ]
        [ [ width>> ] [ height>> ] bi 2array >>dim ]
        [ drop ubyte-components >>component-type ]
    } cleave ;

: decode-greyscale ( loading-png -- image )


: png-bytes-per-pixel ( loading-png -- n )
    dup color-type>> {
        { truecolor [ scale-bit-depth 3 * ] }
        { truecolor-alpha [ scale-bit-depth 4 * ] }
        [ unknown-color-type ]
    } case ; inline

