#include #include #include "common.h" #include "../mask.h" #include "../qrspec.h" #include "decoder.h" static char dot[2] = {'_', '#'}; static char *maskPatterns[8] = { /* (i + j) mod 2 = 0 */ "#_#_#_" "_#_#_#" "#_#_#_" "_#_#_#" "#_#_#_" "_#_#_#", /* i mod 2 = 0 */ "######" "______" "######" "______" "######" "______", /* j mod 3 = 0 */ "#__#__" "#__#__" "#__#__" "#__#__" "#__#__" "#__#__", /* (i + j) mod 3 = 0 */ "#__#__" "__#__#" "_#__#_" "#__#__" "__#__#" "_#__#_", /* ((i div 2) + (j div 3)) mod 2 = 0 */ "###___" "###___" "___###" "___###" "###___" "###___", /* (ij) mod 2 + (ij) mod 3 = 0 */ "######" "#_____" "#__#__" "#_#_#_" "#__#__" "#_____", /* ((ij) mod 2 + (ij) mod 3) mod 2 = 0 */ "######" "###___" "##_##_" "#_#_#_" "#_##_#" "#___##", /* ((ij) mod 3 + (i+j) mod 2) mod 2 = 0 */ "#_#_#_" "___###" "#___##" "_#_#_#" "###___" "_###__" }; static void print_mask(int mask) { const unsigned int w = 6; unsigned char frame[w * w], *masked, *p; int x, y; memset(frame, 0, w * w); masked = Mask_makeMaskedFrame(w, frame, mask); p = masked; for(y=0; y> 1; } } penalty = Mask_calcN2(width, frame); assert_equal(penalty, N2 * 4, "Calculation of N2 penalty is wrong: %d, expected %d", penalty, N2 * 4); width = 4; for(y = 0; y < width; y++) { for(x = 0; x < width; x++) { frame[y * width + x] = (((x + 1) & 2) ^ (y & 2)) >> 1; } } penalty = Mask_calcN2(width, frame); assert_equal(penalty, N2 * 2, "Calculation of N2 penalty is wrong: %d, expected %d", penalty, N2 * 2); width = 6; for(y = 0; y < width; y++) { for(x = 0; x < width; x++) { frame[y * width + x] = (x / 3) ^ (y / 3); } } penalty = Mask_calcN2(width, frame); assert_equal(penalty, N2 * 16, "Calculation of N2 penalty is wrong: %d, expected %d", penalty, N2 * 16); testFinish(); } static void test_eval3(void) { unsigned char *frame; int w = 15; int penalty; int x, y; static unsigned char pattern[7][15] = { {0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0}, // N3x1 {1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1}, // N3x1 {1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1}, // N3x1 {1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0}, // 0 {1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1}, // N3x2 {1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0}, // N3 + (N1+1) {1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1} // (N1+1) }; frame = (unsigned char *)malloc(w * w); testStart("Test mask evaluation (1:1:3:1:1 check)"); for(y=0; y<5; y++) { for(x=0; x 1) { print_masks(); } return 0; }