Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions crates/victory-formats/src/bcpack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
}
Expand Down
Loading