]> gitweb.factorcode.org Git - factor.git/blob - basis/images/images.factor
add 48bpp mode to tiff
[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 math specialized-arrays.direct.uint byte-arrays ;
5 IN: images
6
7 SINGLETONS: BGR RGB BGRA RGBA ABGR ARGB RGBX XRGB BGRX XBGR
8 16R16G16B 32R32G32B ;
9
10 TUPLE: image dim component-order byte-order bitmap ;
11
12 : <image> ( -- image ) image new ; inline
13
14 GENERIC: load-image* ( path tuple -- image )
15
16 : normalize-component-order ( image -- image )
17     dup component-order>>
18     {
19         { RGBA [ ] }
20         { BGRA [
21             [
22                 4 <sliced-groups> dup [ [ 0 3 ] dip <slice> reverse-here ] each
23             ] change-bitmap
24         ] }
25         { RGB [
26             [ 3 <sliced-groups> [ 255 suffix ] map concat ] change-bitmap
27         ] }
28         { BGR [
29             [
30                 3 <sliced-groups> dup [ [ 0 3 ] dip <slice> reverse-here ] each
31                 [ 255 suffix ] map concat
32             ] change-bitmap
33         ] }
34     } case
35     RGBA >>component-order ;
36
37 GENERIC: normalize-scan-line-order ( image -- image )
38
39 M: image normalize-scan-line-order ;
40
41 : normalize-image ( image -- image )
42     normalize-component-order
43     normalize-scan-line-order ;