diff --git a/js/conf/Settings.js b/js/conf/Settings.js index 43be3ea..f515eb0 100644 --- a/js/conf/Settings.js +++ b/js/conf/Settings.js @@ -106,8 +106,8 @@ var Settings = { period: 2.0 // per this period }, edgeDetection: { - sampleWidth: 20, // we take a sample this wide for edge detection - detectionTreshold: 10, // sample needs to have this many non-black pixels to be a valid edge + sampleWidth: 8, // we take a sample this wide for edge detection + detectionTreshold: 4, // sample needs to have this many non-black pixels to be a valid edge singleSideConfirmationTreshold: 0.3, // we need this much edges (out of all samples, not just edges) in order // to confirm an edge in case there's no edges on top or bottom (other // than logo, of course) diff --git a/js/modules/ArDetect.js b/js/modules/ArDetect.js index 4298109..141844b 100644 --- a/js/modules/ArDetect.js +++ b/js/modules/ArDetect.js @@ -148,6 +148,7 @@ var _arSetup = function(cwidth, cheight){ GlobalVars.canvas.width = canvasWidth; GlobalVars.canvas.height = canvasHeight; GlobalVars.canvas.imageDataRowLength = canvasWidth * 4; + GlobalVars.arDetect.noLetterboxCanvasReset = false; _ard_vdraw(0); } catch(ex){ @@ -268,11 +269,13 @@ var _ard_vdraw = function (timeout, force_reset){ var executions = 0; -setInterval(function(){ - console.log("STATS FOR LAST SECOND\nexecutions:", executions,"; vdraw timeouts cleared:", clearTimeoutCount); - executions = 0; - clearTimeoutCount = 0; -}, 1000); +if(Debug.debug){ + setInterval(function(){ + console.log("STATS FOR LAST SECOND\nexecutions:", executions,"; vdraw timeouts cleared:", clearTimeoutCount); + executions = 0; + clearTimeoutCount = 0; + }, 1000); +} var _ard_vdraw_but_for_reals = function() { // thanks dude: @@ -299,12 +302,18 @@ var _ard_vdraw_but_for_reals = function() { var how_far_treshold = 8; // how much can the edge pixel vary (*4) - if(GlobalVars.video == null || GlobalVars.video.paused || GlobalVars.video.ended || Status.arStrat != "auto"){ - // we slow down if paused, no detection + if(GlobalVars.video == null || GlobalVars.video.ended || Status.arStrat != "auto"){ + // we slow down if ended, null, or not auto. Detecting is pointless. _ard_vdraw(Settings.arDetect.timer_paused); return false; } + if(GlobalVars.video.paused){ + // if the video is paused, we still do autodetection. We just increase the interval. + baseTimeout = Settings.arDetect.timer_paused; + } + + try{ GlobalVars.canvas.context.drawImage(GlobalVars.video, 0,0, GlobalVars.canvas.width, GlobalVars.canvas.height); } @@ -416,18 +425,31 @@ var _ard_vdraw_but_for_reals = function() { if(Debug.debug){ console.log("%c[ArDetect::_ard_vdraw] no edge detected. canvas has no edge.", "color: #aaf"); } - - + image = null; - Resizer.reset(); - GlobalVars.lastAr = {type: "auto", ar: null}; + // Pogledamo, ali smo že kdaj ponastavili CSS. Če še nismo, potem to storimo. Če smo že, potem ne. + // Ponastavimo tudi guardline (na null). + // let's chec if we ever reset CSS. If we haven't, then we do so. If we did, then we don't. + // while resetting the CSS, we also reset guardline top and bottom back to null. + if(! GlobalVars.arDetect.noLetterboxCanvasReset){ + Resizer.reset(); + GlobalVars.lastAr = {type: "auto", ar: null}; + GlobalVars.arDetect.guardLine.top = null; + GlobalVars.arDetect.guardLine.bottom = null; + GlobalVars.arDetect.noLetterboxCanvasReset = true; + } triggerTimeout = _ard_getTimeout(baseTimeout, startTime); _ard_vdraw(triggerTimeout); //no letterbox, no problem return; } + // Če preverjamo naprej, potem moramo postaviti to vrednost nazaj na 'false'. V nasprotnem primeru se bo + // css resetiral enkrat na video/pageload namesto vsakič, ko so za nekaj časa obrobe odstranejene + // if we look further we need to reset this value back to false. Otherwise we'll only get CSS reset once + // per video/pageload instead of every time letterbox goes away (this can happen more than once per vid) + GlobalVars.arDetect.noLetterboxCanvasReset = false; // let's do a quick test to see if we're on a black frame // TODO: reimplement but with less bullshit @@ -453,6 +475,9 @@ var _ard_vdraw_but_for_reals = function() { // če sta obe funkciji uspeli, potem se razmerje stranic ni spremenilo. // if both succeed, then aspect ratio hasn't changed. if(imageDetectResult && guardLineResult){ + + console.log("STATS: both guardLine and imageTest tests succeeded. AR didn't change. Guard line:", GlobalVars.arDetect.guardLine); + delete image; triggerTimeout = _ard_getTimeout(baseTimeout, startTime); _ard_vdraw(triggerTimeout); //no letterbox, no problem @@ -861,11 +886,7 @@ var _ard_guardLineImageDetect = function(image){ var offset = parseInt(GlobalVars.canvas.width * Settings.arDetect.guardLine.ignoreEdgeMargin) * 4; - - var offenders = []; - var firstOffender = -1; - var offenderCount = -1; // doing it this way means first offender has offenderCount==0. Ez index. - + // TODO: implement logo check. diff --git a/js/modules/Resizer.js b/js/modules/Resizer.js index 8f52c79..404b468 100644 --- a/js/modules/Resizer.js +++ b/js/modules/Resizer.js @@ -85,9 +85,9 @@ var _res_legacyAr = function(action){ GlobalVars.lastAr = {type: "legacy", action: action}; } -var _res_setAr = function(ar, playerDimensions){ +var _res_setAr = function(ar){ if(Debug.debug) - console.log("[Resizer::_res_setAr] trying to set ar. args are: ar->",ar,"; playerDimensions->",playerDimensions); + console.log("[Resizer::_res_setAr] trying to set ar. args are: ar->",ar,"; playerDimensions->",GlobalVars.playerDimensions); GlobalVars.lastAr = {type: "static", ar: ar}; @@ -115,7 +115,7 @@ var _res_setAr = function(ar, playerDimensions){ if(Debug.debug) - console.log("[Resizer::_res_setAr] ar is " ,ar, ", file ar is", fileAr, ", playerDimensions are ", playerDimensions); + console.log("[Resizer::_res_setAr] ar is " ,ar, ", file ar is", fileAr, ", playerDimensions are ", GlobalVars.playerDimensions); var videoDimensions = { width: 0, @@ -123,33 +123,33 @@ var _res_setAr = function(ar, playerDimensions){ } - if(playerDimensions === undefined){ - playerDimensions = PlayerDetect.getPlayerDimensions(vid); + if(GlobalVars.playerDimensions === undefined){ + GlobalVars.playerDimensions = PlayerDetect.getPlayerDimensions(vid); if(Debug.debug) - console.log("[Resizer::_res_setAr] playerDimensions are undefined, trying to determine new ones ... new dimensions:",playerDimensions); + console.log("[Resizer::_res_setAr] playerDimensions are undefined, trying to determine new ones ... new dimensions:",GlobalVars.playerDimensions); } if(Debug.debug){ - console.log("[Resizer::_res_setAr] Player dimensions?",playerDimensions); + console.log("[Resizer::_res_setAr] Player dimensions?",GlobalVars.playerDimensions); } if( fileAr < ar ){ // imamo letterbox zgoraj in spodaj -> spremenimo velikost videa (ampak nikoli na več, kot je širina zaslona) // letterbox -> change video size (but never to wider than monitor width) - videoDimensions.width = Math.min(playerDimensions.height * ar, playerDimensions.width); + videoDimensions.width = Math.min(GlobalVars.playerDimensions.height * ar, GlobalVars.playerDimensions.width); videoDimensions.height = videoDimensions.width * (1/fileAr); } else{ - videoDimensions.height = Math.min(playerDimensions.width * (1/ar), playerDimensions.height); + videoDimensions.height = Math.min(GlobalVars.playerDimensions.width * (1/ar), GlobalVars.playerDimensions.height); videoDimensions.width = videoDimensions.height * fileAr; } if(Debug.debug){ - console.log("[Resizer::_res_setAr] Video dimensions: ",videoDimensions, "playerDimensions:",playerDimensions); + console.log("[Resizer::_res_setAr] Video dimensions: ",videoDimensions, "playerDimensions:",GlobalVars.playerDimensions); } - var cssValues = _res_computeOffsets(videoDimensions, playerDimensions); + var cssValues = _res_computeOffsets(videoDimensions, GlobalVars.playerDimensions); if(Debug.debug){ console.log("[Resizer::_res_setAr] Offsets for css are: ",cssValues); diff --git a/js/run/GlobalVars.js b/js/run/GlobalVars.js index 592c546..08ae53d 100644 --- a/js/run/GlobalVars.js +++ b/js/run/GlobalVars.js @@ -19,6 +19,7 @@ var GlobalVars = { canvas: null, blackLevel: 10, sampleCols_current: 0, + noLetterboxCanvasReset: false, guardLine: { top: null, bottom: null, diff --git a/js/uw.js b/js/uw.js index e85262b..586c976 100644 --- a/js/uw.js +++ b/js/uw.js @@ -60,7 +60,7 @@ async function main(){ } browser.runtime.onMessage.addListener(receiveMessage); - setInterval( ghettoOnChange, 10000); + setInterval( ghettoOnChange, 100); setInterval( ghettoUrlWatcher, 500); // ko se na ticevki zamenja video, console.log pravi da ultrawidify spremeni razmerje stranic. preglej element @@ -78,7 +78,7 @@ async function main(){ // tukaj gledamo, ali se je velikost predvajalnika spremenila. Če se je, ponovno prožimo resizer // here we check (in the most ghetto way) whether player size has changed. If it has, we retrigger resizer. -var _video_recheck_counter = 0; +var _video_recheck_counter = 5; var _video_recheck_period = 1; // on this many retries function ghettoOnChange(){