// računa velikost videa za približevanje/oddaljevanje // does video size calculations for zooming/cropping class Scaler { // internal variables // functions constructor() { } static modeToAr(mode, video, playerDimensions){ // Skrbi za "stare" možnosti, kot na primer "na širino zaslona", "na višino zaslona" in "ponastavi". // Približevanje opuščeno. // handles "legacy" options, such as 'fit to widht', 'fit to height' and 'reset'. No zoom tho var ar; if (!video) { if(Debug.debug){ console.log("[Scaler.js::modeToAr] No video??",video) } return null; } if(! playerDimensions ){ ar = screen.width / screen.height; } else { ar = playerDimensions.width / playerDimensions.height; } // POMEMBNO: GlobalVars.lastAr je potrebno nastaviti šele po tem, ko kličemo _res_setAr(). _res_setAr() predvideva, // da želimo nastaviti statično (type: 'static') razmerje stranic — tudi, če funkcijo kličemo tu oz. v ArDetect. // // IMPORTANT NOTE: GlobalVars.lastAr needs to be set after _res_setAr() is called, as _res_setAr() assumes we're // setting a static aspect ratio (even if the function is called from here or ArDetect). var fileAr = video.videoWidth / video.videoHeight; if (mode == "fitw"){ return ar > fileAr ? ar : fileAr; } else if(mode == "fith"){ return ar < fileAr ? ar : fileAr; } else if(mode == "reset"){ if(Debug.debug){ console.log("[Scaler.js::modeToAr] Using original aspect ratio -", fileAr) } return fileAr; } return null; } static calculateCrop(mode, video, playerDimensions) { // if 'ar' is string, we'll handle that in legacy wrapper var ar = 0; if(isNaN(mode)){ ar = this.modeToAr(mode); } else { ar = mode; } // handle fuckie-wuckies if (! ar){ return null; } if(Debug.debug) console.log("[Scaler::calculateCrop] trying to set ar. args are: ar->",ar,"; playerDimensions->",playerDimensions.width, "×", playerDimensions.height, "| obj:", GlobalVars.playerDimensions); if(!video || video.videoWidth == 0 || video.videoHeight == 0){ if(Debug.debug) console.log("[Scaler::calculateCrop] ERROR — no video detected.") return {error: "no_video"}; } if(! playerDimensions || playerDimensions.width === 0 || playerDimensions.height){ if(Debug.debug) console.log("[Scaler::calculateCrop] ERROR — no (or invalid) playerDimensions:",playerDimensions); return {error: "playerDimensions_error"}; } // zdaj lahko končno začnemo računati novo velikost videa // we can finally start computing required video dimensions now: // Dejansko razmerje stranic datoteke/