2017-09-24 01:54:46 +02:00
if ( Debug . debug )
console . log ( "Loading: ArDetect" ) ;
2017-12-29 23:34:40 +01:00
var _ard _console _stop = "background: #000; color: #f41" ;
var _ard _console _start = "background: #000; color: #00c399" ;
2017-10-02 00:27:01 +02:00
2017-09-24 01:54:46 +02:00
// global-ish variables
var _ard _oldAr ;
2017-09-27 02:26:47 +02:00
var _ard _currentAr ;
2017-12-29 23:34:40 +01:00
var _ard _setup _timer ;
var _ard _timer
2017-09-27 02:26:47 +02:00
// kjer vzemamo vzorce za blackbox/stuff. 9 vzorcev. Če spremenimo velikost vzorca, moramo spremeniti tudi vrednosti v tej tabeli
// vrednosti v tabeli so na osminskih intervalih od [0, <sample height * 4> - 4].
// we sample these lines in blackbox/stuff. 9 samples. If we change the canvas sample size, we have to correct these values as well
// samples are every eighth between [0, <sample height * 4> - 4].
2017-12-31 18:26:59 +01:00
var _ard _sampleLines = [ 0 , 360 , 720 , 1080 , 1440 , 1800 , 2160 , 2520 , 2876 ] ;
var _ard _sampleCols = [ 128 , 256 , 384 , 512 , 640 , 768 , 896 , 1024 , 1125 ] ;
2017-09-27 02:26:47 +02:00
2017-12-31 18:26:59 +01:00
var _ard _canvasWidth ;
var _ard _canvasHeight ;
var _ard _canvasDrawWindowHOffset = 0 ;
2017-09-27 02:26:47 +02:00
// **** FUNCTIONS **** //
2017-09-24 01:54:46 +02:00
2017-12-31 18:26:59 +01:00
var _arSetup = function ( cwidth , cheight ) {
2017-12-29 23:34:40 +01:00
if ( Debug . debug )
console . log ( "%c[ArDetect::_ard_setup] Starting automatic aspect ratio detection" , _ard _console _start ) ;
2017-12-31 18:26:59 +01:00
2017-12-30 18:36:08 +01:00
this . _halted = false ;
2017-12-29 23:34:40 +01:00
2017-12-31 18:26:59 +01:00
var existingCanvas = document . getElementById ( "uw_ArDetect_canvas" ) ;
if ( existingCanvas ) {
if ( Debug . debug )
console . log ( "[ArDetect::_ard_setup] existing canvas found. REMOVING KEBAB removing kebab\n\n\n\n(im hungry and you're not authorized to have it)" ) ;
existingCanvas . remove ( ) ;
if ( Debug . debug )
console . log ( "[ArDetect::_ard_setup] canvas removed" ) ;
}
var vid = document . getElementsByTagName ( "video" ) [ 0 ] ;
2017-09-24 01:54:46 +02:00
if ( vid === undefined ) {
2017-12-29 23:34:40 +01:00
_ard _setup _timer = setTimeout ( _arSetup , 1000 ) ;
2017-09-24 01:54:46 +02:00
return ;
}
2017-10-02 00:27:01 +02:00
// imamo video, pa tudi problem. Ta problem bo verjetno kmalu popravljen, zato setup začnemo hitreje kot prej
// we have a video, but also a problem. This problem will prolly be fixed very soon, so setup is called with
// less delay than before
2017-12-31 18:26:59 +01:00
if ( vid . videoWidth === 0 || vid . videoHeight === 0 ) {
2017-12-29 23:34:40 +01:00
_ard _setup _timer = setTimeout ( _arSetup , 100 ) ;
2017-10-02 00:27:01 +02:00
return ;
}
2017-12-31 18:26:59 +01:00
2017-09-24 01:54:46 +02:00
var canvas = document . createElement ( "canvas" ) ;
canvas . style . position = "absolute" ;
//todo: change those values to push canvas off-screen
2017-12-31 18:26:59 +01:00
_ard _canvasWidth = cwidth ? cwidth : Settings . arDetect . hSamples ;
_ard _canvasHeight = cheight ? cheight : Settings . arDetect . vSamples ;
2017-09-24 01:54:46 +02:00
2017-10-17 22:17:51 +02:00
if ( Debug . showArDetectCanvas ) {
2017-10-02 00:27:01 +02:00
canvas . style . left = "200px" ;
canvas . style . top = "780px" ;
canvas . style . zIndex = 10000 ;
}
else {
canvas . style . left = "-20000px" ;
canvas . style . top = "-1080px" ;
canvas . style . zIndex = - 10000 ;
}
canvas . id = "uw_ArDetect_canvas" ;
2017-09-24 01:54:46 +02:00
var test = document . getElementsByTagName ( "body" ) [ 0 ] ;
test . appendChild ( canvas ) ;
var context = canvas . getContext ( "2d" ) ;
// do setup once
// tho we could do it for every frame
2017-12-31 18:26:59 +01:00
if ( cwidth && cheight ) {
var canvasWidth = cwidth ;
var canvasHeight = cheight ;
var canvasScaleFactor = cheight / vid . videoHeight ;
}
else {
var canvasScaleFactor = _ard _canvasWidth / vid . videoWidth ;
var canvasWidth = vid . videoWidth * canvasScaleFactor ;
var canvasHeight = vid . videoHeight * canvasScaleFactor ;
}
2017-09-24 01:54:46 +02:00
canvas . width = canvasWidth ;
canvas . height = canvasHeight ;
// init oldAr to physical <video> aspect ratio
_ard _oldAr = vid . videoWidth / vid . videoHeight ;
2017-09-27 02:26:47 +02:00
_ard _currentAr = _ard _oldAr ;
2017-09-24 01:54:46 +02:00
2017-12-31 18:26:59 +01:00
try {
// determine where to sample
var ncol = Settings . arDetect . staticSampleCols ;
var nrow = Settings . arDetect . staticSampleRows ;
var colSpacing = _ard _canvasWidth / ncol ;
var rowSpacing = ( _ard _canvasHeight * 4 ) / nrow ;
_ard _sampleLines = [ ] ;
_ard _sampleCols = [ ] ;
for ( var i = 0 ; i < ncol ; i ++ ) {
if ( i < ncol - 1 )
_ard _sampleCols . push ( Math . round ( colSpacing * i ) ) ;
else {
_ard _sampleCols . push ( Math . round ( colSpacing * i ) - 1 ) ;
}
}
for ( var i = 0 ; i < nrow ; i ++ ) {
if ( i < ncol - 5 )
_ard _sampleLines . push ( Math . round ( rowSpacing * i ) ) ;
else {
_ard _sampleLines . push ( Math . round ( rowSpacing * i ) - 4 ) ;
}
}
}
catch ( ex ) {
console . log ( "%c[ArDetect::_arSetup] something went terribly wrong when calcuating sample colums." , Settings . colors . criticalFail ) ;
console . log ( "settings object:" , Settings ) ;
console . log ( "error:" , ex ) ;
}
2017-12-29 23:34:40 +01:00
this . _forcehalt = false ;
2017-09-24 01:54:46 +02:00
_ard _vdraw ( vid , context , canvasWidth , canvasHeight , false ) ;
} ;
2017-12-31 18:26:59 +01:00
var _ard _canvasReadyForDrawWindow = function ( ) {
if ( Debug . debug )
console . log ( "%c[ArDetect::_ard_canvasReadyForDrawWindow] (?)" , "color: #44f" , _ard _canvasHeight == window . innerHeight , "(ard_height:" , _ard _canvasHeight , "| window height:" , window . innerHeight , ")" ) ;
return _ard _canvasHeight == window . innerHeight
}
2017-09-24 01:54:46 +02:00
2017-12-31 18:26:59 +01:00
var _ard _processAr = function ( video , width , height , edge _h , edge _w , fallbackMode ) {
2017-09-24 01:54:46 +02:00
// width, height —> canvas/sample
//edge_w -—> null/undefined, because we don't autocorrect pillarbox yet
2017-12-31 18:26:59 +01:00
if ( Debug . debug ) {
console . log ( "[ArDetect::_ard_processAr] processing ar. width:" , width , "; height:" , height , "; edge top:" , edge _h ) ;
}
2017-09-27 02:26:47 +02:00
// if we don't specify these things, they'll have some default values.
if ( edge _h === undefined ) {
edge _h = 0 ;
edge _w = 0 ;
}
2017-09-24 01:54:46 +02:00
var letterbox = 2 * edge _h ;
var trueHeight = height - letterbox ;
2017-12-31 18:26:59 +01:00
if ( fallbackMode ) {
if ( edge _h > 1 && edge _h < 20 )
return ;
// let's add some safety border to avoid automatic ar toggling between 21:9 and 16:9
trueHeight += 6 ;
}
2017-09-24 01:54:46 +02:00
var trueAr = width / trueHeight ;
2017-10-02 00:27:01 +02:00
ArDetect . detectedAr = trueAr ;
2017-09-24 01:54:46 +02:00
// poglejmo, če se je razmerje stranic spremenilo
// check if aspect ratio is changed:
var arDiff = trueAr - _ard _oldAr ;
if ( arDiff < 0 )
arDiff = - arDiff ;
// ali je sprememba v mejah dovoljenega? Če da -> fertik
// is ar variance within acceptable levels? If yes -> we done
if ( arDiff < trueAr * Settings . arDetect . allowedVariance )
return ;
// če je sprememba več od dovoljenega, spremeni razmerje stranic. Stvari se razlikujejo glede na to, ali smo v fullscreen ali ne
// if change is greater than allowed, change the aspect ratio. Whether we do that depends on whether we're in fullscreen.
if ( FullScreenDetect . isFullScreen ( ) ) {
if ( Debug . debug )
2017-09-27 02:26:47 +02:00
console . log ( "[ArDetect::_ard_processAr] attempting to fix aspect ratio. New aspect ratio: " , trueAr ) ;
2017-09-24 01:54:46 +02:00
2017-09-27 02:26:47 +02:00
_ard _oldAr = trueAr ;
2017-09-24 01:54:46 +02:00
Resizer . setAr _fs ( trueAr ) ;
}
2017-10-02 00:27:01 +02:00
else {
// če nismo v fullscreen, potem preverimo, ali naša stran dovoljuje ne-fs?
// first, we'll check if our site allows for non-fs autoar detection
if ( SitesConf . nonfsArDetectEnabled ( ) ) {
_ard _oldAr = trueAr ;
Resizer . setAr _nonfs ( trueAr ) ;
}
}
2017-09-24 01:54:46 +02:00
}
var _ard _vdraw = function ( vid , context , w , h , conf ) {
2017-12-29 23:34:40 +01:00
if ( this . _forcehalt )
return ;
2017-12-31 18:26:59 +01:00
var fallbackMode = false ;
2017-09-24 01:54:46 +02:00
var blackbar _tresh = 10 ; // how non-black can the bar be
var how _far _treshold = 8 ; // how much can the edge pixel vary (*4)
2017-12-29 23:34:40 +01:00
if ( Debug . debug )
Settings . arDetect . timer _playing = 1000 ; // how long is the pause between two executions — 33ms ~ 30fps
2017-09-24 01:54:46 +02:00
2017-10-17 22:17:51 +02:00
if ( vid === undefined || vid . paused || vid . ended || Status . arStrat != "auto" ) {
2017-09-24 01:54:46 +02:00
// we slow down if paused, no detection
2017-12-31 18:26:59 +01:00
_ard _timer = setTimeout ( _ard _vdraw , Settings . arDetect . timer _paused , vid , context , w , h ) ;
2017-09-24 01:54:46 +02:00
return false ;
}
2017-12-31 18:26:59 +01:00
try {
context . drawImage ( vid , 0 , 0 , w , h ) ;
}
catch ( ex ) {
if ( Debug . debug )
console . log ( "%c[ArDetect::_ard_vdraw] can't draw image on canvas. Trying canvas.drawWindow instead" , "color:#000; backgroud:#f51;" , ex ) ;
try {
if ( _ard _canvasReadyForDrawWindow ( ) ) {
context . drawWindow ( window , _ard _canvasDrawWindowHOffset , 0 , w , h , "rgba(0,0,0,1)" ) ;
if ( Debug . debug )
console . log ( "%c[ArDetect::_ard_vdraw] canvas.drawImage seems to have worked" , "color:#000; backgroud:#2f5;" ) ;
fallbackMode = true ;
}
else {
// canvas needs to be resized, so let's change setup
_ard _stop ( ) ;
var newCanvasWidth = window . innerHeight * 1.77 ;
var newCanvasHeight = window . innerHeight ;
if ( Settings . miscFullscreenSettings . videoFloat == "center" )
_ard _canvasDrawWindowHOffset = Math . round ( ( window . innerWidth - newCanvasWidth ) * 0.5 ) ;
else if ( Settings . miscFullscreenSettings . videFloat == "left" )
_ard _canvasDrawWindowHOffset = 0 ;
else
_ard _canvasDrawWindowHOffset = window . innerWidth - newCanvasWidth ;
_arSetup ( newCanvasWidth , newCanvasHeight ) ;
return ;
}
}
catch ( ex ) {
if ( Debug . debug )
console . log ( "%c[ArDetect::_ard_vdraw] okay this didnt work either" , "color:#000; backgroud:#f51;" , ex ) ;
_ard _timer = setTimeout ( _ard _vdraw , Settings . arDetect . timer _error , vid , context , w , h ) ;
return ;
}
// _ard_timer = setTimeout(_ard_vdraw, Settings.arDetect.timer_error, vid, context, w, h);
// return;
}
2017-09-27 02:26:47 +02:00
// "random" columns — todo: randomly pick some more
2017-12-31 18:26:59 +01:00
var rc = _ard _sampleCols ;
2017-09-24 01:54:46 +02:00
var cimg = [ ] ;
var cols = [ ] ;
for ( var i = 0 ; i < rc . length ; i ++ ) {
//where-x, where-y, how wide, how tall
//random col, first y, 1 pix wide, all pixels tall
cols [ i ] = context . getImageData ( rc [ i ] , 0 , 1 , h ) . data ;
}
2017-09-27 02:26:47 +02:00
// fast test to see if aspect ratio is correct
2017-09-24 01:54:46 +02:00
isLetter = true ;
for ( var i in cols ) {
// if any of those points fails this check, we aren't letterboxed
2017-12-31 18:26:59 +01:00
isLetter &= ( cols [ i ] [ 0 ] <= blackbar _tresh && cols [ i ] [ 1 ] <= blackbar _tresh && cols [ i ] [ 2 ] <= blackbar _tresh ) ;
2017-09-24 01:54:46 +02:00
// should also check bottom
}
if ( ! isLetter ) {
2017-09-27 02:26:47 +02:00
// tudi če ne zaznamo letterboxa, še vedno poženemo processAr. Lahko, da smo v preteklosti popravili letterbox, to pa moramo
// sedaj razveljaviti
// even if we don't deect letterbox, we still issue processAr in case we adjusted for letterbox earlier and need to exit
// corrected mode.
2017-12-31 18:26:59 +01:00
if ( Debug . debug ) {
console . log ( "%c[ArDetect::_ard_vdraw] no edge detected. canvas has no edge." , "color: #aaf" ) ;
}
2017-09-27 02:26:47 +02:00
_ard _processAr ( vid , w , h ) ;
2017-12-29 23:34:40 +01:00
_ard _timer = setTimeout ( _ard _vdraw , Settings . arDetect . timer _playing , vid , context , w , h ) ; //no letterbox, no problem
2017-09-24 01:54:46 +02:00
return ;
}
// let's do a quick test to see if we're on a black frame
// let's also pick all points in advance (assuming canvas will always be 1280x720)
2017-09-27 02:26:47 +02:00
2017-09-24 01:54:46 +02:00
var blackPoints = 0 ;
2017-09-27 02:26:47 +02:00
var blackPointsMax = cols . length * 9 ; // 9 we sample each col at 9 different places
2017-09-24 01:54:46 +02:00
2017-09-27 02:26:47 +02:00
// indexes in _ard_sampleLines
var color _uppermost = 10 ;
var color _lowermost = 0 ;
// stolpca, v katerih smo našli zgornji številki
// columns, in which the values above were found
var cl _col = [ ] ;
var cu _col = [ ] ;
// if (pixel is black)
for ( var i in cols ) {
// --- piksli na zgornji polovici -----------------//
// --- pixels from the top ------------------------//
if ( cols [ i ] [ _ard _sampleLines [ 0 ] ] < blackbar _tresh &&
cols [ i ] [ _ard _sampleLines [ 0 ] + 1 ] < blackbar _tresh &&
cols [ i ] [ _ard _sampleLines [ 0 ] + 2 ] < blackbar _tresh )
2017-09-24 01:54:46 +02:00
blackPoints ++ ;
2017-09-27 02:26:47 +02:00
else if ( color _uppermost > 0 ) {
color _uppermost = 0 ;
cu _col = [ i ] ;
}
if ( cols [ i ] [ _ard _sampleLines [ 1 ] ] < blackbar _tresh &&
cols [ i ] [ _ard _sampleLines [ 1 ] + 1 ] < blackbar _tresh &&
cols [ i ] [ _ard _sampleLines [ 1 ] + 2 ] < blackbar _tresh )
2017-09-24 01:54:46 +02:00
blackPoints ++ ;
2017-09-27 02:26:47 +02:00
else if ( color _uppermost > 1 ) {
color _uppermost = 1 ;
cu _col = [ i ] ;
}
else if ( color _uppermost == 1 ) {
cu _col . push ( i ) ;
}
if ( cols [ i ] [ _ard _sampleLines [ 2 ] ] < blackbar _tresh &&
cols [ i ] [ _ard _sampleLines [ 2 ] + 1 ] < blackbar _tresh &&
cols [ i ] [ _ard _sampleLines [ 1 ] + 2 ] < blackbar _tresh )
2017-09-24 01:54:46 +02:00
blackPoints ++ ;
2017-09-27 02:26:47 +02:00
else if ( color _uppermost > 2 ) {
color _uppermost = 2 ;
cu _col = [ i ] ;
}
else if ( color _uppermost == 2 ) {
cu _col . push ( i ) ;
}
if ( cols [ i ] [ _ard _sampleLines [ 3 ] ] < blackbar _tresh &&
cols [ i ] [ _ard _sampleLines [ 3 ] + 1 ] < blackbar _tresh &&
cols [ i ] [ _ard _sampleLines [ 3 ] + 2 ] < blackbar _tresh )
2017-09-24 01:54:46 +02:00
blackPoints ++ ;
2017-09-27 02:26:47 +02:00
else if ( color _uppermost > 3 ) {
color _uppermost = 3 ;
cu _col = [ i ] ;
}
else if ( color _uppermost == 3 ) {
cu _col . push ( i ) ;
}
// --- piksli na spodnji polovici ---------------//
// tukaj gremo v obratni smeri, drugače bo v tabeli lahko napačen piksel
// --- pixels on the bottom ---------------------//
// searching in the other direction, otherwise we could get incorrect results
if ( cols [ i ] [ _ard _sampleLines [ 8 ] ] < blackbar _tresh &&
cols [ i ] [ _ard _sampleLines [ 8 ] + 1 ] < blackbar _tresh &&
cols [ i ] [ _ard _sampleLines [ 8 ] + 2 ] < blackbar _tresh )
2017-09-24 01:54:46 +02:00
blackPoints ++ ;
2017-09-27 02:26:47 +02:00
else if ( color _lowermost < 8 ) {
color _lowermost = 8 ;
cl _col = [ i ] ;
}
if ( cols [ i ] [ _ard _sampleLines [ 7 ] ] < blackbar _tresh &&
cols [ i ] [ _ard _sampleLines [ 7 ] + 1 ] < blackbar _tresh &&
cols [ i ] [ _ard _sampleLines [ 7 ] + 2 ] < blackbar _tresh )
2017-09-24 01:54:46 +02:00
blackPoints ++ ;
2017-09-27 02:26:47 +02:00
else if ( color _lowermost < 7 ) {
color _lowermost = 7 ;
cl _col = [ i ] ;
}
else if ( color _lowermost == 7 ) {
cl _col . push ( i ) ;
}
if ( cols [ i ] [ _ard _sampleLines [ 6 ] ] < blackbar _tresh &&
cols [ i ] [ _ard _sampleLines [ 6 ] + 1 ] < blackbar _tresh &&
cols [ i ] [ _ard _sampleLines [ 6 ] + 2 ] < blackbar _tresh )
2017-09-24 01:54:46 +02:00
blackPoints ++ ;
2017-09-27 02:26:47 +02:00
else if ( color _lowermost < 6 ) {
color _lowermost = 6 ;
cl _col = [ i ] ;
}
else if ( color _lowermost == 6 ) {
cl _col . push ( i ) ;
}
if ( cols [ i ] [ _ard _sampleLines [ 5 ] ] < blackbar _tresh &&
cols [ i ] [ _ard _sampleLines [ 5 ] + 1 ] < blackbar _tresh &&
cols [ i ] [ _ard _sampleLines [ 5 ] + 2 ] < blackbar _tresh )
2017-09-24 01:54:46 +02:00
blackPoints ++ ;
2017-09-27 02:26:47 +02:00
else if ( color _lowermost < 5 ) {
color _lowermost = 5 ;
cl _col = [ i ] ;
}
else if ( color _lowermost == 5 ) {
cl _col . push ( i ) ;
}
// --- piksli na sredini ------------------------//
// na sredini ne preverjamo za color_lowermost in color_uppermost. Če bo color_lowermost in color_uppermost relevanten na tem
// nivoju, potem bo a) dovolj črnih točk za blackframe oz b) barvasta točka na višjem nivoju
// --- pixels in the center ---------------------//
// we don't check for color_lowermost and color_uppermost here, because it's pointless.
if ( cols [ i ] [ 1440 ] < blackbar _tresh && cols [ i ] [ 1441 ] < blackbar _tresh && cols [ i ] [ 1442 ] < blackbar _tresh )
blackPoints ++ ;
2017-09-24 01:54:46 +02:00
}
2017-09-27 02:26:47 +02:00
if ( blackPoints > ( blackPointsMax >> 1 ) ) {
2017-09-24 01:54:46 +02:00
// if more than half of those points are black, we consider the entire frame black (or too dark to get anything useful
// out of it, anyway)
2017-12-29 23:34:40 +01:00
_ard _timer = setTimeout ( _ard _vdraw , Settings . arDetect . timer _playing , vid , context , w , h ) ; //no letterbox, no problem
2017-09-24 01:54:46 +02:00
return ;
}
2017-09-27 02:26:47 +02:00
if ( color _lowermost == 8 || color _uppermost == 0 ) {
// zakaj smo potem sploh tukaj?
// why exactly are we here again?
2017-12-31 18:26:59 +01:00
if ( Debug . debug ) {
console . log ( "%c[ArDetect.js] aspect ratio change is being triggered by an event we thought shouldn't be triggering it. Strange.\n\n" , "color: #4af" , "color_lowermost (8=bad):" , color _lowermost , "color_uppermost (0=bad):" , color _uppermost ) ;
}
// _ard_processAr(vid, w, h);
2017-12-29 23:34:40 +01:00
_ard _timer = setTimeout ( _ard _vdraw , Settings . arDetect . timer _playing , vid , context , w , h ) ; //no letterbox, no problem
2017-09-27 02:26:47 +02:00
return ;
}
// pa poglejmo, kje se končajo črne letvice na vrhu in na dnu videa.
// let's see where black bars end. We only need to check in the columns where we detected uppermost and lowermost color.
2017-09-24 01:54:46 +02:00
2017-09-27 02:26:47 +02:00
var endPixelTop = [ ] ;
2017-09-24 01:54:46 +02:00
var endPixelBottom = [ ] ;
2017-09-27 02:26:47 +02:00
for ( var i in cu _col ) {
var tmpEndPixel = _ard _sampleLines [ color _uppermost ] >> 2 ; // this would be the value if loop fails to quit with proper pixel
var j = _ard _sampleLines [ color _uppermost - 1 ] ;
while ( j < _ard _sampleLines [ color _uppermost ] ) {
if ( cols [ cu _col [ i ] ] [ j ] > blackbar _tresh &&
cols [ cu _col [ i ] ] [ j + 1 ] > blackbar _tresh &&
cols [ cu _col [ i ] ] [ j + 2 ] > blackbar _tresh ) {
2017-12-31 18:26:59 +01:00
if ( Debug . debug )
console . log ( "detecting value higher than blackbar_tresh!" ) ;
2017-09-27 02:26:47 +02:00
tmpEndPixel = j >> 2 ;
2017-09-24 01:54:46 +02:00
break ;
}
2017-09-27 02:26:47 +02:00
j += 4 ;
2017-09-24 01:54:46 +02:00
}
2017-09-27 02:26:47 +02:00
endPixelTop . push ( tmpEndPixel ) ;
2017-09-24 01:54:46 +02:00
}
2017-09-27 02:26:47 +02:00
for ( var i in cl _col ) {
var tmpEndPixel = _ard _sampleLines [ color _lowermost ] >> 2 ;
var j = _ard _sampleLines [ color _lowermost ] ;
while ( j < _ard _sampleLines [ color _lowermost + 1 ] ) {
if ( cols [ cl _col [ i ] ] [ j ] < blackbar _tresh &&
cols [ cl _col [ i ] ] [ j + 1 ] < blackbar _tresh &&
cols [ cl _col [ i ] ] [ j + 2 ] < blackbar _tresh ) {
tmpEndPixel = j >> 2 ;
break ;
}
j += 4 ;
}
endPixelBottom . push ( tmpEndPixel ) ;
}
// dobi najvišji in najnižji piksel
var bottomPixel = 0 ;
var topPixel = 222222 ;
2017-09-24 01:54:46 +02:00
2017-09-27 02:26:47 +02:00
for ( var i in endPixelTop ) {
if ( endPixelTop [ i ] < topPixel )
topPixel = endPixelTop [ i ] ;
2017-09-24 01:54:46 +02:00
}
2017-09-27 02:26:47 +02:00
for ( var i in endPixelBottom ) {
if ( endPixelBottom [ i ] > bottomPixel )
bottomPixel = endPixelBottom [ i ] ;
}
// preveri, če sta odmika zgoraj in spodaj podobno velika. Če nista, potem gledamo objekt, ne letterboxa
// check if black borders match; if the line isn't horizontal we could be looking at an object in
// the actual video that shouldn't be cropped out.
var letterDiff = topPixel - ( h - bottomPixel ) ;
if ( letterDiff < 0 )
letterDiff = - letterDiff ;
isLetter = ( letterDiff < h * Settings . arDetect . allowedMisaligned ) ;
2017-09-24 01:54:46 +02:00
if ( isLetter )
2017-12-31 18:26:59 +01:00
_ard _processAr ( vid , w , h , topPixel , null , fallbackMode ) ;
2017-09-24 01:54:46 +02:00
2017-12-29 23:34:40 +01:00
_ard _timer = setTimeout ( _ard _vdraw , Settings . arDetect . timer _playing , vid , context , w , h ) ;
2017-09-24 01:54:46 +02:00
}
2017-12-29 23:34:40 +01:00
var _ard _stop = function ( ) {
if ( Debug . debug ) {
console . log ( "%c[ArDetect::_ard_stop] Stopping automatic aspect ratio detection" , _ard _console _stop ) ;
}
this . _forcehalt = true ;
2017-12-30 18:36:08 +01:00
this . _halted = true ;
2017-12-29 23:34:40 +01:00
clearTimeout ( _ard _timer ) ;
clearTimeout ( _ard _setup _timer ) ;
}
2017-09-24 01:54:46 +02:00
2017-12-30 18:36:08 +01:00
var _ard _isRunning = function ( ) {
return ! this . _halted ;
}
2017-09-24 01:54:46 +02:00
var ArDetect = {
2017-12-29 23:34:40 +01:00
_forcehalt : false ,
2017-12-30 18:36:08 +01:00
_halted : false ,
2017-09-24 01:54:46 +02:00
arSetup : _arSetup ,
2017-12-30 12:55:58 +01:00
init : _arSetup ,
2017-09-24 01:54:46 +02:00
vdraw : _ard _vdraw ,
2017-10-02 00:27:01 +02:00
detectedAr : 1 ,
2017-12-29 23:34:40 +01:00
arChangedCallback : function ( ) { } ,
stop : _ard _stop ,
2017-12-30 18:36:08 +01:00
isRunning : _ard _isRunning
2017-09-24 01:54:46 +02:00
}