klazuka (owner)

Revisions

gist: 203379 Download_button fork
public
Public Clone URL: git://gist.github.com/203379.git
Embed All Files: show embed
Text only #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
: RGB>RGB ( bitmap -- bitmap' ) ;
 
: RGB>BGR ( bitmap -- bitmap' ) BGR>RGB ; inline
 
: RGB>RGBA ( bitmap -- bitmap' ) add-dummy-alpha ; inline
 
: RGB>BGRA ( bitmap -- bitmap' )
    3 <sliced-groups> [ <reversed> add-dummy-alpha ] map concat ; inline
 
: RGB>ARGB ( bitmap -- bitmap' )
    3 <sliced-groups> [ 255 prefix ] map concat ; inline
 
: RGBA>RGBA ( bitmap -- bitmap' ) ;
 
: RGBA>BGR ( bitmap -- bitmap' ) BGRA>RGB ; inline
 
: RGBA>BGRA ( bitmap -- bitmap' ) BGRA>RGBA ; inline
 
: RGBA>RGB ( bitmap -- bitmap' ) BGRA>BGR ; inline
 
: RGBA>ARGB ( bitmap -- bitmap' )
    4 <sliced-groups> [ unclip-last-slice prefix ] map concat ; inline
 
: ARGB>ARGB ( bitmap -- bitmap' ) ;
 
: ARGB>RGB ( bitmap -- bitmap' )
    4 <sliced-groups> [ rest-slice ] map concat ; inline
 
: ARGB>RGBA ( bitmap -- bitmap' )
    4 <sliced-groups> [ unclip-slice suffix ] map concat ; inline
 
: ARGB>BGR ( bitmap -- bitmap' )
    4 <sliced-groups> [ rest-slice <reversed> ] map concat ; inline
 
: ARGB>BGRA ( bitmap -- bitmap' )
    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) ;