run-length-uncompress-bitmap8 ( byte-array m n -- byte-array' )


Vocabulary
compression.run-length

Inputs
byte-arrayan object
man object
nan object


Outputs
byte-array'an object


Definition


:: run-length-uncompress-bitmap8
( byte-array m n -- byte-array' )
byte-array <sequence-parser> :> sp m 1 + n <zero-matrix>
:> matrix n 4 mod n + :> stride 0 :> i! 0 :> j! f :> done?!
[
sp consume dup 0 = [
sp consume dup 3 255 between? [
nip [ sp ] dip dup odd?
[ 1 + take-n but-last ] [ take-n ] if
[ j matrix i swap nth copy ] [ length j + j! ]
bi
] [
nip {
{ 0 ~quotation~ }
{ 1 ~quotation~ }
{ 2 ~quotation~ }
} case
] if
] [
sp consume <array>
[ j matrix i swap nth copy ] [ length j + j! ] bi
] if j stride >= [ 0 j! ] when done? not
] loop matrix B{ } concat-as ;