Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
464 changes: 250 additions & 214 deletions lib/qrcode-decoder.js

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions lib/qrcode-decoder.min.js

Large diffs are not rendered by default.

32 changes: 18 additions & 14 deletions src/alignpat.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,26 @@ function AlignmentPattern(posX, posY, estimatedModuleSize)
this.y=posY;
this.count = 1;
this.estimatedModuleSize = estimatedModuleSize;

this.__defineGetter__("EstimatedModuleSize", function()
{
return this.estimatedModuleSize;
});
this.__defineGetter__("Count", function()
{
return this.count;

Object.defineProperty(this, "EstimatedModuleSize", {
get: function () {
return this.estimatedModuleSize;
}
});
Object.defineProperty(this, "Count", {
get: function() {
return this.count;
}
});
this.__defineGetter__("X", function()
{
return Math.floor(this.x);
Object.defineProperty(this, "X", {
get: function() {
return Math.floor(this.x);
}
});
this.__defineGetter__("Y", function()
{
return Math.floor(this.y);
Object.defineProperty(this, "Y", {
get: function() {
return Math.floor(this.y);
}
});
this.incrementCount = function()
{
Expand Down
30 changes: 16 additions & 14 deletions src/bitmat.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,24 @@ function BitMatrix( width, height)
this.bits = new Array(rowSize * height);
for(var i=0;i<this.bits.length;i++)
this.bits[i]=0;

this.__defineGetter__("Width", function()
{
return this.width;

Object.defineProperty(this, "Width", {
get: function() {
return this.width;
}
});
this.__defineGetter__("Height", function()
{
return this.height;
Object.defineProperty(this, "Height", {
get: function() {
return this.height;
}
});
this.__defineGetter__("Dimension", function()
{
if (this.width != this.height)
{
throw "Can't call getDimension() on a non-square matrix";
}
return this.width;
Object.defineProperty(this, "Dimension", {
get: function() {
if (this.width != this.height) {
throw "Can't call getDimension() on a non-square matrix";
}
return this.width;
}
});

this.get_Renamed=function( x, y)
Expand Down
16 changes: 9 additions & 7 deletions src/datablock.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ function DataBlock(numDataCodewords, codewords)
{
this.numDataCodewords = numDataCodewords;
this.codewords = codewords;

this.__defineGetter__("NumDataCodewords", function()
{
return this.numDataCodewords;

Object.defineProperty(this, "NumDataCodewords", {
get: function() {
return this.numDataCodewords;
}
});
this.__defineGetter__("Codewords", function()
{
return this.codewords;
Object.defineProperty(this, "Codewords", {
get: function() {
return this.codewords;
}
});
}

Expand Down
157 changes: 80 additions & 77 deletions src/databr.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,82 +244,85 @@ function QRCodeDataBlockReader(blocks, version, numErrorCorrectionCode)
return unicodeString;
}

this.__defineGetter__("DataByte", function()
{
var output = new Array();
var MODE_NUMBER = 1;
var MODE_ROMAN_AND_NUMBER = 2;
var MODE_8BIT_BYTE = 4;
var MODE_KANJI = 8;
do
{
var mode = this.NextMode();
//canvas.println("mode: " + mode);
if (mode == 0)
{
if (output.length > 0)
break;
else
throw "Empty data block";
}
//if (mode != 1 && mode != 2 && mode != 4 && mode != 8)
// break;
//}
if (mode != MODE_NUMBER && mode != MODE_ROMAN_AND_NUMBER && mode != MODE_8BIT_BYTE && mode != MODE_KANJI)
{
/* canvas.println("Invalid mode: " + mode);
mode = guessMode(mode);
canvas.println("Guessed mode: " + mode); */
throw "Invalid mode: " + mode + " in (block:" + this.blockPointer + " bit:" + this.bitPointer + ")";
}
dataLength = this.getDataLength(mode);
if (dataLength < 1)
throw "Invalid data length: " + dataLength;
//canvas.println("length: " + dataLength);
switch (mode)
{

case MODE_NUMBER:
//canvas.println("Mode: Figure");
var temp_str = this.getFigureString(dataLength);
var ta = new Array(temp_str.length);
for(var j=0;j<temp_str.length;j++)
ta[j]=temp_str.charCodeAt(j);
output.push(ta);
break;

case MODE_ROMAN_AND_NUMBER:
//canvas.println("Mode: Roman&Figure");
var temp_str = this.getRomanAndFigureString(dataLength);
var ta = new Array(temp_str.length);
for(var j=0;j<temp_str.length;j++)
ta[j]=temp_str.charCodeAt(j);
output.push(ta );
//output.Write(SystemUtils.ToByteArray(temp_sbyteArray2), 0, temp_sbyteArray2.Length);
break;

case MODE_8BIT_BYTE:
//canvas.println("Mode: 8bit Byte");
//sbyte[] temp_sbyteArray3;
var temp_sbyteArray3 = this.get8bitByteArray(dataLength);
output.push(temp_sbyteArray3);
//output.Write(SystemUtils.ToByteArray(temp_sbyteArray3), 0, temp_sbyteArray3.Length);
break;

case MODE_KANJI:
//canvas.println("Mode: Kanji");
//sbyte[] temp_sbyteArray4;
//temp_sbyteArray4 = SystemUtils.ToSByteArray(SystemUtils.ToByteArray(getKanjiString(dataLength)));
//output.Write(SystemUtils.ToByteArray(temp_sbyteArray4), 0, temp_sbyteArray4.Length);
var temp_str = this.getKanjiString(dataLength);
output.push(temp_str);
break;
}
//
//canvas.println("DataLength: " + dataLength);
//Console.out.println(dataString);
}
while (true);
return output;
Object.defineProperty(this, "DataByte", {
get: function() {

var output = new Array();
var MODE_NUMBER = 1;
var MODE_ROMAN_AND_NUMBER = 2;
var MODE_8BIT_BYTE = 4;
var MODE_KANJI = 8;
do
{
var mode = this.NextMode();
//canvas.println("mode: " + mode);
if (mode == 0)
{
if (output.length > 0)
break;
else
throw "Empty data block";
}
//if (mode != 1 && mode != 2 && mode != 4 && mode != 8)
// break;
//}
if (mode != MODE_NUMBER && mode != MODE_ROMAN_AND_NUMBER && mode != MODE_8BIT_BYTE && mode != MODE_KANJI)
{
/* canvas.println("Invalid mode: " + mode);
mode = guessMode(mode);
canvas.println("Guessed mode: " + mode); */
throw "Invalid mode: " + mode + " in (block:" + this.blockPointer + " bit:" + this.bitPointer + ")";
}
dataLength = this.getDataLength(mode);
if (dataLength < 1)
throw "Invalid data length: " + dataLength;
//canvas.println("length: " + dataLength);
switch (mode)
{

case MODE_NUMBER:
//canvas.println("Mode: Figure");
var temp_str = this.getFigureString(dataLength);
var ta = new Array(temp_str.length);
for(var j=0;j<temp_str.length;j++)
ta[j]=temp_str.charCodeAt(j);
output.push(ta);
break;

case MODE_ROMAN_AND_NUMBER:
//canvas.println("Mode: Roman&Figure");
var temp_str = this.getRomanAndFigureString(dataLength);
var ta = new Array(temp_str.length);
for(var j=0;j<temp_str.length;j++)
ta[j]=temp_str.charCodeAt(j);
output.push(ta );
//output.Write(SystemUtils.ToByteArray(temp_sbyteArray2), 0, temp_sbyteArray2.Length);
break;

case MODE_8BIT_BYTE:
//canvas.println("Mode: 8bit Byte");
//sbyte[] temp_sbyteArray3;
var temp_sbyteArray3 = this.get8bitByteArray(dataLength);
output.push(temp_sbyteArray3);
//output.Write(SystemUtils.ToByteArray(temp_sbyteArray3), 0, temp_sbyteArray3.Length);
break;

case MODE_KANJI:
//canvas.println("Mode: Kanji");
//sbyte[] temp_sbyteArray4;
//temp_sbyteArray4 = SystemUtils.ToSByteArray(SystemUtils.ToByteArray(getKanjiString(dataLength)));
//output.Write(SystemUtils.ToByteArray(temp_sbyteArray4), 0, temp_sbyteArray4.Length);
var temp_str = this.getKanjiString(dataLength);
output.push(temp_str);
break;
}
//
//canvas.println("DataLength: " + dataLength);
//Console.out.println(dataString);
}
while (true);

return output;
}
});
}
14 changes: 8 additions & 6 deletions src/errorlevel.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ function ErrorCorrectionLevel(ordinal, bits, name)
this.ordinal_Renamed_Field = ordinal;
this.bits = bits;
this.name = name;
this.__defineGetter__("Bits", function()
{
return this.bits;
Object.defineProperty(this, "Bits", {
get: function() {
return this.bits;
}
});
this.__defineGetter__("Name", function()
{
return this.name;
Object.defineProperty(this, "Name", {
get: function() {
return this.name;
}
});
this.ordinal=function()
{
Expand Down
76 changes: 42 additions & 34 deletions src/findpat.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,26 @@ function FinderPattern(posX, posY, estimatedModuleSize)
this.y=posY;
this.count = 1;
this.estimatedModuleSize = estimatedModuleSize;

this.__defineGetter__("EstimatedModuleSize", function()
{
return this.estimatedModuleSize;
});
this.__defineGetter__("Count", function()
{
return this.count;

Object.defineProperty(this, "EstimatedModuleSize", {
get: function() {
return this.estimatedModuleSize;
}
});
this.__defineGetter__("X", function()
{
return this.x;
Object.defineProperty(this, "Count", {
get: function() {
return this.count;
}
});
this.__defineGetter__("Y", function()
{
return this.y;
Object.defineProperty(this, "X", {
get: function() {
return this.x;
}
});
Object.defineProperty(this, "Y", {
get: function() {
return this.y;
}
});
this.incrementCount = function()
{
Expand All @@ -134,17 +138,20 @@ function FinderPatternInfo(patternCenters)
this.bottomLeft = patternCenters[0];
this.topLeft = patternCenters[1];
this.topRight = patternCenters[2];
this.__defineGetter__("BottomLeft", function()
{
return this.bottomLeft;
});
this.__defineGetter__("TopLeft", function()
{
return this.topLeft;
});
this.__defineGetter__("TopRight", function()
{
return this.topRight;
Object.defineProperty(this, "BottomLeft", {
get: function() {
return this.bottomLeft;
}
});
Object.defineProperty(this, "TopLeft", {
get: function() {
return this.topLeft;
}
});
Object.defineProperty(this, "TopRight", {
get: function() {
return this.topRight;
}
});
}

Expand All @@ -155,15 +162,16 @@ function FinderPatternFinder()
this.hasSkipped = false;
this.crossCheckStateCount = new Array(0,0,0,0,0);
this.resultPointCallback = null;

this.__defineGetter__("CrossCheckStateCount", function()
{
this.crossCheckStateCount[0] = 0;
this.crossCheckStateCount[1] = 0;
this.crossCheckStateCount[2] = 0;
this.crossCheckStateCount[3] = 0;
this.crossCheckStateCount[4] = 0;
return this.crossCheckStateCount;

Object.defineProperty(this, "CrossCheckStateCount", {
get: function() {
this.crossCheckStateCount[0] = 0;
this.crossCheckStateCount[1] = 0;
this.crossCheckStateCount[2] = 0;
this.crossCheckStateCount[3] = 0;
this.crossCheckStateCount[4] = 0;
return this.crossCheckStateCount;
}
});

this.foundPatternCross=function( stateCount)
Expand Down
Loading