DCT computation

This commit is contained in:
Muaz Ahmad 2023-11-28 15:03:58 +05:00
parent 221519c705
commit 03ee4c04cb

View file

@ -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 { pub fn quantize(source: *util.Block, target: *util.BlockQuantized, qtable: *util.QTable) void {
_ = qtable; var source_holder: @Vector(64, f16) = undefined;
_ = target; var dct_holder: @Vector(64, f16) = undefined;
var holder: @Vector(64, f16) = undefined;
for (0..64) |i| { 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]);
} }
} }