BC1 interoperability: two-block synthetic case for the second reference lane #10

Closed
opened 2026-11-26 18:56:06 +00:00 by github-bot · 1 comment
Owner

@⁠tyr0nsur on GitHub · 2026-11-25 20:49 UTC · original

I compared the two BC1 assemblers at bcpack-rs f5145dda7f using two generated blocks and the default tables. The entropy decoders agree on every input symbol. Changing just the second symbol of lane 1 leaves bcpack-rs output identical, while VIctory's BC1 assembler changes both the endpoints and indices of the second block. No dictionary entry before block zero is needed. The zero-reference control agrees byte for byte.

This generates the two streams using your public encoder:

for reference in [0u16, 1] {
    let lanes: Vec<_> = (0..12).map(|i| vec![encode::Fragment {
        symbols: vec![if i >= 2 { 2 + i as u16 % 4 } else { 0 },
                      if i == 1 { reference } else { 0 }],
        q: 7, z: 0,
    }]).collect();
    let stream = encode::encode_lanes(&bc1::BC1_ALPHABET_BITS, &lanes).unwrap();
    let out = bc1::decode(&stream, 2, &bc1::Window::default_table(),
                          &bc1::QuadTable::default_table()).unwrap();
    println!("{reference} {:02x?}", out.blocks);
}
Second BC1 block bcpack-rs VIctory/PortVI
Lane 1 = 0 00 00 00 00 aa aa aa aa 00 00 00 00 aa aa aa aa
Lane 1 = 1 00 00 00 00 aa aa aa aa a1 17 5d f0 0a 0a 5f f5

Both runs have first block a1 17 5d f0 50 50 fa af. Your BC1 assembler takes the endpoint distance from lane 0. VIctory uses the index reference from lane 1 plus the signed endpoint delta from lane 0. A comparison with an independent reference decoder for this pair could settle the intended semantics. I have verified the discrepancy on Windows x64. Thank you for the synthetic encoder. It also let us isolate and fix an unrelated end-of-fragment error in our entropy decoder.

**@⁠tyr0nsur** on GitHub · 2026-11-25 20:49 UTC · [original](https://github.com/Ahmet-Dedeler/bcpack-rs/issues/10) I compared the two BC1 assemblers at bcpack-rs f5145dda7fa6d1a22b499d82f3e63029713b71b6 using two generated blocks and the default tables. The entropy decoders agree on every input symbol. Changing just the second symbol of lane 1 leaves bcpack-rs output identical, while VIctory's BC1 assembler changes both the endpoints and indices of the second block. No dictionary entry before block zero is needed. The zero-reference control agrees byte for byte. This generates the two streams using your public encoder: ```rust for reference in [0u16, 1] { let lanes: Vec<_> = (0..12).map(|i| vec![encode::Fragment { symbols: vec![if i >= 2 { 2 + i as u16 % 4 } else { 0 }, if i == 1 { reference } else { 0 }], q: 7, z: 0, }]).collect(); let stream = encode::encode_lanes(&bc1::BC1_ALPHABET_BITS, &lanes).unwrap(); let out = bc1::decode(&stream, 2, &bc1::Window::default_table(), &bc1::QuadTable::default_table()).unwrap(); println!("{reference} {:02x?}", out.blocks); } ``` | Second BC1 block | bcpack-rs | VIctory/PortVI | | --- | --- | --- | | Lane 1 = 0 | `00 00 00 00 aa aa aa aa` | `00 00 00 00 aa aa aa aa` | | Lane 1 = 1 | `00 00 00 00 aa aa aa aa` | `a1 17 5d f0 0a 0a 5f f5` | Both runs have first block `a1 17 5d f0 50 50 fa af`. Your BC1 assembler takes the endpoint distance from lane 0. VIctory uses the index reference from lane 1 plus the signed endpoint delta from lane 0. A comparison with an independent reference decoder for this pair could settle the intended semantics. I have verified the discrepancy on Windows x64. Thank you for the synthetic encoder. It also let us isolate and fix an unrelated end-of-fragment error in our entropy decoder.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 18:56:06 +00:00
Author
Owner

@⁠Ahmet-Dedeler on GitHub · 2026-11-26 02:54 UTC · original

Thanks, this was a real bug and your two-block case made it easy to pin. Fixed in #11.

You're right about the semantics. bcpack-rs read lane 1 as unused because it was 0 in every retail chunk I measured, so the BC1 assembler took the endpoint reference straight from lane 0. The BC3/BC4/BC5 path in the same crate already did it properly through format::references. Now BC1 does too: lane 1 is the index reference x, the endpoint reference is x + unzigzag(lane 0), and each pixel's index residual is added along the endpoint line, mod 4, to the same pixel of block i - x.

Your case is now a test (bc1_lane1_index_reference). With lane 1 = 1 the second block comes out a1 17 5d f0 0a 0a 5f f5, same as VIctory's. With lane 1 = 0 nothing changes. The Python reference got the same fix and agrees with Rust on the synthetic vectors.

One gap left: an index reference before block 0 has no known table here yet, so it reads zero and the block counts as unfitted. If you have a case where that matters, send it.

**@⁠Ahmet-Dedeler** on GitHub · 2026-11-26 02:54 UTC · [original](https://github.com/Ahmet-Dedeler/bcpack-rs/issues/10#issuecomment-7181222022) Thanks, this was a real bug and your two-block case made it easy to pin. Fixed in #11. You're right about the semantics. bcpack-rs read lane 1 as unused because it was 0 in every retail chunk I measured, so the BC1 assembler took the endpoint reference straight from lane 0. The BC3/BC4/BC5 path in the same crate already did it properly through `format::references`. Now BC1 does too: lane 1 is the index reference `x`, the endpoint reference is `x + unzigzag(lane 0)`, and each pixel's index residual is added along the endpoint line, mod 4, to the same pixel of block `i - x`. Your case is now a test (`bc1_lane1_index_reference`). With lane 1 = 1 the second block comes out `a1 17 5d f0 0a 0a 5f f5`, same as VIctory's. With lane 1 = 0 nothing changes. The Python reference got the same fix and agrees with Rust on the synthetic vectors. One gap left: an index reference before block 0 has no known table here yet, so it reads zero and the block counts as unfitted. If you have a case where that matters, send it.
This discussion has been locked. Commenting is limited to contributors.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Ahmet-Dedeler--bcpack-rs#10
No description provided.