From 7de68f03bf6fcdf94b4c16ba88b35d70ba9d016b Mon Sep 17 00:00:00 2001 From: Nyeogmi Date: Sun, 7 Apr 2024 16:08:47 -0700 Subject: [PATCH] Transform is unavoidably signed Center our input in the signed range, so it adds about 3 bits per pass instead of 4. --- src/transform.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/transform.rs b/src/transform.rs index 8faeb1c..3c71400 100644 --- a/src/transform.rs +++ b/src/transform.rs @@ -4,19 +4,19 @@ use crate::constants::TILE_SZ; // Ported from: // - https://colab.research.google.com/drive/1WjtKwUcqxWafAumFO9ET74RsckZSsw6n#scrollTo=e3r9-RBpcgwH pub fn encode(data: &mut [i32], zero: usize, stride: usize) { - transform(data, zero, stride, 1) + transform(data, zero, stride, -128, 0, 1) } pub fn decode(data: &mut [i32], zero: usize, stride: usize) { - transform(data, zero, stride, 8) + transform(data, zero, stride, 0, 128, 8) } -fn transform(data: &mut [i32], zero: usize, stride: usize, divisor: i32) { +fn transform(data: &mut [i32], zero: usize, stride: usize, offset_in: i32, offset_out: i32, divisor: i32) { let ix = |t| zero + t * stride; let mut row = [0; TILE_SZ]; for i in 0..TILE_SZ { - row[i] = data[ix(i)]; + row[i] = data[ix(i)] + offset_in; } for bit in [4, 2, 1] { @@ -35,7 +35,7 @@ fn transform(data: &mut [i32], zero: usize, stride: usize, divisor: i32) { // basically, this moves important stuff towards the left const GRAY: [usize; TILE_SZ] = [0, 4, 6, 2, 3, 7, 5, 1]; for i in 0..TILE_SZ { - data[ix(GRAY[i])] = row[i] / divisor; + data[ix(GRAY[i])] = row[i] / divisor + offset_out; } }