 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien.c-types kernel accessors grouping sequences
 combinators math byte-arrays fry images half-floats
-specialized-arrays ;
+specialized-arrays words ;
 FROM: alien.c-types => float ;
 SPECIALIZED-ARRAY: uint
 SPECIALIZED-ARRAY: ushort


! TODO RGBX, XRGB, BGRX, XBGR conversions

! BGR>
: BGR>RGB ( bitmap -- bitmap' )
    3 <sliced-groups> [ <reversed> ] map concat ; inline


    4 <sliced-groups>
    [ unclip-slice [ <reversed> ] dip suffix ] map concat ; inline

: (reorder-colors) ( image src-order des-order -- image )
    [ name>> ] bi@ ">" glue "images.normalization.private" lookup
    [ '[ _ execute( image -- image' ) ] change-bitmap ]
    [ "No component-order conversion found." throw ]
    if* ;

PRIVATE>

: reorder-colors ( image component-order -- image )
    [
        [ component-type>> ubyte-components assert= ]
        [ dup component-order>> ] bi
    ] dip (reorder-colors) ;

<PRIVATE

