ultrawidify/js/modules/Stretcher.js

55 lines
1.3 KiB
JavaScript
Raw Normal View History

// računa vrednosti za transform-scale (x, y)
// transform: scale(x,y) se uporablja za raztegovanje videa, ne pa za približevanje
// calculates values for transform scale(x, y)
// transform: scale(x,y) is used for stretching, not zooming.
class Stretcher {
2018-05-07 21:58:11 +02:00
// internal variables
2018-05-07 21:58:11 +02:00
// functions
2018-05-18 23:26:20 +02:00
constructor(videoData) {
this.conf = videoData;
2018-05-07 21:58:11 +02:00
}
static conditionalStretch(videoDimensions, maxDifferencePercent){
// samo razširjamo, nikoli krčimo
// only stretch, no shrink
var x, y;
x = videoDimensions.width / videoDimensions.actualWidth;
y = videoDimensions.height / videoDimensions.actualHeight;
var dmax = 1 + maxDifferencePercent;
if(x < 1 || x > dmax){
x = 1;
}
if(y < 1 || y > dmax){
y = 1;
}
return {
x: x,
y: y
}
2018-05-07 21:58:11 +02:00
}
static calculateStretch(videoDimensions) {
// naj ponovim: samo razširjamo, nikoli krčimo
// let me reiterate: only stretch, no shrink
var stretch = {x: 1, y: 1};
if (videoDimensions.actualWidth < videoDimensions.width) {
stretch.x = videoDimensions.width / videoDimensions.actualWidth;
}
if (videoDimensions.actualHeight < videoDimensions.height){
stretch.y = videoDimensions.height / videoDimensions.actualHeight;
}
return stretch;
}
}