def jpeg.idct.basis

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

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

617# Separable, normalized 8x8 inverse DCT. Coefficients remain quantized until
618# every sequential scan has been decoded; each component has a padded plane.
619def jpeg.idct.basis(+x: U32, +u: U32) -> F32:
620  +k = ((2 * x + 1) * u % 32 : U32)
621  +fold = U.choose(U32, U32.is_gt(k, 16), (32 - k : U32), k)
622  +negative = U32.is_gt(fold, 8)
623  +i = U.choose(U32, negative, (16 - fold : U32), fold)
624  +cosine = U.nth(Con{1.0, Con{0.9807852804032304, Con{0.9238795325112867, Con{0.8314696123025452, Con{0.7071067811865476, Con{0.5555702330196023, Con{0.3826834323650898, Con{0.1950903220161283, Con{0.0, Nil{}}}}}}}}}}, U32.to_nat(i), 0.0)
625  (0.5 * U.choose(F32, U32.is_eq(u, 0), 0.7071067811865476, 1.0) * U.choose(F32, negative, F32.neg(cosine), cosine) : F32)

Uses (14)

Used by (2)