:: png-unfilter-line ( prev curr filter -- curr' ) prev :> c prev 4 tail-slice :> b curr :> a curr 4 tail-slice :> x x length [0,b) filter { { filter-none [ drop ] } { filter-sub [ [| n | n x nth n a nth + 256 wrap n x set-nth ] each ] } { filter-up [ [| n | n x nth n b nth + 256 wrap n x set-nth ] each ] } { filter-average [ [| n | n x nth n a nth n b nth + 2/ + 256 wrap n x set-nth ] each ] } { filter-paeth [ [| n | n x nth n a nth n b nth n c nth paeth + 256 wrap n x set-nth ] each ] } } case curr 4 tail ; : reverse-png-filter ( lines -- byte-array ) dup first length 0 prefix [ { 0 0 0 } prepend ] map 2 clump [ first2 dup [ fourth ] [ 0 swap set-fourth ] bi png-unfilter-line ] map B{ } concat-as ;