preserve import { Y } from '../constants/bt709' ; export interface PointRGBA { r : number ; g : number ; b : number ; a : number ; } /**
 * v8 optimized class
 * 1) "constructor" should have initialization with worst types
 * 2) "set" should have |0 / >>> 0
 */ export class Point implements PointRGBA { r : number ; g : number ; b : number ; a : number ; uint32 : number ; rgba : number [ ] ; static createByQuadruplet ( quadruplet ) { const point = new Point ( ) ; point . r = quadruplet [ 0 ] | 0 ; point . g = quadruplet [ 1 ] | 0 ; point . b = quadruplet [ 2 ] | 0 ; point . a = quadruplet [ 3 ] | 0 ; point . _loadUINT32 ( ) ; point . _loadQuadruplet ( ) ; return point ; } static createByRGBA ( red , green , blue , alpha ) { const point = new Point ( ) ; point . r = red | 0 ; point . g = green | 0 ; point . b = blue | 0 ; point . a = alpha | 0 ; point . _loadUINT32 ( ) ; point . _loadQuadruplet ( ) ; return point ; } static createByUint32 ( uint32 ) { const point = new Point ( ) ; point . uint32 = uint32 >>> 0 ; point . _loadRGBA ( ) ; point . _loadQuadruplet ( ) ; return point ; } constructor ( ) { this . uint32 = - 1 >>> 0 ; this . r = this . g = this . b = this . a = 0 ; this . rgba = new Array ( 4 ) ; this . rgba [ 0 ] = 0 ; this . rgba [ 1 ] = 0 ; this . rgba [ 2 ] = 0 ; this . rgba [ 3 ] = 0 ; } from ( point ) { this . r = point . r ; this . g = point . g ; this . b = point . b ; this . a = point . a ; this . uint32 = point . uint32 ; this . rgba [ 0 ] = point . r ; this . rgba [ 1 ] = point . g ; this . rgba [ 2 ] = point . b ; this . rgba [ 3 ] = point . a ; } getLuminosity ( useAlphaChannel ) { let r = this . r ; let g = this . g ; let b = this . b ; if ( useAlphaChannel ) { r = Math . min ( 255 , 255 - this . a + ( this . a * r ) / 255 ) ; g = Math . min ( 255 , 255 - this . a + ( this . a * g ) / 255 ) ; b = Math . min ( 255 , 255 - this . a + ( this . a * b ) / 255 ) ; } return r * Y . RED + g * Y . GREEN + b * Y . BLUE ; } private _loadUINT32 ( ) { this . uint32 = ( ( this . a << 24 ) | ( this . b << 16 ) | ( this . g << 8 ) | this . r ) >>> 0 ; } private _loadRGBA ( ) { this . r = this . uint32 & 0xff ; this . g = ( this . uint32 >>> 8 ) & 0xff ; this . b = ( this . uint32 >>> 16 ) & 0xff ; this . a = ( this . uint32 >>> 24 ) & 0xff ; } private _loadQuadruplet ( ) { this . rgba [ 0 ] = this . r ; this . rgba [ 1 ] = this . g ; this . rgba [ 2 ] = this . b ; this . rgba [ 3 ] = this . a ; } }