def jpeg.progressive.first.symbol

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

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

277def jpeg.progressive.first.symbol(read: JPEGRead, +index: U32, +end: U32, +offset: U32, +low: U32, +coefficients: Bin.Bytes, +predictor: U32) -> JPEGRefined:
278  JPEGRead{symbol, stream} = read
279  +rs = symbol
280  +input = stream
281  +run = (rs / 16 : U32)
282  +count = (rs % 16 : U32)
283  +eob = U32.is_eq(count, 0) && U32.is_lt(run, 15)
284  +zero = U32.is_eq(rs, 240)
285  +pos = (index + run : U32)
286  +ok = jpeg.stream.valid(input) && (eob || (zero && U32.is_le(pos, end)) || (U32.is_gt(count, 0) && U32.is_le(count, 10) && U32.is_le(pos, end)))
287  JPEGRefined{U.choose(U32, eob || Bool.not(ok), U32.inc(end), U32.inc(pos)),
288    U.branch(JPEGBlock, Bool.not(ok), _ => JPEGBlock{jpeg.stream.invalid(input), coefficients, predictor},
289      _ => U.branch(JPEGBlock, eob, _ => jpeg.progressive.eob(jpeg.bits(input, run), run, coefficients, predictor, 1),
290        _ => U.branch(JPEGBlock, zero, _ => JPEGBlock{input, coefficients, predictor}, _ => jpeg.progressive.ac.bits(jpeg.bits(input, count), count, coefficients, predictor, offset, pos, low))))}

Uses (23)

Used by (1)