| ... | @@ -21,11 +21,6 @@ const GF = blk: { | ... | @@ -21,11 +21,6 @@ const GF = blk: { |
| 21 | }; | 21 | }; |
| 22 | | 22 | |
| 23 | pub fn encode(comptime mode: Mode, comptime level: Level, comptime version: u16, input: []const u8) BitGrid(4 * version + 17) { | 23 | pub fn encode(comptime mode: Mode, comptime level: Level, comptime version: u16, input: []const u8) BitGrid(4 * version + 17) { |
| 24 | _ = &version; | | |
| 25 | _ = &mode; | | |
| 26 | _ = &level; | | |
| 27 | _ = &input; | | |
| 28 | | | |
| 29 | std.log.warn("mode: {s}", .{@tagName(mode)}); | 24 | std.log.warn("mode: {s}", .{@tagName(mode)}); |
| 30 | std.log.warn("level: {s}", .{@tagName(level)}); | 25 | std.log.warn("level: {s}", .{@tagName(level)}); |
| 31 | | 26 | |
| ... | @@ -81,9 +76,7 @@ pub fn encode(comptime mode: Mode, comptime level: Level, comptime version: u16, | ... | @@ -81,9 +76,7 @@ pub fn encode(comptime mode: Mode, comptime level: Level, comptime version: u16, |
| 81 | std.log.warn("total_bits: {d}", .{total_bits}); | 76 | std.log.warn("total_bits: {d}", .{total_bits}); |
| 82 | | 77 | |
| 83 | var scratch: std.bit_set.ArrayBitSet(u8, total_bits) = .initEmpty(); | 78 | var scratch: std.bit_set.ArrayBitSet(u8, total_bits) = .initEmpty(); |
| 84 | _ = &scratch; | | |
| 85 | var scratchw: BitsetWriter(u8, total_bits) = .{ .set = &scratch }; | 79 | var scratchw: BitsetWriter(u8, total_bits) = .{ .set = &scratch }; |
| 86 | _ = &scratchw; | | |
| 87 | | 80 | |
| 88 | scratchw.writeInt(mode_indicator); | 81 | scratchw.writeInt(mode_indicator); |
| 89 | scratchw.writeInt(len_indicator); | 82 | scratchw.writeInt(len_indicator); |
| ... | @@ -92,15 +85,12 @@ pub fn encode(comptime mode: Mode, comptime level: Level, comptime version: u16, | ... | @@ -92,15 +85,12 @@ pub fn encode(comptime mode: Mode, comptime level: Level, comptime version: u16, |
| 92 | const data_bits = input.len * 8 + @bitSizeOf(@TypeOf(mode_indicator)) + @bitSizeOf(@TypeOf(len_indicator)); | 85 | const data_bits = input.len * 8 + @bitSizeOf(@TypeOf(mode_indicator)) + @bitSizeOf(@TypeOf(len_indicator)); |
| 93 | std.log.warn("data_bits: {d}", .{data_bits}); | 86 | std.log.warn("data_bits: {d}", .{data_bits}); |
| 94 | std.debug.assert(scratchw.idx == data_bits); | 87 | std.debug.assert(scratchw.idx == data_bits); |
| 95 | std.debug.assert(scratchw.idx == 44); //temp | | |
| 96 | | 88 | |
| 97 | // write @max(4, padding_bits) 0s | 89 | // write @max(4, padding_bits) 0s |
| 98 | for (0..@min(4, total_bits - scratchw.idx)) |_| scratchw.writeInt(@as(u1, 0)); | 90 | for (0..@min(4, total_bits - scratchw.idx)) |_| scratchw.writeInt(@as(u1, 0)); |
| 99 | std.debug.assert(scratchw.idx == 48); //temp | | |
| 100 | | 91 | |
| 101 | // add zero bits to make data_bits%8 == 0 | 92 | // add zero bits to make data_bits%8 == 0 |
| 102 | for (0..-%scratchw.idx & 7) |_| scratchw.writeInt(@as(u1, 0)); | 93 | for (0..-%scratchw.idx & 7) |_| scratchw.writeInt(@as(u1, 0)); |
| 103 | std.debug.assert(scratchw.idx == 48); //temp | | |
| 104 | | 94 | |
| 105 | // add 236(11101100) 17(00010001) until we reach total_bits | 95 | // add 236(11101100) 17(00010001) until we reach total_bits |
| 106 | while (scratchw.idx < total_bits) { | 96 | while (scratchw.idx < total_bits) { |
| ... | @@ -112,14 +102,6 @@ pub fn encode(comptime mode: Mode, comptime level: Level, comptime version: u16, | ... | @@ -112,14 +102,6 @@ pub fn encode(comptime mode: Mode, comptime level: Level, comptime version: u16, |
| 112 | // std.log.warn("{d}", .{&bitReverse(scratch.masks)}); | 102 | // std.log.warn("{d}", .{&bitReverse(scratch.masks)}); |
| 113 | // std.log.warn("{x}", .{&bitReverse(scratch.masks)}); | 103 | // std.log.warn("{x}", .{&bitReverse(scratch.masks)}); |
| 114 | | 104 | |
| 115 | std.debug.assert(@bitReverse(scratch.masks[0]) == 0b01000000); //temp | | |
| 116 | std.debug.assert(!scratch.isSet(0)); //temp | | |
| 117 | std.debug.assert(scratch.isSet(1)); //temp | | |
| 118 | std.debug.assert(!scratch.isSet(2)); //temp | | |
| 119 | std.debug.assert(!scratch.isSet(3)); //temp | | |
| 120 | // 01000000 01000101 01100110 01010111 00100011 00010000 11101100 00010001 11101100 00010001 11101100 00010001 11101100 00010001 11101100 00010001 11101100 00010001 11101100 | | |
| 121 | // 01000000 01000101 01100110 01010111 00100011 00010000 11101100 00010001 11101100 00010001 11101100 00010001 11101100 00010001 11101100 00010001 11101100 00010001 11101100 | | |
| 122 | | | |
| 123 | const groups = 1; // ? | 105 | const groups = 1; // ? |
| 124 | _ = &groups; | 106 | _ = &groups; |
| 125 | const blocks = 1; // ? | 107 | const blocks = 1; // ? |
| ... | @@ -130,15 +112,12 @@ pub fn encode(comptime mode: Mode, comptime level: Level, comptime version: u16, | ... | @@ -130,15 +112,12 @@ pub fn encode(comptime mode: Mode, comptime level: Level, comptime version: u16, |
| 130 | _ = &ecc_per_block; | 112 | _ = &ecc_per_block; |
| 131 | | 113 | |
| 132 | var message_polynomial = scratch.masks; | 114 | var message_polynomial = scratch.masks; |
| 133 | _ = &message_polynomial; | | |
| 134 | std.log.warn("message_polynomial: {d}", .{&bitReverse(message_polynomial)}); | 115 | std.log.warn("message_polynomial: {d}", .{&bitReverse(message_polynomial)}); |
| 135 | | 116 | |
| 136 | const generator_polynomial = reverseArray(generatorPolynomial(ecc_per_block)); | 117 | const generator_polynomial = reverseArray(generatorPolynomial(ecc_per_block)); |
| 137 | _ = &generator_polynomial; | | |
| 138 | std.log.warn("generator_polynomial: {d}", .{generator_polynomial}); | 118 | std.log.warn("generator_polynomial: {d}", .{generator_polynomial}); |
| 139 | | 119 | |
| 140 | const generator_polynomial_alpha = to_alpha(generator_polynomial); | 120 | const generator_polynomial_alpha = to_alpha(generator_polynomial); |
| 141 | _ = &generator_polynomial_alpha; | | |
| 142 | std.log.warn("generator_polynomial_alpha: {d}", .{generator_polynomial_alpha}); | 121 | std.log.warn("generator_polynomial_alpha: {d}", .{generator_polynomial_alpha}); |
| 143 | | 122 | |
| 144 | // Now that the message and generator polynomials have been created, divide them to get the error codewords. | 123 | // Now that the message and generator polynomials have been created, divide them to get the error codewords. |
| ... | @@ -166,7 +145,6 @@ pub fn encode(comptime mode: Mode, comptime level: Level, comptime version: u16, | ... | @@ -166,7 +145,6 @@ pub fn encode(comptime mode: Mode, comptime level: Level, comptime version: u16, |
| 166 | std.log.warn("error_codewords: {d}", .{error_codewords}); | 145 | std.log.warn("error_codewords: {d}", .{error_codewords}); |
| 167 | | 146 | |
| 168 | const interleaved_message = scratch.masks ++ bitReverse(error_codewords); | 147 | const interleaved_message = scratch.masks ++ bitReverse(error_codewords); |
| 169 | _ = &interleaved_message; | | |
| 170 | std.log.warn("interleaved_message: {b:0>8}", .{&bitReverse(interleaved_message)}); | 148 | std.log.warn("interleaved_message: {b:0>8}", .{&bitReverse(interleaved_message)}); |
| 171 | | 149 | |
| 172 | // remainder bits | 150 | // remainder bits |
| ... | @@ -175,7 +153,6 @@ pub fn encode(comptime mode: Mode, comptime level: Level, comptime version: u16, | ... | @@ -175,7 +153,6 @@ pub fn encode(comptime mode: Mode, comptime level: Level, comptime version: u16, |
| 175 | | 153 | |
| 176 | const size = 4 * version + 17; | 154 | const size = 4 * version + 17; |
| 177 | var grid: BitGrid(size) = .initEmpty(); | 155 | var grid: BitGrid(size) = .initEmpty(); |
| 178 | _ = &grid; | | |
| 179 | | 156 | |
| 180 | // top left finder pattern | 157 | // top left finder pattern |
| 181 | for (0..7) |i| for (0..7) |j| grid.setT(0 + i, 0 + j); | 158 | for (0..7) |i| for (0..7) |j| grid.setT(0 + i, 0 + j); |
| ... | @@ -213,20 +190,16 @@ pub fn encode(comptime mode: Mode, comptime level: Level, comptime version: u16, | ... | @@ -213,20 +190,16 @@ pub fn encode(comptime mode: Mode, comptime level: Level, comptime version: u16, |
| 213 | | 190 | |
| 214 | // write data | 191 | // write data |
| 215 | var data_iter: BufBiterator = .init(&bitReverse(interleaved_message)); | 192 | var data_iter: BufBiterator = .init(&bitReverse(interleaved_message)); |
| 216 | _ = &data_iter; | | |
| 217 | | 193 | |
| 218 | var griditer: GridZigZag = .init(size, 6); | 194 | var griditer: GridZigZag = .init(size, 6); |
| 219 | while (griditer.next()) |idx| { | 195 | while (griditer.next()) |idx| { |
| 220 | const x = idx % size; | 196 | const x = idx % size; |
| 221 | const y = (idx - x) / size; | 197 | const y = (idx - x) / size; |
| 222 | // std.log.warn("idx: {d} {d},{d}", .{ idx, x, y }); | | |
| 223 | if (data_mask.isSet(x, y)) continue; | 198 | if (data_mask.isSet(x, y)) continue; |
| 224 | grid.debug.set((y * size) + x); | 199 | grid.debug.set((y * size) + x); |
| 225 | if (@bitCast(data_iter.next() orelse break)) grid.set(x, y); | 200 | if (@bitCast(data_iter.next() orelse break)) grid.set(x, y); |
| 226 | } | 201 | } |
| 227 | | 202 | |
| 228 | // | | |
| 229 | | | |
| 230 | for (0..8) |y| for (0..8) |x| grid.debug.set((y * size) + x); | 203 | for (0..8) |y| for (0..8) |x| grid.debug.set((y * size) + x); |
| 231 | for (0..8) |y| for (0..8) |x| grid.debug.set((y * size) + size - 8 + x); | 204 | for (0..8) |y| for (0..8) |x| grid.debug.set((y * size) + size - 8 + x); |
| 232 | for (0..8) |y| for (0..8) |x| grid.debug.set(((size - 8 + y) * size) + x); | 205 | for (0..8) |y| for (0..8) |x| grid.debug.set(((size - 8 + y) * size) + x); |