From 65556d9cad4ffc9d56005f5c00e100b7dabe5d0c Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Thu, 25 Nov 2021 00:13:21 +0100 Subject: [PATCH] We will need to distinguish between two automatic aspect ratio types AspectRatioType.Automatic: "start autodetection pls" AspectRatioType.AutomaticUpdate: "Hi I'm aard and I want to change this aspect ratio to something new" --- src/common/enums/AspectRatioType.enum.ts | 15 ++++++++------- src/ext/lib/ar-detect/ArDetector.ts | 18 +++++++++--------- src/ext/lib/video-data/PageInfo.ts | 2 +- src/ext/lib/video-transform/Resizer.ts | 2 +- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/common/enums/AspectRatioType.enum.ts b/src/common/enums/AspectRatioType.enum.ts index 8b9d38e..72e1924 100644 --- a/src/common/enums/AspectRatioType.enum.ts +++ b/src/common/enums/AspectRatioType.enum.ts @@ -1,11 +1,12 @@ enum AspectRatioType { - Initial = -1, // page default - Reset = 0, // reset to initial - Automatic = 1, // set by Aard - FitWidth = 2, // legacy/dynamic = fit to width - FitHeight = 3, // legacy/dynamic = fit to height - Fixed = 4, // pre-determined aspect ratio - Manual = 5, // ratio achieved by zooming in/zooming out + Initial = -1, // page default + Reset = 0, // reset to initial + Automatic = 1, // we want to request automatic aspect ratio detection + FitWidth = 2, // legacy/dynamic = fit to width + FitHeight = 3, // legacy/dynamic = fit to height + Fixed = 4, // pre-determined aspect ratio + Manual = 5, // ratio achieved by zooming in/zooming out + AutomaticUpdate = 6, // set by Aard } export default AspectRatioType; diff --git a/src/ext/lib/ar-detect/ArDetector.ts b/src/ext/lib/ar-detect/ArDetector.ts index cd40a41..ad5b3a7 100644 --- a/src/ext/lib/ar-detect/ArDetector.ts +++ b/src/ext/lib/ar-detect/ArDetector.ts @@ -285,7 +285,7 @@ class ArDetector { this.resetBlackLevel(); // if we're restarting ArDetect, we need to do this in order to force-recalculate aspect ratio - this.conf.resizer.setLastAr({type: AspectRatioType.Automatic, ratio: this.defaultAr}); + this.conf.resizer.setLastAr({type: AspectRatioType.AutomaticUpdate, ratio: this.defaultAr}); this.canvasImageDataRowLength = cwidth << 2; this.noLetterboxCanvasReset = false; @@ -319,9 +319,9 @@ class ArDetector { return; } - if (this.conf.resizer.lastAr.type === AspectRatioType.Automatic) { + if (this.conf.resizer.lastAr.type === AspectRatioType.AutomaticUpdate) { // ensure first autodetection will run in any case - this.conf.resizer.setLastAr({type: AspectRatioType.Automatic, ratio: this.defaultAr}); + this.conf.resizer.setLastAr({type: AspectRatioType.AutomaticUpdate, ratio: this.defaultAr}); } this._paused = false; @@ -638,7 +638,7 @@ class ArDetector { // poglejmo, če se je razmerje stranic spremenilo // check if aspect ratio is changed: let lastAr = this.conf.resizer.getLastAr(); - if (lastAr.type === AspectRatioType.Automatic && lastAr.ratio !== null && lastAr.ratio !== undefined){ + if (lastAr.type === AspectRatioType.AutomaticUpdate && lastAr.ratio !== null && lastAr.ratio !== undefined){ // spremembo lahko zavrnemo samo, če uporabljamo avtomatski način delovanja in če smo razmerje stranic // že nastavili. // @@ -663,7 +663,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.updateAr({type: AspectRatioType.Automatic, ratio: trueAr}); + this.conf.resizer.updateAr({type: AspectRatioType.AutomaticUpdate, ratio: trueAr}); } clearImageData(id) { @@ -790,7 +790,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.updateAr({type: AspectRatioType.Automatic, ratio: this.defaultAr}); + this.conf.resizer.updateAr({type: AspectRatioType.AutomaticUpdate, ratio: this.defaultAr}); this.guardLine.reset(); this.noLetterboxCanvasReset = true; @@ -835,7 +835,7 @@ class ArDetector { if (this.fallbackMode && guardLineOut.blackbarFail) { this.logger.log('warn', 'arDetect_verbose', `%c[ArDetect::frameCheck] <@${this.arid}> We are in fallback mode and blackbar failed. Reverting to initial aspect ratio.`); - this.conf.resizer.setAr({type: AspectRatioType.Automatic, ratio: this.defaultAr}); + this.conf.resizer.setAr({type: AspectRatioType.AutomaticUpdate, ratio: this.defaultAr}); this.guardLine.reset(); this.noLetterboxCanvasReset = true; @@ -851,7 +851,7 @@ class ArDetector { if(this.edgeDetector.findBars(imageData, null, EdgeDetectPrimaryDirection.Horizontal).status === 'ar_known'){ if(guardLineOut.blackbarFail){ this.logger.log('info', 'arDetect', `[ArDetect::frameCheck] Detected blackbar violation and pillarbox. Resetting to default aspect ratio.`); - this.conf.resizer.setAr({type: AspectRatioType.Automatic, ratio: this.defaultAr}); + this.conf.resizer.setAr({type: AspectRatioType.AutomaticUpdate, ratio: this.defaultAr}); this.guardLine.reset(); } else { this.logger.log('info', 'arDetect_verbose', `[ArDetect::frameCheck] Guardline failed, blackbar didn't, and we got pillarbox. Doing nothing.`); @@ -923,7 +923,7 @@ class ArDetector { // WE DO NOT RESET ASPECT RATIO HERE IN CASE OF PROBLEMS, CAUSES UNWARRANTED RESETS: // (eg. here: https://www.youtube.com/watch?v=nw5Z93Yt-UQ&t=410) // - // this.conf.resizer.setAr({type: AspectRatioType.Automatic, ratio: this.defaultAr}); + // this.conf.resizer.setAr({type: AspectRatioType.AutomaticUpdate, ratio: this.defaultAr}); } this.clearImageData(imageData); diff --git a/src/ext/lib/video-data/PageInfo.ts b/src/ext/lib/video-data/PageInfo.ts index 250db89..cf8b51c 100644 --- a/src/ext/lib/video-data/PageInfo.ts +++ b/src/ext/lib/video-data/PageInfo.ts @@ -462,7 +462,7 @@ class PageInfo { setAr(ar, playingOnly?: boolean){ this.logger.log('info', 'debug', '[PageInfo::setAr] aspect ratio:', ar, "playing only?", playingOnly) - if (ar.type !== AspectRatioType.Automatic) { + if (ar.type !== AspectRatioType.AutomaticUpdate && ar.type !== AspectRatioType.Automatic) { this.stopArDetection(playingOnly); } else { this.logger.log('info', 'debug', '[PageInfo::setAr] aspect ratio is auto'); diff --git a/src/ext/lib/video-transform/Resizer.ts b/src/ext/lib/video-transform/Resizer.ts index 01833bf..3be400d 100644 --- a/src/ext/lib/video-transform/Resizer.ts +++ b/src/ext/lib/video-transform/Resizer.ts @@ -190,7 +190,7 @@ class Resizer { // Some options require a bit more testing re: whether they make sense // if they don't, we refuse to update aspect ratio until they do - if (ar.type === AspectRatioType.Automatic || ar.type === AspectRatioType.Fixed) { + if (ar.type === AspectRatioType.AutomaticUpdate || ar.type === AspectRatioType.Fixed) { if (!ar.ratio || isNaN(ar.ratio)) { return; }