]> gitweb.factorcode.org Git - factor.git/blob - basis/images/images.factor
Merge branch 'master' into new_ui
[factor.git] / basis / images / images.factor
1 ! Copyright (C) 2009 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel accessors grouping sequences combinators ;
4 IN: images
5
6 SINGLETONS: BGR RGB BGRA RGBA ABGR ARGB RGBX XRGB BGRX XBGR ;
7
8 TUPLE: image dim component-order byte-order bitmap ;
9
10 : <image> ( -- image ) image new ; inline
11
12 GENERIC: load-image* ( path tuple -- image )
13
14 : normalize-component-order ( image -- image )
15     dup component-order>>
16     {
17         { RGBA [ ] }
18         { BGRA [
19             [
20                 4 <sliced-groups> dup [ [ 0 3 ] dip <slice> reverse-here ] each
21             ] change-bitmap
22         ] }
23         { RGB [
24             [ 3 <sliced-groups> [ 255 suffix ] map concat ] change-bitmap
25         ] }
26         { BGR [
27             [
28                 3 <sliced-groups> dup [ [ 0 3 ] dip <slice> reverse-here ] each
29                 [ 255 suffix ] map concat
30             ] change-bitmap
31         ] }
32     } case
33     RGBA >>component-order ;
34
35 GENERIC: normalize-scan-line-order ( image -- image )
36
37 M: image normalize-scan-line-order ;
38
39 : normalize-image ( image -- image )
40     normalize-component-order
41     normalize-scan-line-order ;