def jpeg.quant.segment
gralha-jpeg-decode@0.1.0.1 · jpeg.bend:142
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
142def jpeg.quant.segment(+src: Bin.Bytes, +at: U32, +end: U32, +frame: JPEGFrame) -> JPEGFrame:
143 JPEGFrame{w, h, hm, vm, progressive, components, quants, huffs, restart, adobe, valid} = frame
144 +pq = Bin.bytes.get(src, at)
145 +stride = U32.inc((pq / 16 : U32))
146 +next = (at + 1 + 64 * stride : U32)
147 U.branch(JPEGFrame, U32.is_eq(at, end), _ => frame,
148 _ => U.branch(JPEGFrame, U32.is_gt(at, end) || U32.is_gt(pq, 19) || U32.is_gt((pq % 16 : U32), 3) || U32.is_gt(next, end), _ => jpeg.frame.invalid(frame),
149 _ => jpeg.quant.segment(src, next, end, JPEGFrame{w, h, hm, vm, progressive, components, Con{JPEGQuant{(pq % 16 : U32), jpeg.quant.read(64n, src, U32.inc(at), stride, 0, Bin.bytes.zero(64))}, quants}, huffs, restart, adobe, valid})))