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]); } }