 ! (c)Joe Groff bsd license
-USING: alien.data.map generalizations kernel math.vectors
-math.vectors.conversion math.vectors.simd
+USING: alien.data.map fry generalizations kernel math.vectors
+math.vectors.conversion math math.vectors.simd
 specialized-arrays tools.test ;
 FROM: alien.c-types => uchar short int float ;
 SIMDS: float int short uchar ;

        1.0 0.1 0.2 0.3
        0.3 0.2 0.9 0.5
        0.1 1.0 1.5 2.0
    } [
        [ 255.0 v*n float-4 int-4 vconvert ] 4 napply 
        [ int-4 short-8 vconvert ] 2bi@
        short-8 uchar-16 vconvert
    ] data-map( float-4[4] -- uchar-16 )
] unit-test

[

    [ dup ] data-map!( int -- float[2] )
] unit-test

: float-pixels>byte-pixels* ( floats scale bias -- bytes )
    '[
        [ _ 255.0 * v*n _ 255.0 * v+n float-4 int-4 vconvert ] 4 napply 
        [ int-4 short-8 vconvert ] 2bi@
        short-8 uchar-16 vconvert
    ] data-map( float-4[4] -- uchar-16 ) ; inline

: float-pixels>byte-pixels ( floats -- bytes )
    1.0 0.0 float-pixels>byte-pixels* ;

[
    B{
        127 191 255 63
