Transform is unavoidably signed
Center our input in the signed range, so it adds about 3 bits per pass instead of 4.
This commit is contained in:
parent
5c70367116
commit
7de68f03bf
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user