QRCODE: fix dark mods count and percentage calc broken by [cd214a]

This commit is contained in:
gitlost 2020-12-10 19:48:52 +00:00
parent 6322c0c2b0
commit fe70911ea3
11 changed files with 178 additions and 154 deletions

View File

@ -1069,6 +1069,7 @@ static int evaluate(unsigned char *local, const int size) {
}
/* Horizontal */
dark_mods = 0; /* Count dark mods simultaneously (see Test 4 below) */
for (y = 0; y < size; y++) {
r = y * size;
block = 0;
@ -1083,6 +1084,9 @@ static int evaluate(unsigned char *local, const int size) {
block = 1;
state = local[r + x];
}
if (state) {
dark_mods++;
}
}
if (block >= 5) {
result += block - 2;
@ -1097,7 +1101,6 @@ static int evaluate(unsigned char *local, const int size) {
#endif
/* Test 2: Block of modules in same color */
dark_mods = 0; /* Count dark mods simultaneously (see Test 4 below) */
for (x = 0; x < size - 1; x++) {
for (y = 0; y < size - 1; y++) {
k = local[(y * size) + x];
@ -1106,9 +1109,6 @@ static int evaluate(unsigned char *local, const int size) {
(k == local[((y + 1) * size) + (x + 1)])) {
result += 3;
}
if (k) {
dark_mods++;
}
}
}
@ -1215,11 +1215,7 @@ static int evaluate(unsigned char *local, const int size) {
/* Test 4: Proportion of dark modules in entire symbol */
percentage = (100.0 * dark_mods) / (size * size);
if (percentage < 50.0) {
k = (int) ceil(((100.0 - percentage) - 50.0) / 5.0);
} else {
k = (int) ceil((percentage - 50.0) / 5.0);
}
k = (int) (fabs(percentage - 50.0) / 5.0);
result += 10 * k;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 398 B

After

Width:  |  Height:  |  Size: 398 B

View File

@ -17,9 +17,9 @@ TE
0.00 0.00 0.00 setrgbcolor
2.00 40.00 TB 0.00 14.00 TR
TE
2.00 40.00 TB 20.00 2.00 TR
2.00 40.00 TB 16.00 2.00 TR
TE
2.00 40.00 TB 24.00 2.00 TR
2.00 40.00 TB 22.00 4.00 TR
TE
2.00 40.00 TB 28.00 14.00 TR
TE
@ -27,147 +27,147 @@ TE
TE
10.00 30.00 TB 12.00 2.00 TR
TE
2.00 38.00 TB 18.00 2.00 TR
TE
2.00 38.00 TB 24.00 2.00 TR
TE
10.00 30.00 TB 28.00 2.00 TR
TE
10.00 30.00 TB 40.00 2.00 TR
TE
6.00 32.00 TB 4.00 6.00 TR
TE
10.00 28.00 TB 16.00 2.00 TR
2.00 36.00 TB 16.00 2.00 TR
TE
2.00 36.00 TB 20.00 2.00 TR
2.00 36.00 TB 22.00 2.00 TR
TE
6.00 32.00 TB 32.00 6.00 TR
TE
2.00 34.00 TB 22.00 2.00 TR
2.00 34.00 TB 18.00 2.00 TR
TE
2.00 32.00 TB 20.00 2.00 TR
6.00 30.00 TB 22.00 4.00 TR
TE
2.00 32.00 TB 24.00 2.00 TR
TE
2.00 30.00 TB 22.00 2.00 TR
2.00 30.00 TB 16.00 4.00 TR
TE
2.00 28.00 TB 0.00 14.00 TR
TE
2.00 28.00 TB 16.00 2.00 TR
TE
2.00 28.00 TB 20.00 2.00 TR
TE
2.00 28.00 TB 24.00 2.00 TR
4.00 26.00 TB 24.00 2.00 TR
TE
2.00 28.00 TB 28.00 14.00 TR
TE
2.00 26.00 TB 16.00 4.00 TR
4.00 22.00 TB 0.00 2.00 TR
TE
2.00 24.00 TB 0.00 2.00 TR
4.00 22.00 TB 4.00 2.00 TR
TE
2.00 24.00 TB 4.00 10.00 TR
2.00 24.00 TB 12.00 4.00 TR
TE
2.00 24.00 TB 22.00 2.00 TR
2.00 24.00 TB 20.00 2.00 TR
TE
2.00 24.00 TB 28.00 10.00 TR
2.00 24.00 TB 30.00 2.00 TR
TE
2.00 22.00 TB 4.00 6.00 TR
2.00 24.00 TB 36.00 2.00 TR
TE
2.00 22.00 TB 16.00 2.00 TR
2.00 24.00 TB 40.00 2.00 TR
TE
2.00 22.00 TB 20.00 10.00 TR
4.00 20.00 TB 8.00 2.00 TR
TE
2.00 22.00 TB 34.00 8.00 TR
2.00 22.00 TB 16.00 8.00 TR
TE
2.00 20.00 TB 0.00 2.00 TR
2.00 22.00 TB 26.00 6.00 TR
TE
2.00 20.00 TB 10.00 6.00 TR
2.00 22.00 TB 34.00 2.00 TR
TE
2.00 20.00 TB 18.00 4.00 TR
2.00 22.00 TB 38.00 4.00 TR
TE
2.00 20.00 TB 24.00 2.00 TR
2.00 20.00 TB 0.00 6.00 TR
TE
2.00 20.00 TB 28.00 4.00 TR
2.00 20.00 TB 12.00 2.00 TR
TE
2.00 20.00 TB 34.00 2.00 TR
2.00 20.00 TB 16.00 4.00 TR
TE
2.00 20.00 TB 40.00 2.00 TR
2.00 20.00 TB 22.00 6.00 TR
TE
2.00 18.00 TB 2.00 2.00 TR
2.00 20.00 TB 30.00 4.00 TR
TE
2.00 18.00 TB 8.00 4.00 TR
2.00 20.00 TB 38.00 2.00 TR
TE
4.00 16.00 TB 0.00 4.00 TR
TE
2.00 18.00 TB 6.00 6.00 TR
TE
2.00 18.00 TB 14.00 2.00 TR
TE
2.00 18.00 TB 22.00 8.00 TR
4.00 16.00 TB 18.00 2.00 TR
TE
2.00 18.00 TB 36.00 6.00 TR
2.00 18.00 TB 22.00 2.00 TR
TE
2.00 16.00 TB 0.00 2.00 TR
2.00 18.00 TB 26.00 6.00 TR
TE
2.00 16.00 TB 4.00 4.00 TR
2.00 18.00 TB 38.00 4.00 TR
TE
2.00 16.00 TB 12.00 2.00 TR
2.00 16.00 TB 6.00 10.00 TR
TE
4.00 14.00 TB 16.00 6.00 TR
2.00 16.00 TB 22.00 14.00 TR
TE
4.00 14.00 TB 24.00 2.00 TR
2.00 16.00 TB 40.00 2.00 TR
TE
4.00 14.00 TB 30.00 2.00 TR
2.00 14.00 TB 16.00 2.00 TR
TE
2.00 16.00 TB 38.00 2.00 TR
TE
2.00 14.00 TB 36.00 2.00 TR
2.00 14.00 TB 20.00 2.00 TR
TE
2.00 12.00 TB 0.00 14.00 TR
TE
2.00 12.00 TB 18.00 2.00 TR
2.00 12.00 TB 16.00 6.00 TR
TE
2.00 12.00 TB 22.00 2.00 TR
2.00 12.00 TB 28.00 2.00 TR
TE
2.00 12.00 TB 26.00 2.00 TR
TE
2.00 12.00 TB 32.00 4.00 TR
TE
4.00 10.00 TB 40.00 2.00 TR
2.00 12.00 TB 38.00 2.00 TR
TE
10.00 2.00 TB 0.00 2.00 TR
TE
10.00 2.00 TB 12.00 2.00 TR
TE
4.00 8.00 TB 16.00 4.00 TR
2.00 10.00 TB 24.00 2.00 TR
TE
2.00 10.00 TB 30.00 4.00 TR
2.00 10.00 TB 32.00 2.00 TR
TE
2.00 10.00 TB 36.00 2.00 TR
2.00 10.00 TB 40.00 2.00 TR
TE
6.00 4.00 TB 4.00 6.00 TR
TE
2.00 8.00 TB 22.00 2.00 TR
2.00 8.00 TB 18.00 4.00 TR
TE
2.00 8.00 TB 26.00 2.00 TR
2.00 8.00 TB 28.00 2.00 TR
TE
2.00 8.00 TB 32.00 6.00 TR
2.00 8.00 TB 36.00 6.00 TR
TE
2.00 6.00 TB 16.00 2.00 TR
2.00 6.00 TB 18.00 6.00 TR
TE
2.00 6.00 TB 20.00 12.00 TR
2.00 6.00 TB 26.00 4.00 TR
TE
4.00 4.00 TB 34.00 4.00 TR
2.00 6.00 TB 34.00 2.00 TR
TE
2.00 4.00 TB 16.00 6.00 TR
2.00 4.00 TB 16.00 4.00 TR
TE
2.00 4.00 TB 24.00 2.00 TR
2.00 4.00 TB 22.00 6.00 TR
TE
2.00 4.00 TB 28.00 4.00 TR
2.00 4.00 TB 30.00 4.00 TR
TE
2.00 2.00 TB 18.00 2.00 TR
2.00 4.00 TB 36.00 6.00 TR
TE
2.00 2.00 TB 22.00 10.00 TR
2.00 2.00 TB 22.00 2.00 TR
TE
2.00 2.00 TB 36.00 4.00 TR
2.00 2.00 TB 26.00 4.00 TR
TE
2.00 2.00 TB 38.00 2.00 TR
TE
2.00 0.00 TB 0.00 14.00 TR
TE
2.00 0.00 TB 16.00 2.00 TR
TE
2.00 0.00 TB 24.00 2.00 TR
TE
2.00 0.00 TB 30.00 2.00 TR
TE
2.00 0.00 TB 36.00 2.00 TR
2.00 0.00 TB 20.00 22.00 TR
TE

Binary file not shown.

Before

Width:  |  Height:  |  Size: 247 B

After

Width:  |  Height:  |  Size: 244 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 287 B

After

Width:  |  Height:  |  Size: 288 B

View File

@ -9,82 +9,82 @@
<g id="barcode" fill="#000000">
<rect x="0" y="0" width="42" height="42" fill="#FFFFFF" />
<rect x="0.00" y="0.00" width="14.00" height="2.00" />
<rect x="20.00" y="0.00" width="2.00" height="2.00" />
<rect x="24.00" y="0.00" width="2.00" height="2.00" />
<rect x="16.00" y="0.00" width="2.00" height="2.00" />
<rect x="22.00" y="0.00" width="4.00" height="2.00" />
<rect x="28.00" y="0.00" width="14.00" height="2.00" />
<rect x="0.00" y="2.00" width="2.00" height="10.00" />
<rect x="12.00" y="2.00" width="2.00" height="10.00" />
<rect x="18.00" y="2.00" width="2.00" height="2.00" />
<rect x="24.00" y="2.00" width="2.00" height="2.00" />
<rect x="28.00" y="2.00" width="2.00" height="10.00" />
<rect x="40.00" y="2.00" width="2.00" height="10.00" />
<rect x="4.00" y="4.00" width="6.00" height="6.00" />
<rect x="16.00" y="4.00" width="2.00" height="10.00" />
<rect x="20.00" y="4.00" width="2.00" height="2.00" />
<rect x="16.00" y="4.00" width="2.00" height="2.00" />
<rect x="22.00" y="4.00" width="2.00" height="2.00" />
<rect x="32.00" y="4.00" width="6.00" height="6.00" />
<rect x="22.00" y="6.00" width="2.00" height="2.00" />
<rect x="20.00" y="8.00" width="2.00" height="2.00" />
<rect x="24.00" y="8.00" width="2.00" height="2.00" />
<rect x="22.00" y="10.00" width="2.00" height="2.00" />
<rect x="18.00" y="6.00" width="2.00" height="2.00" />
<rect x="22.00" y="6.00" width="4.00" height="6.00" />
<rect x="16.00" y="10.00" width="4.00" height="2.00" />
<rect x="0.00" y="12.00" width="14.00" height="2.00" />
<rect x="16.00" y="12.00" width="2.00" height="2.00" />
<rect x="20.00" y="12.00" width="2.00" height="2.00" />
<rect x="24.00" y="12.00" width="2.00" height="2.00" />
<rect x="24.00" y="12.00" width="2.00" height="4.00" />
<rect x="28.00" y="12.00" width="14.00" height="2.00" />
<rect x="16.00" y="14.00" width="4.00" height="2.00" />
<rect x="0.00" y="16.00" width="2.00" height="2.00" />
<rect x="4.00" y="16.00" width="10.00" height="2.00" />
<rect x="22.00" y="16.00" width="2.00" height="2.00" />
<rect x="28.00" y="16.00" width="10.00" height="2.00" />
<rect x="4.00" y="18.00" width="6.00" height="2.00" />
<rect x="16.00" y="18.00" width="2.00" height="2.00" />
<rect x="20.00" y="18.00" width="10.00" height="2.00" />
<rect x="34.00" y="18.00" width="8.00" height="2.00" />
<rect x="0.00" y="20.00" width="2.00" height="2.00" />
<rect x="10.00" y="20.00" width="6.00" height="2.00" />
<rect x="18.00" y="20.00" width="4.00" height="2.00" />
<rect x="24.00" y="20.00" width="2.00" height="2.00" />
<rect x="28.00" y="20.00" width="4.00" height="2.00" />
<rect x="34.00" y="20.00" width="2.00" height="2.00" />
<rect x="40.00" y="20.00" width="2.00" height="2.00" />
<rect x="2.00" y="22.00" width="2.00" height="2.00" />
<rect x="8.00" y="22.00" width="4.00" height="2.00" />
<rect x="0.00" y="16.00" width="2.00" height="4.00" />
<rect x="4.00" y="16.00" width="2.00" height="4.00" />
<rect x="12.00" y="16.00" width="4.00" height="2.00" />
<rect x="20.00" y="16.00" width="2.00" height="2.00" />
<rect x="30.00" y="16.00" width="2.00" height="2.00" />
<rect x="36.00" y="16.00" width="2.00" height="2.00" />
<rect x="40.00" y="16.00" width="2.00" height="2.00" />
<rect x="8.00" y="18.00" width="2.00" height="4.00" />
<rect x="16.00" y="18.00" width="8.00" height="2.00" />
<rect x="26.00" y="18.00" width="6.00" height="2.00" />
<rect x="34.00" y="18.00" width="2.00" height="2.00" />
<rect x="38.00" y="18.00" width="4.00" height="2.00" />
<rect x="0.00" y="20.00" width="6.00" height="2.00" />
<rect x="12.00" y="20.00" width="2.00" height="2.00" />
<rect x="16.00" y="20.00" width="4.00" height="2.00" />
<rect x="22.00" y="20.00" width="6.00" height="2.00" />
<rect x="30.00" y="20.00" width="4.00" height="2.00" />
<rect x="38.00" y="20.00" width="2.00" height="2.00" />
<rect x="0.00" y="22.00" width="4.00" height="4.00" />
<rect x="6.00" y="22.00" width="6.00" height="2.00" />
<rect x="14.00" y="22.00" width="2.00" height="2.00" />
<rect x="22.00" y="22.00" width="8.00" height="2.00" />
<rect x="36.00" y="22.00" width="6.00" height="2.00" />
<rect x="0.00" y="24.00" width="2.00" height="2.00" />
<rect x="4.00" y="24.00" width="4.00" height="2.00" />
<rect x="12.00" y="24.00" width="2.00" height="2.00" />
<rect x="16.00" y="24.00" width="6.00" height="4.00" />
<rect x="24.00" y="24.00" width="2.00" height="4.00" />
<rect x="30.00" y="24.00" width="2.00" height="4.00" />
<rect x="38.00" y="24.00" width="2.00" height="2.00" />
<rect x="36.00" y="26.00" width="2.00" height="2.00" />
<rect x="18.00" y="22.00" width="2.00" height="4.00" />
<rect x="22.00" y="22.00" width="2.00" height="2.00" />
<rect x="26.00" y="22.00" width="6.00" height="2.00" />
<rect x="38.00" y="22.00" width="4.00" height="2.00" />
<rect x="6.00" y="24.00" width="10.00" height="2.00" />
<rect x="22.00" y="24.00" width="14.00" height="2.00" />
<rect x="40.00" y="24.00" width="2.00" height="2.00" />
<rect x="16.00" y="26.00" width="2.00" height="2.00" />
<rect x="20.00" y="26.00" width="2.00" height="2.00" />
<rect x="0.00" y="28.00" width="14.00" height="2.00" />
<rect x="18.00" y="28.00" width="2.00" height="2.00" />
<rect x="22.00" y="28.00" width="2.00" height="2.00" />
<rect x="26.00" y="28.00" width="2.00" height="2.00" />
<rect x="32.00" y="28.00" width="4.00" height="2.00" />
<rect x="40.00" y="28.00" width="2.00" height="4.00" />
<rect x="16.00" y="28.00" width="6.00" height="2.00" />
<rect x="28.00" y="28.00" width="2.00" height="2.00" />
<rect x="38.00" y="28.00" width="2.00" height="2.00" />
<rect x="0.00" y="30.00" width="2.00" height="10.00" />
<rect x="12.00" y="30.00" width="2.00" height="10.00" />
<rect x="16.00" y="30.00" width="4.00" height="4.00" />
<rect x="30.00" y="30.00" width="4.00" height="2.00" />
<rect x="36.00" y="30.00" width="2.00" height="2.00" />
<rect x="24.00" y="30.00" width="2.00" height="2.00" />
<rect x="32.00" y="30.00" width="2.00" height="2.00" />
<rect x="40.00" y="30.00" width="2.00" height="2.00" />
<rect x="4.00" y="32.00" width="6.00" height="6.00" />
<rect x="22.00" y="32.00" width="2.00" height="2.00" />
<rect x="26.00" y="32.00" width="2.00" height="2.00" />
<rect x="32.00" y="32.00" width="6.00" height="2.00" />
<rect x="16.00" y="34.00" width="2.00" height="2.00" />
<rect x="20.00" y="34.00" width="12.00" height="2.00" />
<rect x="34.00" y="34.00" width="4.00" height="4.00" />
<rect x="16.00" y="36.00" width="6.00" height="2.00" />
<rect x="24.00" y="36.00" width="2.00" height="2.00" />
<rect x="28.00" y="36.00" width="4.00" height="2.00" />
<rect x="18.00" y="38.00" width="2.00" height="2.00" />
<rect x="22.00" y="38.00" width="10.00" height="2.00" />
<rect x="36.00" y="38.00" width="4.00" height="2.00" />
<rect x="18.00" y="32.00" width="4.00" height="2.00" />
<rect x="28.00" y="32.00" width="2.00" height="2.00" />
<rect x="36.00" y="32.00" width="6.00" height="2.00" />
<rect x="18.00" y="34.00" width="6.00" height="2.00" />
<rect x="26.00" y="34.00" width="4.00" height="2.00" />
<rect x="34.00" y="34.00" width="2.00" height="2.00" />
<rect x="16.00" y="36.00" width="4.00" height="2.00" />
<rect x="22.00" y="36.00" width="6.00" height="2.00" />
<rect x="30.00" y="36.00" width="4.00" height="2.00" />
<rect x="36.00" y="36.00" width="6.00" height="2.00" />
<rect x="22.00" y="38.00" width="2.00" height="2.00" />
<rect x="26.00" y="38.00" width="4.00" height="2.00" />
<rect x="38.00" y="38.00" width="2.00" height="2.00" />
<rect x="0.00" y="40.00" width="14.00" height="2.00" />
<rect x="16.00" y="40.00" width="2.00" height="2.00" />
<rect x="24.00" y="40.00" width="2.00" height="2.00" />
<rect x="30.00" y="40.00" width="2.00" height="2.00" />
<rect x="36.00" y="40.00" width="2.00" height="2.00" />
<rect x="20.00" y="40.00" width="22.00" height="2.00" />
</g>
</svg>

Before

Width:  |  Height:  |  Size: 5.1 KiB

After

Width:  |  Height:  |  Size: 5.1 KiB

View File

@ -1,21 +1,21 @@
FE 2B F8
82 02 08
BA A2 E8
FE 9B F8
82 4A 08
BA 92 E8
BA AA E8
82 92 08
BA 5A E8
BA 1A E8
82 DA 08
FE AB F8
00 C0 00
BE 13 E0
38 BE 78
87 6B 48
4D 1E 38
B2 E9 10
00 E9 20
FE 54 C8
82 C1 A8
BA D4 E0
BA BF 60
BA EB 60
82 5F 30
FE 89 20
00 08 00
A3 21 28
A8 F7 58
EA DD 90
DD 57 18
DF 5F C8
00 A0 00
FE E2 10
82 08 88
BA 62 38
BA 76 40
BA DD B8
82 16 10
FE BF F8

View File

@ -87,6 +87,7 @@ static void test_qr_options(int index, int debug) {
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d\n", i);
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -242,6 +243,7 @@ static void test_qr_input(int index, int generate, int debug) {
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d\n", i);
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -302,6 +304,7 @@ static void test_qr_gs1(int index, int generate, int debug) {
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d\n", i);
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -380,6 +383,7 @@ static void test_qr_optimize(int index, int generate, int debug) {
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d\n", i);
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -1195,12 +1199,36 @@ static void test_qr_encode(int index, int generate, int debug) {
"100000100100111010000"
"111111100011001000110"
},
/* 19*/ { BARCODE_QRCODE, UNICODE_MODE, 2, 1, -1, "1234567890", 0, 21, 21, "test_print example, automatic mask 001 (same score as mask 010)",
"111111101001101111111"
"100000100100101000001"
"101110101001001011101"
"101110100101101011101"
"101110100001101011101"
"100000101101101000001"
"111111101010101111111"
"000000000000100000000"
"101000110010000100101"
"101010001111011101011"
"111010101101110110010"
"110111010101011100011"
"110111110101111111001"
"000000001010000000000"
"111111101110001000010"
"100000100000100010001"
"101110100110001000111"
"101110100111011001000"
"101110101101110110111"
"100000100001011000010"
"111111101011111111111"
},
};
int data_size = ARRAY_SIZE(data);
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d\n", i);
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");