@@ -617,6 +617,20 @@ Object.defineProperty(SIMDopeColor.prototype, 'a', {
617617 get : function ( ) { "use strict" ; return clamp_uint8 ( this . storage_uint8_ [ 0 ] ) ; } ,
618618} ) ;
619619
620+ // Properties of number object
621+ Object . defineProperty ( SIMDopeColor . prototype , 'z' , {
622+ get : function ( ) { "use strict" ; return clamp_uint8 ( this . storage_uint8_ [ 3 ] ) ; } ,
623+ } ) ;
624+ Object . defineProperty ( SIMDopeColor . prototype , 'y' , {
625+ get : function ( ) { "use strict" ; return clamp_uint8 ( this . storage_uint8_ [ 2 ] ) ; } ,
626+ } ) ;
627+ Object . defineProperty ( SIMDopeColor . prototype , 'x' , {
628+ get : function ( ) { "use strict" ; return clamp_uint8 ( this . storage_uint8_ [ 1 ] ) ; } ,
629+ } ) ;
630+ Object . defineProperty ( SIMDopeColor . prototype , 'w' , {
631+ get : function ( ) { "use strict" ; return clamp_uint8 ( this . storage_uint8_ [ 0 ] ) ; } ,
632+ } ) ;
633+
620634Object . defineProperty ( SIMDopeColor . prototype , 'uint32' , {
621635 get : function ( ) { "use strict" ;
622636 return ( ( this . storage_uint8_ [ 3 ] << 24 ) | ( this . storage_uint8_ [ 2 ] << 16 ) | ( this . storage_uint8_ [ 1 ] << 8 ) | ( this . storage_uint8_ [ 0 ] << 0 ) | 0 ) >>> 0 ;
@@ -703,6 +717,15 @@ Object.defineProperty(SIMDopeColor.prototype, 'set', {
703717 }
704718 } }
705719} ) ;
720+ Object . defineProperty ( SIMDopeColor . prototype , 'set_out_of' , {
721+ get : function ( ) { "use strict" ; return function ( w , x , y , z ) {
722+ this . storage_uint8_ [ 0 ] = clamp_uint8 ( w ) ;
723+ this . storage_uint8_ [ 1 ] = clamp_uint8 ( x ) ;
724+ this . storage_uint8_ [ 2 ] = clamp_uint8 ( y ) ;
725+ this . storage_uint8_ [ 3 ] = clamp_uint8 ( z ) ;
726+
727+ } }
728+ } ) ;
706729Object . defineProperty ( SIMDopeColor . prototype , 'subarray' , {
707730 get : function ( ) { "use strict" ; return this . storage_uint8_ . subarray ( 0 , 4 ) ; }
708731} ) ;
@@ -940,6 +963,27 @@ SIMDopeColor.blend = function(base_uint8x4, added_uint8x4, amount_alpha, should_
940963 return base_uint8x4 . copy ( ) . blend_with ( added_uint8x4 , amount_alpha , should_return_transparent , alpha_addition ) ;
941964} ;
942965
966+ SIMDopeColor . prototype . merge_with_a_fixed = function ( t2 , alpha ) {
967+ var uint8a = this . subarray ;
968+ uint8a [ 0 ] = clamp_uint8 ( alpha ) ;
969+ uint8a [ 1 ] = plus_uint ( this . b , t2 . b ) ;
970+ uint8a [ 2 ] = plus_uint ( this . g , t2 . g ) ;
971+ uint8a [ 3 ] = plus_uint ( this . r , t2 . r ) ;
972+ }
973+
974+ function alpha_add ( a , b ) {
975+ return clamp_uint8 ( divide_uint ( plus_uint ( a , b ) , 2 ) ) ;
976+ }
977+ function alpha_euc ( a , b ) {
978+ return clamp_uint8 ( inverse_255 ( divide_255 ( multiply_uint ( inverse_255 ( a ) , inverse_255 ( b ) ) ) ) ) ;
979+ }
980+ function get_alpha_with ( a , b ) {
981+ return clamp_uint8 ( divide_uint ( multiply_uint ( a , 255 ) , b ) ) ;
982+ }
983+ function get_alpha_from ( a , b , c ) {
984+ return clamp_uint8 ( divide_255 ( multiply_uint ( a , divide_uint ( multiply_uint ( inverse_255 ( b ) , 255 ) , c ) ) ) )
985+ }
986+
943987SIMDopeColor . blend_all_four = function ( from_a ,
944988 from_b ,
945989 from_c ,
@@ -971,42 +1015,42 @@ SIMDopeColor.blend_all_four = function(from_a,
9711015 var alpha_from = new Uint8Array ( 4 ) ;
9721016
9731017 if ( ( alpha_addition | 0 ) > 0 ) {
974- alpha [ 0 ] = clamp_uint8 ( divide_uint ( plus_uint ( from_a . a , amount_alpha_a ) , 2 ) ) ;
975- alpha [ 1 ] = clamp_uint8 ( divide_uint ( plus_uint ( from_b . a , amount_alpha_b ) , 2 ) ) ;
976- alpha [ 2 ] = clamp_uint8 ( divide_uint ( plus_uint ( from_c . a , amount_alpha_c ) , 2 ) ) ;
977- alpha [ 3 ] = clamp_uint8 ( divide_uint ( plus_uint ( from_d . a , amount_alpha_d ) , 2 ) ) ;
1018+ alpha [ 0 ] = alpha_add ( from_a . a , amount_alpha_a ) ;
1019+ alpha [ 1 ] = alpha_add ( from_b . a , amount_alpha_b ) ;
1020+ alpha [ 2 ] = alpha_add ( from_c . a , amount_alpha_c ) ;
1021+ alpha [ 3 ] = alpha_add ( from_d . a , amount_alpha_d ) ;
9781022 } else {
9791023
980- alpha [ 0 ] = clamp_uint8 ( inverse_255 ( divide_255 ( multiply_uint ( inverse_255 ( with_a . a ) , inverse_255 ( from_a . a ) ) ) ) ) ;
981- alpha [ 1 ] = clamp_uint8 ( inverse_255 ( divide_255 ( multiply_uint ( inverse_255 ( with_b . a ) , inverse_255 ( from_b . a ) ) ) ) ) ;
982- alpha [ 2 ] = clamp_uint8 ( inverse_255 ( divide_255 ( multiply_uint ( inverse_255 ( with_c . a ) , inverse_255 ( from_c . a ) ) ) ) ) ;
983- alpha [ 3 ] = clamp_uint8 ( inverse_255 ( divide_255 ( multiply_uint ( inverse_255 ( with_d . a ) , inverse_255 ( from_d . a ) ) ) ) ) ;
1024+ alpha [ 0 ] = alpha_euc ( with_a . a , from_a . a ) ;
1025+ alpha [ 1 ] = alpha_euc ( with_b . a , from_b . a ) ;
1026+ alpha [ 2 ] = alpha_euc ( with_c . a , from_c . a ) ;
1027+ alpha [ 3 ] = alpha_euc ( with_d . a , from_d . a ) ;
9841028 }
9851029
986- alpha_with [ 0 ] = clamp_uint8 ( divide_uint ( multiply_uint ( with_a . a , 255 ) , alpha [ 0 ] ) ) ;
987- alpha_with [ 1 ] = clamp_uint8 ( divide_uint ( multiply_uint ( with_b . a , 255 ) , alpha [ 1 ] ) ) ;
988- alpha_with [ 2 ] = clamp_uint8 ( divide_uint ( multiply_uint ( with_c . a , 255 ) , alpha [ 2 ] ) ) ;
989- alpha_with [ 3 ] = clamp_uint8 ( divide_uint ( multiply_uint ( with_d . a , 255 ) , alpha [ 3 ] ) ) ;
990-
991- alpha_from [ 0 ] = clamp_uint8 ( divide_255 ( multiply_uint ( from_a . a , divide_uint ( multiply_uint ( inverse_255 ( with_a . a ) , 255 ) , alpha [ 0 ] ) ) ) ) ;
992- alpha_from [ 1 ] = clamp_uint8 ( divide_255 ( multiply_uint ( from_b . a , divide_uint ( multiply_uint ( inverse_255 ( with_b . a ) , 255 ) , alpha [ 1 ] ) ) ) ) ;
993- alpha_from [ 2 ] = clamp_uint8 ( divide_255 ( multiply_uint ( from_c . a , divide_uint ( multiply_uint ( inverse_255 ( with_c . a ) , 255 ) , alpha [ 2 ] ) ) ) ) ;
994- alpha_from [ 3 ] = clamp_uint8 ( divide_255 ( multiply_uint ( from_d . a , divide_uint ( multiply_uint ( inverse_255 ( with_d . a ) , 255 ) , alpha [ 3 ] ) ) ) ) ;
995-
996- with_a . set ( Uint8Array . of ( 0 , divide_255 ( multiply_uint ( with_a . b , alpha_with [ 0 ] ) ) , divide_255 ( multiply_uint ( with_a . g , alpha_with [ 0 ] ) ) , divide_255 ( multiply_uint ( with_a . r , alpha_with [ 0 ] ) ) ) ) ;
997- with_b . set ( Uint8Array . of ( 0 , divide_255 ( multiply_uint ( with_b . b , alpha_with [ 1 ] ) ) , divide_255 ( multiply_uint ( with_b . g , alpha_with [ 1 ] ) ) , divide_255 ( multiply_uint ( with_b . r , alpha_with [ 1 ] ) ) ) ) ;
998- with_c . set ( Uint8Array . of ( 0 , divide_255 ( multiply_uint ( with_c . b , alpha_with [ 2 ] ) ) , divide_255 ( multiply_uint ( with_c . g , alpha_with [ 2 ] ) ) , divide_255 ( multiply_uint ( with_c . r , alpha_with [ 2 ] ) ) ) ) ;
999- with_d . set ( Uint8Array . of ( 0 , divide_255 ( multiply_uint ( with_d . b , alpha_with [ 3 ] ) ) , divide_255 ( multiply_uint ( with_d . g , alpha_with [ 3 ] ) ) , divide_255 ( multiply_uint ( with_d . r , alpha_with [ 3 ] ) ) ) ) ;
1000-
1001- from_a . set ( Uint8Array . of ( 0 , divide_255 ( multiply_uint ( from_a . b , alpha_from [ 0 ] ) ) , divide_255 ( multiply_uint ( from_a . g , alpha_from [ 0 ] ) ) , divide_255 ( multiply_uint ( from_a . r , alpha_from [ 0 ] ) ) ) ) ;
1002- from_b . set ( Uint8Array . of ( 0 , divide_255 ( multiply_uint ( from_b . b , alpha_from [ 1 ] ) ) , divide_255 ( multiply_uint ( from_b . g , alpha_from [ 1 ] ) ) , divide_255 ( multiply_uint ( from_b . r , alpha_from [ 1 ] ) ) ) ) ;
1003- from_c . set ( Uint8Array . of ( 0 , divide_255 ( multiply_uint ( from_c . b , alpha_from [ 2 ] ) ) , divide_255 ( multiply_uint ( from_c . g , alpha_from [ 2 ] ) ) , divide_255 ( multiply_uint ( from_c . r , alpha_from [ 2 ] ) ) ) ) ;
1004- from_d . set ( Uint8Array . of ( 0 , divide_255 ( multiply_uint ( from_d . b , alpha_from [ 3 ] ) ) , divide_255 ( multiply_uint ( from_d . g , alpha_from [ 3 ] ) ) , divide_255 ( multiply_uint ( from_d . r , alpha_from [ 3 ] ) ) ) ) ;
1005-
1006- from_a . set ( SIMDopeColor . merge_with_a_fixed ( from_a , with_a , alpha [ 0 ] ) ) ;
1007- from_b . set ( SIMDopeColor . merge_with_a_fixed ( from_b , with_b , alpha [ 1 ] ) ) ;
1008- from_c . set ( SIMDopeColor . merge_with_a_fixed ( from_c , with_c , alpha [ 2 ] ) ) ;
1009- from_d . set ( SIMDopeColor . merge_with_a_fixed ( from_d , with_d , alpha [ 3 ] ) ) ;
1030+ alpha_with [ 0 ] = get_alpha_with ( with_a . a , alpha [ 0 ] ) ;
1031+ alpha_with [ 1 ] = get_alpha_with ( with_b . a , alpha [ 1 ] ) ;
1032+ alpha_with [ 2 ] = get_alpha_with ( with_c . a , alpha [ 2 ] ) ;
1033+ alpha_with [ 3 ] = get_alpha_with ( with_d . a , alpha [ 3 ] ) ;
1034+
1035+ alpha_from [ 0 ] = get_alpha_from ( from_a . a , with_a . a , alpha [ 0 ] ) ;
1036+ alpha_from [ 1 ] = get_alpha_from ( from_b . a , with_b . a , alpha [ 1 ] ) ;
1037+ alpha_from [ 2 ] = get_alpha_from ( from_c . a , with_c . a , alpha [ 2 ] ) ;
1038+ alpha_from [ 3 ] = get_alpha_from ( from_d . a , with_d . a , alpha [ 3 ] ) ;
1039+
1040+ with_a . set_out_of ( 0 , divide_255 ( multiply_uint ( with_a . b , alpha_with [ 0 ] ) ) , divide_255 ( multiply_uint ( with_a . g , alpha_with [ 0 ] ) ) , divide_255 ( multiply_uint ( with_a . r , alpha_with [ 0 ] ) ) ) ;
1041+ with_b . set_out_of ( 0 , divide_255 ( multiply_uint ( with_b . b , alpha_with [ 1 ] ) ) , divide_255 ( multiply_uint ( with_b . g , alpha_with [ 1 ] ) ) , divide_255 ( multiply_uint ( with_b . r , alpha_with [ 1 ] ) ) ) ;
1042+ with_c . set_out_of ( 0 , divide_255 ( multiply_uint ( with_c . b , alpha_with [ 2 ] ) ) , divide_255 ( multiply_uint ( with_c . g , alpha_with [ 2 ] ) ) , divide_255 ( multiply_uint ( with_c . r , alpha_with [ 2 ] ) ) ) ;
1043+ with_d . set_out_of ( 0 , divide_255 ( multiply_uint ( with_d . b , alpha_with [ 3 ] ) ) , divide_255 ( multiply_uint ( with_d . g , alpha_with [ 3 ] ) ) , divide_255 ( multiply_uint ( with_d . r , alpha_with [ 3 ] ) ) ) ;
1044+
1045+ from_a . set_out_of ( 0 , divide_255 ( multiply_uint ( from_a . b , alpha_from [ 0 ] ) ) , divide_255 ( multiply_uint ( from_a . g , alpha_from [ 0 ] ) ) , divide_255 ( multiply_uint ( from_a . r , alpha_from [ 0 ] ) ) ) ;
1046+ from_b . set_out_of ( 0 , divide_255 ( multiply_uint ( from_b . b , alpha_from [ 1 ] ) ) , divide_255 ( multiply_uint ( from_b . g , alpha_from [ 1 ] ) ) , divide_255 ( multiply_uint ( from_b . r , alpha_from [ 1 ] ) ) ) ;
1047+ from_c . set_out_of ( 0 , divide_255 ( multiply_uint ( from_c . b , alpha_from [ 2 ] ) ) , divide_255 ( multiply_uint ( from_c . g , alpha_from [ 2 ] ) ) , divide_255 ( multiply_uint ( from_c . r , alpha_from [ 2 ] ) ) ) ;
1048+ from_d . set_out_of ( 0 , divide_255 ( multiply_uint ( from_d . b , alpha_from [ 3 ] ) ) , divide_255 ( multiply_uint ( from_d . g , alpha_from [ 3 ] ) ) , divide_255 ( multiply_uint ( from_d . r , alpha_from [ 3 ] ) ) ) ;
1049+
1050+ from_a . merge_with_a_fixed ( with_a , alpha [ 0 ] ) ;
1051+ from_b . merge_with_a_fixed ( with_b , alpha [ 1 ] ) ;
1052+ from_c . merge_with_a_fixed ( with_c , alpha [ 2 ] ) ;
1053+ from_d . merge_with_a_fixed ( with_d , alpha [ 3 ] ) ;
10101054} ;
10111055
10121056// From a given operation and number object perform the operation and return a the number object
0 commit comments