USING: accessors alien alien.c-types arrays byte-arrays columns
combinators fry grouping io io.binary io.encodings.binary io.files
kernel macros math math.bitwise math.functions namespaces sequences
-strings images endian summary ;
+strings images endian summary annotations ;
IN: images.bitmap
TUPLE: bitmap-image < image ;
{
[ [ width>> ] [ height>> ] bi 2array ]
[ bitmap>component-order ]
- [ drop little-endian ] ! XXX
+ [ drop little-endian ] !XXX
[ buffer>> ]
} cleave bitmap-image boa ;
SINGLETONS: BGR RGB BGRA RGBA ABGR ARGB RGBX XRGB BGRX XBGR
R16G16B16 R32G32B32 ;
-TUPLE: image dim component-order byte-order bitmap ;
+TUPLE: image dim component-order bitmap ;
: <image> ( -- image ) image new ; inline
ERROR: unknown-component-order ifd ;
+: fix-bitmap-endianness ( ifd -- ifd )
+ dup [ bitmap>> ] [ bits-per-sample find-tag ] bi
+ {
+ { { 32 32 32 32 } [ 4 seq>native-endianness ] }
+ { { 32 32 32 } [ 4 seq>native-endianness ] }
+ { { 16 16 16 16 } [ 2 seq>native-endianness ] }
+ { { 16 16 16 } [ 2 seq>native-endianness ] }
+ { { 8 8 8 8 } [ ] }
+ { { 8 8 8 } [ ] }
+ [ unknown-component-order ]
+ } case >>bitmap ;
+
: ifd-component-order ( ifd -- byte-order )
bits-per-sample find-tag {
{ { 32 32 32 } [ R32G32B32 ] }
{
[ [ image-width find-tag ] [ image-length find-tag ] bi 2array ]
[ ifd-component-order ]
- [ drop big-endian ] ! XXX
[ bitmap>> ]
} cleave tiff-image boa ;
dup ifds>> [
process-ifd read-strips
uncompress-strips
- strips>bitmap drop
+ strips>bitmap
+ fix-bitmap-endianness
+ drop
] each
] with-endianness
] with-file-reader ;