From 03ee4c04cb04bca07bb31a67c039eaa140026f88 Mon Sep 17 00:00:00 2001 From: Muaz Ahmad Date: Tue, 28 Nov 2023 15:03:58 +0500 Subject: [PATCH] DCT computation --- src/transform.zig | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/transform.zig b/src/transform.zig index 113fd0a..8d85a9c 100644 --- a/src/transform.zig +++ b/src/transform.zig @@ -55,10 +55,20 @@ fn gen_coeffs() [8][8]@Vector(64, f16) { } pub fn quantize(source: *util.Block, target: *util.BlockQuantized, qtable: *util.QTable) void { - _ = qtable; - _ = target; - var holder: @Vector(64, f16) = undefined; + var source_holder: @Vector(64, f16) = undefined; + var dct_holder: @Vector(64, f16) = undefined; for (0..64) |i| { - holder[i] = @floatFromInt(source[i]); + source_holder[i] = @floatFromInt(source[i]); + } + const level_shift: @Vector(64, f16) = @splat(128.0); + const source_shifted = source_holder - level_shift; + for (0..8) |u| { + for (0..8) |v| { + dct_holder[u * 8 + v] = @reduce(.Add, dct_coeffs[u][v] * source_shifted); + } + } + const quantized = @round(dct_holder / qtable.*); + for (0..64) |i| { + target[i] = @intFromFloat(quantized[i]); } }