zigzag order fix

This commit is contained in:
Muaz Ahmad 2023-12-11 16:26:32 +05:00
parent eeb67c3b79
commit a4c4b1fdcf

View file

@ -16,16 +16,15 @@ inline fn dct_coeff(u: usize, v: usize) f16 {
inline fn zz_conv(u: usize, v: usize) struct { u: usize, v: usize } { inline fn zz_conv(u: usize, v: usize) struct { u: usize, v: usize } {
var band_i = u + v; var band_i = u + v;
const band_max_u = @min(7, band_i); const band_max = @min(7, band_i);
const band_max_v = @min(7, band_i);
var idx: usize = 0; var idx: usize = 0;
for (0..band_i) |i| { for (0..band_i) |i| {
idx += zz_band_len(i); idx += zz_band_len(i);
} }
if (band_i % 2 == 0) { if (band_i % 2 == 0) {
idx += band_max_v - v; idx += band_max - v;
} else { } else {
idx += band_max_u - u; idx += band_max - u;
} }
return .{ return .{
.u = idx / 8, .u = idx / 8,
@ -45,7 +44,7 @@ fn gen_coeffs() [8][8]@Vector(64, f16) {
const zz_idx = zz_conv(u, v); const zz_idx = zz_conv(u, v);
for (0..8) |x| { for (0..8) |x| {
for (0..8) |y| { for (0..8) |y| {
ret[zz_idx.u][zz_idx.v][x * 8 + y] = dct_coeff(zz_idx.u, zz_idx.v) * dct_cos(x, zz_idx.u) * dct_cos(y, zz_idx.v); ret[zz_idx.u][zz_idx.v][y * 8 + x] = dct_coeff(u, v) * dct_cos(x, u) * dct_cos(y, v);
} }
} }
} }