Skip to content
This repository has been archived by the owner on Sep 4, 2019. It is now read-only.

Commit

Permalink
Various bug fixes. (Thanks to Adam Shepherd)
Browse files Browse the repository at this point in the history
  • Loading branch information
fukuchi committed Oct 17, 2011
1 parent 296e792 commit 709a485
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
19 changes: 9 additions & 10 deletions mask.c
Expand Up @@ -2,7 +2,7 @@
* qrencode - QR Code encoder
*
* Masking.
* Copyright (C) 2006-2010 Kentaro Fukuchi <kentaro@fukuchi.org>
* Copyright (C) 2006-2011 Kentaro Fukuchi <kentaro@fukuchi.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -203,10 +203,10 @@ __STATIC int Mask_calcN1N3(int length, int *runLength)
runLength[i-1] == fact &&
runLength[i+1] == fact &&
runLength[i+2] == fact) {
if(runLength[i-3] < 0 || runLength[i-3] >= 4 * fact) {
if(i == 3 || runLength[i-3] >= 4 * fact) {
demerit += N3;
//n3 += N3;
} else if(i+3 >= length || runLength[i+3] >= 4 * fact) {
} else if(i+4 >= length || runLength[i+3] >= 4 * fact) {
demerit += N3;
//n3 += N3;
}
Expand Down Expand Up @@ -249,9 +249,6 @@ __STATIC int Mask_calcRunLength(int width, unsigned char *frame, int dir, int *r
int pitch;

pitch = (dir==0)?1:width;
for(i=0; i<width+1; i++) {
runLength[i] = 0;
}
if(frame[0] & 1) {
runLength[0] = -1;
head = 1;
Expand Down Expand Up @@ -303,9 +300,11 @@ unsigned char *Mask_mask(int width, unsigned char *frame, QRecLevel level)
int minDemerit = INT_MAX;
int bestMaskNum = 0;
int blacks;
int bratio;
int demerit;
int w2 = width * width;

mask = (unsigned char *)malloc(width * width);
mask = (unsigned char *)malloc(w2);
if(mask == NULL) return NULL;
bestMask = NULL;

Expand All @@ -314,8 +313,8 @@ unsigned char *Mask_mask(int width, unsigned char *frame, QRecLevel level)
demerit = 0;
blacks = maskMakers[i](width, frame, mask);
blacks += Mask_writeFormatInformation(width, mask, i, level);
blacks = 100 * blacks / (width * width);
demerit = (abs(blacks - 50) / 5) * N4;
bratio = (200 * blacks + w2) / w2 / 2; /* (int)(100*blacks/w2+0.5) */
demerit = (abs(bratio - 50) / 5) * N4;
// n4 = demerit;
demerit += Mask_evaluateSymbol(width, mask);
// printf("(%d,%d,%d,%d)=%d\n", n1, n2, n3 ,n4, demerit);
Expand All @@ -324,7 +323,7 @@ unsigned char *Mask_mask(int width, unsigned char *frame, QRecLevel level)
bestMaskNum = i;
free(bestMask);
bestMask = mask;
mask = (unsigned char *)malloc(width * width);
mask = (unsigned char *)malloc(w2);
if(mask == NULL) break;
}
}
Expand Down
3 changes: 2 additions & 1 deletion mask.h
Expand Up @@ -2,7 +2,7 @@
* qrencode - QR Code encoder
*
* Masking.
* Copyright (C) 2006-2010 Kentaro Fukuchi <kentaro@fukuchi.org>
* Copyright (C) 2006-2011 Kentaro Fukuchi <kentaro@fukuchi.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand All @@ -27,6 +27,7 @@ extern unsigned char *Mask_mask(int width, unsigned char *frame, QRecLevel level

#ifdef WITH_TESTS
extern int Mask_calcN2(int width, unsigned char *frame);
extern int Mask_calcN1N3(int length, int *runLength);
extern int Mask_calcRunLength(int width, unsigned char *frame, int dir, int *runLength);
extern int Mask_evaluateSymbol(int width, unsigned char *frame);
extern int Mask_writeFormatInformation(int width, unsigned char *frame, int mask, QRecLevel level);
Expand Down

0 comments on commit 709a485

Please sign in to comment.