From aa4dbc15f6caf133934d28288cc97927f610803b Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Thu, 21 Feb 2019 21:51:35 +0100 Subject: [PATCH] Gradient detect mode --- src/common/enums/anti-gradient-mode.enum.js | 7 +++++ src/ext/conf/Debug.js | 4 +-- src/ext/conf/ExtensionConf.js | 3 +++ .../lib/ar-detect/edge-detect/EdgeDetect.js | 26 ++++++++++++------- 4 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 src/common/enums/anti-gradient-mode.enum.js diff --git a/src/common/enums/anti-gradient-mode.enum.js b/src/common/enums/anti-gradient-mode.enum.js new file mode 100644 index 0000000..6a2787f --- /dev/null +++ b/src/common/enums/anti-gradient-mode.enum.js @@ -0,0 +1,7 @@ +var AntiGradientMode = Object.freeze({ + Disabled: 0, + Lax: 1, + Strict: 2 +}); + +export default EdgeDetectPrimaryDirection; diff --git a/src/ext/conf/Debug.js b/src/ext/conf/Debug.js index bd2e252..9097015 100644 --- a/src/ext/conf/Debug.js +++ b/src/ext/conf/Debug.js @@ -9,7 +9,7 @@ var Debug = { // debug: false, // keyboard: true, // debugResizer: true, - debugArDetect: true, + // debugArDetect: true, // debugStorage: false, // debugStorage: true, // comms: false, @@ -18,7 +18,7 @@ var Debug = { // flushStoredSettings: true, flushStoredSettings: false, // playerDetectDebug: true, - periodic: true, + // periodic: true, // videoRescan: true, // mousemove: true, arDetect: { diff --git a/src/ext/conf/ExtensionConf.js b/src/ext/conf/ExtensionConf.js index 9811230..5bc2b29 100644 --- a/src/ext/conf/ExtensionConf.js +++ b/src/ext/conf/ExtensionConf.js @@ -3,6 +3,7 @@ import currentBrowser from './BrowserDetect'; import VideoAlignment from '../../common/enums/video-alignment.enum'; import Stretch from '../../common/enums/stretch.enum'; import ExtensionMode from '../../common/enums/extension-mode.enum'; +import AntiGradientMode from '../../common/enums/anti-gradient-mode.enum'; if(Debug.debug) console.log("Loading: ExtensionConf.js"); @@ -61,6 +62,8 @@ var ExtensionConf = { // the last pixel that's darker than our treshold, and position of the first pixel that's // brighter than our image treshold. If positions are more than this many pixels apart, // we assume we aren't looking at letterbox and thus don't correct the aspect ratio. + gradientSampleSize: 8, // How far do we look to find the gradient + antiGradientMode: AntiGradientMode.Strict, }, variableBlackbarTresholdOptions: { // In case of poor bitrate videos, jpeg artifacts may cause us issues // FOR FUTURE USE diff --git a/src/ext/lib/ar-detect/edge-detect/EdgeDetect.js b/src/ext/lib/ar-detect/edge-detect/EdgeDetect.js index 2cf48cc..a1630cc 100644 --- a/src/ext/lib/ar-detect/edge-detect/EdgeDetect.js +++ b/src/ext/lib/ar-detect/edge-detect/EdgeDetect.js @@ -140,19 +140,29 @@ class EdgeDetect{ const res_bottom = []; for (let item of res_top_preliminary) { - if (!item.image) { - continue; - } - if (item.image > -1 && item.image <= item.black + this.settings.active.arDetect.blackbar.gradientTreshold) { + if (this.settings.active.arDetect.blackbar.antiGradientMode === AntiGradientMode.Disabled) { res_top.push({top: item.image, col: item.col}); + } else if (this.settings.active.arDetect.blackbar.antiGradientMode === AntiGradientMode.Lax) { + if (item.image === undefined || item.image <= item.black + this.settings.active.arDetect.blackbar.gradientTreshold) { + res_top.push({top: item.image, col: item.col}); + } + } else { + if ( item.image !== undefined && item.image <= item.black + this.settings.active.arDetect.blackbar.gradientTreshold) { + res_top.push({top: item.image, col: item.col}); + } } } for (let item of res_bottom_preliminary) { if (!item.image) { continue; } - if (item.image >= item.black - this.settings.active.arDetect.blackbar.gradientTreshold) { + if (this.settings.active.arDetect.blackbar.antiGradientMode === AntiGradientMode.Disabled) { res_bottom.push({bottom: item.image, col: item.col}); + } else { + if ( (item.image !== undefined || this.settings.active.arDetect.blackbar.antiGradientMode === AntiGradientMode.Lax) + && item.image >= item.black - this.settings.active.arDetect.blackbar.gradientTreshold) { + res_bottom.push({bottom: item.image, col: item.col}); + } } } @@ -551,7 +561,6 @@ class EdgeDetect{ colsOut[c].black = (i / this.conf.canvasImageDataRowLength) - 1; colsOut[c].col = colsIn[c].value; colsIn[c].blackFound = 1; - console.log("BLACK FOUND AT COL:", colsIn[c].value, '|', colsOut[c].col, "LINE:", colsOut[c].black, colsOut, colsOut[c]) // prisili, da se zanka izvede še enkrat ter preveri, // ali trenuten piksel preseže tudi imageTreshold @@ -562,7 +571,7 @@ class EdgeDetect{ continue; } } else { - if (colsIn[c].blackFound++ > this.settings.active.arDetect.blackbar.gradientTreshold) { + if (colsIn[c].blackFound++ > this.settings.active.arDetect.blackbar.gradientSampleSize) { colsIn[c].imageFound = true; continue; } @@ -605,7 +614,6 @@ class EdgeDetect{ colsOut[c].black = (i / this.conf.canvasImageDataRowLength); colsOut[c].col = colsIn[c].value; colsIn[c].blackFound = true; - console.log("BLACK FOUND AT COL:", colsIn[c].value, '|', colsOut[c].col, "LINE:", colsOut[c].black, colsOut, colsOut[c]) // prisili, da se zanka izvede še enkrat ter preveri, // ali trenuten piksel preseže tudi imageTreshold @@ -616,7 +624,7 @@ class EdgeDetect{ continue; } } else { - if (colsIn[c].blackFound++ > this.settings.active.arDetect.blackbar.gradientTreshold) { + if (colsIn[c].blackFound++ > this.settings.active.arDetect.blackbar.gradientSampleSize) { colsIn[c].imageFound = true; continue; }