1 ! Copyright (C) 2009 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel accessors grouping sequences combinators
4 math specialized-arrays.direct.uint byte-arrays ;
7 SINGLETONS: BGR RGB BGRA RGBA ABGR ARGB RGBX XRGB BGRX XBGR
10 TUPLE: image dim component-order byte-order bitmap ;
12 : <image> ( -- image ) image new ; inline
14 GENERIC: load-image* ( path tuple -- image )
16 : normalize-component-order ( image -- image )
23 ! dup length 4 /i <direct-uint-array> [ 32 2^ /i ] map
25 ! 4 <sliced-groups> le> [ 32 2^ /i ] map concat
30 4 <sliced-groups> dup [ [ 0 3 ] dip <slice> reverse-here ] each
34 [ 3 <sliced-groups> [ 255 suffix ] map concat ] change-bitmap
38 3 <sliced-groups> dup [ [ 0 3 ] dip <slice> reverse-here ] each
39 [ 255 suffix ] map concat
43 RGBA >>component-order ;
45 GENERIC: normalize-scan-line-order ( image -- image )
47 M: image normalize-scan-line-order ;
49 : normalize-image ( image -- image )
50 normalize-component-order
51 normalize-scan-line-order ;