Scaler.js - calculateCrop() and modeToAr() no longer take 'video' and 'playerDimensions' as arguments, instead reading those properties from videoData

This commit is contained in:
Tamius Han 2018-05-23 00:34:18 +02:00
parent a7aef8856d
commit 8d7cefd420
2 changed files with 15 additions and 15 deletions

View File

@ -58,7 +58,7 @@ class Resizer {
this.videoData.destroy(); this.videoData.destroy();
} }
var dimensions = this.scaler.calculateCrop(ar, this.video, this.conf.player.dimensions); var dimensions = this.scaler.calculateCrop(ar);
if(! dimensions || dimensions.error){ if(! dimensions || dimensions.error){
if(Debug.debug){ if(Debug.debug){

View File

@ -10,7 +10,7 @@ class Scaler {
this.conf = videoData; this.conf = videoData;
} }
modeToAr(mode, video, playerDimensions){ modeToAr(mode){
// Skrbi za "stare" možnosti, kot na primer "na širino zaslona", "na višino zaslona" in "ponastavi". // Skrbi za "stare" možnosti, kot na primer "na širino zaslona", "na višino zaslona" in "ponastavi".
// Približevanje opuščeno. // Približevanje opuščeno.
// handles "legacy" options, such as 'fit to widht', 'fit to height' and 'reset'. No zoom tho // handles "legacy" options, such as 'fit to widht', 'fit to height' and 'reset'. No zoom tho
@ -25,11 +25,11 @@ class Scaler {
} }
if(! playerDimensions ){ if(! this.conf.player.dimensions ){
ar = screen.width / screen.height; ar = screen.width / screen.height;
} }
else { else {
ar = playerDimensions.width / playerDimensions.height; ar = this.conf.player.dimensions.width / this.conf.player.dimensions.height;
} }
// POMEMBNO: GlobalVars.lastAr je potrebno nastaviti šele po tem, ko kličemo _res_setAr(). _res_setAr() predvideva, // POMEMBNO: GlobalVars.lastAr je potrebno nastaviti šele po tem, ko kličemo _res_setAr(). _res_setAr() predvideva,
@ -57,7 +57,7 @@ class Scaler {
return null; return null;
} }
calculateCrop(mode, video, playerDimensions) { calculateCrop(mode) {
if(!this.conf.video || this.conf.video.videoWidth == 0 || this.conf.video.videoHeight == 0){ if(!this.conf.video || this.conf.video.videoWidth == 0 || this.conf.video.videoHeight == 0){
@ -85,12 +85,12 @@ class Scaler {
} }
if(Debug.debug) if(Debug.debug)
console.log("[Scaler::calculateCrop] trying to set ar. args are: ar->",ar,"; playerDimensions->",playerDimensions.width, "×", playerDimensions.height, "| obj:", playerDimensions); console.log("[Scaler::calculateCrop] trying to set ar. args are: ar->",ar,"; this.conf.player.dimensions->",this.conf.player.dimensions.width, "×", this.conf.player.dimensions.height, "| obj:", this.conf.player.dimensions);
if( (! playerDimensions) || playerDimensions.width === 0 || playerDimensions.height === 0 ){ if( (! this.conf.player.dimensions) || this.conf.player.dimensions.width === 0 || this.conf.player.dimensions.height === 0 ){
if(Debug.debug) if(Debug.debug)
console.log("[Scaler::calculateCrop] ERROR — no (or invalid) playerDimensions:",playerDimensions); console.log("[Scaler::calculateCrop] ERROR — no (or invalid) this.conf.player.dimensions:",this.conf.player.dimensions);
return {error: "playerDimensions_error"}; return {error: "this.conf.player.dimensions_error"};
} }
// zdaj lahko končno začnemo računati novo velikost videa // zdaj lahko končno začnemo računati novo velikost videa
@ -100,14 +100,14 @@ class Scaler {
// Dejansko razmerje stranic datoteke/<video> značke // Dejansko razmerje stranic datoteke/<video> značke
// Actual aspect ratio of the file/<video> tag // Actual aspect ratio of the file/<video> tag
var fileAr = this.conf.video.videoWidth / this.conf.video.videoHeight; var fileAr = this.conf.video.videoWidth / this.conf.video.videoHeight;
var playerAr = playerDimensions.width / playerDimensions.height; var playerAr = this.conf.player.dimensions.width / this.conf.player.dimensions.height;
if(mode == "default" || !ar) if(mode == "default" || !ar)
ar = fileAr; ar = fileAr;
if(Debug.debug) if(Debug.debug)
console.log("[Scaler::calculateCrop] ar is " ,ar, ", file ar is", fileAr, ", playerDimensions are ", playerDimensions.width, "×", playerDimensions.height, "| obj:", playerDimensions); console.log("[Scaler::calculateCrop] ar is " ,ar, ", file ar is", fileAr, ", this.conf.player.dimensions are ", this.conf.player.dimensions.width, "×", this.conf.player.dimensions.height, "| obj:", this.conf.player.dimensions);
var videoDimensions = { var videoDimensions = {
width: 0, width: 0,
@ -117,18 +117,18 @@ class Scaler {
} }
if(Debug.debug){ if(Debug.debug){
console.log("[Scaler::calculateCrop] Player dimensions?", playerDimensions.width, "×", playerDimensions.height, "| obj:", playerDimensions); console.log("[Scaler::calculateCrop] Player dimensions?", this.conf.player.dimensions.width, "×", this.conf.player.dimensions.height, "| obj:", this.conf.player.dimensions);
} }
if( fileAr < ar ){ if( fileAr < ar ){
// imamo letterbox zgoraj in spodaj -> spremenimo velikost videa (a nikoli širše od ekrana) // imamo letterbox zgoraj in spodaj -> spremenimo velikost videa (a nikoli širše od ekrana)
// letterbox -> change video size (but never to wider than monitor width) // letterbox -> change video size (but never to wider than monitor width)
videoDimensions.width = Math.min(playerDimensions.height * ar, playerDimensions.width); videoDimensions.width = Math.min(this.conf.player.dimensions.height * ar, this.conf.player.dimensions.width);
videoDimensions.height = videoDimensions.width * (1/fileAr); videoDimensions.height = videoDimensions.width * (1/fileAr);
} }
else{ else{
videoDimensions.height = Math.min(playerDimensions.width / ar, playerDimensions.height); videoDimensions.height = Math.min(this.conf.player.dimensions.width / ar, this.conf.player.dimensions.height);
videoDimensions.width = videoDimensions.height * fileAr; videoDimensions.width = videoDimensions.height * fileAr;
} }
@ -148,7 +148,7 @@ class Scaler {
} }
if(Debug.debug){ if(Debug.debug){
console.log("[Scaler::calculateCrop] Video dimensions: ", videoDimensions.width, "×", videoDimensions.height, "(obj:", videoDimensions, "); playerDimensions:",playerDimensions.width, "×", playerDimensions.height, "(obj:", playerDimensions, ")"); console.log("[Scaler::calculateCrop] Video dimensions: ", videoDimensions.width, "×", videoDimensions.height, "(obj:", videoDimensions, "); this.conf.player.dimensions:",this.conf.player.dimensions.width, "×", this.conf.player.dimensions.height, "(obj:", this.conf.player.dimensions, ")");
} }
return videoDimensions; return videoDimensions;