From 08b10220e1f0093cb6b0d05625963c5f1b6661f7 Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Fri, 18 May 2018 23:26:20 +0200 Subject: [PATCH] Scaler no longer static --- js/modules/ArDetect.js | 4 +++- js/modules/Resizer.js | 8 ++++---- js/modules/Scaler.js | 17 ++++++++++------- js/modules/Stretcher.js | 4 ++-- js/modules/Zoom.js | 3 ++- 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/js/modules/ArDetect.js b/js/modules/ArDetect.js index 8141426..d319617 100644 --- a/js/modules/ArDetect.js +++ b/js/modules/ArDetect.js @@ -278,8 +278,10 @@ class ArDetector { var trueHeight = this.canvas.height - letterbox; if(this.fallbackMode){ - if(edge.top > 1 && edge.top <= ExtensionConf.arDetect.fallbackMode.noTriggerZonePx ) + if(edges.top > 1 && edges.top <= ExtensionConf.arDetect.fallbackMode.noTriggerZonePx ){ + console.log("Edge is in the no-trigger zone. Aspect ratio change is not triggered.") return; + } // varnostno območje, ki naj ostane črno (da lahko v fallback načinu odkrijemo ožanje razmerja stranic). // x2, ker je safetyBorderPx definiran za eno stran. diff --git a/js/modules/Resizer.js b/js/modules/Resizer.js index 5120eae..f1b02fb 100644 --- a/js/modules/Resizer.js +++ b/js/modules/Resizer.js @@ -15,9 +15,9 @@ class Resizer { this.video = videoData.video; - this.scaler = new Scaler(); - this.stretcher = new Stretcher(); - this.zoom = new Zoom(); + this.scaler = new Scaler(this.conf); + this.stretcher = new Stretcher(this.conf); + this.zoom = new Zoom(this.conf); // load up default values this.correctedVideoDimensions = {}; @@ -58,7 +58,7 @@ class Resizer { this.videoData.destroy(); } - var dimensions = Scaler.calculateCrop(ar, this.video, this.conf.player.dimensions); + var dimensions = this.scaler.calculateCrop(ar, this.video, this.conf.player.dimensions); if(! dimensions || dimensions.error){ if(Debug.debug){ diff --git a/js/modules/Scaler.js b/js/modules/Scaler.js index 862cf66..0e41ed2 100644 --- a/js/modules/Scaler.js +++ b/js/modules/Scaler.js @@ -6,10 +6,11 @@ class Scaler { // internal variables // functions - constructor() { + constructor(videoData) { + this.conf = videoData; } - static modeToAr(mode, video, playerDimensions){ + modeToAr(mode, video, playerDimensions){ // Skrbi za "stare" možnosti, kot na primer "na širino zaslona", "na višino zaslona" in "ponastavi". // Približevanje opuščeno. // handles "legacy" options, such as 'fit to widht', 'fit to height' and 'reset'. No zoom tho @@ -17,9 +18,9 @@ class Scaler { if (!video) { if(Debug.debug){ - console.log("[Scaler.js::modeToAr] No video??",video) + console.log("[Scaler.js::modeToAr] No video??",video, "killing videoData"); } - + this.conf.destroy(); return null; } @@ -56,12 +57,14 @@ class Scaler { return null; } - static calculateCrop(mode, video, playerDimensions) { + calculateCrop(mode, video, playerDimensions) { if(!video || video.videoWidth == 0 || video.videoHeight == 0){ if(Debug.debug) - console.log("[Scaler::calculateCrop] ERROR — no video detected.") + console.log("[Scaler::calculateCrop] ERROR — no video detected."); + + this.conf.destroy(); return {error: "no_video"}; } @@ -69,7 +72,7 @@ class Scaler { // if 'ar' is string, we'll handle that in legacy wrapper var ar = 0; if(isNaN(mode)){ - ar = Scaler.modeToAr(mode); + ar = this.modeToAr(mode); } else { ar = mode; } diff --git a/js/modules/Stretcher.js b/js/modules/Stretcher.js index da56fd8..ab003e6 100644 --- a/js/modules/Stretcher.js +++ b/js/modules/Stretcher.js @@ -9,8 +9,8 @@ class Stretcher { // functions - constructor() { - + constructor(videoData) { + this.conf = videoData; } static conditionalStretch(videoDimensions, maxDifferencePercent){ diff --git a/js/modules/Zoom.js b/js/modules/Zoom.js index b8300a7..f782aeb 100644 --- a/js/modules/Zoom.js +++ b/js/modules/Zoom.js @@ -6,11 +6,12 @@ class Zoom { // functions - constructor() { + constructor(videoData) { this.scale = 1; this.scaleStep = 1.2; this.minScale = 0.5; // not accurate, actually slightly less this.maxScale = 8; // not accurate, actually slightly more + this.conf = videoData; } reset(){