]> gitweb.factorcode.org Git - factor.git/commitdiff
gif: preparing for LZW re-integration with TIFF
authorKeith Lazuka <klazuka@gmail.com>
Fri, 25 Sep 2009 15:12:40 +0000 (11:12 -0400)
committerKeith Lazuka <klazuka@gmail.com>
Fri, 25 Sep 2009 15:12:40 +0000 (11:12 -0400)
extra/compression/lzw-gif/lzw-gif.factor
extra/images/gif/gif-tests.factor
extra/images/gif/gif.factor

index 1d98fdd4ee9d4f756c5f25665b855863dd08c33e..01e94d5114c1e7f57ea871812e5912773b1f9367 100644 (file)
@@ -13,8 +13,6 @@ SYMBOL: end-of-information
 
 TUPLE: lzw input output table code old-code initial-code-size code-size ;
 
-SYMBOL: table-full
-
 : initial-uncompress-table ( -- seq )
     end-of-information get 1 + iota [ 1vector ] V{ } map-as ;
 
@@ -22,11 +20,11 @@ SYMBOL: table-full
     initial-uncompress-table >>table
     dup initial-code-size>> >>code-size ;
 
-: <lzw-uncompress> ( code-size input -- obj )
+: <lzw-uncompress> ( input code-size -- obj )
     lzw new
-        swap >>input
         swap >>initial-code-size
         dup initial-code-size>> >>code-size
+        swap >>input
         BV{ } clone >>output
         reset-lzw-uncompress ;
 
@@ -103,14 +101,19 @@ DEFER: lzw-uncompress-char
         drop
     ] if* ;
 
-: register-special-codes ( first-code-size -- )
+: register-special-codes ( first-code-size -- first-code-size )
     [
         1 - 2^ dup clear-code set
         1 + end-of-information set
     ] keep ;
 
-: lzw-uncompress ( code-size seq -- byte-array )
-    [ register-special-codes ] dip
-    bs:<lsb0-bit-reader>
+: lzw-uncompress ( bitstream code-size -- byte-array )
+    register-special-codes
     <lzw-uncompress>
     [ lzw-uncompress-char ] [ output>> ] bi ;
+
+: lzw-uncompress-msb0 ( seq code-size -- byte-array )
+    [ bs:<msb0-bit-reader> ] dip lzw-uncompress ;
+
+: lzw-uncompress-lsb0 ( seq code-size -- byte-array )
+    [ bs:<lsb0-bit-reader> ] dip lzw-uncompress ;
index b62565ffbc519ef415a5956ebcf2b39a2ff7ad99..629ab300d4cd52b6c07ab2079e6c5c1bc026d155 100644 (file)
@@ -47,9 +47,9 @@ IN: images.gif.tests
 [ 2 ] [ gif-example3 declared-num-colors ] unit-test
 
 : >index-stream ( gif -- seq )
-    [ image-descriptor>> first-code-size>> ]
-    [ compressed-bytes>> ] bi
-    lzw-uncompress ;
+    [ compressed-bytes>> ]
+    [ image-descriptor>> first-code-size>> ] bi
+    lzw-uncompress-lsb0 ;
 
 [
     BV{
index 6672ff456c58ea5a41c5bb72a97b78469664a902..8652e049e04351610310c0ed0627fc7adb150c61 100644 (file)
@@ -225,9 +225,9 @@ ERROR: unhandled-data byte ;
     ] with-input-stream ;
 
 : decompress ( loading-gif -- indexes )
-    [ image-descriptor>> first-code-size>> ]
-    [ compressed-bytes>> ] bi
-    lzw-uncompress ;
+    [ compressed-bytes>> ]
+    [ image-descriptor>> first-code-size>> ] bi
+    lzw-uncompress-lsb0 ;
 
 : colorize ( index palette transparent-index/f -- seq )
     pick = [ 2drop B{ 0 0 0 0 } ] [ nth 255 suffix ] if ;