1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-02-27 00:30:26 +00:00

Switch both: (i) which bits are odd/even; and (ii) nibble ordering.

This commit is contained in:
Thomas Harte 2021-10-09 13:45:19 -07:00
parent 6b0dd19442
commit aeaea073c6

View File

@ -20,17 +20,18 @@ template <typename IteratorT> void write_block(IteratorT begin, IteratorT end, s
// Parse 1: write odd bits. // Parse 1: write odd bits.
auto cursor = begin; auto cursor = begin;
while(cursor != end) { while(cursor != end) {
uint8_t source = auto source = uint8_t(
((*cursor & 0x01) >> 0) | ((*cursor & 0x02) << 3) |
((*cursor & 0x04) >> 1) | ((*cursor & 0x08) << 2) |
((*cursor & 0x10) >> 2) | ((*cursor & 0x20) << 1) |
((*cursor & 0x40) >> 3); ((*cursor & 0x80) << 0)
);
++cursor; ++cursor;
source |= source |=
((*cursor & 0x01) << 4) | ((*cursor & 0x02) >> 1) |
((*cursor & 0x04) << 3) | ((*cursor & 0x08) >> 2) |
((*cursor & 0x10) << 2) | ((*cursor & 0x20) >> 3) |
((*cursor & 0x40) << 1); ((*cursor & 0x80) >> 4);
++cursor; ++cursor;
encoder->add_byte(source); encoder->add_byte(source);
@ -39,17 +40,18 @@ template <typename IteratorT> void write_block(IteratorT begin, IteratorT end, s
// Parse 2: write even bits. // Parse 2: write even bits.
cursor = begin; cursor = begin;
while(cursor != end) { while(cursor != end) {
uint8_t source = auto source = uint8_t(
((*cursor & 0x02) >> 1) | ((*cursor & 0x01) << 4) |
((*cursor & 0x08) >> 2) | ((*cursor & 0x04) << 3) |
((*cursor & 0x20) >> 3) | ((*cursor & 0x10) << 2) |
((*cursor & 0x80) >> 4); ((*cursor & 0x40) << 1)
);
++cursor; ++cursor;
source |= source |=
((*cursor & 0x02) << 3) | ((*cursor & 0x01) >> 0) |
((*cursor & 0x08) << 2) | ((*cursor & 0x04) >> 1) |
((*cursor & 0x20) << 1) | ((*cursor & 0x10) >> 2) |
((*cursor & 0x80) << 0); ((*cursor & 0x40) >> 3);
++cursor; ++cursor;
encoder->add_byte(source); encoder->add_byte(source);