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:
Tamius Han 2018-05-14 20:39:15 +02:00
parent 3686341677
commit a106d0f468
6 changed files with 89 additions and 58 deletions

View File

@ -29,12 +29,12 @@ class EdgeDetect{
findBars(image, sampleCols, direction = EdgeDetectPrimaryDirection.VERTICAL, quality = EdgeDetectQuality.IMPROVED, guardLineOut){
var fastCandidates, edgeCandidates, bars;
if (direction == EdgeDetectPrimaryDirection.VERTICAL) {
fastCandidates = this.findCandidates(image, sampleCols, guardLine);
fastCandidates = this.findCandidates(image, sampleCols, guardLineOut);
// if(quality == EdgeDetectQuality.FAST){
// edges = fastCandidates; // todo: processing
// } else {
edgeCandidates = this.edgeDetect(image, edges);
edgeCandidates = this.edgeDetect(image, fastCandidates);
bars = this.edgePostprocess(edgeCandidates, this.conf.canvas.height);
// }
} else {
@ -52,16 +52,16 @@ class EdgeDetect{
var cols_b = []
// 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;
}
var res_top = [];
var res_bottom = [];
this.colsTreshold = cols.length * ExtensionConf.arDetect.edgeDetection.minColsForSearch;
if(colsTreshold == 0)
colsTreshold = 1;
this.colsTreshold = sampleCols.length * ExtensionConf.arDetect.edgeDetection.minColsForSearch;
if(this.colsTreshold == 0)
this.colsTreshold = 1;
this.blackbarTreshold = this.conf.blackLevel + ExtensionConf.arDetect.blackbarTreshold;
@ -137,6 +137,7 @@ class EdgeDetect{
var topEdgeCount = 0;
var bottomEdgeCount = 0;
var sample;
for(sample of samples.res_top){
blackEdgeViolation = false; // reset this
@ -365,7 +366,7 @@ class EdgeDetect{
var midpoint = (middleRowStart + (this.conf.canvas.width >> 1)) << 2
var rowEnd = middleRowEnd << 2;
var edge_left = -1; edge_right = -1;
var edge_left = -1, edge_right = -1;
// preverimo na levi strani
// let's check for edge on the left side
@ -503,7 +504,7 @@ class EdgeDetect{
col: col,
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);
} else {
this.conf.debugCanvas.trace(tmpI, DebugCanvasClasses.EDGEDETECT_ONBLACK);

View File

@ -99,7 +99,7 @@ class PlayerData {
return;
}
var isFullScreen = this.isFullScreen();
var isFullScreen = PlayerData.isFullScreen();
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)

View File

@ -2,20 +2,23 @@ class VideoData {
constructor(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
this.resizer = new Resizer(this);
// POZOR: VRSTNI RED JE POMEMBEN (arDetect mora bit zadnji)
// NOTE: ORDERING OF OBJ INITIALIZATIONS IS IMPORTANT (arDetect needs to go last)
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:
// this.player.dimensions
}
initAr() {
initArDetection() {
this.arDetector.init();
}
startAr() {
startArDetection() {
this.arDetector.start();
}

View File

@ -1,20 +1,27 @@
class ArDetector {
constructor(videoData){
this.videoData = videoData;
this.conf = videoData;
this.video = videoData.video;
this.setupTimer = null;
this.timer = null;
this.sampleCols = [];
// todo: dynamically detect the following two
this.canFallback = true;
this.fallbackMode = false;
this.blackLevel = ExtensionConf.arDetect.blackLevel_default;
this.init();
}
init(){
if(Debug.debug){
console.log("[ArDetect::init] Initializing autodetection")
}
this.guardLine = new GuardLine(this);
this.edgeDetector = new EdgeDetect(this);
this.debugCanvas = new DebugCanvas(this);
@ -22,6 +29,16 @@ class ArDetector {
}
setup(cwidth, cheight){
if(Debug.debug){
console.log("[ArDetect::setup] Starting autodetection setup");
}
if(!cwidth){
cwidth = ExtensionConf.arDetect.hSamples;
cheight = ExtensionConf.arDetect.vSamples;
}
try{
if(Debug.debug)
console.log("%c[ArDetect::_ard_setup] Starting automatic aspect ratio detection", _ard_console_start);
@ -29,13 +46,13 @@ class ArDetector {
this._halted = false;
this.detectionTimeoutEventCount = 0;
// vstavimo začetne stolpce v _ard_sampleCols.
// let's insert initial columns to _ard_sampleCols
// vstavimo začetne stolpce v this.sampleCols.
// let's insert initial columns to this.sampleCols
this.sampleCols = [];
var samplingIntervalPx = parseInt(cheight / ExtensionConf.arDetect.samplingInterval)
for(var i = 1; i < ExtensionConf.arDetect.samplingInterval; i++){
_ard_sampleCols.push(i * samplingIntervalPx);
this.sampleCols.push(i * samplingIntervalPx);
}
if(this.canvas){
@ -68,7 +85,7 @@ class ArDetector {
// do setup once
// tho we could do it for every frame
this.canvasScaleFactor = cheight / vid.videoHeight;
this.canvasScaleFactor = cheight / this.video.videoHeight;
try{
// determine where to sample
@ -107,11 +124,11 @@ class ArDetector {
this.guardLine.top = null;
this.guardLine.bottom = null;
_ard_resetBlackLevel();
this.resetBlackLevel();
this._forcehalt = false;
// 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.noLetterboxCanvasReset = false;
@ -123,7 +140,7 @@ class ArDetector {
}
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});
}
}
@ -147,27 +164,6 @@ class ArDetector {
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(){
if(Debug.debugCanvas.enabled){
@ -260,7 +256,7 @@ class ArDetector {
// poglejmo, če se je razmerje stranic spremenilo
// check if aspect ratio is changed:
var lastAr = this.videoData.getLastAr();
var lastAr = this.conf.getLastAr();
if( lastAr.type == "auto" && lastAr.ar != null){
// spremembo lahko zavrnemo samo, če uporabljamo avtomatski način delovanja in če smo razmerje stranic
// ž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
// 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(){
@ -395,7 +391,7 @@ class ArDetector {
if(Debug.debugArDetect)
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
@ -484,7 +480,7 @@ class ArDetector {
// while resetting the CSS, we also reset guardline top and bottom back to null.
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.bottom = null;
this.noLetterboxCanvasReset = true;
@ -508,7 +504,7 @@ class ArDetector {
// let's check if we're cropping too much (or whatever)
var guardLineOut;
guardLineOut = GuardLine.check(image, fallbackMode);
guardLineOut = this.guardLine.check(image, fallbackMode);
if (guardLineOut.blackbarFail) { // add new ssamples to our sample columns
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 (fallbackMode && guardLineOut.blackbarFail) {
this.videoData.resizer.reset({type: "auto", ar: null});
this.conf.resizer.reset({type: "auto", ar: null});
this.guardLine.reset();
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.
if(guardLineOut.blackbarFail || guardLineOut.imageFail){
if(pillarTest(image)){
if(this.edgeDetector.findBars(image, null, EdgeDetectPrimaryDirection.HORIZONTAL).status === 'ar_known'){
if(Debug.debug && guardLineOut.blackbarFail){
console.log("[ArDetect::_ard_vdraw] Detected blackbar violation and pillarbox. Resetting to default aspect ratio.");
}
if(! guardLineResult){
this.videoData.resizer.reset({type: "auto", ar: null});
this.conf.resizer.reset({type: "auto", ar: null});
this.guardLine.reset();
}
@ -571,10 +567,8 @@ class ArDetector {
GlobalVars.sampleCols_current = sampleCols.length;
// blackSamples -> {res_top, res_bottom}
var blackbarSamples = _ard_findBlackbarLimits(image, sampleCols, guardLineResult, imageDetectResult);
var edgeCandidates = _ard_edgeDetect(image, blackbarSamples);
var edgePost = _ard_edgePostprocess(edgeCandidates, this.canvas.height);
var edgePost = this.edgeDetector.findBars(image, sampleCols, EdgeDetectPrimaryDirection.VERTICAL, EdgeDetectQuality.IMPROVED, guardLineOut);
// 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)

View File

@ -19,7 +19,7 @@ class PageInfo {
return;
}
debugger;
// debugger;
// add new videos
for(var video of vids){
@ -41,9 +41,9 @@ class PageInfo {
}
}
initAr(){
initArDetection(){
for(var vd in this.videos){
vd.initAr();
vd.initArDetection();
}
}

View File

@ -70,6 +70,10 @@ class Resizer {
this.applyCss(cssOffsets, stretchFactors);
}
setLastAr(override){
this.lastAr = override;
}
setStretchMode(stretchMode){
this.stretch.mode = stretchMode;
}