Skip to content

Commit

Permalink
Some code cleanups.
Browse files Browse the repository at this point in the history
  • Loading branch information
fukuchi committed May 4, 2015
1 parent d75eee5 commit fb7c980
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 96 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* qrenc.c:
- X Pixmap (XPM) support has been added. (closes #52)
(Thanks to @tklauser)
* Some code cleanups.

2015.05.04 Kentaro Fukuchi <kentaro@fukuchi.org>
* qrenc.c:
Expand Down
12 changes: 6 additions & 6 deletions bitstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ static void BitStream_writeNum(unsigned char *dest, int bits, unsigned int num)

p = dest;
mask = 1 << (bits - 1);
for(i=0; i<bits; i++) {
for(i = 0; i < bits; i++) {
if(num & mask) {
*p = 1;
} else {
Expand All @@ -89,9 +89,9 @@ static void BitStream_writeBytes(unsigned char *dest, int size, unsigned char *d
unsigned char *p;

p = dest;
for(i=0; i<size; i++) {
for(i = 0; i < size; i++) {
mask = 0x80;
for(j=0; j<8; j++) {
for(j = 0; j < 8; j++) {
if(data[i] & mask) {
*p = 1;
} else {
Expand Down Expand Up @@ -175,9 +175,9 @@ unsigned char *BitStream_toByte(BitStream *bstream)
bytes = size / 8;

p = bstream->data;
for(i=0; i<bytes; i++) {
for(i = 0; i < bytes; i++) {
v = 0;
for(j=0; j<8; j++) {
for(j = 0; j < 8; j++) {
v = v << 1;
v |= *p;
p++;
Expand All @@ -186,7 +186,7 @@ unsigned char *BitStream_toByte(BitStream *bstream)
}
if(size & 7) {
v = 0;
for(j=0; j<(size & 7); j++) {
for(j = 0; j < (size & 7); j++) {
v = v << 1;
v |= *p;
p++;
Expand Down
24 changes: 12 additions & 12 deletions mask.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ __STATIC int Mask_writeFormatInformation(int width, unsigned char *frame, int ma

format = QRspec_getFormatInfo(mask, level);

for(i=0; i<8; i++) {
for(i = 0; i < 8; i++) {
if(format & 1) {
blacks += 2;
v = 0x85;
Expand All @@ -55,7 +55,7 @@ __STATIC int Mask_writeFormatInformation(int width, unsigned char *frame, int ma
}
format= format >> 1;
}
for(i=0; i<7; i++) {
for(i = 0; i < 7; i++) {
if(format & 1) {
blacks += 2;
v = 0x85;
Expand Down Expand Up @@ -87,8 +87,8 @@ __STATIC int Mask_writeFormatInformation(int width, unsigned char *frame, int ma
int x, y;\
int b = 0;\
\
for(y=0; y<width; y++) {\
for(x=0; x<width; x++) {\
for(y = 0; y < width; y++) {\
for(x = 0; x < width; x++) {\
if(*s & 0x80) {\
*d = *s;\
} else {\
Expand Down Expand Up @@ -191,7 +191,7 @@ __STATIC int Mask_calcN1N3(int length, int *runLength)
int demerit = 0;
int fact;

for(i=0; i<length; i++) {
for(i = 0; i < length; i++) {
if(runLength[i] >= 5) {
demerit += N1 + (runLength[i] - 5);
//n1 += N1 + (runLength[i] - 5);
Expand Down Expand Up @@ -226,8 +226,8 @@ __STATIC int Mask_calcN2(int width, unsigned char *frame)
int demerit = 0;

p = frame + width + 1;
for(y=1; y<width; y++) {
for(x=1; x<width; x++) {
for(y = 1; y < width; y++) {
for(x = 1; x < width; x++) {
b22 = p[0] & p[-1] & p[-width] & p [-width-1];
w22 = p[0] | p[-1] | p[-width] | p [-width-1];
if((b22 | (w22 ^ 1))&1) {
Expand Down Expand Up @@ -256,7 +256,7 @@ __STATIC int Mask_calcRunLengthH(int width, unsigned char *frame, int *runLength
runLength[head] = 1;
prev = frame[0];

for(i=1; i<width; i++) {
for(i = 1; i < width; i++) {
if((frame[i] ^ prev) & 1) {
head++;
runLength[head] = 1;
Expand Down Expand Up @@ -284,7 +284,7 @@ __STATIC int Mask_calcRunLengthV(int width, unsigned char *frame, int *runLength
runLength[head] = 1;
prev = frame[0];

for(i=1; i<width; i++) {
for(i = 1; i < width; i++) {
if((frame[i * width] ^ prev) & 1) {
head++;
runLength[head] = 1;
Expand All @@ -306,12 +306,12 @@ __STATIC int Mask_evaluateSymbol(int width, unsigned char *frame)

demerit += Mask_calcN2(width, frame);

for(y=0; y<width; y++) {
for(y = 0; y < width; y++) {
length = Mask_calcRunLengthH(width, frame + y * width, runLength);
demerit += Mask_calcN1N3(length, runLength);
}

for(x=0; x<width; x++) {
for(x = 0; x < width; x++) {
length = Mask_calcRunLengthV(width, frame + x, runLength);
demerit += Mask_calcN1N3(length, runLength);
}
Expand All @@ -337,7 +337,7 @@ unsigned char *Mask_mask(int width, unsigned char *frame, QRecLevel level)
return NULL;
}

for(i=0; i<maskNum; i++) {
for(i = 0; i < maskNum; i++) {
// n1 = n2 = n3 = n4 = 0;
demerit = 0;
blacks = maskMakers[i](width, frame, mask);
Expand Down
14 changes: 7 additions & 7 deletions mmask.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ __STATIC void MMask_writeFormatInformation(int version, int width, unsigned char

format = MQRspec_getFormatInfo(mask, version, level);

for(i=0; i<8; i++) {
for(i = 0; i < 8; i++) {
v = 0x84 | (format & 1);
frame[width * (i + 1) + 8] = v;
format = format >> 1;
}
for(i=0; i<7; i++) {
for(i = 0; i < 7; i++) {
v = 0x84 | (format & 1);
frame[width * 8 + 7 - i] = v;
format = format >> 1;
Expand All @@ -54,8 +54,8 @@ __STATIC void MMask_writeFormatInformation(int version, int width, unsigned char
#define MASKMAKER(__exp__) \
int x, y;\
\
for(y=0; y<width; y++) {\
for(x=0; x<width; x++) {\
for(y = 0; y < width; y++) {\
for(x = 0; x < width; x++) {\
if(*s & 0x80) {\
*d = *s;\
} else {\
Expand Down Expand Up @@ -132,12 +132,12 @@ __STATIC int MMask_evaluateSymbol(int width, unsigned char *frame)
int sum1 = 0, sum2 = 0;

p = frame + width * (width - 1);
for(x=1; x<width; x++) {
for(x = 1; x < width; x++) {
sum1 += (p[x] & 1);
}

p = frame + width * 2 - 1;
for(y=1; y<width; y++) {
for(y = 1; y < width; y++) {
sum2 += (*p & 1);
p += width;
}
Expand All @@ -159,7 +159,7 @@ unsigned char *MMask_mask(int version, unsigned char *frame, QRecLevel level)
if(mask == NULL) return NULL;
bestMask = NULL;

for(i=0; i<maskNum; i++) {
for(i = 0; i < maskNum; i++) {
score = 0;
maskMakers[i](width, frame, mask);
MMask_writeFormatInformation(version, width, mask, i, level);
Expand Down
10 changes: 5 additions & 5 deletions mqrspec.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ static void putFinderPattern(unsigned char *frame, int width, int ox, int oy)

frame += oy * width + ox;
s = finder;
for(y=0; y<7; y++) {
for(x=0; x<7; x++) {
for(y = 0; y < 7; y++) {
for(x = 0; x < 7; x++) {
frame[x] = s[x];
}
frame += width;
Expand All @@ -199,22 +199,22 @@ static unsigned char *MQRspec_createFrame(int version)
putFinderPattern(frame, width, 0, 0);
/* Separator */
p = frame;
for(y=0; y<7; y++) {
for(y = 0; y < 7; y++) {
p[7] = 0xc0;
p += width;
}
memset(frame + width * 7, 0xc0, 8);
/* Mask format information area */
memset(frame + width * 8 + 1, 0x84, 8);
p = frame + width + 8;
for(y=0; y<7; y++) {
for(y = 0; y < 7; y++) {
*p = 0x84;
p += width;
}
/* Timing pattern */
p = frame + 8;
q = frame + width * 8;
for(x=1; x<width-7; x++) {
for(x = 1; x < width-7; x++) {
*p = 0x90 | (x & 1);
*q = 0x90 | (x & 1);
p++;
Expand Down
Loading

0 comments on commit fb7c980

Please sign in to comment.