def jpeg.stream.fill
gralha-jpeg-decode@0.1.0.1 · jpeg.bend:36
import gralha-jpeg-decode@0.1.0.1/jpeg.bend as Jpeg
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
36def jpeg.stream.fill(+stream: JPEGStream) -> JPEGStream:
37 JPEGStream{data, position, word, count, scan, valid} = stream
38 +v = Bin.bytes.get(data, position)
39 +escaped = U32.is_eq(v, 255)
40 +next = (position + U.choose(U32, escaped, 2, 1) : U32)
41 U.branch(JPEGStream, U32.is_gt(count, 0), _ => stream,
42 _ => JPEGStream{data, next, v, 8, scan, valid && U32.is_le(next, Bin.bytes.size(data)) && (Bool.not(escaped) || U32.is_eq(Bin.bytes.get(data, U32.inc(position)), 0))})