From 6547f11c970cd06ab652e0332339cfd8db248a39 Mon Sep 17 00:00:00 2001 From: Stuart Langridge Date: Sat, 1 Jun 2013 19:25:27 +0200 Subject: [PATCH] Fix accidental global variables --- src/QRCode.js | 6 +++--- src/databr.js | 2 +- src/datamask.js | 2 +- src/decoder.js | 2 +- src/detector.js | 22 +++++++++++----------- src/findpat.js | 6 +++--- src/grid.js | 2 +- 7 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/QRCode.js b/src/QRCode.js index a145caf5..8d692028 100644 --- a/src/QRCode.js +++ b/src/QRCode.js @@ -15,7 +15,7 @@ */ -qrcode = {}; +var qrcode = {}; qrcode.imagedata = null; qrcode.width = 0; qrcode.height = 0; @@ -154,8 +154,8 @@ qrcode.getPixel = function(x,y){ if (qrcode.height < y) { throw "point error"; } - point = (x * 4) + (y * qrcode.width * 4); - p = (qrcode.imagedata.data[point]*33 + qrcode.imagedata.data[point + 1]*34 + qrcode.imagedata.data[point + 2]*33)/100; + var point = (x * 4) + (y * qrcode.width * 4); + var p = (qrcode.imagedata.data[point]*33 + qrcode.imagedata.data[point + 1]*34 + qrcode.imagedata.data[point + 2]*33)/100; return p; } diff --git a/src/databr.js b/src/databr.js index 66279c41..8c54d21b 100644 --- a/src/databr.js +++ b/src/databr.js @@ -272,7 +272,7 @@ function QRCodeDataBlockReader(blocks, version, numErrorCorrectionCode) canvas.println("Guessed mode: " + mode); */ throw "Invalid mode: " + mode + " in (block:" + this.blockPointer + " bit:" + this.bitPointer + ")"; } - dataLength = this.getDataLength(mode); + var dataLength = this.getDataLength(mode); if (dataLength < 1) throw "Invalid data length: " + dataLength; //canvas.println("length: " + dataLength); diff --git a/src/datamask.js b/src/datamask.js index 64e7adbe..2f99523a 100644 --- a/src/datamask.js +++ b/src/datamask.js @@ -23,7 +23,7 @@ */ -DataMask = {}; +var DataMask = {}; DataMask.forReference = function(reference) { diff --git a/src/decoder.js b/src/decoder.js index c71e3f18..e218f0e5 100644 --- a/src/decoder.js +++ b/src/decoder.js @@ -23,7 +23,7 @@ */ -Decoder={}; +var Decoder={}; Decoder.rsDecoder = new ReedSolomonDecoder(GF256.QR_CODE_FIELD); Decoder.correctErrors=function( codewordBytes, numDataCodewords) diff --git a/src/detector.js b/src/detector.js index 012f8c5d..a6245a96 100644 --- a/src/detector.js +++ b/src/detector.js @@ -90,21 +90,21 @@ PerspectiveTransform.quadrilateralToQuadrilateral=function( x0, y0, x1, y1, PerspectiveTransform.squareToQuadrilateral=function( x0, y0, x1, y1, x2, y2, x3, y3) { - dy2 = y3 - y2; - dy3 = y0 - y1 + y2 - y3; + var dy2 = y3 - y2; + var dy3 = y0 - y1 + y2 - y3; if (dy2 == 0.0 && dy3 == 0.0) { return new PerspectiveTransform(x1 - x0, x2 - x1, x0, y1 - y0, y2 - y1, y0, 0.0, 0.0, 1.0); } else { - dx1 = x1 - x2; - dx2 = x3 - x2; - dx3 = x0 - x1 + x2 - x3; - dy1 = y1 - y2; - denominator = dx1 * dy2 - dx2 * dy1; - a13 = (dx3 * dy2 - dx2 * dy3) / denominator; - a23 = (dx1 * dy3 - dx3 * dy1) / denominator; + var dx1 = x1 - x2; + var dx2 = x3 - x2; + var dx3 = x0 - x1 + x2 - x3; + var dy1 = y1 - y2; + var denominator = dx1 * dy2 - dx2 * dy1; + var a13 = (dx3 * dy2 - dx2 * dy3) / denominator; + var a23 = (dx1 * dy3 - dx3 * dy1) / denominator; return new PerspectiveTransform(x1 - x0 + a13 * x1, x3 - x0 + a23 * x3, x0, y1 - y0 + a13 * y1, y3 - y0 + a23 * y3, y0, a13, a23, 1.0); } } @@ -258,8 +258,8 @@ function Detector(image) this.distance=function( pattern1, pattern2) { - xDiff = pattern1.X - pattern2.X; - yDiff = pattern1.Y - pattern2.Y; + var xDiff = pattern1.X - pattern2.X; + var yDiff = pattern1.Y - pattern2.Y; return Math.sqrt( (xDiff * xDiff + yDiff * yDiff)); } this.computeDimension=function( topLeft, topRight, bottomLeft, moduleSize) diff --git a/src/findpat.js b/src/findpat.js index 70c6be5a..54bcd838 100644 --- a/src/findpat.js +++ b/src/findpat.js @@ -33,8 +33,8 @@ qrcode.orderBestPatterns=function(patterns) function distance( pattern1, pattern2) { - xDiff = pattern1.X - pattern2.X; - yDiff = pattern1.Y - pattern2.Y; + var xDiff = pattern1.X - pattern2.X; + var yDiff = pattern1.Y - pattern2.Y; return Math.sqrt( (xDiff * xDiff + yDiff * yDiff)); } @@ -391,7 +391,7 @@ function FinderPatternFinder() if (startSize < 3) { // Couldn't find enough finder patterns - throw "Couldn't find enough finder patterns"; + throw "Couldn't find enough finder patterns (found " + startSize + ")"; } // Filter outlier possibilities whose module size is too different diff --git a/src/grid.js b/src/grid.js index 70602fe3..5eabe8f5 100644 --- a/src/grid.js +++ b/src/grid.js @@ -23,7 +23,7 @@ */ -GridSampler = {}; +var GridSampler = {}; GridSampler.checkAndNudgePoints=function( image, points) {