Fixed syntax errors and errors with inexisting or improperly declared variables. Didn't fix things that make stuff not work tho
This commit is contained in:
parent
3686341677
commit
a106d0f468
@ -29,12 +29,12 @@ class EdgeDetect{
|
|||||||
findBars(image, sampleCols, direction = EdgeDetectPrimaryDirection.VERTICAL, quality = EdgeDetectQuality.IMPROVED, guardLineOut){
|
findBars(image, sampleCols, direction = EdgeDetectPrimaryDirection.VERTICAL, quality = EdgeDetectQuality.IMPROVED, guardLineOut){
|
||||||
var fastCandidates, edgeCandidates, bars;
|
var fastCandidates, edgeCandidates, bars;
|
||||||
if (direction == EdgeDetectPrimaryDirection.VERTICAL) {
|
if (direction == EdgeDetectPrimaryDirection.VERTICAL) {
|
||||||
fastCandidates = this.findCandidates(image, sampleCols, guardLine);
|
fastCandidates = this.findCandidates(image, sampleCols, guardLineOut);
|
||||||
|
|
||||||
// if(quality == EdgeDetectQuality.FAST){
|
// if(quality == EdgeDetectQuality.FAST){
|
||||||
// edges = fastCandidates; // todo: processing
|
// edges = fastCandidates; // todo: processing
|
||||||
// } else {
|
// } else {
|
||||||
edgeCandidates = this.edgeDetect(image, edges);
|
edgeCandidates = this.edgeDetect(image, fastCandidates);
|
||||||
bars = this.edgePostprocess(edgeCandidates, this.conf.canvas.height);
|
bars = this.edgePostprocess(edgeCandidates, this.conf.canvas.height);
|
||||||
// }
|
// }
|
||||||
} else {
|
} else {
|
||||||
@ -52,16 +52,16 @@ class EdgeDetect{
|
|||||||
var cols_b = []
|
var cols_b = []
|
||||||
|
|
||||||
// todo: cloning can be done better. check array.splice or whatever
|
// todo: cloning can be done better. check array.splice or whatever
|
||||||
for(var i in cols){
|
for(var i in sampleCols){
|
||||||
cols_b[i] = cols_a[i] + 0;
|
cols_b[i] = cols_a[i] + 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
var res_top = [];
|
var res_top = [];
|
||||||
var res_bottom = [];
|
var res_bottom = [];
|
||||||
|
|
||||||
this.colsTreshold = cols.length * ExtensionConf.arDetect.edgeDetection.minColsForSearch;
|
this.colsTreshold = sampleCols.length * ExtensionConf.arDetect.edgeDetection.minColsForSearch;
|
||||||
if(colsTreshold == 0)
|
if(this.colsTreshold == 0)
|
||||||
colsTreshold = 1;
|
this.colsTreshold = 1;
|
||||||
|
|
||||||
this.blackbarTreshold = this.conf.blackLevel + ExtensionConf.arDetect.blackbarTreshold;
|
this.blackbarTreshold = this.conf.blackLevel + ExtensionConf.arDetect.blackbarTreshold;
|
||||||
|
|
||||||
@ -137,6 +137,7 @@ class EdgeDetect{
|
|||||||
var topEdgeCount = 0;
|
var topEdgeCount = 0;
|
||||||
var bottomEdgeCount = 0;
|
var bottomEdgeCount = 0;
|
||||||
|
|
||||||
|
var sample;
|
||||||
|
|
||||||
for(sample of samples.res_top){
|
for(sample of samples.res_top){
|
||||||
blackEdgeViolation = false; // reset this
|
blackEdgeViolation = false; // reset this
|
||||||
@ -365,7 +366,7 @@ class EdgeDetect{
|
|||||||
var midpoint = (middleRowStart + (this.conf.canvas.width >> 1)) << 2
|
var midpoint = (middleRowStart + (this.conf.canvas.width >> 1)) << 2
|
||||||
var rowEnd = middleRowEnd << 2;
|
var rowEnd = middleRowEnd << 2;
|
||||||
|
|
||||||
var edge_left = -1; edge_right = -1;
|
var edge_left = -1, edge_right = -1;
|
||||||
|
|
||||||
// preverimo na levi strani
|
// preverimo na levi strani
|
||||||
// let's check for edge on the left side
|
// let's check for edge on the left side
|
||||||
@ -503,7 +504,7 @@ class EdgeDetect{
|
|||||||
col: col,
|
col: col,
|
||||||
top: (i / this.conf.canvasImageDataRowLength) - 1
|
top: (i / this.conf.canvasImageDataRowLength) - 1
|
||||||
});
|
});
|
||||||
colsIn.splice(cols_a.indexOf(col), 1);
|
colsIn.splice(colsIn.indexOf(col), 1);
|
||||||
this.conf.debugCanvas.trace(tmpI, DebugCanvasClasses.EDGEDETECT_CANDIDATE);
|
this.conf.debugCanvas.trace(tmpI, DebugCanvasClasses.EDGEDETECT_CANDIDATE);
|
||||||
} else {
|
} else {
|
||||||
this.conf.debugCanvas.trace(tmpI, DebugCanvasClasses.EDGEDETECT_ONBLACK);
|
this.conf.debugCanvas.trace(tmpI, DebugCanvasClasses.EDGEDETECT_ONBLACK);
|
||||||
|
@ -99,7 +99,7 @@ class PlayerData {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var isFullScreen = this.isFullScreen();
|
var isFullScreen = PlayerData.isFullScreen();
|
||||||
|
|
||||||
var trustCandidateAfterGrows = 2; // if candidate_width or candidate_height increases in either dimensions this many
|
var trustCandidateAfterGrows = 2; // if candidate_width or candidate_height increases in either dimensions this many
|
||||||
// times, we say we found our player. (This number ignores weird elements)
|
// times, we say we found our player. (This number ignores weird elements)
|
||||||
|
@ -2,20 +2,23 @@ class VideoData {
|
|||||||
|
|
||||||
constructor(video){
|
constructor(video){
|
||||||
this.video = video;
|
this.video = video;
|
||||||
// todo: add ArDetect instance
|
|
||||||
this.arDetector = new ArDetector(video); // this starts Ar detection. needs optional parameter that prevets ardetdctor from starting
|
// POZOR: VRSTNI RED JE POMEMBEN (arDetect mora bit zadnji)
|
||||||
this.resizer = new Resizer(this);
|
// NOTE: ORDERING OF OBJ INITIALIZATIONS IS IMPORTANT (arDetect needs to go last)
|
||||||
this.player = new PlayerData(this);
|
this.player = new PlayerData(this);
|
||||||
|
this.resizer = new Resizer(this);
|
||||||
|
|
||||||
|
this.arDetector = new ArDetector(this); // this starts Ar detection. needs optional parameter that prevets ardetdctor from starting
|
||||||
|
|
||||||
// player dimensions need to be in:
|
// player dimensions need to be in:
|
||||||
// this.player.dimensions
|
// this.player.dimensions
|
||||||
}
|
}
|
||||||
|
|
||||||
initAr() {
|
initArDetection() {
|
||||||
this.arDetector.init();
|
this.arDetector.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
startAr() {
|
startArDetection() {
|
||||||
this.arDetector.start();
|
this.arDetector.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,20 +1,27 @@
|
|||||||
class ArDetector {
|
class ArDetector {
|
||||||
|
|
||||||
constructor(videoData){
|
constructor(videoData){
|
||||||
this.videoData = videoData;
|
this.conf = videoData;
|
||||||
this.video = videoData.video;
|
this.video = videoData.video;
|
||||||
|
|
||||||
this.setupTimer = null;
|
this.setupTimer = null;
|
||||||
this.timer = null;
|
this.timer = null;
|
||||||
|
|
||||||
|
this.sampleCols = [];
|
||||||
|
|
||||||
// todo: dynamically detect the following two
|
// todo: dynamically detect the following two
|
||||||
this.canFallback = true;
|
this.canFallback = true;
|
||||||
this.fallbackMode = false;
|
this.fallbackMode = false;
|
||||||
|
|
||||||
|
this.blackLevel = ExtensionConf.arDetect.blackLevel_default;
|
||||||
|
|
||||||
this.init();
|
this.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
init(){
|
init(){
|
||||||
|
if(Debug.debug){
|
||||||
|
console.log("[ArDetect::init] Initializing autodetection")
|
||||||
|
}
|
||||||
this.guardLine = new GuardLine(this);
|
this.guardLine = new GuardLine(this);
|
||||||
this.edgeDetector = new EdgeDetect(this);
|
this.edgeDetector = new EdgeDetect(this);
|
||||||
this.debugCanvas = new DebugCanvas(this);
|
this.debugCanvas = new DebugCanvas(this);
|
||||||
@ -22,6 +29,16 @@ class ArDetector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setup(cwidth, cheight){
|
setup(cwidth, cheight){
|
||||||
|
if(Debug.debug){
|
||||||
|
console.log("[ArDetect::setup] Starting autodetection setup");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!cwidth){
|
||||||
|
cwidth = ExtensionConf.arDetect.hSamples;
|
||||||
|
cheight = ExtensionConf.arDetect.vSamples;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
try{
|
try{
|
||||||
if(Debug.debug)
|
if(Debug.debug)
|
||||||
console.log("%c[ArDetect::_ard_setup] Starting automatic aspect ratio detection", _ard_console_start);
|
console.log("%c[ArDetect::_ard_setup] Starting automatic aspect ratio detection", _ard_console_start);
|
||||||
@ -29,13 +46,13 @@ class ArDetector {
|
|||||||
this._halted = false;
|
this._halted = false;
|
||||||
this.detectionTimeoutEventCount = 0;
|
this.detectionTimeoutEventCount = 0;
|
||||||
|
|
||||||
// vstavimo začetne stolpce v _ard_sampleCols.
|
// vstavimo začetne stolpce v this.sampleCols.
|
||||||
// let's insert initial columns to _ard_sampleCols
|
// let's insert initial columns to this.sampleCols
|
||||||
this.sampleCols = [];
|
this.sampleCols = [];
|
||||||
|
|
||||||
var samplingIntervalPx = parseInt(cheight / ExtensionConf.arDetect.samplingInterval)
|
var samplingIntervalPx = parseInt(cheight / ExtensionConf.arDetect.samplingInterval)
|
||||||
for(var i = 1; i < ExtensionConf.arDetect.samplingInterval; i++){
|
for(var i = 1; i < ExtensionConf.arDetect.samplingInterval; i++){
|
||||||
_ard_sampleCols.push(i * samplingIntervalPx);
|
this.sampleCols.push(i * samplingIntervalPx);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.canvas){
|
if(this.canvas){
|
||||||
@ -68,7 +85,7 @@ class ArDetector {
|
|||||||
|
|
||||||
// do setup once
|
// do setup once
|
||||||
// tho we could do it for every frame
|
// tho we could do it for every frame
|
||||||
this.canvasScaleFactor = cheight / vid.videoHeight;
|
this.canvasScaleFactor = cheight / this.video.videoHeight;
|
||||||
|
|
||||||
try{
|
try{
|
||||||
// determine where to sample
|
// determine where to sample
|
||||||
@ -107,11 +124,11 @@ class ArDetector {
|
|||||||
this.guardLine.top = null;
|
this.guardLine.top = null;
|
||||||
this.guardLine.bottom = null;
|
this.guardLine.bottom = null;
|
||||||
|
|
||||||
_ard_resetBlackLevel();
|
this.resetBlackLevel();
|
||||||
this._forcehalt = false;
|
this._forcehalt = false;
|
||||||
// if we're restarting ArDetect, we need to do this in order to force-recalculate aspect ratio
|
// if we're restarting ArDetect, we need to do this in order to force-recalculate aspect ratio
|
||||||
|
|
||||||
videoData.setLastAr({type: "auto", ar: null});
|
this.conf.resizer.setLastAr({type: "auto", ar: null});
|
||||||
|
|
||||||
this.canvasImageDataRowLength = cwidth << 2;
|
this.canvasImageDataRowLength = cwidth << 2;
|
||||||
this.noLetterboxCanvasReset = false;
|
this.noLetterboxCanvasReset = false;
|
||||||
@ -123,7 +140,7 @@ class ArDetector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(Debug.debugCanvas.enabled){
|
if(Debug.debugCanvas.enabled){
|
||||||
DebugCanvas.init({width: cwidth, height: cheight});
|
this.debugCanvas.init({width: cwidth, height: cheight});
|
||||||
// DebugCanvas.draw("test marker","test","rect", {x:5, y:5}, {width: 5, height: 5});
|
// DebugCanvas.draw("test marker","test","rect", {x:5, y:5}, {width: 5, height: 5});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -147,27 +164,6 @@ class ArDetector {
|
|||||||
return ! this._halted;
|
return ! this._halted;
|
||||||
}
|
}
|
||||||
|
|
||||||
scheduleFrameCheck(timeout, force_reset){
|
|
||||||
if(! timeout){
|
|
||||||
this.frameCheck();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// run anything that needs to be run after frame check
|
|
||||||
this.postFrameCheck();
|
|
||||||
|
|
||||||
// don't allow more than 1 instance
|
|
||||||
if(this.timer){
|
|
||||||
clearTimeout(this.timer);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.timer = setTimeout(function(){
|
|
||||||
this.timer = null;
|
|
||||||
this.frameCheck();
|
|
||||||
},
|
|
||||||
timeout
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
postFrameCheck(){
|
postFrameCheck(){
|
||||||
if(Debug.debugCanvas.enabled){
|
if(Debug.debugCanvas.enabled){
|
||||||
@ -260,7 +256,7 @@ class ArDetector {
|
|||||||
|
|
||||||
// poglejmo, če se je razmerje stranic spremenilo
|
// poglejmo, če se je razmerje stranic spremenilo
|
||||||
// check if aspect ratio is changed:
|
// check if aspect ratio is changed:
|
||||||
var lastAr = this.videoData.getLastAr();
|
var lastAr = this.conf.getLastAr();
|
||||||
if( lastAr.type == "auto" && lastAr.ar != null){
|
if( lastAr.type == "auto" && lastAr.ar != null){
|
||||||
// spremembo lahko zavrnemo samo, če uporabljamo avtomatski način delovanja in če smo razmerje stranic
|
// spremembo lahko zavrnemo samo, če uporabljamo avtomatski način delovanja in če smo razmerje stranic
|
||||||
// že nastavili.
|
// že nastavili.
|
||||||
@ -300,7 +296,7 @@ class ArDetector {
|
|||||||
// IMPORTANT NOTE: GlobalVars.lastAr needs to be set after _res_setAr() is called, as _res_setAr() assumes we're
|
// IMPORTANT NOTE: GlobalVars.lastAr needs to be set after _res_setAr() is called, as _res_setAr() assumes we're
|
||||||
// setting a static aspect ratio (even if the function is called from here or ArDetect).
|
// setting a static aspect ratio (even if the function is called from here or ArDetect).
|
||||||
|
|
||||||
this.videoData.resizer.setAr(trueAr, {type: "auto", ar: trueAr});
|
this.conf.resizer.setAr(trueAr, {type: "auto", ar: trueAr});
|
||||||
}
|
}
|
||||||
|
|
||||||
frameCheck(){
|
frameCheck(){
|
||||||
@ -395,7 +391,7 @@ class ArDetector {
|
|||||||
if(Debug.debugArDetect)
|
if(Debug.debugArDetect)
|
||||||
console.log("[ArDetect::_ard_vdraw] black level undefined, resetting");
|
console.log("[ArDetect::_ard_vdraw] black level undefined, resetting");
|
||||||
|
|
||||||
_ard_resetBlackLevel();
|
this.resetBlackLevel();
|
||||||
}
|
}
|
||||||
|
|
||||||
// we get the entire frame so there's less references for garbage collection to catch
|
// we get the entire frame so there's less references for garbage collection to catch
|
||||||
@ -484,7 +480,7 @@ class ArDetector {
|
|||||||
// while resetting the CSS, we also reset guardline top and bottom back to null.
|
// while resetting the CSS, we also reset guardline top and bottom back to null.
|
||||||
|
|
||||||
if(! GlobalVars.arDetect.noLetterboxCanvasReset){
|
if(! GlobalVars.arDetect.noLetterboxCanvasReset){
|
||||||
this.videoData.resizer.reset({type: "auto", ar: null});
|
this.conf.resizer.reset({type: "auto", ar: null});
|
||||||
this.guardLine.top = null;
|
this.guardLine.top = null;
|
||||||
this.guardLine.bottom = null;
|
this.guardLine.bottom = null;
|
||||||
this.noLetterboxCanvasReset = true;
|
this.noLetterboxCanvasReset = true;
|
||||||
@ -508,7 +504,7 @@ class ArDetector {
|
|||||||
// let's check if we're cropping too much (or whatever)
|
// let's check if we're cropping too much (or whatever)
|
||||||
var guardLineOut;
|
var guardLineOut;
|
||||||
|
|
||||||
guardLineOut = GuardLine.check(image, fallbackMode);
|
guardLineOut = this.guardLine.check(image, fallbackMode);
|
||||||
|
|
||||||
if (guardLineOut.blackbarFail) { // add new ssamples to our sample columns
|
if (guardLineOut.blackbarFail) { // add new ssamples to our sample columns
|
||||||
for(var col of guardLineOut.offenders){
|
for(var col of guardLineOut.offenders){
|
||||||
@ -521,7 +517,7 @@ class ArDetector {
|
|||||||
|
|
||||||
// if we're in fallback mode and blackbar test failed, we restore CSS
|
// if we're in fallback mode and blackbar test failed, we restore CSS
|
||||||
if (fallbackMode && guardLineOut.blackbarFail) {
|
if (fallbackMode && guardLineOut.blackbarFail) {
|
||||||
this.videoData.resizer.reset({type: "auto", ar: null});
|
this.conf.resizer.reset({type: "auto", ar: null});
|
||||||
this.guardLine.reset();
|
this.guardLine.reset();
|
||||||
this.arDetect.noLetterboxCanvasReset = true;
|
this.arDetect.noLetterboxCanvasReset = true;
|
||||||
|
|
||||||
@ -548,14 +544,14 @@ class ArDetector {
|
|||||||
// that we will cut too much, we rather avoid doing anything at all. There's gonna be a next chance.
|
// that we will cut too much, we rather avoid doing anything at all. There's gonna be a next chance.
|
||||||
|
|
||||||
if(guardLineOut.blackbarFail || guardLineOut.imageFail){
|
if(guardLineOut.blackbarFail || guardLineOut.imageFail){
|
||||||
if(pillarTest(image)){
|
if(this.edgeDetector.findBars(image, null, EdgeDetectPrimaryDirection.HORIZONTAL).status === 'ar_known'){
|
||||||
|
|
||||||
if(Debug.debug && guardLineOut.blackbarFail){
|
if(Debug.debug && guardLineOut.blackbarFail){
|
||||||
console.log("[ArDetect::_ard_vdraw] Detected blackbar violation and pillarbox. Resetting to default aspect ratio.");
|
console.log("[ArDetect::_ard_vdraw] Detected blackbar violation and pillarbox. Resetting to default aspect ratio.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(! guardLineResult){
|
if(! guardLineResult){
|
||||||
this.videoData.resizer.reset({type: "auto", ar: null});
|
this.conf.resizer.reset({type: "auto", ar: null});
|
||||||
this.guardLine.reset();
|
this.guardLine.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -571,10 +567,8 @@ class ArDetector {
|
|||||||
GlobalVars.sampleCols_current = sampleCols.length;
|
GlobalVars.sampleCols_current = sampleCols.length;
|
||||||
|
|
||||||
// blackSamples -> {res_top, res_bottom}
|
// blackSamples -> {res_top, res_bottom}
|
||||||
var blackbarSamples = _ard_findBlackbarLimits(image, sampleCols, guardLineResult, imageDetectResult);
|
|
||||||
|
var edgePost = this.edgeDetector.findBars(image, sampleCols, EdgeDetectPrimaryDirection.VERTICAL, EdgeDetectQuality.IMPROVED, guardLineOut);
|
||||||
var edgeCandidates = _ard_edgeDetect(image, blackbarSamples);
|
|
||||||
var edgePost = _ard_edgePostprocess(edgeCandidates, this.canvas.height);
|
|
||||||
|
|
||||||
// console.log("SAMPLES:", blackbarSamples, "candidates:", edgeCandidates, "post:", edgePost,"\n\nblack level:",GlobalVars.arDetect.blackLevel, "tresh:", this.blackLevel + ExtensionConf.arDetect.blackbarTreshold);
|
// console.log("SAMPLES:", blackbarSamples, "candidates:", edgeCandidates, "post:", edgePost,"\n\nblack level:",GlobalVars.arDetect.blackLevel, "tresh:", this.blackLevel + ExtensionConf.arDetect.blackbarTreshold);
|
||||||
|
|
||||||
@ -615,6 +609,35 @@ class ArDetector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resetBlackLevel(){
|
||||||
|
this.blackLevel = ExtensionConf.arDetect.blackLevel_default;
|
||||||
|
}
|
||||||
|
|
||||||
|
scheduleFrameCheck(timeout, force_reset){
|
||||||
|
if(! timeout){
|
||||||
|
this.frameCheck();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// run anything that needs to be run after frame check
|
||||||
|
this.postFrameCheck();
|
||||||
|
|
||||||
|
// don't allow more than 1 instance
|
||||||
|
if(this.timer){
|
||||||
|
clearTimeout(this.timer);
|
||||||
|
}
|
||||||
|
|
||||||
|
var ths = this;
|
||||||
|
|
||||||
|
this.timer = setTimeout(function(){
|
||||||
|
ths.timer = null;
|
||||||
|
ths.frameCheck();
|
||||||
|
ths = null;
|
||||||
|
},
|
||||||
|
timeout
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Debug.debug)
|
if(Debug.debug)
|
||||||
|
@ -19,7 +19,7 @@ class PageInfo {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
debugger;
|
// debugger;
|
||||||
|
|
||||||
// add new videos
|
// add new videos
|
||||||
for(var video of vids){
|
for(var video of vids){
|
||||||
@ -41,9 +41,9 @@ class PageInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
initAr(){
|
initArDetection(){
|
||||||
for(var vd in this.videos){
|
for(var vd in this.videos){
|
||||||
vd.initAr();
|
vd.initArDetection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,6 +70,10 @@ class Resizer {
|
|||||||
this.applyCss(cssOffsets, stretchFactors);
|
this.applyCss(cssOffsets, stretchFactors);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setLastAr(override){
|
||||||
|
this.lastAr = override;
|
||||||
|
}
|
||||||
|
|
||||||
setStretchMode(stretchMode){
|
setStretchMode(stretchMode){
|
||||||
this.stretch.mode = stretchMode;
|
this.stretch.mode = stretchMode;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user