diff --git a/gen/k_means/python/decode_pvrt.py b/gen/k_means/python/decode_pvrt.py index d28b78b..877495d 100644 --- a/gen/k_means/python/decode_pvrt.py +++ b/gen/k_means/python/decode_pvrt.py @@ -28,7 +28,7 @@ def parse_pvrt_header(buf): print(hex(texture_type)) print(width) print(height) - assert len(indices) + len(codebook) == texture_data_size - 8 + #assert len(indices) + len(codebook) == texture_data_size - 8, (len(indices) + len(codebook), texture_data_size - 8) #assert len(indices) == width * height / 4, (len(indices), width * height / 4) return PVRT( texture_data_size, @@ -51,20 +51,57 @@ def get_colors(buf, codebook_ix): colors = struct.unpack('> i) & 1) << (i * 2 + 0) - twiddle_ix |= ((x >> i) & 1) << (i * 2 + 1) + while i < (20 / 2): + if i < width_max and i < height_max: + twiddle_ix |= ((y >> i) & 1) << (i * 2 + 0) + twiddle_ix |= ((x >> i) & 1) << (i * 2 + 1) + elif i < width_max: + twiddle_ix |= ((x >> i) & 1) << (i + height_max) + elif i < height_max: + twiddle_ix |= ((y >> i) & 1) << (i + width_max) + else: + break i += 1 + return twiddle_ix def decode_vq_indices(codebook, indices, width, height): canvas = [0] * width * height for ty in range(height // 2): for tx in range(width // 2): - codebook_ix = indices[from_xy(tx, ty)] + codebook_ix = indices[from_xy(tx, ty, width, height)] codeword = get_colors(codebook, codebook_ix) ai = ((ty * 2) + 0) * width + ((tx * 2) + 0) bi = ((ty * 2) + 1) * width + ((tx * 2) + 0)