From f3168081b908d9214a02a8b03d24359916d76f31 Mon Sep 17 00:00:00 2001 From: Rohit Paul <113459757+RohitPaul12345@users.noreply.github.com> Date: Thu, 17 Aug 2023 19:12:12 +0530 Subject: [PATCH] Update qrcode.js --- src/qrcode.js | 140 +++++++++++++++++++++++++------------------------- 1 file changed, 70 insertions(+), 70 deletions(-) diff --git a/src/qrcode.js b/src/qrcode.js index a83bddef..ad4f48d2 100644 --- a/src/qrcode.js +++ b/src/qrcode.js @@ -15,7 +15,7 @@ */ -var qrcode = {}; +let qrcode = {}; qrcode.imagedata = null; qrcode.width = 0; qrcode.height = 0; @@ -90,10 +90,10 @@ qrcode.captureToCanvas = function() qrcode.setWebcam = function(videoId) { - var n=navigator; + let n=navigator; qrcode.video=document.getElementById(videoId); - var options = true; + let options = true; if(navigator.mediaDevices && navigator.mediaDevices.enumerateDevices) { try{ @@ -142,13 +142,13 @@ qrcode.decode = function(src){ { if(qrcode.canvas_qr2) { - var canvas_qr = qrcode.canvas_qr2; - var context = qrcode.qrcontext2; + let canvas_qr = qrcode.canvas_qr2; + let context = qrcode.qrcontext2; } else { - var canvas_qr = document.getElementById("qr-canvas"); - var context = canvas_qr.getContext('2d'); + let canvas_qr = document.getElementById("qr-canvas"); + let context = canvas_qr.getContext('2d'); } qrcode.width = canvas_qr.width; qrcode.height = canvas_qr.height; @@ -160,25 +160,25 @@ qrcode.decode = function(src){ } else { - var image = new Image(); + let image = new Image(); image.crossOrigin = "Anonymous"; image.onload=function(){ //var canvas_qr = document.getElementById("qr-canvas"); - var canvas_out = document.getElementById("out-canvas"); + let canvas_out = document.getElementById("out-canvas"); if(canvas_out!=null) { - var outctx = canvas_out.getContext('2d'); + let outctx = canvas_out.getContext('2d'); outctx.clearRect(0, 0, 320, 240); outctx.drawImage(image, 0, 0, 320, 240); } - var canvas_qr = document.createElement('canvas'); - var context = canvas_qr.getContext('2d'); - var nheight = image.height; - var nwidth = image.width; + let canvas_qr = document.createElement('canvas'); + let context = canvas_qr.getContext('2d'); + let nheight = image.height; + let nwidth = image.width; if(image.width*image.height>qrcode.maxImgSize) { - var ir = image.width / image.height; + let ir = image.width / image.height; nheight = Math.sqrt(qrcode.maxImgSize/ir); nwidth=ir*nheight; } @@ -221,13 +221,13 @@ qrcode.decode = function(src){ qrcode.isUrl = function(s) { - var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/; + let regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/; return regexp.test(s); } qrcode.decode_url = function (s) { - var escaped = ""; + let escaped = ""; try{ escaped = escape( s ); } @@ -258,18 +258,18 @@ qrcode.decode_utf8 = function ( s ) qrcode.process = function(ctx){ - var start = new Date().getTime(); + let start = new Date().getTime(); - var image = qrcode.grayScaleToBitmap(qrcode.grayscale()); + let image = qrcode.grayScaleToBitmap(qrcode.grayscale()); //var image = qrcode.binarize(128); if(qrcode.debug) { - for (var y = 0; y < qrcode.height; y++) + for (let y = 0; y < qrcode.height; y++) { - for (var x = 0; x < qrcode.width; x++) + for (let x = 0; x < qrcode.width; x++) { - var point = (x * 4) + (y * qrcode.width * 4); + let point = (x * 4) + (y * qrcode.width * 4); qrcode.imagedata.data[point] = image[x+y*qrcode.width]?0:0; qrcode.imagedata.data[point+1] = image[x+y*qrcode.width]?0:0; qrcode.imagedata.data[point+2] = image[x+y*qrcode.width]?255:0; @@ -280,17 +280,17 @@ qrcode.process = function(ctx){ //var finderPatternInfo = new FinderPatternFinder().findFinderPattern(image); - var detector = new Detector(image); + let detector = new Detector(image); - var qRCodeMatrix = detector.detect(); + let qRCodeMatrix = detector.detect(); if(qrcode.debug) { - for (var y = 0; y < qRCodeMatrix.bits.Height; y++) + for (let y = 0; y < qRCodeMatrix.bits.Height; y++) { - for (var x = 0; x < qRCodeMatrix.bits.Width; x++) + for (let x = 0; x < qRCodeMatrix.bits.Width; x++) { - var point = (x * 4*2) + (y*2 * qrcode.width * 4); + let point = (x * 4*2) + (y*2 * qrcode.width * 4); qrcode.imagedata.data[point] = qRCodeMatrix.bits.get_Renamed(x,y)?0:0; qrcode.imagedata.data[point+1] = qRCodeMatrix.bits.get_Renamed(x,y)?0:0; qrcode.imagedata.data[point+2] = qRCodeMatrix.bits.get_Renamed(x,y)?255:0; @@ -300,17 +300,17 @@ qrcode.process = function(ctx){ } - var reader = Decoder.decode(qRCodeMatrix.bits); - var data = reader.DataByte; - var str=""; - for(var i=0;i minmax[ax][ay][1]) @@ -377,14 +377,14 @@ qrcode.getMiddleBrightnessPerArea=function(image) //minmax[ax][ay][0] = (minmax[ax][ay][0] + minmax[ax][ay][1]) / 2; } } - var middle = new Array(numSqrtArea); - for (var i3 = 0; i3 < numSqrtArea; i3++) + let middle = new Array(numSqrtArea); + for (let i3 = 0; i3 < numSqrtArea; i3++) { middle[i3] = new Array(numSqrtArea); } - for (var ay = 0; ay < numSqrtArea; ay++) + for (let ay = 0; ay < numSqrtArea; ay++) { - for (var ax = 0; ax < numSqrtArea; ax++) + for (let ax = 0; ax < numSqrtArea; ax++) { middle[ax][ay] = Math.floor((minmax[ax][ay][0] + minmax[ax][ay][1]) / 2); //Console.out.print(middle[ax][ay] + ","); @@ -398,23 +398,23 @@ qrcode.getMiddleBrightnessPerArea=function(image) qrcode.grayScaleToBitmap=function(grayScale) { - var middle = qrcode.getMiddleBrightnessPerArea(grayScale); - var sqrtNumArea = middle.length; - var areaWidth = Math.floor(qrcode.width / sqrtNumArea); - var areaHeight = Math.floor(qrcode.height / sqrtNumArea); + let middle = qrcode.getMiddleBrightnessPerArea(grayScale); + let sqrtNumArea = middle.length; + let areaWidth = Math.floor(qrcode.width / sqrtNumArea); + let areaHeight = Math.floor(qrcode.height / sqrtNumArea); - var buff = new ArrayBuffer(qrcode.width*qrcode.height); - var bitmap = new Uint8Array(buff); + let buff = new ArrayBuffer(qrcode.width*qrcode.height); + let bitmap = new Uint8Array(buff); //var bitmap = new Array(qrcode.height*qrcode.width); - for (var ay = 0; ay < sqrtNumArea; ay++) + for (let ay = 0; ay < sqrtNumArea; ay++) { - for (var ax = 0; ax < sqrtNumArea; ax++) + for (let ax = 0; ax < sqrtNumArea; ax++) { - for (var dy = 0; dy < areaHeight; dy++) + for (let dy = 0; dy < areaHeight; dy++) { - for (var dx = 0; dx < areaWidth; dx++) + for (let dx = 0; dx < areaWidth; dx++) { bitmap[areaWidth * ax + dx+ (areaHeight * ay + dy)*qrcode.width] = (grayScale[areaWidth * ax + dx+ (areaHeight * ay + dy)*qrcode.width] < middle[ax][ay])?true:false; } @@ -426,15 +426,15 @@ qrcode.grayScaleToBitmap=function(grayScale) qrcode.grayscale = function() { - var buff = new ArrayBuffer(qrcode.width*qrcode.height); - var ret = new Uint8Array(buff); + let buff = new ArrayBuffer(qrcode.width*qrcode.height); + let ret = new Uint8Array(buff); //var ret = new Array(qrcode.width*qrcode.height); - for (var y = 0; y < qrcode.height; y++) + for (let y = 0; y < qrcode.height; y++) { - for (var x = 0; x < qrcode.width; x++) + for (let x = 0; x < qrcode.width; x++) { - var gray = qrcode.getPixel(x, y); + let gray = qrcode.getPixel(x, y); ret[x+y*qrcode.width] = gray; }