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 )
22 4 <sliced-groups> dup [ [ 0 3 ] dip <slice> reverse-here ] each
26 [ 3 <sliced-groups> [ 255 suffix ] map concat ] change-bitmap
30 3 <sliced-groups> dup [ [ 0 3 ] dip <slice> reverse-here ] each
31 [ 255 suffix ] map concat
35 RGBA >>component-order ;
37 GENERIC: normalize-scan-line-order ( image -- image )
39 M: image normalize-scan-line-order ;
41 : normalize-image ( image -- image )
42 normalize-component-order
43 normalize-scan-line-order ;