diff --git a/extra/compression/lzw-gif/lzw-gif.factor b/extra/compression/lzw-gif/lzw-gif.factor index 1d98fdd4ee..01e94d5114 100644 --- a/extra/compression/lzw-gif/lzw-gif.factor +++ b/extra/compression/lzw-gif/lzw-gif.factor @@ -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 ; -: ( code-size input -- obj ) +: ( 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: +: lzw-uncompress ( bitstream code-size -- byte-array ) + register-special-codes [ lzw-uncompress-char ] [ output>> ] bi ; + +: lzw-uncompress-msb0 ( seq code-size -- byte-array ) + [ bs: ] dip lzw-uncompress ; + +: lzw-uncompress-lsb0 ( seq code-size -- byte-array ) + [ bs: ] dip lzw-uncompress ; diff --git a/extra/images/gif/gif-tests.factor b/extra/images/gif/gif-tests.factor index b62565ffbc..629ab300d4 100644 --- a/extra/images/gif/gif-tests.factor +++ b/extra/images/gif/gif-tests.factor @@ -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{ diff --git a/extra/images/gif/gif.factor b/extra/images/gif/gif.factor index 6672ff456c..8652e049e0 100644 --- a/extra/images/gif/gif.factor +++ b/extra/images/gif/gif.factor @@ -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 ;