def jpeg.stream.take

gralha-jpeg-decode@0.1.0.1 · jpeg.bend:44

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

44def jpeg.stream.take(+stream: JPEGStream) -> JPEGRead:
45  JPEGStream{data, position, word, count, scan, valid} = stream
46  U.branch(JPEGRead, valid && U32.is_gt(count, 0),
47    _ => JPEGRead{U32.and(U32.shrn(word, U32.to_nat((count - 1 : U32))), 1), JPEGStream{data, position, word, (count - 1 : U32), scan, valid}},
48    _ => JPEGRead{0, jpeg.stream.invalid(stream)})

Uses (11)

Used by (1)