qrcode-terminal
Advanced tools
Comparing version 0.8.0 to 0.9.0
{ | ||
"name": "qrcode-terminal", | ||
"keywords": ["ansi", "ascii", "qrcode", "console"], | ||
"version" : "0.8.0", | ||
"version" : "0.9.0", | ||
"description" : "QRCodes, in the terminal", | ||
@@ -30,7 +30,8 @@ "homepage": "https://github.com/gtanner/qrcode-terminal", | ||
"mocha": "*", | ||
"expect.js": "*" | ||
"expect.js": "*", | ||
"jshint": "*" | ||
}, | ||
"scripts": { | ||
"test": "node example/basic.js && ./node_modules/mocha/bin/mocha -R nyan" | ||
"test": "./node_modules/jshint/bin/jshint lib vendor && node example/basic.js && ./node_modules/mocha/bin/mocha -R nyan" | ||
} | ||
} |
@@ -16,2 +16,4 @@ //--------------------------------------------------------------------- | ||
//--------------------------------------------------------------------- | ||
// Modified to work in node for this project (and some refactoring) | ||
//--------------------------------------------------------------------- | ||
@@ -30,3 +32,3 @@ var QR8bitByte = require('./QR8bitByte'); | ||
this.dataCache = null; | ||
this.dataList = new Array(); | ||
this.dataList = []; | ||
} | ||
@@ -66,4 +68,4 @@ | ||
for (var i = 0; i < this.dataList.length; i++) { | ||
var data = this.dataList[i]; | ||
for (var x = 0; x < this.dataList.length; x++) { | ||
var data = this.dataList[x]; | ||
buffer.put(data.mode, 4); | ||
@@ -106,3 +108,3 @@ buffer.put(data.getLength(), QRUtil.getLengthInBits(data.mode, typeNumber) ); | ||
if (this.dataCache == null) { | ||
if (this.dataCache === null) { | ||
this.dataCache = QRCode.createData(this.typeNumber, this.errorCorrectLevel, this.dataList); | ||
@@ -124,5 +126,5 @@ } | ||
if ( (0 <= r && r <= 6 && (c == 0 || c == 6) ) | ||
|| (0 <= c && c <= 6 && (r == 0 || r == 6) ) | ||
|| (2 <= r && r <= 4 && 2 <= c && c <= 4) ) { | ||
if ( (0 <= r && r <= 6 && (c === 0 || c === 6) ) || | ||
(0 <= c && c <= 6 && (r === 0 || r === 6) ) || | ||
(2 <= r && r <= 4 && 2 <= c && c <= 4) ) { | ||
this.modules[row + r][col + c] = true; | ||
@@ -147,3 +149,3 @@ } else { | ||
if (i == 0 || minLostPoint > lostPoint) { | ||
if (i === 0 || minLostPoint > lostPoint) { | ||
minLostPoint = lostPoint; | ||
@@ -190,13 +192,13 @@ pattern = i; | ||
for (var r = 8; r < this.moduleCount - 8; r++) { | ||
if (this.modules[r][6] != null) { | ||
if (this.modules[r][6] !== null) { | ||
continue; | ||
} | ||
this.modules[r][6] = (r % 2 == 0); | ||
this.modules[r][6] = (r % 2 === 0); | ||
} | ||
for (var c = 8; c < this.moduleCount - 8; c++) { | ||
if (this.modules[6][c] != null) { | ||
if (this.modules[6][c] !== null) { | ||
continue; | ||
} | ||
this.modules[6][c] = (c % 2 == 0); | ||
this.modules[6][c] = (c % 2 === 0); | ||
} | ||
@@ -216,3 +218,3 @@ }, | ||
if (this.modules[row][col] != null) { | ||
if (this.modules[row][col] !== null) { | ||
continue; | ||
@@ -225,4 +227,5 @@ } | ||
if (r == -2 || r == 2 || c == -2 || c == 2 | ||
|| (r == 0 && c == 0) ) { | ||
if (Math.abs(r) === 2 || | ||
Math.abs(c) === 2 || | ||
(r === 0 && c === 0) ) { | ||
this.modules[row + r][col + c] = true; | ||
@@ -241,11 +244,12 @@ } else { | ||
var bits = QRUtil.getBCHTypeNumber(this.typeNumber); | ||
var mod; | ||
for (var i = 0; i < 18; i++) { | ||
var mod = (!test && ( (bits >> i) & 1) == 1); | ||
mod = (!test && ( (bits >> i) & 1) === 1); | ||
this.modules[Math.floor(i / 3)][i % 3 + this.moduleCount - 8 - 3] = mod; | ||
} | ||
for (var i = 0; i < 18; i++) { | ||
var mod = (!test && ( (bits >> i) & 1) == 1); | ||
this.modules[i % 3 + this.moduleCount - 8 - 3][Math.floor(i / 3)] = mod; | ||
for (var x = 0; x < 18; x++) { | ||
mod = (!test && ( (bits >> x) & 1) === 1); | ||
this.modules[x % 3 + this.moduleCount - 8 - 3][Math.floor(x / 3)] = mod; | ||
} | ||
@@ -258,14 +262,15 @@ }, | ||
var bits = QRUtil.getBCHTypeInfo(data); | ||
var mod; | ||
// vertical | ||
for (var i = 0; i < 15; i++) { | ||
for (var v = 0; v < 15; v++) { | ||
var mod = (!test && ( (bits >> i) & 1) == 1); | ||
mod = (!test && ( (bits >> v) & 1) === 1); | ||
if (i < 6) { | ||
this.modules[i][8] = mod; | ||
} else if (i < 8) { | ||
this.modules[i + 1][8] = mod; | ||
if (v < 6) { | ||
this.modules[v][8] = mod; | ||
} else if (v < 8) { | ||
this.modules[v + 1][8] = mod; | ||
} else { | ||
this.modules[this.moduleCount - 15 + i][8] = mod; | ||
this.modules[this.moduleCount - 15 + v][8] = mod; | ||
} | ||
@@ -275,12 +280,12 @@ } | ||
// horizontal | ||
for (var i = 0; i < 15; i++) { | ||
for (var h = 0; h < 15; h++) { | ||
var mod = (!test && ( (bits >> i) & 1) == 1); | ||
mod = (!test && ( (bits >> h) & 1) === 1); | ||
if (i < 8) { | ||
this.modules[8][this.moduleCount - i - 1] = mod; | ||
} else if (i < 9) { | ||
this.modules[8][15 - i - 1 + 1] = mod; | ||
if (h < 8) { | ||
this.modules[8][this.moduleCount - h - 1] = mod; | ||
} else if (h < 9) { | ||
this.modules[8][15 - h - 1 + 1] = mod; | ||
} else { | ||
this.modules[8][15 - i - 1] = mod; | ||
this.modules[8][15 - h - 1] = mod; | ||
} | ||
@@ -303,3 +308,3 @@ } | ||
if (col == 6) col--; | ||
if (col === 6) col--; | ||
@@ -310,3 +315,3 @@ while (true) { | ||
if (this.modules[row][col - c] == null) { | ||
if (this.modules[row][col - c] === null) { | ||
@@ -316,3 +321,3 @@ var dark = false; | ||
if (byteIndex < data.length) { | ||
dark = ( ( (data[byteIndex] >>> bitIndex) & 1) == 1); | ||
dark = ( ( (data[byteIndex] >>> bitIndex) & 1) === 1); | ||
} | ||
@@ -329,3 +334,3 @@ | ||
if (bitIndex == -1) { | ||
if (bitIndex === -1) { | ||
byteIndex++; | ||
@@ -369,12 +374,12 @@ bitIndex = 7; | ||
var totalDataCount = 0; | ||
for (var i = 0; i < rsBlocks.length; i++) { | ||
totalDataCount += rsBlocks[i].dataCount; | ||
for (var x = 0; x < rsBlocks.length; x++) { | ||
totalDataCount += rsBlocks[x].dataCount; | ||
} | ||
if (buffer.getLengthInBits() > totalDataCount * 8) { | ||
throw new Error("code length overflow. (" | ||
+ buffer.getLengthInBits() | ||
+ ">" | ||
+ totalDataCount * 8 | ||
+ ")"); | ||
throw new Error("code length overflow. (" + | ||
buffer.getLengthInBits() + | ||
">" + | ||
totalDataCount * 8 + | ||
")"); | ||
} | ||
@@ -388,3 +393,3 @@ | ||
// padding | ||
while (buffer.getLengthInBits() % 8 != 0) { | ||
while (buffer.getLengthInBits() % 8 !== 0) { | ||
buffer.putBit(false); | ||
@@ -408,3 +413,3 @@ } | ||
return QRCode.createBytes(buffer, rsBlocks); | ||
} | ||
}; | ||
@@ -441,5 +446,5 @@ QRCode.createBytes = function(buffer, rsBlocks) { | ||
ecdata[r] = new Array(rsPoly.getLength() - 1); | ||
for (var i = 0; i < ecdata[r].length; i++) { | ||
var modIndex = i + modPoly.getLength() - ecdata[r].length; | ||
ecdata[r][i] = (modIndex >= 0)? modPoly.get(modIndex) : 0; | ||
for (var x = 0; x < ecdata[r].length; x++) { | ||
var modIndex = x + modPoly.getLength() - ecdata[r].length; | ||
ecdata[r][x] = (modIndex >= 0)? modPoly.get(modIndex) : 0; | ||
} | ||
@@ -450,4 +455,4 @@ | ||
var totalCodeCount = 0; | ||
for (var i = 0; i < rsBlocks.length; i++) { | ||
totalCodeCount += rsBlocks[i].totalCount; | ||
for (var y = 0; y < rsBlocks.length; y++) { | ||
totalCodeCount += rsBlocks[y].totalCount; | ||
} | ||
@@ -458,6 +463,6 @@ | ||
for (var i = 0; i < maxDcCount; i++) { | ||
for (var r = 0; r < rsBlocks.length; r++) { | ||
if (i < dcdata[r].length) { | ||
data[index++] = dcdata[r][i]; | ||
for (var z = 0; z < maxDcCount; z++) { | ||
for (var s = 0; s < rsBlocks.length; s++) { | ||
if (z < dcdata[s].length) { | ||
data[index++] = dcdata[s][z]; | ||
} | ||
@@ -467,6 +472,6 @@ } | ||
for (var i = 0; i < maxEcCount; i++) { | ||
for (var r = 0; r < rsBlocks.length; r++) { | ||
if (i < ecdata[r].length) { | ||
data[index++] = ecdata[r][i]; | ||
for (var xx = 0; xx < maxEcCount; xx++) { | ||
for (var t = 0; t < rsBlocks.length; t++) { | ||
if (xx < ecdata[t].length) { | ||
data[index++] = ecdata[t][xx]; | ||
} | ||
@@ -478,4 +483,4 @@ } | ||
} | ||
}; | ||
module.exports = QRCode; |
@@ -1,7 +0,1 @@ | ||
//--------------------------------------------------------------------- | ||
// QR8bitByte | ||
//--------------------------------------------------------------------- | ||
// | ||
// NOTES: | ||
// Updated for this project to work in node (see line: 1242) | ||
var QRMode = require('./QRMode'); | ||
@@ -16,3 +10,3 @@ | ||
getLength : function(buffer) { | ||
getLength : function() { | ||
return this.data.length; | ||
@@ -19,0 +13,0 @@ }, |
function QRBitBuffer() { | ||
this.buffer = new Array(); | ||
this.buffer = []; | ||
this.length = 0; | ||
@@ -4,0 +4,0 @@ } |
@@ -1,5 +0,1 @@ | ||
//--------------------------------------------------------------------- | ||
// QRErrorCorrectLevel | ||
//--------------------------------------------------------------------- | ||
module.exports = { | ||
@@ -6,0 +2,0 @@ L : 1, |
@@ -1,11 +0,6 @@ | ||
//--------------------------------------------------------------------- | ||
// QRMode | ||
//--------------------------------------------------------------------- | ||
module.exports = { | ||
MODE_NUMBER : 1 << 0, | ||
MODE_ALPHA_NUM : 1 << 1, | ||
MODE_8BIT_BYTE : 1 << 2, | ||
MODE_KANJI : 1 << 3 | ||
MODE_NUMBER : 1 << 0, | ||
MODE_ALPHA_NUM : 1 << 1, | ||
MODE_8BIT_BYTE : 1 << 2, | ||
MODE_KANJI : 1 << 3 | ||
}; | ||
var QRMath = require('./QRMath'); | ||
function QRPolynomial(num, shift) { | ||
if (num.length == undefined) { | ||
if (num.length === undefined) { | ||
throw new Error(num.length + "/" + shift); | ||
@@ -10,3 +10,3 @@ } | ||
while (offset < num.length && num[offset] == 0) { | ||
while (offset < num.length && num[offset] === 0) { | ||
offset++; | ||
@@ -58,4 +58,4 @@ } | ||
for (var i = 0; i < e.getLength(); i++) { | ||
num[i] ^= QRMath.gexp(QRMath.glog(e.get(i) ) + ratio); | ||
for (var x = 0; x < e.getLength(); x++) { | ||
num[x] ^= QRMath.gexp(QRMath.glog(e.get(x) ) + ratio); | ||
} | ||
@@ -62,0 +62,0 @@ |
@@ -260,3 +260,3 @@ var QRErrorCorrectLevel = require('./QRErrorCorrectLevel'); | ||
if (rsBlock == undefined) { | ||
if (rsBlock === undefined) { | ||
throw new Error("bad rs block @ typeNumber:" + typeNumber + "/errorCorrectLevel:" + errorCorrectLevel); | ||
@@ -267,3 +267,3 @@ } | ||
var list = new Array(); | ||
var list = []; | ||
@@ -282,3 +282,3 @@ for (var i = 0; i < length; i++) { | ||
return list; | ||
} | ||
}; | ||
@@ -299,4 +299,4 @@ QRRSBlock.getRsBlockTable = function(typeNumber, errorCorrectLevel) { | ||
} | ||
} | ||
}; | ||
module.exports = QRRSBlock; |
@@ -9,42 +9,42 @@ var QRMode = require('./QRMode'); | ||
PATTERN_POSITION_TABLE : [ | ||
[], | ||
[6, 18], | ||
[6, 22], | ||
[6, 26], | ||
[6, 30], | ||
[6, 34], | ||
[6, 22, 38], | ||
[6, 24, 42], | ||
[6, 26, 46], | ||
[6, 28, 50], | ||
[6, 30, 54], | ||
[6, 32, 58], | ||
[6, 34, 62], | ||
[6, 26, 46, 66], | ||
[6, 26, 48, 70], | ||
[6, 26, 50, 74], | ||
[6, 30, 54, 78], | ||
[6, 30, 56, 82], | ||
[6, 30, 58, 86], | ||
[6, 34, 62, 90], | ||
[6, 28, 50, 72, 94], | ||
[6, 26, 50, 74, 98], | ||
[6, 30, 54, 78, 102], | ||
[6, 28, 54, 80, 106], | ||
[6, 32, 58, 84, 110], | ||
[6, 30, 58, 86, 114], | ||
[6, 34, 62, 90, 118], | ||
[6, 26, 50, 74, 98, 122], | ||
[6, 30, 54, 78, 102, 126], | ||
[6, 26, 52, 78, 104, 130], | ||
[6, 30, 56, 82, 108, 134], | ||
[6, 34, 60, 86, 112, 138], | ||
[6, 30, 58, 86, 114, 142], | ||
[6, 34, 62, 90, 118, 146], | ||
[6, 30, 54, 78, 102, 126, 150], | ||
[6, 24, 50, 76, 102, 128, 154], | ||
[6, 28, 54, 80, 106, 132, 158], | ||
[6, 32, 58, 84, 110, 136, 162], | ||
[6, 26, 54, 82, 110, 138, 166], | ||
[6, 30, 58, 86, 114, 142, 170] | ||
[], | ||
[6, 18], | ||
[6, 22], | ||
[6, 26], | ||
[6, 30], | ||
[6, 34], | ||
[6, 22, 38], | ||
[6, 24, 42], | ||
[6, 26, 46], | ||
[6, 28, 50], | ||
[6, 30, 54], | ||
[6, 32, 58], | ||
[6, 34, 62], | ||
[6, 26, 46, 66], | ||
[6, 26, 48, 70], | ||
[6, 26, 50, 74], | ||
[6, 30, 54, 78], | ||
[6, 30, 56, 82], | ||
[6, 30, 58, 86], | ||
[6, 34, 62, 90], | ||
[6, 28, 50, 72, 94], | ||
[6, 26, 50, 74, 98], | ||
[6, 30, 54, 78, 102], | ||
[6, 28, 54, 80, 106], | ||
[6, 32, 58, 84, 110], | ||
[6, 30, 58, 86, 114], | ||
[6, 34, 62, 90, 118], | ||
[6, 26, 50, 74, 98, 122], | ||
[6, 30, 54, 78, 102, 126], | ||
[6, 26, 52, 78, 104, 130], | ||
[6, 30, 56, 82, 108, 134], | ||
[6, 34, 60, 86, 112, 138], | ||
[6, 30, 58, 86, 114, 142], | ||
[6, 34, 62, 90, 118, 146], | ||
[6, 30, 54, 78, 102, 126, 150], | ||
[6, 24, 50, 76, 102, 128, 154], | ||
[6, 28, 54, 80, 106, 132, 158], | ||
[6, 32, 58, 84, 110, 136, 162], | ||
[6, 26, 54, 82, 110, 138, 166], | ||
[6, 30, 58, 86, 114, 142, 170] | ||
], | ||
@@ -54,18 +54,18 @@ | ||
G18 : (1 << 12) | (1 << 11) | (1 << 10) | (1 << 9) | (1 << 8) | (1 << 5) | (1 << 2) | (1 << 0), | ||
G15_MASK : (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1), | ||
G15_MASK : (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1), | ||
getBCHTypeInfo : function(data) { | ||
var d = data << 10; | ||
while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15) >= 0) { | ||
d ^= (QRUtil.G15 << (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15) ) ); | ||
} | ||
return ( (data << 10) | d) ^ QRUtil.G15_MASK; | ||
var d = data << 10; | ||
while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15) >= 0) { | ||
d ^= (QRUtil.G15 << (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15) ) ); | ||
} | ||
return ( (data << 10) | d) ^ QRUtil.G15_MASK; | ||
}, | ||
getBCHTypeNumber : function(data) { | ||
var d = data << 12; | ||
while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18) >= 0) { | ||
d ^= (QRUtil.G18 << (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18) ) ); | ||
} | ||
return (data << 12) | d; | ||
var d = data << 12; | ||
while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18) >= 0) { | ||
d ^= (QRUtil.G18 << (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18) ) ); | ||
} | ||
return (data << 12) | d; | ||
}, | ||
@@ -75,32 +75,32 @@ | ||
var digit = 0; | ||
var digit = 0; | ||
while (data != 0) { | ||
digit++; | ||
data >>>= 1; | ||
} | ||
while (data !== 0) { | ||
digit++; | ||
data >>>= 1; | ||
} | ||
return digit; | ||
return digit; | ||
}, | ||
getPatternPosition : function(typeNumber) { | ||
return QRUtil.PATTERN_POSITION_TABLE[typeNumber - 1]; | ||
return QRUtil.PATTERN_POSITION_TABLE[typeNumber - 1]; | ||
}, | ||
getMask : function(maskPattern, i, j) { | ||
switch (maskPattern) { | ||
case QRMaskPattern.PATTERN000 : return (i + j) % 2 == 0; | ||
case QRMaskPattern.PATTERN001 : return i % 2 == 0; | ||
case QRMaskPattern.PATTERN010 : return j % 3 == 0; | ||
case QRMaskPattern.PATTERN011 : return (i + j) % 3 == 0; | ||
case QRMaskPattern.PATTERN100 : return (Math.floor(i / 2) + Math.floor(j / 3) ) % 2 == 0; | ||
case QRMaskPattern.PATTERN101 : return (i * j) % 2 + (i * j) % 3 == 0; | ||
case QRMaskPattern.PATTERN110 : return ( (i * j) % 2 + (i * j) % 3) % 2 == 0; | ||
case QRMaskPattern.PATTERN111 : return ( (i * j) % 3 + (i + j) % 2) % 2 == 0; | ||
switch (maskPattern) { | ||
case QRMaskPattern.PATTERN000 : return (i + j) % 2 === 0; | ||
case QRMaskPattern.PATTERN001 : return i % 2 === 0; | ||
case QRMaskPattern.PATTERN010 : return j % 3 === 0; | ||
case QRMaskPattern.PATTERN011 : return (i + j) % 3 === 0; | ||
case QRMaskPattern.PATTERN100 : return (Math.floor(i / 2) + Math.floor(j / 3) ) % 2 === 0; | ||
case QRMaskPattern.PATTERN101 : return (i * j) % 2 + (i * j) % 3 === 0; | ||
case QRMaskPattern.PATTERN110 : return ( (i * j) % 2 + (i * j) % 3) % 2 === 0; | ||
case QRMaskPattern.PATTERN111 : return ( (i * j) % 3 + (i + j) % 2) % 2 === 0; | ||
default : | ||
throw new Error("bad maskPattern:" + maskPattern); | ||
} | ||
default : | ||
throw new Error("bad maskPattern:" + maskPattern); | ||
} | ||
}, | ||
@@ -110,9 +110,9 @@ | ||
var a = new QRPolynomial([1], 0); | ||
var a = new QRPolynomial([1], 0); | ||
for (var i = 0; i < errorCorrectLength; i++) { | ||
a = a.multiply(new QRPolynomial([1, QRMath.gexp(i)], 0) ); | ||
} | ||
for (var i = 0; i < errorCorrectLength; i++) { | ||
a = a.multiply(new QRPolynomial([1, QRMath.gexp(i)], 0) ); | ||
} | ||
return a; | ||
return a; | ||
}, | ||
@@ -122,150 +122,152 @@ | ||
if (1 <= type && type < 10) { | ||
if (1 <= type && type < 10) { | ||
// 1 - 9 | ||
// 1 - 9 | ||
switch(mode) { | ||
case QRMode.MODE_NUMBER : return 10; | ||
case QRMode.MODE_ALPHA_NUM : return 9; | ||
case QRMode.MODE_8BIT_BYTE : return 8; | ||
case QRMode.MODE_KANJI : return 8; | ||
default : | ||
throw new Error("mode:" + mode); | ||
} | ||
switch(mode) { | ||
case QRMode.MODE_NUMBER : return 10; | ||
case QRMode.MODE_ALPHA_NUM : return 9; | ||
case QRMode.MODE_8BIT_BYTE : return 8; | ||
case QRMode.MODE_KANJI : return 8; | ||
default : | ||
throw new Error("mode:" + mode); | ||
} | ||
} else if (type < 27) { | ||
} else if (type < 27) { | ||
// 10 - 26 | ||
// 10 - 26 | ||
switch(mode) { | ||
case QRMode.MODE_NUMBER : return 12; | ||
case QRMode.MODE_ALPHA_NUM : return 11; | ||
case QRMode.MODE_8BIT_BYTE : return 16; | ||
case QRMode.MODE_KANJI : return 10; | ||
default : | ||
throw new Error("mode:" + mode); | ||
} | ||
switch(mode) { | ||
case QRMode.MODE_NUMBER : return 12; | ||
case QRMode.MODE_ALPHA_NUM : return 11; | ||
case QRMode.MODE_8BIT_BYTE : return 16; | ||
case QRMode.MODE_KANJI : return 10; | ||
default : | ||
throw new Error("mode:" + mode); | ||
} | ||
} else if (type < 41) { | ||
} else if (type < 41) { | ||
// 27 - 40 | ||
// 27 - 40 | ||
switch(mode) { | ||
case QRMode.MODE_NUMBER : return 14; | ||
case QRMode.MODE_ALPHA_NUM : return 13; | ||
case QRMode.MODE_8BIT_BYTE : return 16; | ||
case QRMode.MODE_KANJI : return 12; | ||
default : | ||
throw new Error("mode:" + mode); | ||
} | ||
switch(mode) { | ||
case QRMode.MODE_NUMBER : return 14; | ||
case QRMode.MODE_ALPHA_NUM : return 13; | ||
case QRMode.MODE_8BIT_BYTE : return 16; | ||
case QRMode.MODE_KANJI : return 12; | ||
default : | ||
throw new Error("mode:" + mode); | ||
} | ||
} else { | ||
throw new Error("type:" + type); | ||
} | ||
} else { | ||
throw new Error("type:" + type); | ||
} | ||
}, | ||
getLostPoint : function(qrCode) { | ||
var moduleCount = qrCode.getModuleCount(); | ||
var lostPoint = 0; | ||
// LEVEL1 | ||
for (var row = 0; row < moduleCount; row++) { | ||
var moduleCount = qrCode.getModuleCount(); | ||
var lostPoint = 0; | ||
var row = 0; | ||
var col = 0; | ||
for (var col = 0; col < moduleCount; col++) { | ||
// LEVEL1 | ||
for (row = 0; row < moduleCount; row++) { | ||
var sameCount = 0; | ||
var dark = qrCode.isDark(row, col); | ||
for (col = 0; col < moduleCount; col++) { | ||
for (var r = -1; r <= 1; r++) { | ||
var sameCount = 0; | ||
var dark = qrCode.isDark(row, col); | ||
if (row + r < 0 || moduleCount <= row + r) { | ||
continue; | ||
} | ||
for (var r = -1; r <= 1; r++) { | ||
for (var c = -1; c <= 1; c++) { | ||
if (row + r < 0 || moduleCount <= row + r) { | ||
continue; | ||
} | ||
if (col + c < 0 || moduleCount <= col + c) { | ||
continue; | ||
} | ||
for (var c = -1; c <= 1; c++) { | ||
if (r == 0 && c == 0) { | ||
continue; | ||
} | ||
if (col + c < 0 || moduleCount <= col + c) { | ||
continue; | ||
} | ||
if (dark == qrCode.isDark(row + r, col + c) ) { | ||
sameCount++; | ||
} | ||
} | ||
} | ||
if (r === 0 && c === 0) { | ||
continue; | ||
} | ||
if (sameCount > 5) { | ||
lostPoint += (3 + sameCount - 5); | ||
} | ||
} | ||
} | ||
if (dark === qrCode.isDark(row + r, col + c) ) { | ||
sameCount++; | ||
} | ||
} | ||
} | ||
// LEVEL2 | ||
if (sameCount > 5) { | ||
lostPoint += (3 + sameCount - 5); | ||
} | ||
} | ||
} | ||
for (var row = 0; row < moduleCount - 1; row++) { | ||
for (var col = 0; col < moduleCount - 1; col++) { | ||
var count = 0; | ||
if (qrCode.isDark(row, col ) ) count++; | ||
if (qrCode.isDark(row + 1, col ) ) count++; | ||
if (qrCode.isDark(row, col + 1) ) count++; | ||
if (qrCode.isDark(row + 1, col + 1) ) count++; | ||
if (count == 0 || count == 4) { | ||
lostPoint += 3; | ||
} | ||
} | ||
} | ||
// LEVEL2 | ||
// LEVEL3 | ||
for (row = 0; row < moduleCount - 1; row++) { | ||
for (col = 0; col < moduleCount - 1; col++) { | ||
var count = 0; | ||
if (qrCode.isDark(row, col ) ) count++; | ||
if (qrCode.isDark(row + 1, col ) ) count++; | ||
if (qrCode.isDark(row, col + 1) ) count++; | ||
if (qrCode.isDark(row + 1, col + 1) ) count++; | ||
if (count === 0 || count === 4) { | ||
lostPoint += 3; | ||
} | ||
} | ||
} | ||
for (var row = 0; row < moduleCount; row++) { | ||
for (var col = 0; col < moduleCount - 6; col++) { | ||
if (qrCode.isDark(row, col) | ||
&& !qrCode.isDark(row, col + 1) | ||
&& qrCode.isDark(row, col + 2) | ||
&& qrCode.isDark(row, col + 3) | ||
&& qrCode.isDark(row, col + 4) | ||
&& !qrCode.isDark(row, col + 5) | ||
&& qrCode.isDark(row, col + 6) ) { | ||
lostPoint += 40; | ||
} | ||
} | ||
} | ||
// LEVEL3 | ||
for (var col = 0; col < moduleCount; col++) { | ||
for (var row = 0; row < moduleCount - 6; row++) { | ||
if (qrCode.isDark(row, col) | ||
&& !qrCode.isDark(row + 1, col) | ||
&& qrCode.isDark(row + 2, col) | ||
&& qrCode.isDark(row + 3, col) | ||
&& qrCode.isDark(row + 4, col) | ||
&& !qrCode.isDark(row + 5, col) | ||
&& qrCode.isDark(row + 6, col) ) { | ||
lostPoint += 40; | ||
} | ||
} | ||
} | ||
for (row = 0; row < moduleCount; row++) { | ||
for (col = 0; col < moduleCount - 6; col++) { | ||
if (qrCode.isDark(row, col) && | ||
!qrCode.isDark(row, col + 1) && | ||
qrCode.isDark(row, col + 2) && | ||
qrCode.isDark(row, col + 3) && | ||
qrCode.isDark(row, col + 4) && | ||
!qrCode.isDark(row, col + 5) && | ||
qrCode.isDark(row, col + 6) ) { | ||
lostPoint += 40; | ||
} | ||
} | ||
} | ||
// LEVEL4 | ||
var darkCount = 0; | ||
for (col = 0; col < moduleCount; col++) { | ||
for (row = 0; row < moduleCount - 6; row++) { | ||
if (qrCode.isDark(row, col) && | ||
!qrCode.isDark(row + 1, col) && | ||
qrCode.isDark(row + 2, col) && | ||
qrCode.isDark(row + 3, col) && | ||
qrCode.isDark(row + 4, col) && | ||
!qrCode.isDark(row + 5, col) && | ||
qrCode.isDark(row + 6, col) ) { | ||
lostPoint += 40; | ||
} | ||
} | ||
} | ||
for (var col = 0; col < moduleCount; col++) { | ||
for (var row = 0; row < moduleCount; row++) { | ||
if (qrCode.isDark(row, col) ) { | ||
darkCount++; | ||
} | ||
} | ||
} | ||
var ratio = Math.abs(100 * darkCount / moduleCount / moduleCount - 50) / 5; | ||
lostPoint += ratio * 10; | ||
// LEVEL4 | ||
var darkCount = 0; | ||
return lostPoint; | ||
for (col = 0; col < moduleCount; col++) { | ||
for (row = 0; row < moduleCount; row++) { | ||
if (qrCode.isDark(row, col) ) { | ||
darkCount++; | ||
} | ||
} | ||
} | ||
var ratio = Math.abs(100 * darkCount / moduleCount / moduleCount - 50) / 5; | ||
lostPoint += ratio * 10; | ||
return lostPoint; | ||
} | ||
@@ -272,0 +274,0 @@ |
Sorry, the diff of this file is not supported yet
91189
4
1038