 
 ERROR: unknown-color-type n ;
 ERROR: unimplemented-color-type image ;
+ERROR: unknown-filter-method image ;
 
 : inflate-data ( loading-png -- bytes )
     find-compressed-bytes zlib-inflate ; 


: decode-png ( loading-png -- loading-png ) 
    dup color-type>> {
        { 0 [ validate-greyscale decode-greyscale ] }
        { 2 [ validate-truecolor decode-truecolor ] }
        { 3 [ validate-indexed-color decode-indexed-color ] }
        { 4 [ validate-greyscale-alpha decode-greyscale-alpha ] }
        { 6 [ validate-truecolor-alpha decode-truecolor-alpha ] }
        [ unknown-color-type ]
    } case ;


        [ unknown-color-type ]
    } case ;

: filter-png ( groups loading-png -- byte-array )
    filter-method>> {
        { filter-none [ reverse-png-filter ] }
        [ unknown-filter-method ]
    } case ;

: png-image-bytes ( loading-png -- byte-array )
    [ [ inflate-data ] [ png-group-width ] bi group ]
    [ filter-png ] bi ;

: decode-greyscale ( loading-png -- loading-png )
    unimplemented-color-type ;
