Jpeg.jpeg.sample: def of gralha-jpeg-decode@0.1.0.1 Import: import gralha-jpeg-decode@0.1.0.1/jpeg.bend as Jpeg Lines 670-688 of gralha-jpeg-decode@0.1.0.1/jpeg.bend: https://jend.leeeet.dev/read.txt?path=gralha-jpeg-decode@0.1.0.1/jpeg.bend&start_line=670&end_line=688 import Base import gralha-text-scan@0.1.0.1/scan.bend as U def jpeg.sample(component: JPEGComponent, +w: U32, +h: U32, +hm: U32, +vm: U32, +x: U32, +y: U32) -> F32: JPEGComponent{id, ch, cv, quant, dc, ac, predictor, bw, bh, coefficients, samples} = component +hh = ch +vv = cv +data = samples +stride = (bw * 8 : U32) +width = jpeg.ceil((w * hh : U32), hm) +height = jpeg.ceil((h * vv : U32), vm) # libjpeg's horizontally doubled narrow planes use box reconstruction. +box = U32.is_eq((hh * 2 : U32), hm) && U32.is_le(width, 2) && (U32.is_eq(vv, vm) || U32.is_eq((vv * 2 : U32), vm)) +px = U.choose(F32, box, U32.to_f32((x * hh / hm : U32)), U.clamp(((U32.to_f32(x) + 0.5) * U32.to_f32(hh) / U32.to_f32(hm) - 0.5 : F32), 0.0, U32.to_f32((width - 1 : U32)))) +py = U.choose(F32, box, U32.to_f32((y * vv / vm : U32)), U.clamp(((U32.to_f32(y) + 0.5) * U32.to_f32(vv) / U32.to_f32(vm) - 0.5 : F32), 0.0, U32.to_f32((height - 1 : U32)))) +x0 = F32.to_u32(F32.floor(px)) +y0 = F32.to_u32(F32.floor(py)) +x1 = U.choose(U32, U32.is_lt(U32.inc(x0), width), U32.inc(x0), x0) +y1 = U.choose(U32, U32.is_lt(U32.inc(y0), height), U32.inc(y0), y0) +fx = (px - U32.to_f32(x0) : F32) +fy = (py - U32.to_f32(y0) : F32) (jpeg.sample.byte(data, stride, x0, y0) * (1.0 - fx) * (1.0 - fy) + jpeg.sample.byte(data, stride, x1, y0) * fx * (1.0 - fy) + jpeg.sample.byte(data, stride, x0, y1) * (1.0 - fx) * fy + jpeg.sample.byte(data, stride, x1, y1) * fx * fy : F32) Uses (23): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Bool.and https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Bool.or https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=F32 https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=F32.add https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=F32.div https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=F32.floor https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=F32.mul https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=F32.sub https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=F32.to_u32 https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32 https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.div https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.inc https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.is_eq https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.is_le https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.is_lt https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.mul https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.sub https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.to_f32 https://jend.leeeet.dev/definition.txt?path=gralha-jpeg-decode@0.1.0.1/jpeg.bend&name=JPEGComponent https://jend.leeeet.dev/definition.txt?path=gralha-jpeg-decode@0.1.0.1/jpeg.bend&name=jpeg.ceil https://jend.leeeet.dev/definition.txt?path=gralha-jpeg-decode@0.1.0.1/jpeg.bend&name=jpeg.sample.byte https://jend.leeeet.dev/definition.txt?path=gralha-text-scan@0.1.0.1/scan.bend&name=choose https://jend.leeeet.dev/definition.txt?path=gralha-text-scan@0.1.0.1/scan.bend&name=clamp