Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug fix & enhancements #72

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions src/alignpat.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function AlignmentPattern(posX, posY, estimatedModuleSize)
});
this.incrementCount = function()
{
this.count++;
++this.count;
}
this.aboutEquals=function( moduleSize, i, j)
{
Expand All @@ -65,13 +65,13 @@ function AlignmentPattern(posX, posY, estimatedModuleSize)
function AlignmentPatternFinder( image, startX, startY, width, height, moduleSize, resultPointCallback)
{
this.image = image;
this.possibleCenters = new Array();
this.possibleCenters = [];
this.startX = startX;
this.startY = startY;
this.width = width;
this.height = height;
this.moduleSize = moduleSize;
this.crossCheckStateCount = new Array(0,0,0);
this.crossCheckStateCount = [0,0,0];
this.resultPointCallback = resultPointCallback;

this.centerFromEnd=function(stateCount, end)
Expand All @@ -82,7 +82,7 @@ function AlignmentPatternFinder( image, startX, startY, width, height, modu
{
var moduleSize = this.moduleSize;
var maxVariance = moduleSize / 2.0;
for (var i = 0; i < 3; i++)
for (var i = 0; i < 3; ++i)
{
if (Math.abs(moduleSize - stateCount[i]) >= maxVariance)
{
Expand All @@ -106,8 +106,8 @@ function AlignmentPatternFinder( image, startX, startY, width, height, modu
var i = startI;
while (i >= 0 && image[centerJ + i*qrcode.width] && stateCount[1] <= maxCount)
{
stateCount[1]++;
i--;
++stateCount[1];
--i;
}
// If already too many modules in this state or ran off the edge:
if (i < 0 || stateCount[1] > maxCount)
Expand All @@ -116,8 +116,8 @@ function AlignmentPatternFinder( image, startX, startY, width, height, modu
}
while (i >= 0 && !image[centerJ + i*qrcode.width] && stateCount[0] <= maxCount)
{
stateCount[0]++;
i--;
++stateCount[0];
--i;
}
if (stateCount[0] > maxCount)
{
Expand All @@ -128,17 +128,17 @@ function AlignmentPatternFinder( image, startX, startY, width, height, modu
i = startI + 1;
while (i < maxI && image[centerJ + i*qrcode.width] && stateCount[1] <= maxCount)
{
stateCount[1]++;
i++;
++stateCount[1];
++i;
}
if (i == maxI || stateCount[1] > maxCount)
{
return NaN;
}
while (i < maxI && !image[centerJ + i*qrcode.width] && stateCount[2] <= maxCount)
{
stateCount[2]++;
i++;
++stateCount[2];
++i;
}
if (stateCount[2] > maxCount)
{
Expand All @@ -163,7 +163,7 @@ function AlignmentPatternFinder( image, startX, startY, width, height, modu
{
var estimatedModuleSize = (stateCount[0] + stateCount[1] + stateCount[2]) / 3.0;
var max = this.possibleCenters.length;
for (var index = 0; index < max; index++)
for (var index = 0; index < max; ++index)
{
var center = this.possibleCenters[index];
// Look for about the same center and module size:
Expand Down Expand Up @@ -191,8 +191,8 @@ function AlignmentPatternFinder( image, startX, startY, width, height, modu
var middleI = startY + (height >> 1);
// We are looking for black/white/black modules in 1:1:1 ratio;
// this tracks the number of black/white/black modules seen so far
var stateCount = new Array(0,0,0);
for (var iGen = 0; iGen < height; iGen++)
var stateCount = [0,0,0];
for (var iGen = 0; iGen < height; ++iGen)
{
// Search from middle outwards
var i = middleI + ((iGen & 0x01) == 0?((iGen + 1) >> 1):- ((iGen + 1) >> 1));
Expand All @@ -205,7 +205,7 @@ function AlignmentPatternFinder( image, startX, startY, width, height, modu
// white run continued to the left of the start point
while (j < maxJ && !image[j + qrcode.width* i])
{
j++;
++j;
}
var currentState = 0;
while (j < maxJ)
Expand All @@ -216,7 +216,7 @@ function AlignmentPatternFinder( image, startX, startY, width, height, modu
if (currentState == 1)
{
// Counting black pixels
stateCount[currentState]++;
++stateCount[currentState];
}
else
{
Expand All @@ -240,7 +240,7 @@ function AlignmentPatternFinder( image, startX, startY, width, height, modu
}
else
{
stateCount[++currentState]++;
++stateCount[++currentState];
}
}
}
Expand All @@ -250,11 +250,11 @@ function AlignmentPatternFinder( image, startX, startY, width, height, modu
if (currentState == 1)
{
// Counting black pixels
currentState++;
++currentState;
}
stateCount[currentState]++;
++stateCount[currentState];
}
j++;
++j;
}
if (this.foundPatternCross(stateCount))
{
Expand Down
15 changes: 5 additions & 10 deletions src/bitmat.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@ function BitMatrix( width, height)
var rowSize = width >> 5;
if ((width & 0x1f) != 0)
{
rowSize++;
++rowSize;
}
this.rowSize = rowSize;
this.bits = new Array(rowSize * height);
for(var i=0;i<this.bits.length;i++)
this.bits[i]=0;
this.bits.fill(0);

this.__defineGetter__("Width", function()
{
Expand Down Expand Up @@ -77,11 +76,7 @@ function BitMatrix( width, height)
}
this.clear=function()
{
var max = this.bits.length;
for (var i = 0; i < max; i++)
{
this.bits[i] = 0;
}
this.bits.fill(0);
}
this.setRegion=function( left, top, width, height)
{
Expand All @@ -99,10 +94,10 @@ function BitMatrix( width, height)
{
throw "The region must fit inside the matrix";
}
for (var y = top; y < bottom; y++)
for (var y = top; y < bottom; ++y)
{
var offset = y * this.rowSize;
for (var x = left; x < right; x++)
for (var x = left; x < right; ++x)
{
this.bits[offset + (x >> 5)] |= 1 << (x & 0x1f);
}
Expand Down
24 changes: 12 additions & 12 deletions src/bmparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function BitMatrixParser(bitMatrix)

// Read top-left format info bits
var formatInfoBits = 0;
for (var i = 0; i < 6; i++)
for (var i = 0; i < 6; ++i)
{
formatInfoBits = this.copyBit(i, 8, formatInfoBits);
}
Expand All @@ -57,7 +57,7 @@ function BitMatrixParser(bitMatrix)
formatInfoBits = this.copyBit(8, 8, formatInfoBits);
formatInfoBits = this.copyBit(8, 7, formatInfoBits);
// .. and skip a bit in the timing pattern ...
for (var j = 5; j >= 0; j--)
for (var j = 5; j >= 0; --j)
{
formatInfoBits = this.copyBit(8, j, formatInfoBits);
}
Expand All @@ -72,11 +72,11 @@ function BitMatrixParser(bitMatrix)
var dimension = this.bitMatrix.Dimension;
formatInfoBits = 0;
var iMin = dimension - 8;
for (var i = dimension - 1; i >= iMin; i--)
for (var i = dimension - 1; i >= iMin; --i)
{
formatInfoBits = this.copyBit(i, 8, formatInfoBits);
}
for (var j = dimension - 7; j < dimension; j++)
for (var j = dimension - 7; j < dimension; ++j)
{
formatInfoBits = this.copyBit(8, j, formatInfoBits);
}
Expand Down Expand Up @@ -107,9 +107,9 @@ function BitMatrixParser(bitMatrix)
// Read top-right version info: 3 wide by 6 tall
var versionBits = 0;
var ijMin = dimension - 11;
for (var j = 5; j >= 0; j--)
for (var j = 5; j >= 0; --j)
{
for (var i = dimension - 9; i >= ijMin; i--)
for (var i = dimension - 9; i >= ijMin; --i)
{
versionBits = this.copyBit(i, j, versionBits);
}
Expand All @@ -123,9 +123,9 @@ function BitMatrixParser(bitMatrix)

// Hmm, failed. Try bottom left: 6 wide by 3 tall
versionBits = 0;
for (var i = 5; i >= 0; i--)
for (var i = 5; i >= 0; --i)
{
for (var j = dimension - 9; j >= ijMin; j--)
for (var j = dimension - 9; j >= ijMin; --j)
{
versionBits = this.copyBit(i, j, versionBits);
}
Expand Down Expand Up @@ -164,19 +164,19 @@ function BitMatrixParser(bitMatrix)
{
// Skip whole column with vertical alignment pattern;
// saves time and makes the other code proceed more cleanly
j--;
--j;
}
// Read alternatingly from bottom to top then top to bottom
for (var count = 0; count < dimension; count++)
for (var count = 0; count < dimension; ++count)
{
var i = readingUp?dimension - 1 - count:count;
for (var col = 0; col < 2; col++)
for (var col = 0; col < 2; ++col)
{
// Ignore bits covered by the function pattern
if (!functionPattern.get_Renamed(j - col, i))
{
// Read a bit
bitsRead++;
++bitsRead;
currentByte <<= 1;
if (this.bitMatrix.get_Renamed(j - col, i))
{
Expand Down
20 changes: 10 additions & 10 deletions src/datablock.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,18 @@ DataBlock.getDataBlocks=function(rawCodewords, version, ecLevel)
// First count the total number of data blocks
var totalBlocks = 0;
var ecBlockArray = ecBlocks.getECBlocks();
for (var i = 0; i < ecBlockArray.length; i++)
for (var i = 0; i < ecBlockArray.length; ++i)
{
totalBlocks += ecBlockArray[i].Count;
}

// Now establish DataBlocks of the appropriate size and number of data codewords
var result = new Array(totalBlocks);
var numResultBlocks = 0;
for (var j = 0; j < ecBlockArray.length; j++)
for (var j = 0; j < ecBlockArray.length; ++j)
{
var ecBlock = ecBlockArray[j];
for (var i = 0; i < ecBlock.Count; i++)
for (var i = 0; i < ecBlock.Count; ++i)
{
var numDataCodewords = ecBlock.DataCodewords;
var numBlockCodewords = ecBlocks.ECCodewordsPerBlock + numDataCodewords;
Expand All @@ -83,31 +83,31 @@ DataBlock.getDataBlocks=function(rawCodewords, version, ecLevel)
{
break;
}
longerBlocksStartAt--;
--longerBlocksStartAt;
}
longerBlocksStartAt++;
++longerBlocksStartAt;

var shorterBlocksNumDataCodewords = shorterBlocksTotalCodewords - ecBlocks.ECCodewordsPerBlock;
// The last elements of result may be 1 element longer;
// first fill out as many elements as all of them have
var rawCodewordsOffset = 0;
for (var i = 0; i < shorterBlocksNumDataCodewords; i++)
for (var i = 0; i < shorterBlocksNumDataCodewords; ++i)
{
for (var j = 0; j < numResultBlocks; j++)
for (var j = 0; j < numResultBlocks; ++j)
{
result[j].codewords[i] = rawCodewords[rawCodewordsOffset++];
}
}
// Fill out the last data block in the longer ones
for (var j = longerBlocksStartAt; j < numResultBlocks; j++)
for (var j = longerBlocksStartAt; j < numResultBlocks; ++j)
{
result[j].codewords[shorterBlocksNumDataCodewords] = rawCodewords[rawCodewordsOffset++];
}
// Now add in error correction blocks
var max = result[0].codewords.length;
for (var i = shorterBlocksNumDataCodewords; i < max; i++)
for (var i = shorterBlocksNumDataCodewords; i < max; ++i)
{
for (var j = 0; j < numResultBlocks; j++)
for (var j = 0; j < numResultBlocks; ++j)
{
var iOffset = j < longerBlocksStartAt?i:i + 1;
result[j].codewords[iOffset] = rawCodewords[rawCodewordsOffset++];
Expand Down
Loading