Revised data mask scoring

Revision of 4 tests from Table 11, reflecting clarification given in ISO/IEC 18004:2015
This commit is contained in:
Robin Stuart 2016-02-17 20:31:50 +00:00
parent 97a7afa246
commit 001a0a88d9

View File

@ -406,8 +406,6 @@ void qr_binary(int datastream[], int version, int target_binlen, char mode[], in
position += short_data_block_length; position += short_data_block_length;
} while (position < length) ; } while (position < length) ;
printf("Actual binary: %d\n", (int) strlen(binary));
/* Terminator */ /* Terminator */
concat(binary, "0000"); concat(binary, "0000");
@ -765,14 +763,13 @@ int write_log(char log[])
int evaluate(unsigned char *grid, int size, int pattern) int evaluate(unsigned char *grid, int size, int pattern)
{ {
int x, y, block; int x, y, block, weight;
int result = 0; int result = 0;
char state; char state;
int p; int p;
int dark_mods; int dark_mods;
int percentage, k, k2; int percentage, k;
int m; int a, b, afterCount, beforeCount;
int smallest;
#ifdef ZINTLOG #ifdef ZINTLOG
int result_b = 0; int result_b = 0;
char str[15]; char str[15];
@ -864,24 +861,17 @@ int evaluate(unsigned char *grid, int size, int pattern)
write_log(str); write_log(str);
#endif #endif
/* Test 2 fd02131114 */ /* Test 2: Block of modules in same color */
for(x = 0; x < size-1; x++) { for (x = 0; x < size - 1; x++) {
for(y = 0; y < (size - 7) -1; y++) { for (y = 0; y < size - 1; y++) {
// y + 1??? if (((local[(y * size) + x] == local[((y + 1) * size) + x]) &&
if((local[((y + 1) * size) + x] == '1') && (local[(y * size) + x] == local[(y * size) + (x + 1)])) &&
(local[((y + 1) * size) + x+1] == '1') && (local[(y * size) + x] == local[((y + 1) * size) + (x + 1)])) {
(local[(((y + 1)+1) * size) + x] == '1') && result += 3;
(local[(((y + 1)+1) * size) + x+1] == '1') }
) { result += 3; } }
}
if((local[((y + 1) * size) + x] == '0') &&
(local[((y + 1) * size) + x+1] == '0') &&
(local[(((y + 1)+1) * size) + x] == '0') &&
(local[(((y + 1)+1) * size) + x+1] == '0')
) { result += 3; }
}
}
#ifdef ZINTLOG #ifdef ZINTLOG
/* output Test 2 */ /* output Test 2 */
sprintf(str, "%d", result-result_b); sprintf(str, "%d", result-result_b);
@ -889,92 +879,98 @@ int evaluate(unsigned char *grid, int size, int pattern)
write_log(str); write_log(str);
#endif #endif
/* Test 3: fd02131114 */ /* Test 3: 1:1:3:1:1 ratio pattern in row/column */
/*pattern 10111010000 */ /* Vertical */
/* Vertical */ for (x = 0; x < size; x++) {
for(x = 0; x < size; x++) { for (y = 0; y < (size - 7); y++) {
for(y = 0; y < (size - 11); y++) { p = 0;
p = 0; for (weight = 0; weight < 7; weight++) {
if(local[(y * size) + x] == '1') { p += 1; } if (local[((y + weight) * size) + x] == '1') {
if(local[((y + 1) * size) + x] == '0') { p += 1; } p += (0x40 >> weight);
if(local[((y + 2) * size) + x] == '1') { p += 1; } }
if(local[((y + 3) * size) + x] == '1') { p += 1; } }
if(local[((y + 4) * size) + x] == '1') { p += 1; } if (p == 0x5d) {
if(local[((y + 5) * size) + x] == '0') { p += 1; } /* Pattern found, check before and after */
if(local[((y + 6) * size) + x] == '1') { p += 1; } beforeCount = 0;
if(local[((y + 7) * size) + x] == '0') { p += 1; } for (b = (y - 4); b < y; b++) {
if(local[((y + 8) * size) + x] == '0') { p += 1; } if (b < 0) {
if(local[((y + 9) * size) + x] == '0') { p += 1; } beforeCount++;
if(local[((y + 10) * size) + x] == '0') { p += 1; } } else {
if(p == 11) { if (local[(b * size) + x] == '0') {
result += 40; beforeCount++;
} } else {
} beforeCount = 0;
} }
}
}
afterCount = 0;
for (a = (y + 7); a <= (y + 10); a++) {
if (a >= size) {
afterCount++;
} else {
if (local[(a * size) + x] == '0') {
afterCount++;
} else {
afterCount = 0;
}
}
}
if ((beforeCount == 4) || (afterCount == 4)) {
/* Pattern is preceeded or followed by light area
4 modules wide */
result += 40;
}
}
}
}
/* Horizontal */ /* Horizontal */
for(y = 0; y < size; y++) { for (y = 0; y < size; y++) {
for(x = 0; x < (size - 11); x++) { for (x = 0; x < (size - 7); x++) {
p = 0; p = 0;
if(local[(y * size) + x] == '1') { p += 1; } for (weight = 0; weight < 7; weight++) {
if(local[(y * size) + x + 1] == '0') { p += 1; } if (local[(y * size) + x + weight] == '1') {
if(local[(y * size) + x + 2] == '1') { p += 1; } p += (0x40 >> weight);
if(local[(y * size) + x + 3] == '1') { p += 1; } }
if(local[(y * size) + x + 4] == '1') { p += 1; } }
if(local[(y * size) + x + 5] == '0') { p += 1; } if (p == 0x5d) {
if(local[(y * size) + x + 6] == '1') { p += 1; } /* Pattern found, check before and after */
if(local[(y * size) + x + 7] == '0') { p += 1; } beforeCount = 0;
if(local[(y * size) + x + 8] == '0') { p += 1; } for (b = (x - 4); b < x; b++) {
if(local[(y * size) + x + 9] == '0') { p += 1; } if (b < 0) {
if(local[(y * size) + x + 10] == '0') { p += 1; } beforeCount++;
if(p == 11) { } else {
result += 40; if (local[(y * size) + b] == '0') {
} beforeCount++;
} } else {
} beforeCount = 0;
}
/*pattern 00001011101 */ }
/* Vertical */ }
for(x = 0; x < size; x++) {
for(y = 0; y < (size - 11); y++) { afterCount = 0;
p = 0; for (a = (x + 7); a <= (x + 10); a++) {
if(local[(y * size) + x] == '0') { p += 1; } if (a >= size) {
if(local[((y + 1) * size) + x] == '0') { p += 1; } afterCount++;
if(local[((y + 2) * size) + x] == '0') { p += 1; } } else {
if(local[((y + 3) * size) + x] == '0') { p += 1; } if (local[(y * size) + a] == '0') {
if(local[((y + 4) * size) + x] == '1') { p += 1; } afterCount++;
if(local[((y + 5) * size) + x] == '0') { p += 1; } } else {
if(local[((y + 6) * size) + x] == '1') { p += 1; } afterCount = 0;
if(local[((y + 7) * size) + x] == '1') { p += 1; } }
if(local[((y + 8) * size) + x] == '1') { p += 1; } }
if(local[((y + 9) * size) + x] == '0') { p += 1; } }
if(local[((y + 10) * size) + x] == '1') { p += 1; }
if(p == 11) { if ((beforeCount == 4) || (afterCount == 4)) {
result += 40; /* Pattern is preceeded or followed by light area
} 4 modules wide */
} result += 40;
} }
}
/* Horizontal */ }
for(y = 0; y < size; y++) { }
for(x = 0; x < (size - 11); x++) {
p = 0;
if(local[(y * size) + x] == '0') { p += 1; }
if(local[(y * size) + x + 1] == '0') { p += 1; }
if(local[(y * size) + x + 2] == '0') { p += 1; }
if(local[(y * size) + x + 3] == '0') { p += 1; }
if(local[(y * size) + x + 4] == '1') { p += 1; }
if(local[(y * size) + x + 5] == '0') { p += 1; }
if(local[(y * size) + x + 6] == '1') { p += 1; }
if(local[(y * size) + x + 7] == '1') { p += 1; }
if(local[(y * size) + x + 8] == '1') { p += 1; }
if(local[(y * size) + x + 9] == '0') { p += 1; }
if(local[(y * size) + x + 10] == '1') { p += 1; }
if(p == 11) {
result += 40;
}
}
}
#ifdef ZINTLOG #ifdef ZINTLOG
/* output Test 3 */ /* output Test 3 */
@ -993,21 +989,13 @@ int evaluate(unsigned char *grid, int size, int pattern)
} }
} }
percentage = 100 * (dark_mods / (size * size)); percentage = 100 * (dark_mods / (size * size));
m=0; if (percentage <= 50) {
for(x = 0; x < 100; x+=5) { k = ((100 - percentage) - 50) / 5;
if(x<percentage) } else {
m=x; k = (percentage - 50) / 5;
} }
result += 10 * k;
k=abs((m-50)/5);
k2=abs((m+5-50)/5);
smallest=k;
if(k2<smallest)
smallest=k2;
result += 10 * smallest;
#ifdef ZINTLOG #ifdef ZINTLOG
/* output Test 4+summary */ /* output Test 4+summary */