From 0eadb1aac669a0ca95badd26f49f0e727da7f611 Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Mon, 4 Nov 2019 23:53:28 +0100 Subject: [PATCH] Don't set aspect ratio pointlessly --- src/ext/lib/ar-detect/ArDetector.js | 4 ++-- src/ext/lib/video-data/PlayerData.js | 19 +++++++++++++++++-- src/ext/lib/video-transform/Resizer.js | 23 +++++++++++++++++------ 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/ext/lib/ar-detect/ArDetector.js b/src/ext/lib/ar-detect/ArDetector.js index 9976501..20a7231 100644 --- a/src/ext/lib/ar-detect/ArDetector.js +++ b/src/ext/lib/ar-detect/ArDetector.js @@ -489,7 +489,7 @@ class ArDetector { } this.logger.log('info', 'debug', `%c[ArDetect::processAr] <@${this.arid}> Triggering aspect ratio change. New aspect ratio: ${trueAr}`, _ard_console_change); - this.conf.resizer.setAr({type: AspectRatio.Automatic, ratio: trueAr}, {type: AspectRatio.Automatic, ratio: trueAr}); + this.conf.resizer.updateAr({type: AspectRatio.Automatic, ratio: trueAr}, {type: AspectRatio.Automatic, ratio: trueAr}); } clearImageData(id) { @@ -582,7 +582,7 @@ class ArDetector { // da je letterbox izginil. // If we don't detect letterbox, we reset aspect ratio to aspect ratio of the video file. The aspect ratio could // have been corrected manually. It's also possible that letterbox (that was there before) disappeared. - this.conf.resizer.setAr({type: AspectRatio.Automatic, ratio: this.getDefaultAr()}); + this.conf.resizer.updateAr({type: AspectRatio.Automatic, ratio: this.getDefaultAr()}); this.guardLine.reset(); this.noLetterboxCanvasReset = true; diff --git a/src/ext/lib/video-data/PlayerData.js b/src/ext/lib/video-data/PlayerData.js index ec6ae3f..950466d 100644 --- a/src/ext/lib/video-data/PlayerData.js +++ b/src/ext/lib/video-data/PlayerData.js @@ -192,6 +192,16 @@ class PlayerData { return false; } + updatePlayerDimensions(element) { + const isFullScreen = PlayerData.isFullScreen(); + + this.dimensions = { + width: element.offsetWidth, + height: element.offsetHeight, + fullscreen: isFullScreen + }; + } + getPlayer() { const host = window.location.host; let element = this.video.parentNode; @@ -223,6 +233,7 @@ class PlayerData { element = element.parentNode; } if (element) { + this.updatePlayerDimensions(element); return element; } } else if (this.settings.active.sites[host].DOM.player.querySelectors) { @@ -256,7 +267,9 @@ class PlayerData { if (elementQ.length) { // return element with biggest score // if video player has not been found, proceed to automatic detection - return elementQ.sort( (a,b) => b.score - a.score)[0].element; + const playerElement = elementQ.sort( (a,b) => b.score - a.score)[0].element; + this.updatePlayerDimensions(playerElement); + return playerElement; } } } @@ -310,7 +323,9 @@ class PlayerData { if (elementQ.length) { // return element with biggest score - return elementQ.sort( (a,b) => b.score - a.score)[0].element; + const playerElement = elementQ.sort( (a,b) => b.score - a.score)[0].element; + this.updatePlayerDimensions(playerElement); + return playerElement; } // if no candidates were found, something is obviously very, _very_ wrong. diff --git a/src/ext/lib/video-transform/Resizer.js b/src/ext/lib/video-transform/Resizer.js index e26b89c..dd87f6b 100644 --- a/src/ext/lib/video-transform/Resizer.js +++ b/src/ext/lib/video-transform/Resizer.js @@ -120,6 +120,12 @@ class Resizer { } + updateAr(ar) { + if (!this.lastAr || ar.type !== this.lastAr.type || ar.ratio !== this.lastAr.ratio) { + this.setAr(ar); + } + } + setAr(ar, lastAr) { if (this.destroyed) { return; @@ -408,27 +414,32 @@ class Resizer { // mostly internal stuff computeOffsets(stretchFactors){ - this.logger.log('info', 'debug', "[Resizer::computeOffsets] video will be aligned to ", this.settings.active.sites['@global'].videoAlignment); const wdiff = this.conf.player.dimensions.width - this.conf.video.offsetWidth; const hdiff = this.conf.player.dimensions.height - this.conf.video.offsetHeight; + if (wdiff < 0 && hdiff < 0 && this.zoom.scale > 1) { + this.conf.player.re + } + const wdiffAfterZoom = this.conf.video.offsetWidth * stretchFactors.xFactor - this.conf.player.dimensions.width; const hdiffAfterZoom = this.conf.video.offsetHeight * stretchFactors.yFactor - this.conf.player.dimensions.height; - var translate = { + const translate = { x: wdiff * 0.5, y: hdiff * 0.5, }; + + + if (this.pan) { // don't offset when video is smaller than player - if(wdiffAfterZoom < 0 && hdiffAfterZoom < 0) { - return translate; + if(wdiffAfterZoom >= 0 || hdiffAfterZoom >= 0) { + translate.x += wdiffAfterZoom * this.pan.relativeOffsetX * this.zoom.scale; + translate.y += hdiffAfterZoom * this.pan.relativeOffsetY * this.zoom.scale; } - translate.x += wdiffAfterZoom * this.pan.relativeOffsetX * this.zoom.scale; - translate.y += hdiffAfterZoom * this.pan.relativeOffsetY * this.zoom.scale; } else { if (this.videoAlignment == VideoAlignment.Left) { translate.x += wdiffAfterZoom * 0.5;