mirror of
https://git.code.sf.net/p/zint/code
synced 2025-05-13 22:54:35 -04:00
QRCODE: fix dark mods count and percentage calc broken by [cd214a]
This commit is contained in:
parent
6322c0c2b0
commit
fe70911ea3
11 changed files with 178 additions and 154 deletions
14
backend/qr.c
14
backend/qr.c
|
@ -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;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue