Forego phone-sized floats for now

This commit is contained in:
Pyrex 2024-04-10 12:34:19 -07:00
parent 89cb8eead7
commit bab78aa61a
4 changed files with 11 additions and 4 deletions

BIN
inputs/avatar2_small.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

View File

@ -11,7 +11,7 @@ pub fn decode_tile<R: Read>(
for _ in 0..quality { for _ in 0..quality {
let ix = reader.read_u8()?; let ix = reader.read_u8()?;
let val = decode_value(reader.read_u8()?); let val = decode_value(reader.read_u16()?);
coefs[ix as usize] = val; coefs[ix as usize] = val;
} }
@ -48,7 +48,9 @@ pub fn decode_tile<R: Read>(
Ok(()) Ok(())
} }
pub fn decode_value(enc: u8) -> i32 { pub fn decode_value(enc: u16) -> i32 {
return (enc as i16) as i32 * 16;
/*
// mu law // mu law
let sign = enc & 0x80 != 0; let sign = enc & 0x80 != 0;
let exponent = (enc >> 4) & 0x7; let exponent = (enc >> 4) & 0x7;
@ -59,4 +61,5 @@ pub fn decode_value(enc: u8) -> i32 {
// unquantize // unquantize
return value * 32; return value * 32;
*/
} }

View File

@ -57,12 +57,14 @@ pub fn encode_tile<W: Write>(
for i in 0..quality { for i in 0..quality {
let ix = indices[i as usize]; let ix = indices[i as usize];
writer.write_u8(ix as u8)?; writer.write_u8(ix as u8)?;
writer.write_u8(encode_value(coefs[ix]))?; writer.write_u16(encode_value(coefs[ix]))?;
}; };
Ok(()) Ok(())
} }
pub fn encode_value(value: i32) -> u8 { pub fn encode_value(value: i32) -> u16 {
return ((value / 16) as i16) as u16;
/*
// quantize // quantize
let value = value / 32; let value = value / 32;
@ -101,4 +103,5 @@ mod test {
canon == decode_value(encode_value(canon as i32)) canon == decode_value(encode_value(canon as i32))
} }
*/
} }

View File

@ -15,6 +15,7 @@ fn main() {
run_for("lohikar".to_string()); run_for("lohikar".to_string());
run_for("zonked".to_string()); run_for("zonked".to_string());
run_for("avatar2".to_string()); run_for("avatar2".to_string());
run_for("avatar2_small".to_string());
} }
fn run_for(name: String) { fn run_for(name: String) {
let image = png_utils::load_image( let image = png_utils::load_image(