diff --git a/crates/victory-formats/src/bcpack.rs b/crates/victory-formats/src/bcpack.rs index 11dada0f..a86cd4a7 100644 --- a/crates/victory-formats/src/bcpack.rs +++ b/crates/victory-formats/src/bcpack.rs @@ -222,10 +222,11 @@ impl Tables { bits: [r.u8(), r.u8()], ..Default::default() }; - // Unused: the widths again in all entries but the first. - r.u16(); - // Only 15 slots for set 1, which no entry uses (0 bits). - for v in &mut ix.ix.as_flattened_mut()[..31] { + // Microsoft's decoder takes the word after the widths (the + // widths again in all entries but the first) as pixel 0's + // index, so the stored indices land one pixel late and the + // last spills into set 1, which no entry uses (0 bits). + for v in ix.ix.as_flattened_mut() { *v = r.u16() as i16; } (ep, ix) @@ -1699,14 +1700,15 @@ mod tests { assert!(n > 0); } - /// A dictionary entry stands in for a block the decoder made: a set with - /// 0 index bits holds no indices, and pixel 0 is the anchor (top bit clear). + /// Dictionary entries as Microsoft's decoder reads them (checked against + /// BCPack.dll): pixel 0 holds the widths word in all entries but the + /// first, and set 1 never has index bits. #[test] fn bc7_dictionary_indices_line_up() { let t = Tables::builtin().unwrap(); for (k, (_, ix)) in t.bc7.iter().enumerate() { - let anchor = 0..1 << (ix.bits[0] - 1); - let ok = (ix.bits[1] != 0 || ix.ix[1] == [0; 16]) && anchor.contains(&ix.ix[0][0]); + let widths = i16::from(ix.bits[0]) | i16::from(ix.bits[1]) << 8; + let ok = ix.bits[1] == 0 && (k == 0 || ix.ix[0][0] == widths); assert!(ok, "entry {k}: {:?}", ix.ix); } }