gif-1.0.tgz ??

Luke Gorrie luke@REDACTED
Mon Feb 3 01:32:05 CET 2003


"Wiger Ulf" <ulf.wiger@REDACTED> writes:

> I did start on an erlang-based gif package, but didn't quite manage to get
> the LZW compression to work. This is not terribly easy using pre-bit syntax
> Erlang, and may not be that easy with bit syntax either... LZW uses variable
> word lengths, and I got lost in all the bit shifting across the 8-bit
> boundaries of binary_to_list().
> 
> I don't know if you could use the built-in lzw compression that erlang
> offers nowadays (I assume you could.) If so, I think I have a nearly working
> gif implementation (AFAIR, the rest was reasonably easy.) No promises
> though.
> 
> I can send you what I have so far, but it may well be that there is nothing
> in there you can use.

I have a GIF _decoder_ in a similar state, i.e. there is some bug in
the LZW decompressor that completely eludes me. Same offer applies.

Actually, the bug may be in some other part, since I'm convinced that
the LZW-coded data I give to my decompressor is not correct :-) but
that's easy to be wrong about.

For reading LZW codes I used a "bitstream" datatype that gets
initialized with a binary and then lets you read N-bit integers one by
one. The bit syntax helps quite a bit I think:

  %% BitStream = {TakenBits, binary()}
  %%
  %% TakenBits is the number of bits already taken from the first byte
  %% of the binary.

  new(Bin) -> {0, Bin}.

  take(N, {I0, Bin0}) ->
      I1 = (I0 + N) rem 8,
      SufBits = (8 - I1) rem 8,
      <<_:I0, Value:N, _:SufBits, _/binary>> = Bin0,
      TakenBytes = (I0 + N) div 8,	% whole bytes taken
      <<_:TakenBytes/binary, Bin1/binary>> = Bin0,
      {Value, {I1, Bin1}}.

Though after a year and a bit that doesn't seem quite so crystal
clear.. :-)

BTW, for using built-in LZW, it's worth a try but I think there are a
lot of variations on LZW around. For instance, GIF and TIFF use
very-slightly-different ones. The TIFF 6 spec also has the best LZW
tutorial I've seen, and is googlable. I *think* the only difference is
that TIFF increases the code size one value earlier than GIF, which
seems silly (wastes a code.)

Cheers,
Luke




More information about the erlang-questions mailing list