]> gitweb.factorcode.org Git - factor.git/commitdiff
get the byte ordering correct for tiffs
authorDoug Coleman <doug.coleman@gmail.com>
Fri, 13 Feb 2009 21:46:36 +0000 (15:46 -0600)
committerDoug Coleman <doug.coleman@gmail.com>
Fri, 13 Feb 2009 21:46:36 +0000 (15:46 -0600)
basis/images/bitmap/bitmap.factor
basis/images/images.factor
basis/images/tiff/tiff.factor

index c9bb15192b786da84e711a41008ef5c637957da6..6713a729b56d5e8c66ddb90563b6d3c838986aa0 100755 (executable)
@@ -3,7 +3,7 @@
 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 ;
@@ -105,7 +105,7 @@ ERROR: unknown-component-order bitmap ;
     {
         [ [ width>> ] [ height>> ] bi 2array ]
         [ bitmap>component-order ]
-        [ drop little-endian ] ! XXX
+        [ drop little-endian ] !XXX
         [ buffer>> ]
     } cleave bitmap-image boa ;
 
index e366dd2700c54d16a040238282b5b49398c9d08f..11452aa7d259acdb06ce1f8af6a392d7a01f28a5 100644 (file)
@@ -7,7 +7,7 @@ IN: images
 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
 
index 674188992a0cd69e277c790956d9bc860764bcb1..8e981a816322cc5a389e99883b687c33b18c0914 100755 (executable)
@@ -286,6 +286,18 @@ ERROR: unhandled-compression compression ;
 
 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 ] }
@@ -299,7 +311,6 @@ ERROR: unknown-component-order ifd ;
     {
         [ [ image-width find-tag ] [ image-length find-tag ] bi 2array ]
         [ ifd-component-order ]
-        [ drop big-endian ] ! XXX
         [ bitmap>> ]
     } cleave tiff-image boa ;
 
@@ -314,7 +325,9 @@ ERROR: unknown-component-order ifd ;
             dup ifds>> [
                 process-ifd read-strips
                 uncompress-strips
-                strips>bitmap drop
+                strips>bitmap
+                fix-bitmap-endianness
+                drop
             ] each
         ] with-endianness
     ] with-file-reader ;