change REV_U8 array to invert function

main
kirbylife 2022-05-04 23:21:58 -05:00
parent 64751fc675
commit ec8dd2ddee
1 changed files with 8 additions and 7 deletions

View File

@ -165,19 +165,20 @@ impl DynHuffman16 {
with_codes!(clens, 15 => u16, |i: u16, code: u16, bits: u8| -> _ { with_codes!(clens, 15 => u16, |i: u16, code: u16, bits: u8| -> _ {
let entry = i | (u16::from(bits) << 12); let entry = i | (u16::from(bits) << 12);
if bits <= 8 { if bits <= 8 {
let base = match (code << (8 - bits)).swap_bits() { let base = match u8::try_from(code << (8 - bits)) {
Some(&v) => v, Ok(v) => v.swap_bits(),
None => return Err("invalid length code") _ => return Err("invalid length code")
}; };
for rest in 0u8 .. 1 << (8 - bits) { for rest in 0u8 .. 1 << (8 - bits) {
patterns[(base | (rest << (bits & 7))) as usize] = entry; patterns[(base | (rest << (bits & 7))) as usize] = entry;
} }
} else { } else {
let low = match (code >> (bits - 8)).swap_bits() { let low = match u8::try_from(code >> (bits - 8)) {
Some(&v) => v, Ok(v) => v.swap_bits(),
None => return Err("invalid length code") _ => return Err("invalid length code")
}; };
let high = ((code << (16 - bits)) & 0xff).swap_bits(); let high = (code << (16 - bits)) & 0xff;
let high = (high as u8).swap_bits();
let (min_bits, idx) = if patterns[low as usize] != 0xffff { let (min_bits, idx) = if patterns[low as usize] != 0xffff {
let bits_prev = (patterns[low as usize] >> 12) as u8; let bits_prev = (patterns[low as usize] >> 12) as u8;
(core::cmp::min(bits_prev, bits), patterns[low as usize] & 0x7ff) (core::cmp::min(bits_prev, bits), patterns[low as usize] & 0x7ff)