ultrawidify/src/ext/lib/video-transform/Zoom.ts

107 lines
2.5 KiB
TypeScript
Raw Normal View History

import Debug from '../../conf/Debug';
2021-02-08 22:45:51 +01:00
import Logger from '../Logger';
import VideoData from '../video-data/VideoData';
// računa približevanje ter računa/popravlja odmike videa
// calculates zooming and video offsets/panning
class Zoom {
2021-02-08 22:45:51 +01:00
//#region flags
//#endregion
//#region helper objects
conf: VideoData;
logger: Logger;
//#endregion
//#region misc data
scale: number = 1;
2021-10-31 23:19:32 +01:00
scaleY: number = 1;
2021-02-08 22:45:51 +01:00
logScale: number = 0;
2021-10-31 23:19:32 +01:00
logScaleY: number = 0;
scaleStep: number = 0.1;
2021-02-08 22:45:51 +01:00
minScale: number = -1; // 50% (log2(0.5) = -1)
maxScale: number = 3; // 800% (log2(8) = 3)
//#endregion
2019-09-03 22:55:10 +02:00
constructor(videoData) {
2019-09-03 23:01:23 +02:00
this.conf = videoData;
this.logger = videoData.logger;
2018-05-12 02:51:58 +02:00
}
2018-05-12 02:51:58 +02:00
reset(){
this.scale = 1;
2019-11-02 02:45:24 +01:00
this.logScale = 0;
2018-05-12 02:51:58 +02:00
}
2021-10-31 23:19:32 +01:00
/**
* Increases zoom by a given amount. Does not allow per-axis zoom.
* Will set zoom level to x axis (+ given amount) if x and y zooms differ.
* @param amount
*/
zoomStep(amount){
this.logScale += amount;
if (this.logScale <= this.minScale) {
this.logScale = this.minScale;
}
if (this.logScale >= this.maxScale) {
this.logScale = this.maxScale;
}
2021-10-31 23:19:32 +01:00
this.logScaleY = this.logScale;
2018-09-13 23:47:20 +02:00
2021-10-31 23:19:32 +01:00
this.scale = Math.pow(2, this.logScale);
2019-11-02 02:45:24 +01:00
2021-10-31 23:19:32 +01:00
this.logger.log('info', 'debug', "[Zoom::zoomStep] changing zoom by", amount, ". New zoom level:", this.scale);
this.processZoom();
2018-05-12 02:51:58 +02:00
}
setZoom(scale: number, axis?: 'x' |'y', noAnnounce?){
this.logger.log('info', 'debug', "[Zoom::setZoom] Setting zoom to", scale, "!");
2019-01-03 02:07:16 +01:00
2018-09-19 22:52:53 +02:00
// NOTE: SCALE IS NOT LOGARITHMIC
2019-01-03 02:07:16 +01:00
if(scale < Math.pow(2, this.minScale)) {
scale = this.minScale;
2019-01-03 02:07:16 +01:00
} else if (scale > Math.pow(2, this.maxScale)) {
scale = this.maxScale;
}
2021-10-31 23:19:32 +01:00
switch (axis) {
case 'x':
this.scale = scale;
break;
case 'y':
this.scaleY = scale;
break;
default:
this.scale = scale;
this.scaleY = scale;
}
this.processZoom();
}
processZoom() {
// this.conf.resizer.toFixedAr();
this.conf.resizer.applyScaling({xFactor: this.scale, yFactor: this.scaleY}, {noAnnounce: true});
2018-05-12 02:51:58 +02:00
}
applyZoom(stretchFactors){
2019-02-15 00:26:54 +01:00
if (!stretchFactors) {
return;
}
this.logger.log('info', 'debug', "[Zoom::setZoom] Applying zoom. Stretch factors pre:", stretchFactors, " —> scale:", this.scale);
2019-01-03 02:07:16 +01:00
stretchFactors.xFactor *= this.scale;
stretchFactors.yFactor *= this.scale;
2019-01-03 02:07:16 +01:00
this.logger.log('info', 'debug', "[Zoom::setZoom] Applying zoom. Stretch factors post:", stretchFactors);
2018-05-12 02:51:58 +02:00
}
}
export default Zoom;