authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-02-28 15:55:35 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-02-28 15:55:35 -08:00
log9f19706657bfbf8a00e0f46d301b78e14179bd95
tree222264d1f157654d88f2417e214d3d560c15899d
parent2b93cd627ba3cf1085513d862bd5973f293f5fb9

remove debug logs


1 files changed, 1 insertions(+), 54 deletions(-)

qrcode.zig+1-54
......@@ -22,9 +22,6 @@ const GF = blk: {
2222};
2323
2424pub fn encode(comptime mode: Mode, comptime level: Level, comptime version: u16, input: []const u8) BitGrid(4 * version + 17) {
25 std.log.warn("mode: {s}", .{@tagName(mode)});
26 std.log.warn("level: {s}", .{@tagName(level)});
27
2825 if (mode == .numeric) std.debug.assert(extras.matchesAll(u8, input, isNumeric));
2926 if (mode == .alphanumeric) std.debug.assert(extras.matchesAll(u8, input, isAlphanumeric));
3027 // latin1 is a full 1-byte format, some readers can detect utf-8
......@@ -32,17 +29,9 @@ pub fn encode(comptime mode: Mode, comptime level: Level, comptime version: u16,
3229
3330 const max_lengths = comptime maxLenPerModeLevelVersion(mode, level);
3431 const max_length = max_lengths[version];
35 std.log.warn("actual version: {d},{d},{d}", .{ version, max_length, input.len });
3632 std.debug.assert(input.len <= max_length);
37 for (max_lengths, 0..) |l, i| if (l > input.len) break std.log.warn("reccom version: {d},{d}", .{ i, l });
3833
3934 const dataCodewordsCount, const ecCodewordsPerBlock, const groupOneBlockCount, const groupOneDataCodewordsCountPerBlock, const groupTwoBlockCount, const groupTwoDataCodewordsCountPerBlock = comptime errorCorrection(level, version);
40 std.log.warn("dataCodewordsCount: {d}", .{dataCodewordsCount});
41 std.log.warn("ecCodewordsPerBlock: {d}", .{ecCodewordsPerBlock});
42 std.log.warn("groupOneBlockCount: {d}", .{groupOneBlockCount});
43 std.log.warn("groupOneDataCodewordsCountPerBlock: {d}", .{groupOneDataCodewordsCountPerBlock});
44 std.log.warn("groupTwoBlockCount: {?d}", .{groupTwoBlockCount});
45 std.log.warn("groupTwoDataCodewordsCountPerBlock: {?d}", .{groupTwoDataCodewordsCountPerBlock});
4635
4736 const mode_indicator: u4 = switch (mode) {
4837 .numeric => 0b0001,
......@@ -50,7 +39,6 @@ pub fn encode(comptime mode: Mode, comptime level: Level, comptime version: u16,
5039 .latin1 => 0b0100,
5140 .shiftjis => 0b1000,
5241 };
53 std.log.warn("mode_indicator: {d}", .{mode_indicator});
5442
5543 const LenIndicator = switch (mode) {
5644 .numeric => switch (version) {
......@@ -79,10 +67,8 @@ pub fn encode(comptime mode: Mode, comptime level: Level, comptime version: u16,
7967 },
8068 };
8169 const len_indicator: LenIndicator = @intCast(input.len);
82 std.log.warn("len_indicator: {d}", .{len_indicator});
8370
8471 const total_bits = dataCodewordsCount * 8;
85 std.log.warn("total_bits: {d}", .{total_bits});
8672
8773 var scratch: std.bit_set.ArrayBitSet(u8, total_bits) = .initEmpty();
8874 var scratchw: BitsetWriter(u8, total_bits) = .{ .set = &scratch };
......@@ -92,7 +78,6 @@ pub fn encode(comptime mode: Mode, comptime level: Level, comptime version: u16,
9278 for (input) |x| scratchw.writeInt(x);
9379
9480 const data_bits = input.len * 8 + @bitSizeOf(@TypeOf(mode_indicator)) + @bitSizeOf(@TypeOf(len_indicator));
95 std.log.warn("data_bits: {d}", .{data_bits});
9681 std.debug.assert(scratchw.idx == data_bits);
9782
9883 // write @max(4, padding_bits) 0s
......@@ -107,15 +92,8 @@ pub fn encode(comptime mode: Mode, comptime level: Level, comptime version: u16,
10792 scratchw.writeInt(@as(u8, 0x11));
10893 }
10994
110 std.log.warn("{b:0>8}", .{&bitReverse(scratch.masks)});
111 std.log.warn("{d}", .{&bitReverse(scratch.masks)});
112 std.log.warn("{x}", .{&bitReverse(scratch.masks)});
113
11495 const generator_polynomial = reverseArray(generatorPolynomial(ecCodewordsPerBlock));
115 std.log.warn("generator_polynomial: {d}", .{generator_polynomial});
116
11796 const generator_polynomial_alpha = to_alpha(generator_polynomial);
118 std.log.warn("generator_polynomial_alpha: {d}", .{generator_polynomial_alpha});
11997
12098 // Now that the message and generator polynomials have been created, divide them to get the error codewords.
12199 {
......@@ -134,7 +112,6 @@ pub fn encode(comptime mode: Mode, comptime level: Level, comptime version: u16,
134112
135113 for (&group1_ec, 0..) |*g, gn| {
136114 const message_polynomial = scratch.masks[groupOneDataCodewordsCountPerBlock * gn ..][0..groupOneDataCodewordsCountPerBlock];
137 std.log.warn("message_polynomial: 1,{d},{d},{d}", .{ gn, message_polynomial.len, &bitReverse(message_polynomial.*) });
138115
139116 var mp: [groupOneDataCodewordsCountPerBlock + ecCodewordsPerBlock]?u8 = @splat(null);
140117 for (message_polynomial, 0..) |x, i| mp[i] = to_alpha(.{@bitReverse(x)})[0];
......@@ -153,7 +130,6 @@ pub fn encode(comptime mode: Mode, comptime level: Level, comptime version: u16,
153130 }
154131 for (&group2_ec, 0..) |*g, gn| {
155132 const message_polynomial = scratch.masks[groupOneBlockCount * groupOneDataCodewordsCountPerBlock ..][group2_datacodewords_per_block * gn ..][0..group2_datacodewords_per_block];
156 std.log.warn("message_polynomial: 2,{d},{d},{d}", .{ gn, message_polynomial.len, &bitReverse(message_polynomial.*) });
157133
158134 var mp: [group2_datacodewords_per_block + ecCodewordsPerBlock]?u8 = @splat(null);
159135 for (message_polynomial, 0..) |x, i| mp[i] = to_alpha(.{@bitReverse(x)})[0];
......@@ -208,11 +184,11 @@ pub fn encode(comptime mode: Mode, comptime level: Level, comptime version: u16,
208184 imi += 1;
209185 }
210186 }
211 std.log.warn("interleaved_message: {b:0>8}", .{&bitReverse(interleaved_message)});
212187 std.debug.assert(imi == interleaved_message.len);
213188
214189 // remainder bits
215190 const remainder_bits_count = comptime remainderBitsCount(version);
191 _ = remainder_bits_count;
216192
217193 //
218194
......@@ -295,21 +271,8 @@ pub fn encode(comptime mode: Mode, comptime level: Level, comptime version: u16,
295271 const x = idx % size;
296272 const y = (idx - x) / size;
297273 if (data_mask.isSet(x, y)) continue;
298 grid.debug.set((y * size) + x);
299274 if (@bitCast(data_iter.next() orelse break)) grid.set(x, y);
300275 }
301 for (0..remainder_bits_count) |_| {
302 const idx = griditer.next().?;
303 const x = idx % size;
304 const y = (idx - x) / size;
305 grid.debug.set((y * size) + x);
306 }
307
308 for (0..8) |y| for (0..8) |x| grid.debug.set((y * size) + x);
309 for (0..8) |y| for (0..8) |x| grid.debug.set((y * size) + size - 8 + x);
310 for (0..8) |y| for (0..8) |x| grid.debug.set(((size - 8 + y) * size) + x);
311 for (0..size) |i| grid.debug.set((6 * size) + i);
312 for (0..size) |i| grid.debug.set((i * size) + 6);
313276
314277 // format info
315278 var masks = [_]std.bit_set.IntegerBitSet(15){
......@@ -466,30 +429,23 @@ pub fn encode(comptime mode: Mode, comptime level: Level, comptime version: u16,
466429 const div = [_]u32{ @divFloor(sub[0], 5), @divFloor(sub[1], 5) };
467430 penaltys[i][3] += std.mem.min(u32, &div) * 10;
468431 }
469 for (&penaltys) |x| std.log.warn("penaltys: {d}", .{&x});
470432
471433 var penalty: [8]u32 = @splat(0);
472434 for (0..8) |i| penalty[i] = extras.sum(u32, &penaltys[i]);
473435
474436 const min_penalty = std.mem.min(u32, &penalty);
475 std.log.warn("min_penalty: {d}", .{min_penalty});
476437 const min_mask = std.mem.indexOfScalar(u32, &penalty, min_penalty).?;
477 std.log.warn("min_mask: {d}", .{min_mask});
478
479 std.log.warn("", .{});
480438 return grids[min_mask];
481439}
482440
483441fn BitGrid(comptime size: usize) type {
484442 return struct {
485443 bset: std.bit_set.ArrayBitSet(usize, size * size),
486 debug: std.bit_set.ArrayBitSet(usize, size * size),
487444 comptime size: usize = size,
488445
489446 pub fn initEmpty() @This() {
490447 return .{
491448 .bset = .initEmpty(),
492 .debug = .initEmpty(),
493449 };
494450 }
495451
......@@ -499,30 +455,21 @@ fn BitGrid(comptime size: usize) type {
499455
500456 pub fn set(self: *@This(), x: usize, y: usize) void {
501457 self.bset.set((y * size) + x);
502 self.debug.set((y * size) + x);
503458 }
504459
505460 pub fn setF(self: *@This(), x: usize, y: usize) void {
506461 self.bset.setValue((y * size) + x, false);
507 self.debug.setValue((y * size) + x, true);
508462 }
509463
510464 pub fn setT(self: *@This(), x: usize, y: usize) void {
511465 self.bset.setValue((y * size) + x, true);
512 self.debug.setValue((y * size) + x, true);
513466 }
514467
515468 pub fn setV(self: *@This(), x: usize, y: usize, value: bool) void {
516469 self.bset.setValue((y * size) + x, value);
517 self.debug.setValue((y * size) + x, true);
518 }
519
520 pub fn hasSet(self: *const @This(), x: usize, y: usize) bool {
521 return self.debug.isSet((y * size) + x);
522470 }
523471
524472 pub fn flip(self: *@This(), x: usize, y: usize) void {
525 std.debug.assert(self.debug.isSet((y * size) + x));
526473 self.bset.toggle((y * size) + x);
527474 }
528475