11import obsWebsocketJs from 'obs-websocket-js' ;
22import { icons } from './icons' ;
33
4- const autocropThreshold = 35 ;
5- const gdqGreen = [ 1 , 128 , 1 ] ;
6- const gdqGreen2 = [ 0 , 255 , 0 ] ;
4+ const autocropThreshold = 30 ; // 35;
5+ /* const gdqGreen = [1, 128, 1];
6+ const gdqGreen2 = [0, 255, 0]; */
77let screenshotBase64 = '' ;
88
99let connectedToOBS = false ;
@@ -359,18 +359,18 @@ function cropItemToTarget(check?: 'check') {
359359 } else activelyCropping = false ;
360360}
361361document . getElementById ( 'thinify' ) ! . onclick = ( ) => {
362- arControl . value = '0.75' ;
362+ arControl . value = '0.75' ;
363363 targetAr = 0.75 ;
364364 adjustAr ( ) ;
365365} ;
366366document . getElementById ( 'revert-ar' ) ! . onclick = ( ) => {
367- arControl . value = '1' ;
367+ arControl . value = '1' ;
368368 targetAr = 1 ;
369369 adjustAr ( ) ;
370370} ;
371371document . getElementById ( 'wideify' ) ! . onclick = ( ) => {
372- arControl . value = ( 4 / 3 ) . toString ( ) ;
373- targetAr = 4 / 3 ;
372+ arControl . value = ( 4 / 3 ) . toString ( ) ;
373+ targetAr = 4 / 3 ;
374374 adjustAr ( ) ;
375375} ;
376376arControl . oninput = ( ) => {
@@ -1461,6 +1461,7 @@ function cropViewportFeed(cropType: 'camera' | 'game1' | 'game2') {
14611461 const height = cropItem . height ;
14621462 const y1 = 0.124 * height ; //always game1 to webcam gap
14631463 const y2 = 0.546 * height ; //game1 to game2 gap
1464+ const x0 = 0.05 * width ; //game1 left checkstop, for when people are struggling at layouts
14641465 const x1 = 0.176 * width ; //webcam y/ game2 y
14651466 const x2 = 0.718 * width ; //game1 y
14661467 const canvas = document . createElement ( 'canvas' ) ;
@@ -1474,9 +1475,9 @@ function cropViewportFeed(cropType: 'camera' | 'game1' | 'game2') {
14741475 ctx . drawImage ( cropImg , 0 , 0 ) ;
14751476 let temp : [ number , number ] ;
14761477 let newItemRec = { left : - 1 , right : - 1 , top : - 1 , bottom : - 1 } ;
1477- const camera = { left : - 1 , right : - 1 , top : - 1 , bottom : - 1 } ;
1478- const game1 = { left : - 1 , right : - 1 , top : - 1 , bottom : - 1 } ;
1479- const game2 = { left : - 1 , right : - 1 , top : - 1 , bottom : - 1 } ;
1478+ let camera = { left : - 1 , right : width , top : - 1 , bottom : height } ;
1479+ let game1 = { left : - 1 , right : width , top : - 1 , bottom : height } ;
1480+ let game2 = { left : - 1 , right : width , top : - 1 , bottom : height } ;
14801481 temp = findGreenBlock ( ctx , 'y' , y1 , y2 , x1 , true ) ;
14811482 if ( temp [ 1 ] < y2 ) game2 . top = temp [ 1 ] ;
14821483 camera . bottom = temp [ 0 ] ;
@@ -1486,6 +1487,7 @@ function cropViewportFeed(cropType: 'camera' | 'game1' | 'game2') {
14861487 camera . left = temp [ 1 ] == - 1 ? 0 : temp [ 1 ] ;
14871488 temp = findGreenBlock ( ctx , 'x' , x2 , x1 , y2 , true ) ;
14881489 game2 . right = temp [ 0 ] > x1 - 1 ? temp [ 0 ] : - 1 ;
1490+ temp = findGreenBlock ( ctx , 'x' , x2 , x0 , y2 , true ) ;
14891491 game1 . left = temp [ 1 ] ;
14901492 temp = findGreenBlock ( ctx , 'x' , x1 , x2 , y1 , true ) ;
14911493 camera . right = temp [ 0 ] == - 1 ? game1 . left : temp [ 0 ] ;
@@ -1501,12 +1503,18 @@ function cropViewportFeed(cropType: 'camera' | 'game1' | 'game2') {
15011503 game2 . bottom = temp [ 0 ] == - 1 ? height - 1 : temp [ 0 ] ;
15021504 switch ( cropType ) {
15031505 case 'game1' :
1506+ if ( game1 . left > game1 . right || game1 . top > game1 . bottom )
1507+ game1 = { left : - 1 , right : width , top : - 1 , bottom : height } ;
15041508 newItemRec = game1 ;
15051509 break ;
15061510 case 'game2' :
1511+ if ( game2 . left > game2 . right || game2 . top > game2 . bottom )
1512+ game2 = { left : - 1 , right : width , top : - 1 , bottom : height } ;
15071513 newItemRec = game2 ;
15081514 break ;
15091515 case 'camera' :
1516+ if ( camera . left > camera . right || camera . top > camera . bottom )
1517+ camera = { left : - 1 , right : width , top : - 1 , bottom : height } ;
15101518 newItemRec = camera ;
15111519 break ;
15121520 }
@@ -1556,7 +1564,8 @@ function findGreenBlock(
15561564 start : number ,
15571565 end : number ,
15581566 otherAxis : number ,
1559- allowend ?: boolean
1567+ allowend ?: boolean ,
1568+ print ?: 'print'
15601569) : [ number , number ] {
15611570 let direction = 1 ;
15621571 if ( start > end ) direction = - 1 ;
@@ -1568,6 +1577,7 @@ function findGreenBlock(
15681577 for ( let i = start ; ( end - i ) * direction >= 0 ; i += direction ) {
15691578 let coords : [ number , number ] = [ i , otherAxis ] ;
15701579 if ( axis == 'y' ) coords = [ otherAxis , i ] ;
1580+ if ( print ) console . log ( compareToGreen ( ctx , ...coords ) ) ;
15711581 if ( compareToGreen ( ctx , ...coords ) < autocropThreshold ) {
15721582 if ( curBlock [ 1 ] == i - direction ) {
15731583 curBlock [ 1 ] = i ;
@@ -1601,14 +1611,15 @@ function compareToGreen(
16011611 y : number
16021612) : number {
16031613 const pixel = Array . from ( ctx . getImageData ( x , y , 1 , 1 ) . data ) ;
1604- return Math . min (
1614+ return pixel [ 0 ] + pixel [ 2 ] + ( pixel [ 1 ] > 100 ? 0 : 100 ) ;
1615+ /* Math.min(
16051616 Math.abs(pixel[0] - gdqGreen[0]) +
16061617 Math.abs(pixel[1] - gdqGreen[1]) +
16071618 Math.abs(pixel[2] - gdqGreen[2]),
16081619 Math.abs(pixel[0] - gdqGreen2[0]) +
16091620 Math.abs(pixel[1] - gdqGreen2[1]) +
16101621 Math.abs(pixel[2] - gdqGreen2[2])
1611- ) ;
1622+ ); */
16121623}
16131624
16141625//Type Checking:
0 commit comments