MCPcopy Create free account
hub / github.com/TactilityProject/Tactility / getPenaltyScore

Method getPenaltyScore

Libraries/QRCode/tests/QrCode.cpp:416–493  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

414
415
416int qrcodegen::QrCode::getPenaltyScore() const {
417 int result = 0;
418
419 // Adjacent modules in row having same color
420 for (int y = 0; y < size; y++) {
421 bool colorX = modules.at(y).at(0);
422 for (int x = 1, runX = 1; x < size; x++) {
423 if (modules.at(y).at(x) != colorX) {
424 colorX = modules.at(y).at(x);
425 runX = 1;
426 } else {
427 runX++;
428 if (runX == 5)
429 result += PENALTY_N1;
430 else if (runX > 5)
431 result++;
432 }
433 }
434 }
435 // Adjacent modules in column having same color
436 for (int x = 0; x < size; x++) {
437 bool colorY = modules.at(0).at(x);
438 for (int y = 1, runY = 1; y < size; y++) {
439 if (modules.at(y).at(x) != colorY) {
440 colorY = modules.at(y).at(x);
441 runY = 1;
442 } else {
443 runY++;
444 if (runY == 5)
445 result += PENALTY_N1;
446 else if (runY > 5)
447 result++;
448 }
449 }
450 }
451
452 // 2*2 blocks of modules having same color
453 for (int y = 0; y < size - 1; y++) {
454 for (int x = 0; x < size - 1; x++) {
455 bool color = modules.at(y).at(x);
456 if ( color == modules.at(y).at(x + 1) &&
457 color == modules.at(y + 1).at(x) &&
458 color == modules.at(y + 1).at(x + 1))
459 result += PENALTY_N2;
460 }
461 }
462
463 // Finder-like pattern in rows
464 for (int y = 0; y < size; y++) {
465 for (int x = 0, bits = 0; x < size; x++) {
466 bits = ((bits << 1) & 0x7FF) | (modules.at(y).at(x) ? 1 : 0);
467 if (x >= 10 && (bits == 0x05D || bits == 0x5D0)) // Needs 11 bits accumulated
468 result += PENALTY_N3;
469 }
470 }
471 // Finder-like pattern in columns
472 for (int x = 0; x < size; x++) {
473 for (int y = 0, bits = 0; y < size; y++) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected