def jpeg.huff.segment
gralha-jpeg-decode@0.1.0.1 · jpeg.bend:179
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
179def jpeg.huff.segment(+src: Bin.Bytes, +at: U32, +end: U32, +frame: JPEGFrame) -> JPEGFrame:
180 +spec = Bin.bytes.get(src, at)
181 U.branch(JPEGFrame, U32.is_eq(at, end), _ => frame,
182 _ => U.branch(JPEGFrame, Bool.not(jpeg.frame.valid(frame)) || U32.is_gt((at + 17 : U32), end) || U32.is_gt(spec, 19) || U32.is_gt((spec % 16 : U32), 3), _ => jpeg.frame.invalid(frame),
183 _ => jpeg.huff.install(jpeg.huff.lengths(16n, src, U32.inc(at), 1, JPEGCoding{Bin.HuffEmpty{}, 0, (at + 17 : U32), True{}}), frame, spec, end, pos => updated => jpeg.huff.segment(src, pos, end, updated))))