diff --git a/inputs/avatar2_small.png b/inputs/avatar2_small.png new file mode 100644 index 0000000..f716808 Binary files /dev/null and b/inputs/avatar2_small.png differ diff --git a/src/decode_tile.rs b/src/decode_tile.rs index f222092..d77cb96 100644 --- a/src/decode_tile.rs +++ b/src/decode_tile.rs @@ -11,7 +11,7 @@ pub fn decode_tile( for _ in 0..quality { let ix = reader.read_u8()?; - let val = decode_value(reader.read_u8()?); + let val = decode_value(reader.read_u16()?); coefs[ix as usize] = val; } @@ -48,7 +48,9 @@ pub fn decode_tile( Ok(()) } -pub fn decode_value(enc: u8) -> i32 { +pub fn decode_value(enc: u16) -> i32 { + return (enc as i16) as i32 * 16; + /* // mu law let sign = enc & 0x80 != 0; let exponent = (enc >> 4) & 0x7; @@ -59,4 +61,5 @@ pub fn decode_value(enc: u8) -> i32 { // unquantize return value * 32; + */ } \ No newline at end of file diff --git a/src/encode_tile.rs b/src/encode_tile.rs index 085a003..597ecd4 100644 --- a/src/encode_tile.rs +++ b/src/encode_tile.rs @@ -57,12 +57,14 @@ pub fn encode_tile( for i in 0..quality { let ix = indices[i as usize]; writer.write_u8(ix as u8)?; - writer.write_u8(encode_value(coefs[ix]))?; + writer.write_u16(encode_value(coefs[ix]))?; }; Ok(()) } -pub fn encode_value(value: i32) -> u8 { +pub fn encode_value(value: i32) -> u16 { + return ((value / 16) as i16) as u16; + /* // quantize let value = value / 32; @@ -101,4 +103,5 @@ mod test { canon == decode_value(encode_value(canon as i32)) } + */ } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 12da4ab..3e8189f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,6 +15,7 @@ fn main() { run_for("lohikar".to_string()); run_for("zonked".to_string()); run_for("avatar2".to_string()); + run_for("avatar2_small".to_string()); } fn run_for(name: String) { let image = png_utils::load_image(