def png.unfilter
gralha-png-decode@0.1.0.1 · png.bend:80
import gralha-png-decode@0.1.0.1/png.bend as Png
import Base
import gralha-text-scan@0.1.0.1/scan.bend as U
import gralha-bytes@0.1.0.1/bytes.bend as Bin
80def png.unfilter(n: Nat, +raw: Bin.Bytes, +at: U32, +stride: U32, +bpp: U32, +out: Bin.Bytes) -> Maybe<&2, Bin.Bytes>:
81 match n:
82 case 0n: Some{out}
83 case 1n+d:
84 +kind = Bin.bytes.get(raw, at)
85 U.branch(Maybe<&2, Bin.Bytes>, U32.is_le(kind, 4), _ => png.unfilter(d, raw, (at + stride + 1 : U32), stride, bpp, png.unfilter.row(U32.to_nat(stride), raw, U32.inc(at), 0, stride, bpp, kind, out)), _ => None{})