From 75a214962c2ebb407fe21ebc551c34b9532cf4fd Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Tue, 26 May 2020 01:40:25 +0200 Subject: [PATCH] switch arDetect with aard --- src/ext/lib/ar-detect/AardGl.js | 57 ++++++++------ src/ext/lib/ar-detect/ArDetector.js | 68 ++++++++--------- src/ext/lib/ar-detect/GuardLine.js | 22 +++--- .../lib/ar-detect/edge-detect/EdgeDetect.js | 76 +++++++++---------- src/ext/lib/comms/CommsServer.js | 6 +- 5 files changed, 118 insertions(+), 111 deletions(-) diff --git a/src/ext/lib/ar-detect/AardGl.js b/src/ext/lib/ar-detect/AardGl.js index 812c6f3..846991d 100644 --- a/src/ext/lib/ar-detect/AardGl.js +++ b/src/ext/lib/ar-detect/AardGl.js @@ -9,7 +9,7 @@ import DebugCanvas from './DebugCanvas'; import VideoAlignment from '../../../common/enums/video-alignment.enum'; import AspectRatio from '../../../common/enums/aspect-ratio.enum'; import { generateHorizontalAdder } from './gllib/shader-generators/HorizontalAdderGenerator'; -import { getVertexShader } from './gllib/shaders/vertex-shader'; +import { getBasicVertexShader } from './gllib/shaders/vertex-shader'; import { sleep } from '../Util'; /** @@ -30,7 +30,7 @@ class AardGl { this.canFallback = true; this.fallbackMode = false; - this.blackLevel = this.settings.active.arDetect.blackbar.blackLevel; + this.blackLevel = this.settings.activeaard.blackbar.blackLevel; this.arid = (Math.random()*100).toFixed(); @@ -61,15 +61,15 @@ class AardGl { // we slow down if ended or pausing. Detecting is pointless. // we don't stop outright in case seeking happens during pause/after video was // ended and video gets into 'playing' state again - return Date.now() - lastFrameCheckStartTime > this.settings.active.arDetect.timers.paused; + return Date.now() - lastFrameCheckStartTime > this.settings.activeaard.timers.paused; } if (this.video.error){ // če je video pavziran, še vedno skušamo zaznati razmerje stranic - ampak bolj poredko. // if the video is paused, we still do autodetection. We just do it less often. - return Date.now() - lastFrameCheckStartTime > this.settings.active.arDetect.timers.error; + return Date.now() - lastFrameCheckStartTime > this.settings.activeaard.timers.error; } - return Date.now() - lastFrameCheckStartTime > this.settings.active.arDetect.timers.playing; + return Date.now() - lastFrameCheckStartTime > this.settings.activeaard.timers.playing; } isRunning(){ @@ -114,7 +114,7 @@ class AardGl { } resetBlackLevel(){ - this.blackLevel = this.settings.active.arDetect.blackbar.blackLevel; + this.blackLevel = this.settings.activeaard.blackbar.blackLevel; } clearImageData(id) { @@ -223,7 +223,7 @@ class AardGl { glContext.compileShader(shader); // check if shader was compiled successfully - if (! glContext.getShaderParameter(shader, gl.COMPILE_STATUS)) { + if (! glContext.getShaderParameter(shader, this.gl.COMPILE_STATUS)) { glContext.deleteShader(shader); this.logger.log('error', ['init', 'debug', 'arDetect'], `%c[AardGl::setupShader] <@${this.arid}> Failed to setup shader.`, _ard_console_stop); return null; @@ -238,8 +238,9 @@ class AardGl { * @param {*} shaders — shaders (previously compiled with setupShader()) */ compileProgram(glContext, shaders) { + console.log(glContext, shaders); const program = glContext.createProgram(); - for (const shader of shadersr) { + for (const shader of shaders) { glContext.attachShader(program, shader); } glContext.linkProgram(program); @@ -306,8 +307,8 @@ class AardGl { // if (!cwidth) { - cwidth = this.settings.active.aardGl.canvasDimensions.sampleCanvas.width; - cheight = this.settings.active.aardGl.canvasDimensions.sampleCanvas.height; + cwidth = this.settings.activeaard.Gl.canvasDimensions.sampleCanvas.width; + cheight = this.settings.activeaard.Gl.canvasDimensions.sampleCanvas.height; } if (this.canvas) { @@ -322,11 +323,12 @@ class AardGl { this.canvas.width = cwidth; this.canvas.height = cheight; this.blackframeCanvas = document.createElement("canvas"); - this.blackframeCanvas.width = this.settings.active.arDetect.canvasDimensions.blackframeCanvas.width; - this.blackframeCanvas.height = this.settings.active.arDetect.canvasDimensions.blackframeCanvas.height; + this.blackframeCanvas.width = this.settings.activeaard.canvasDimensions.blackframeCanvas.width; + this.blackframeCanvas.height = this.settings.activeaard.canvasDimensions.blackframeCanvas.height; - this.context = this.canvas.getContext("2d"); + // this.context = this.canvas.getContext("2d"); + this.pixelBuffer = new Uint8Array(cwidth * cheight * 4); // // [2] SETUP WEBGL STUFF ————————————————————————————————————————————————————————————————————————————————— @@ -345,8 +347,8 @@ class AardGl { const glProgram = this.compileProgram(this.gl, [vertexShader, horizontalAdderShader]); // look up where the vertex data needs to go - const positionLocation = this.gl.getAttributeLocation(program, 'a_position'); - const textureCoordsLocation = this.gl.getAttributeLocation(program, 'a_textureCoords'); + // const positionLocation = this.gl.getAttributeLocation(glProgram, 'a_position'); + // const textureCoordsLocation = this.gl.getAttributeLocation(glProgram, 'a_textureCoords'); // create buffers and bind them const positionBuffer = this.gl.createBuffer(); @@ -355,18 +357,18 @@ class AardGl { this.gl.bindBuffer(this.gl.ARRAY_BUFFER, textureCoordsBuffer); // create a texture - const texture = this.gl.createTexture(); - this.gl.bindTexture(this.gl.TEXTURE_2D, texture); + this.texture = this.gl.createTexture(); + this.gl.bindTexture(this.gl.TEXTURE_2D, this.texture); // set some parameters // btw we don't need to set gl.TEXTURE_WRAP_[S|T], because it's set to repeat by default — which is what we want - this.gl.texParameteri(this.gl, this.gl.TEXTURE_MAG_FILTER, gl.NEAREST); - this.gl.texParameteri(this.gl, this.gl.TEXTURE_MIN_FILTER, gl.NEAREST); + this.gl.texParameteri(this.gl, this.gl.TEXTURE_MAG_FILTER, this.gl.NEAREST); + this.gl.texParameteri(this.gl, this.gl.TEXTURE_MIN_FILTER, this.gl.NEAREST); // we need a rectangle. This is output data, not texture. This means that the size of the rectangle should be // [sample count] x height of the sample, as shader can sample frame at a different resolution than what gets // rendered here. We don't need all horizontal pixels on our output. We do need all vertical pixels, though) - this.glSetRectangle(this.gl, this.settings.active.aard.sampleCols, cheight); + this.glSetRectangle(this.gl, this.settings.activeaard..sampleCols, cheight); // do setup once // tho we could do it for every frame @@ -418,6 +420,7 @@ class AardGl { } this.conf.arSetupComplete = true; + console.log("DRAWING BUFFER SIZE:", this.gl.drawingBufferWidth, '×', this.gl.drawingBufferHeight); } drawFrame() { @@ -455,7 +458,7 @@ class AardGl { while (!this._exited && exitedRetries --> 0) { this.logger.log('warn', 'debug', `[AardGl::main] <@${this.arid}> We are trying to start another instance of autodetection on current video, but the previous instance hasn't exited yet. Waiting for old instance to exit ...`); - await sleep(this.settings.active.arDetect.timers.tickrate); + await sleep(this.settings.activeaard.timers.tickrate); } if (!this._exited) { this.logger.log('error', 'debug', `[AardGl::main] <@${this.arid}> Previous instance didn't exit in time. Not starting a new one.`); @@ -469,7 +472,7 @@ class AardGl { this._exited = false; // set initial timestamps so frame check will trigger the first time we run the loop - let lastFrameCheckStartTime = Date.now() - (this.settings.active.aardGl.timers.playing << 1); + let lastFrameCheckStartTime = Date.now() - (this.settings.activeaard.Gl.timers.playing << 1); const frameCheckTimes = new Array(10).fill(-1); let frameCheckBufferIndex = 0; @@ -523,8 +526,12 @@ class AardGl { // // [0] try drawing image to canvas // + let imageData; + try { this.drawFrame(); + + this.fallbackMode = false; } catch (e) { this.logger.log('error', 'arDetect', `%c[AardGl::frameCheck] <@${this.arid}> %c[AardGl::frameCheck] can't draw image on canvas. ${this.canDoFallbackMode ? 'Trying canvas.drawWindow instead' : 'Doing nothing as browser doesn\'t support fallback mode.'}`, "color:#000; backgroud:#f51;", e); @@ -593,7 +600,7 @@ class AardGl { var trueHeight = this.canvas.height * zoomFactor - letterbox; - if(edges.top > 1 && edges.top <= this.settings.active.arDetect.fallbackMode.noTriggerZonePx ){ + if(edges.top > 1 && edges.top <= this.settings.activeaard.fallbackMode.noTriggerZonePx ){ this.logger.log('info', 'arDetect', `%c[AardGl::calculateArFromEdges] <@${this.arid}> Edge is in the no-trigger zone. Aspect ratio change is not triggered.`) return; } @@ -602,7 +609,7 @@ class AardGl { // x2, ker je safetyBorderPx definiran za eno stran. // safety border so we can detect aspect ratio narrowing (21:9 -> 16:9). // x2 because safetyBorderPx is for one side. - trueHeight += (this.settings.active.arDetect.fallbackMode.safetyBorderPx << 1); + trueHeight += (this.settings.activeaard.fallbackMode.safetyBorderPx << 1); return this.canvas.width * zoomFactor / trueHeight; } @@ -631,7 +638,7 @@ class AardGl { // is ar variance within acceptable levels? If yes -> we done this.logger.log('info', 'arDetect', `%c[AardGl::processAr] <@${this.arid}> New aspect ratio varies from the old one by this much:\n`,"color: #aaf","old Ar", lastAr.ar, "current ar", trueAr, "arDiff (absolute):",arDiff,"ar diff (relative to new ar)", arDiff_percent); - if (arDiff < trueAr * this.settings.active.arDetect.allowedArVariance){ + if (arDiff < trueAr * this.settings.activeaard.allowedArVariance){ this.logger.log('info', 'arDetect', `%c[AardGl::processAr] <@${this.arid}> Aspect ratio change denied — diff %: ${arDiff_percent}`, "background: #740; color: #fa2"); return; } diff --git a/src/ext/lib/ar-detect/ArDetector.js b/src/ext/lib/ar-detect/ArDetector.js index 4af5875..6ef8f2c 100644 --- a/src/ext/lib/ar-detect/ArDetector.js +++ b/src/ext/lib/ar-detect/ArDetector.js @@ -25,7 +25,7 @@ class ArDetector { this.canFallback = true; this.fallbackMode = false; - this.blackLevel = this.settings.active.arDetect.blackbar.blackLevel; + this.blackLevel = this.settings.activeaard.blackbar.blackLevel; this.arid = (Math.random()*100).toFixed(); @@ -97,8 +97,8 @@ class ArDetector { // if (!cwidth) { - cwidth = this.settings.active.arDetect.canvasDimensions.sampleCanvas.width; - cheight = this.settings.active.arDetect.canvasDimensions.sampleCanvas.height; + cwidth = this.settings.activeaard.canvasDimensions.sampleCanvas.width; + cheight = this.settings.activeaard.canvasDimensions.sampleCanvas.height; } if (this.canvas) { @@ -113,8 +113,8 @@ class ArDetector { this.canvas.width = cwidth; this.canvas.height = cheight; this.blackframeCanvas = document.createElement("canvas"); - this.blackframeCanvas.width = this.settings.active.arDetect.canvasDimensions.blackframeCanvas.width; - this.blackframeCanvas.height = this.settings.active.arDetect.canvasDimensions.blackframeCanvas.height; + this.blackframeCanvas.width = this.settings.activeaard.canvasDimensions.blackframeCanvas.width; + this.blackframeCanvas.height = this.settings.activeaard.canvasDimensions.blackframeCanvas.height; this.context = this.canvas.getContext("2d"); this.blackframeContext = this.blackframeCanvas.getContext("2d"); @@ -129,8 +129,8 @@ class ArDetector { // [2] determine places we'll use to sample our main frame // - var ncol = this.settings.active.arDetect.sampling.staticCols; - var nrow = this.settings.active.arDetect.sampling.staticRows; + var ncol = this.settings.activeaard.sampling.staticCols; + var nrow = this.settings.activeaard.sampling.staticRows; var colSpacing = this.canvas.width / ncol; var rowSpacing = (this.canvas.height << 2) / nrow; @@ -258,7 +258,7 @@ class ArDetector { while (!this._exited && exitedRetries --> 0) { this.logger.log('warn', 'debug', `[ArDetect::main] <@${this.arid}> We are trying to start another instance of autodetection on current video, but the previous instance hasn't exited yet. Waiting for old instance to exit ...`); - await sleep(this.settings.active.arDetect.timers.tickrate); + await sleep(this.settings.activeaard.timers.tickrate); } if (!this._exited) { this.logger.log('error', 'debug', `[ArDetect::main] <@${this.arid}> Previous instance didn't exit in time. Not starting a new one.`); @@ -272,7 +272,7 @@ class ArDetector { this._exited = false; // set initial timestamps so frame check will trigger the first time we run the loop - let lastFrameCheckStartTime = Date.now() - (this.settings.active.arDetect.timers.playing << 1); + let lastFrameCheckStartTime = Date.now() - (this.settings.activeaard.timers.playing << 1); const frameCheckTimes = new Array(10).fill(-1); let frameCheckBufferIndex = 0; @@ -303,7 +303,7 @@ class ArDetector { } } - await sleep(this.settings.active.arDetect.timers.tickrate); + await sleep(this.settings.activeaard.timers.tickrate); } this.logger.log('info', 'debug', `%c[ArDetect::main] <@${this.arid}> Main autodetection loop exited. Halted? ${this._halted}`, _ard_console_stop); @@ -319,15 +319,15 @@ class ArDetector { // we slow down if ended or pausing. Detecting is pointless. // we don't stop outright in case seeking happens during pause/after video was // ended and video gets into 'playing' state again - return Date.now() - lastFrameCheckStartTime > this.settings.active.arDetect.timers.paused; + return Date.now() - lastFrameCheckStartTime > this.settings.activeaard.timers.paused; } if (this.video.error){ // če je video pavziran, še vedno skušamo zaznati razmerje stranic - ampak bolj poredko. // if the video is paused, we still do autodetection. We just do it less often. - return Date.now() - lastFrameCheckStartTime > this.settings.active.arDetect.timers.error; + return Date.now() - lastFrameCheckStartTime > this.settings.activeaard.timers.error; } - return Date.now() - lastFrameCheckStartTime > this.settings.active.arDetect.timers.playing; + return Date.now() - lastFrameCheckStartTime > this.settings.activeaard.timers.playing; } isRunning(){ @@ -445,7 +445,7 @@ class ArDetector { var trueHeight = this.canvas.height * zoomFactor - letterbox; - if(edges.top > 1 && edges.top <= this.settings.active.arDetect.fallbackMode.noTriggerZonePx ){ + if(edges.top > 1 && edges.top <= this.settings.activeaard.fallbackMode.noTriggerZonePx ){ this.logger.log('info', 'arDetect', `%c[ArDetect::calculateArFromEdges] <@${this.arid}> Edge is in the no-trigger zone. Aspect ratio change is not triggered.`) return; } @@ -454,7 +454,7 @@ class ArDetector { // x2, ker je safetyBorderPx definiran za eno stran. // safety border so we can detect aspect ratio narrowing (21:9 -> 16:9). // x2 because safetyBorderPx is for one side. - trueHeight += (this.settings.active.arDetect.fallbackMode.safetyBorderPx << 1); + trueHeight += (this.settings.activeaard.fallbackMode.safetyBorderPx << 1); return this.canvas.width * zoomFactor / trueHeight; } @@ -483,7 +483,7 @@ class ArDetector { // is ar variance within acceptable levels? If yes -> we done this.logger.log('info', 'arDetect', `%c[ArDetect::processAr] <@${this.arid}> New aspect ratio varies from the old one by this much:\n`,"color: #aaf","old Ar", lastAr.ar, "current ar", trueAr, "arDiff (absolute):",arDiff,"ar diff (relative to new ar)", arDiff_percent); - if (arDiff < trueAr * this.settings.active.arDetect.allowedArVariance){ + if (arDiff < trueAr * this.settings.activeaard.allowedArVariance){ this.logger.log('info', 'arDetect', `%c[ArDetect::processAr] <@${this.arid}> Aspect ratio change denied — diff %: ${arDiff_percent}`, "background: #740; color: #fa2"); return; } @@ -698,11 +698,11 @@ class ArDetector { } else { if (this.conf.player.dimensions){ this.guardLine.setBlackbarManual({ - top: this.settings.active.arDetect.fallbackMode.noTriggerZonePx, - bottom: this.conf.player.dimensions.height - this.settings.active.arDetect.fallbackMode.noTriggerZonePx - 1 + top: this.settings.activeaard.fallbackMode.noTriggerZonePx, + bottom: this.conf.player.dimensions.height - this.settings.activeaard.fallbackMode.noTriggerZonePx - 1 },{ - top: edgePost.guardLineTop + this.settings.active.arDetect.guardLine.edgeTolerancePx, - bottom: edgePost.guardLineBottom - this.settings.active.arDetect.guardLine.edgeTolerancePx + top: edgePost.guardLineTop + this.settings.activeaard.guardLine.edgeTolerancePx, + bottom: edgePost.guardLineBottom - this.settings.activeaard.guardLine.edgeTolerancePx }) } } @@ -724,7 +724,7 @@ class ArDetector { } resetBlackLevel(){ - this.blackLevel = this.settings.active.arDetect.blackbar.blackLevel; + this.blackLevel = this.settings.activeaard.blackbar.blackLevel; } blackLevelTest_full() { @@ -749,7 +749,7 @@ class ArDetector { let cumulativeValue = 0; let blackPixelCount = 0; const bfImageData = this.blackframeContext.getImageData(0, 0, cols, rows).data; - const blackTreshold = this.blackLevel + this.settings.active.arDetect.blackbar.frameTreshold; + const blackTreshold = this.blackLevel + this.settings.activeaard.blackbar.frameTreshold; // we do some recon for letterbox and pillarbox. While this can't determine whether letterbox/pillarbox exists @@ -810,17 +810,17 @@ class ArDetector { } } - const hasSufficientVariance = Math.abs(var_r - var_g) / Math.max(var_r, var_g, 1) > this.settings.active.arDetect.blackframe.sufficientColorVariance - || Math.abs(var_r - var_b) / Math.max(var_r, var_b, 1) > this.settings.active.arDetect.blackframe.sufficientColorVariance - || Math.abs(var_b - var_g) / Math.max(var_b, var_g, 1) > this.settings.active.arDetect.blackframe.sufficientColorVariance + const hasSufficientVariance = Math.abs(var_r - var_g) / Math.max(var_r, var_g, 1) > this.settings.activeaard.blackframe.sufficientColorVariance + || Math.abs(var_r - var_b) / Math.max(var_r, var_b, 1) > this.settings.activeaard.blackframe.sufficientColorVariance + || Math.abs(var_b - var_g) / Math.max(var_b, var_g, 1) > this.settings.activeaard.blackframe.sufficientColorVariance - let isBlack = (blackPixelCount/(cols * rows) > this.settings.active.arDetect.blackframe.blackPixelsCondition); + let isBlack = (blackPixelCount/(cols * rows) > this.settings.activeaard.blackframe.blackPixelsCondition); if (! isBlack) { if (hasSufficientVariance) { - isBlack = cumulativeValue < this.settings.active.arDetect.blackframe.cumulativeThresholdLax; + isBlack = cumulativeValue < this.settings.activeaard.blackframe.cumulativeThresholdLax; } else { - isBlack = cumulativeValue < this.settings.active.arDetect.blackframe.cumulativeThresholdStrict; + isBlack = cumulativeValue < this.settings.activeaard.blackframe.cumulativeThresholdStrict; } } @@ -842,13 +842,13 @@ class ArDetector { gb: Math.abs(var_b - var_g) / Math.max(var_b, var_g, 1), }, relativePercent: { - rg: Math.abs(var_r - var_g) / Math.max(var_r, var_g, 1) / this.settings.active.arDetect.blackframe.sufficientColorVariance, - rb: Math.abs(var_r - var_b) / Math.max(var_r, var_b, 1) / this.settings.active.arDetect.blackframe.sufficientColorVariance, - gb: Math.abs(var_b - var_g) / Math.max(var_b, var_g, 1) / this.settings.active.arDetect.blackframe.sufficientColorVariance, + rg: Math.abs(var_r - var_g) / Math.max(var_r, var_g, 1) / this.settings.activeaard.blackframe.sufficientColorVariance, + rb: Math.abs(var_r - var_b) / Math.max(var_r, var_b, 1) / this.settings.activeaard.blackframe.sufficientColorVariance, + gb: Math.abs(var_b - var_g) / Math.max(var_b, var_g, 1) / this.settings.activeaard.blackframe.sufficientColorVariance, }, - varianceLimit: this.settings.active.arDetect.blackframe.sufficientColorVariance, + varianceLimit: this.settings.activeaard.blackframe.sufficientColorVariance, }, - cumulativeValuePercent: cumulativeValue / (hasSufficientVariance ? this.settings.active.arDetect.blackframe.cumulativeThresholdLax : this.settings.active.arDetect.blackframe.cumulativeThresholdStrict), + cumulativeValuePercent: cumulativeValue / (hasSufficientVariance ? this.settings.activeaard.blackframe.cumulativeThresholdLax : this.settings.activeaard.blackframe.cumulativeThresholdStrict), rowMax: rowMax, colMax: colMax, }; @@ -867,7 +867,7 @@ class ArDetector { // If we detect anything darker than blackLevel, we modify blackLevel to the new lowest value const rowOffset = this.canvas.width * (this.canvas.height - 1); - let currentMin = 255, currentMax = 0, colOffset_r, colOffset_g, colOffset_b, colOffset_rb, colOffset_gb, colOffset_bb, blthreshold = this.settings.active.arDetect.blackbar.threshold; + let currentMin = 255, currentMax = 0, colOffset_r, colOffset_g, colOffset_b, colOffset_rb, colOffset_gb, colOffset_bb, blthreshold = this.settings.activeaard.blackbar.threshold; // detect black level. if currentMax comes above blackbar + blackbar threshold, we know we aren't letterboxed diff --git a/src/ext/lib/ar-detect/GuardLine.js b/src/ext/lib/ar-detect/GuardLine.js index de95cf6..49ecff0 100644 --- a/src/ext/lib/ar-detect/GuardLine.js +++ b/src/ext/lib/ar-detect/GuardLine.js @@ -28,8 +28,8 @@ class GuardLine { } setBlackbar(bbconf){ - var bbTop = bbconf.top - this.settings.active.arDetect.guardLine.edgeTolerancePx; - var bbBottom = bbconf.bottom + this.settings.active.arDetect.guardLine.edgeTolerancePx; + var bbTop = bbconf.top - this.settings.activeaard.guardLine.edgeTolerancePx; + var bbBottom = bbconf.bottom + this.settings.activeaard.guardLine.edgeTolerancePx; // to odstrani vse neveljavne nastavitve in vse možnosti, ki niso smiselne // this removes any configs with invalid values or values that dont make sense @@ -43,16 +43,16 @@ class GuardLine { } this.imageBar = { - top: bbconf.top + 1 + this.settings.active.arDetect.guardLine.edgeTolerancePx, - bottom: bbconf.bottom - 1 - this.settings.active.arDetect.guardLine.edgeTolerancePx + top: bbconf.top + 1 + this.settings.activeaard.guardLine.edgeTolerancePx, + bottom: bbconf.bottom - 1 - this.settings.activeaard.guardLine.edgeTolerancePx } } check(image, fallbackMode){ // izračunaj enkrat in shrani na objekt // calculate once and save object-instance-wide - this.blackbarThreshold = this.conf.blackLevel + this.settings.active.arDetect.blackbar.threshold; - this.imageThreshold = this.blackbarThreshold + this.settings.active.arDetect.blackbar.imageThreshold; + this.blackbarThreshold = this.conf.blackLevel + this.settings.activeaard.blackbar.threshold; + this.imageThreshold = this.blackbarThreshold + this.settings.activeaard.blackbar.imageThreshold; // dejansko testiranje // actual checks @@ -95,7 +95,7 @@ class GuardLine { return { success: true }; } - var offset = parseInt(this.conf.canvas.width * this.settings.active.arDetect.guardLine.ignoreEdgeMargin) << 2; + var offset = parseInt(this.conf.canvas.width * this.settings.activeaard.guardLine.ignoreEdgeMargin) << 2; var offenders = []; var offenderCount = -1; // doing it this way means first offender has offenderCount==0. Ez index. @@ -160,7 +160,7 @@ class GuardLine { if(!this.imageBar.top || !this.imageBar.bottom) return { success: false }; - var offset = (this.conf.canvas.width * this.settings.active.arDetect.guardLine.ignoreEdgeMargin) << 2; + var offset = (this.conf.canvas.width * this.settings.activeaard.guardLine.ignoreEdgeMargin) << 2; // TODO: implement logo check. @@ -169,8 +169,8 @@ class GuardLine { // check both rows - by the rules and definitions, we shouldn't go out of bounds here. no need to check, then // if(fallbackMode){ - // var edge_upper = this.settings.active.arDetect.fallbackMode.noTriggerZonePx; - // var edge_lower = this.conf.canvas.height - this.settings.active.arDetect.fallbackMode.noTriggerZonePx - 1; + // var edge_upper = this.settings.activeaard.fallbackMode.noTriggerZonePx; + // var edge_lower = this.conf.canvas.height - this.settings.activeaard.fallbackMode.noTriggerZonePx - 1; // } // else{ var edge_upper = this.imageBar.top; @@ -181,7 +181,7 @@ class GuardLine { // robu (eden izmed robov je lahko v celoti črn) // how many non-black pixels we need to consider this check a success. We only need to detect enough pixels // on one edge (one of the edges can be black as long as both aren't) - var successThreshold = (this.conf.canvas.width * this.settings.active.arDetect.guardLine.imageTestThreshold); + var successThreshold = (this.conf.canvas.width * this.settings.activeaard.guardLine.imageTestThreshold); var rowStart, rowEnd; diff --git a/src/ext/lib/ar-detect/edge-detect/EdgeDetect.js b/src/ext/lib/ar-detect/edge-detect/EdgeDetect.js index 8931667..85685a0 100644 --- a/src/ext/lib/ar-detect/edge-detect/EdgeDetect.js +++ b/src/ext/lib/ar-detect/edge-detect/EdgeDetect.js @@ -15,10 +15,10 @@ class EdgeDetect{ this.logger = ardConf.logger; this.settings = ardConf.settings; - this.sampleWidthBase = this.settings.active.arDetect.edgeDetection.sampleWidth << 2; // corrected so we can work on imageData + this.sampleWidthBase = this.settings.active.aard.edgeDetection.sampleWidth << 2; // corrected so we can work on imageData this.halfSample = this.sampleWidthBase >> 1; - this.detectionThreshold = this.settings.active.arDetect.edgeDetection.detectionThreshold; + this.detectionThreshold = this.settings.active.aard.edgeDetection.detectionThreshold; this.init(); // initiate things that can change } @@ -73,12 +73,12 @@ class EdgeDetect{ const cols_b = cols_a.slice(0); const res_bottom = []; - this.colsThreshold = sampleCols.length * this.settings.active.arDetect.edgeDetection.minColsForSearch; + this.colsThreshold = sampleCols.length * this.settings.active.aard.edgeDetection.minColsForSearch; if (this.colsThreshold == 0) this.colsThreshold = 1; - this.blackbarThreshold = this.conf.blackLevel + this.settings.active.arDetect.blackbar.threshold; - this.imageThreshold = this.blackbarThreshold + this.settings.active.arDetect.blackbar.imageThreshold; + this.blackbarThreshold = this.conf.blackLevel + this.settings.active.aard.blackbar.threshold; + this.imageThreshold = this.blackbarThreshold + this.settings.active.aard.blackbar.imageThreshold; // if guardline didn't fail and imageDetect did, we don't have to check the upper few pixels // but only if upper and lower edge are defined. If they're not, we need to check full height @@ -100,14 +100,14 @@ class EdgeDetect{ lower_bottom = this.conf.canvas.height - 1; } else { upper_top = 0; - upper_bottom = (this.conf.canvas.height >> 1) /*- parseInt(this.conf.canvas.height * this.settings.active.arDetect.edgeDetection.middleIgnoredArea);*/ - lower_top = (this.conf.canvas.height >> 1) /*+ parseInt(this.conf.canvas.height * this.settings.active.arDetect.edgeDetection.middleIgnoredArea);*/ + upper_bottom = (this.conf.canvas.height >> 1) /*- parseInt(this.conf.canvas.height * this.settings.active.aard.edgeDetection.middleIgnoredArea);*/ + lower_top = (this.conf.canvas.height >> 1) /*+ parseInt(this.conf.canvas.height * this.settings.active.aard.edgeDetection.middleIgnoredArea);*/ lower_bottom = this.conf.canvas.height - 1; } } else{ upper_top = 0; - upper_bottom = (this.conf.canvas.height >> 1) /*- parseInt(this.conf.canvas.height * this.settings.active.arDetect.edgeDetection.middleIgnoredArea);*/ - lower_top = (this.conf.canvas.height >> 1) /*+ parseInt(this.conf.canvas.height * this.settings.active.arDetect.edgeDetection.middleIgnoredArea);*/ + upper_bottom = (this.conf.canvas.height >> 1) /*- parseInt(this.conf.canvas.height * this.settings.active.aard.edgeDetection.middleIgnoredArea);*/ + lower_top = (this.conf.canvas.height >> 1) /*+ parseInt(this.conf.canvas.height * this.settings.active.aard.edgeDetection.middleIgnoredArea);*/ lower_bottom = this.conf.canvas.height - 1; } @@ -251,8 +251,8 @@ class EdgeDetect{ sampleEnd = this.conf.canvasImageDataRowLength; // calculate row offsets for imageData array - sampleRow_black = (sample.black - this.settings.active.arDetect.edgeDetection.edgeTolerancePx - 1) * this.conf.canvasImageDataRowLength; - sampleRow_color = (sample.black + this.settings.active.arDetect.edgeDetection.edgeTolerancePx) * this.conf.canvasImageDataRowLength; + sampleRow_black = (sample.black - this.settings.active.aard.edgeDetection.edgeTolerancePx - 1) * this.conf.canvasImageDataRowLength; + sampleRow_color = (sample.black + this.settings.active.aard.edgeDetection.edgeTolerancePx) * this.conf.canvasImageDataRowLength; // že ena kršitev črnega roba pomeni, da kandidat ni primeren // even a single black edge violation means the candidate is not an edge @@ -294,8 +294,8 @@ class EdgeDetect{ sampleEnd = this.conf.canvasImageDataRowLength; // calculate row offsets for imageData array - sampleRow_black = (sample.black + this.settings.active.arDetect.edgeDetection.edgeTolerancePx + 1) * this.conf.canvasImageDataRowLength; - sampleRow_color = (sample.black - this.settings.active.arDetect.edgeDetection.edgeTolerancePx) * this.conf.canvasImageDataRowLength; + sampleRow_black = (sample.black + this.settings.active.aard.edgeDetection.edgeTolerancePx + 1) * this.conf.canvasImageDataRowLength; + sampleRow_color = (sample.black - this.settings.active.aard.edgeDetection.edgeTolerancePx) * this.conf.canvasImageDataRowLength; // že ena kršitev črnega roba pomeni, da kandidat ni primeren // even a single black edge violation means the candidate is not an edge @@ -337,7 +337,7 @@ class EdgeDetect{ edgePostprocess(edges){ var edgesTop = []; var edgesBottom = []; - var alignMargin = this.conf.canvas.height * this.settings.active.arDetect.allowedMisaligned; + var alignMargin = this.conf.canvas.height * this.settings.active.aard.allowedMisaligned; var missingEdge = edges.edgeCandidatesTopCount == 0 || edges.edgeCandidatesBottomCount == 0; @@ -391,8 +391,8 @@ class EdgeDetect{ var blackbarWidth = edgesTop[0].distance > edgesBottom[0].distance ? edgesTop[0].distance : edgesBottom[0].distance; - if (edgesTop[0].count + edgesBottom[0].count > this.settings.active.arDetect.edgeDetection.singleSideConfirmationThreshold - || ( edgesTop[0].count > this.settings.active.arDetect.edgeDetection.confirmationThreshold && edgesBottom[0].count > this.settings.active.arDetect.edgeDetection.confirmationThreshold) ){ + if (edgesTop[0].count + edgesBottom[0].count > this.settings.active.aard.edgeDetection.singleSideConfirmationThreshold + || ( edgesTop[0].count > this.settings.active.aard.edgeDetection.confirmationThreshold && edgesBottom[0].count > this.settings.active.aard.edgeDetection.confirmationThreshold) ){ return { status: EdgeStatus.AR_KNOWN, blackbarWidth: blackbarWidth, @@ -409,7 +409,7 @@ class EdgeDetect{ // it could be watermark. It could be a dark frame. Let's check for watermark first. if (edgesTop[0].distance < edgesBottom[0].distance && edgesTop[0].count < edgesBottom[0].count && - edgesTop[0].count < this.conf.sampleCols.length * this.settings.active.arDetect.edgeDetection.logoThreshold){ + edgesTop[0].count < this.conf.sampleCols.length * this.settings.active.aard.edgeDetection.logoThreshold){ // možno, da je watermark zgoraj. Preverimo, če se kateri od drugih potencialnih robov na zgornjem robu // ujema s prvim spodnjim (+/- variance). Če je temu tako, potem bo verjetno watermark. Logo mora imeti // manj vzorcev kot navaden rob. @@ -425,8 +425,8 @@ class EdgeDetect{ var blackbarWidth = edgesTop[i].distance > edgesBottom[0].distance ? edgesTop[i].distance : edgesBottom[0].distance; - if (edgesTop[i].count + edgesBottom[0].count > this.settings.active.arDetect.edgeDetection.singleSideConfirmationThreshold - || (edgesTop[i].count > this.settings.active.arDetect.edgeDetection.singleSideConfirmationThreshold && edgesBottom[0].count > this.settings.active.arDetect.edgeDetection.confirmationThreshold) ) { + if (edgesTop[i].count + edgesBottom[0].count > this.settings.active.aard.edgeDetection.singleSideConfirmationThreshold + || (edgesTop[i].count > this.settings.active.aard.edgeDetection.singleSideConfirmationThreshold && edgesBottom[0].count > this.settings.active.aard.edgeDetection.confirmationThreshold) ) { return { status: EdgeStatus.AR_KNOWN, blackbarWidth: blackbarWidth, @@ -443,7 +443,7 @@ class EdgeDetect{ } if (edgesBottom[0].distance < edgesTop[0].distance && edgesBottom[0].count < edgesTop[0].count && - edgesBottom[0].count < this.conf.sampleCols.length * this.settings.active.arDetect.edgeDetection.logoThreshold){ + edgesBottom[0].count < this.conf.sampleCols.length * this.settings.active.aard.edgeDetection.logoThreshold){ if(edgesBottom[0].length > 1){ var lowMargin = edgesTop[0].distance - alignMargin; @@ -456,8 +456,8 @@ class EdgeDetect{ var blackbarWidth = edgesBottom[i].distance > edgesTop[0].distance ? edgesBottom[i].distance : edgesTop[0].distance; - if (edgesTop[0].count + edgesBottom[i].count > this.settings.active.arDetect.edgeDetection.singleSideConfirmationThreshold - || (edgesTop[0].count > this.settings.active.arDetect.edgeDetection.singleSideConfirmationThreshold && edgesBottom[i].count > this.settings.active.arDetect.edgeDetection.confirmationThreshold)) { + if (edgesTop[0].count + edgesBottom[i].count > this.settings.active.aard.edgeDetection.singleSideConfirmationThreshold + || (edgesTop[0].count > this.settings.active.aard.edgeDetection.singleSideConfirmationThreshold && edgesBottom[i].count > this.settings.active.aard.edgeDetection.confirmationThreshold)) { return { status: EdgeStatus.AR_KNOWN, blackbarWidth: blackbarWidth, @@ -479,7 +479,7 @@ class EdgeDetect{ // either the top or the bottom edge remains undetected, but we have one more trick that we // can try. It also tries to work around logos. - const edgeDetectionThreshold = this.settings.active.arDetect.edgeDetection.singleSideConfirmationThreshold; + const edgeDetectionThreshold = this.settings.active.aard.edgeDetection.singleSideConfirmationThreshold; if (edges.edgeCandidatesTopCount == 0 && edges.edgeCandidatesBottomCount != 0){ for(var edge of edgesBottom){ @@ -524,7 +524,7 @@ class EdgeDetect{ // we also return true if we detect too much black var blackbarThreshold, upper, lower; - blackbarThreshold = this.conf.blackLevel + this.settings.active.arDetect.blackbar.threshold; + blackbarThreshold = this.conf.blackLevel + this.settings.active.aard.blackbar.threshold; var middleRowStart = (this.conf.canvas.height >> 1) * this.conf.canvas.width; @@ -562,11 +562,11 @@ class EdgeDetect{ // če sta oba robova v mejah merske napake, potem vrnemo 'false' // if both edges resemble rounding error, we retunr 'false' - if(edge_left < this.settings.active.arDetect.pillarTest.ignoreThinPillarsPx && edge_right < this.settings.active.arDetect.pillarTest.ignoreThinPillarsPx){ + if(edge_left < this.settings.active.aard.pillarTest.ignoreThinPillarsPx && edge_right < this.settings.active.aard.pillarTest.ignoreThinPillarsPx){ return false; } - var edgeError = this.settings.active.arDetect.pillarTest.allowMisaligned; + var edgeError = this.settings.active.aard.pillarTest.allowMisaligned; var error_low = 1 - edgeError; var error_hi = 1 + edgeError; @@ -646,7 +646,7 @@ class EdgeDetect{ imageRow: -1, lastValue: -1, diffIndex: 0, - diffs: new Array(this.settings.active.arDetect.blackbar.gradientSampleSize).fill(0) + diffs: new Array(this.settings.active.aard.blackbar.gradientSampleSize).fill(0) } } @@ -724,7 +724,7 @@ class EdgeDetect{ } colsTmp[c].diffIndex++; - if (colsTmp[c].diffIndex > this.settings.active.arDetect.blackbar.gradientSampleSize) { + if (colsTmp[c].diffIndex > this.settings.active.aard.blackbar.gradientSampleSize) { colsTmp[c].imageFound = true; continue; } @@ -737,11 +737,11 @@ class EdgeDetect{ // let's process our results for (const c of colsTmp) { if (c.blackFound) { - if (this.settings.active.arDetect.blackbar.antiGradientMode === AntiGradientMode.Disabled) { + if (this.settings.active.aard.blackbar.antiGradientMode === AntiGradientMode.Disabled) { // if gradient detection is disabled, we treat such columns as detections/not gradient } if (c.imageFound) { - if (c.imageRow - c.blackRow <= this.settings.active.arDetect.blackbar.gradientThreshold) { + if (c.imageRow - c.blackRow <= this.settings.active.aard.blackbar.gradientThreshold) { // this is within our margin of error. Colums like this are auto-accepted colsOut.push({ col: c.col, @@ -757,7 +757,7 @@ class EdgeDetect{ tmpVal += c.diffs[i]; // if difference is negative, we aren't looking at a gradient - if (c.diffs[i] < this.settings.active.arDetect.blackbar.gradientNegativeTreshold) { + if (c.diffs[i] < this.settings.active.aard.blackbar.gradientNegativeTreshold) { colsOut.push({ col: c.col, black: c.blackRow @@ -766,7 +766,7 @@ class EdgeDetect{ } // if difference is too big, we assume we aren't looking at a gradient - if (c.diffs[i] > this.settings.active.arDetect.blackbar.maxGradient) { + if (c.diffs[i] > this.settings.active.aard.blackbar.maxGradient) { colsOut.push({ col: c.col, black: c.blackRow @@ -789,7 +789,7 @@ class EdgeDetect{ stdev = Math.sqrt((squareSum / (c.diffIndex - 1))); // if standard deviation is too big, we're not on a gradient (prolly) - if (stdev > this.settings.active.arDetect.blackbar.gradientMaxSD) { + if (stdev > this.settings.active.aard.blackbar.gradientMaxSD) { colsOut.push({ col: c.col, black: c.blackRow @@ -821,7 +821,7 @@ class EdgeDetect{ // we have blackbar but we haven't found a point that goes over imageTreshold. // how these cases are handled is determiend by what antiGradientMode we're using. // strict mode — treat as gradient. Lax mode — treat as not gradient - if (this.settings.active.arDetect.blackbar.antiGradientMode === AntiGradientMode.Lax) { + if (this.settings.active.aard.blackbar.antiGradientMode === AntiGradientMode.Lax) { colsOut.push({ col: c.col, black: c.blackRow @@ -852,7 +852,7 @@ class EdgeDetect{ c.diffs = []; } if (reverseSearchDirection) { - if (this.settings.active.arDetect.blackbar.antiGradientMode === AntiGradientMode.Disabled) { + if (this.settings.active.aard.blackbar.antiGradientMode === AntiGradientMode.Disabled) { // todo: remove gradient detection code from this branch for(var i = bottom - this.conf.canvasImageDataRowLength; i >= top; i-= this.conf.canvasImageDataRowLength){ for(let c = 0; c < colsIn.length; c++){ @@ -883,7 +883,7 @@ class EdgeDetect{ continue; } } else { - if (colsIn[c].blackFound++ > this.settings.active.arDetect.blackbar.gradientSampleSize) { + if (colsIn[c].blackFound++ > this.settings.active.aard.blackbar.gradientSampleSize) { colsIn[c].imageFound = true; continue; } @@ -961,7 +961,7 @@ class EdgeDetect{ } else { // če smo dobili piksel, ki presega blackbar, preverimo do gradientSampleSize dodatnih pikslov. // ko dobimo piksel čez imageTreshold oz. gradientSampleSize, izračunamo ali gre za gradient. - if (colsIn[c].blackFound++ > this.settings.active.arDetect.blackbar.gradientSampleSize) { + if (colsIn[c].blackFound++ > this.settings.active.aard.blackbar.gradientSampleSize) { colsIn[c].imageFound = true; continue; } @@ -1024,7 +1024,7 @@ class EdgeDetect{ continue; } } else { - if (colsIn[c].blackFound++ > this.settings.active.arDetect.blackbar.gradientSampleSize) { + if (colsIn[c].blackFound++ > this.settings.active.aard.blackbar.gradientSampleSize) { colsIn[c].imageFound = true; continue; } diff --git a/src/ext/lib/comms/CommsServer.js b/src/ext/lib/comms/CommsServer.js index b3a6d16..306edfa 100644 --- a/src/ext/lib/comms/CommsServer.js +++ b/src/ext/lib/comms/CommsServer.js @@ -97,9 +97,9 @@ class CommsServer { (message) => { this.settings.active.sites['@global'].autoar = "disabled"; if (message.reason){ - this.settings.active.arDetect.disabledReason = message.reason; + this.settings.active.aard.disabledReason = message.reason; } else { - this.settings.active.arDetect.disabledReason = 'User disabled'; + this.settings.active.aard.disabledReason = 'User disabled'; } this.settings.save(); this.logger.log('info', 'comms', "[uw-bg] autoar set to disabled. evidenz:", this.settings.active); @@ -111,7 +111,7 @@ class CommsServer { // set fairly liberal limit var timeout = message.timeout < 4 ? 4 : message.timeout; - this.settings.active.arDetect.timer_playing = timeout; + this.settings.active.aard.timer_playing = timeout; this.settings.save(); } ],