MCPcopy Create free account
hub / github.com/BruceDevices/firmware / badcheck

Function badcheck

lib/TFT_eSPI_QRcode/src/qrencode.c:397–449  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

395}
396
397int badcheck()
398{
399 unsigned char x, y, h, b, b1;
400 unsigned thisbad = 0;
401 int bw = 0;
402
403 // blocks of same color.
404 for (y = 0; y < WD - 1; y++)
405 for (x = 0; x < WD - 1; x++)
406 if ((QRBIT(x, y) && QRBIT(x + 1, y) && QRBIT(x, y + 1) && QRBIT(x + 1, y + 1)) // all black
407 || !(QRBIT(x, y) || QRBIT(x + 1, y) || QRBIT(x, y + 1) || QRBIT(x + 1, y + 1))) // all white
408 thisbad += N2;
409
410 // X runs
411 for (y = 0; y < WD; y++) {
412 rlens[0] = 0;
413 for (h = b = x = 0; x < WD; x++) {
414 if ((b1 = QRBIT(x, y)) == b)
415 rlens[h]++;
416 else
417 rlens[++h] = 1;
418 b = b1;
419 bw += b ? 1 : -1;
420 }
421 thisbad += badruns(h);
422 }
423
424 // black/white imbalance
425 if (bw < 0)
426 bw = -bw;
427
428 unsigned long big = bw;
429 unsigned count = 0;
430 big += big << 2;
431 big <<= 1;
432 while (big > WD * WD)
433 big -= WD * WD, count++;
434 thisbad += count * N4;
435
436 // Y runs
437 for (x = 0; x < WD; x++) {
438 rlens[0] = 0;
439 for (h = b = y = 0; y < WD; y++) {
440 if ((b1 = QRBIT(x, y)) == b)
441 rlens[h]++;
442 else
443 rlens[++h] = 1;
444 b = b1;
445 }
446 thisbad += badruns(h);
447 }
448 return thisbad;
449}
450
451// final format bits with mask
452// level << 3 | mask

Callers 1

qrencodeFunction · 0.85

Calls 1

badrunsFunction · 0.85

Tested by

no test coverage detected