Live data from Hacker News

LZW and GIF explained

eecis.udel.edu

11–16 of 16 posts

Re: LZW and GIF explained

#11
post #8

Earlier quoted context omitted.

...though with the slightly unexpected side effect (for Brotli, at least) that your executable may end up containing (~200KB, from memory) of very unexpected[-1] plain text strings which might (& has[0]) lead to questions from software end-users asking why your software contains "random"[1] text (including potentially "culturally sensitive" words/phrases related to religion such as "Holy Roman Emperor", "Muslims", "d…

Just XOR it with 0x55 ;)

"Pros always use this one weird trick Brotli compression hates." :)

Re: LZW and GIF explained

#12
Thanks for reminding me I implemented this 10 years ago. Here it is in 180 lines* of C https://github.com/fsmv/Tiny-GIF/blob/master/src/LZW.c

* The dictionary part takes up a similar amount so maybe 2x that

I think some image viewers didn't like how I made the gif data and then I didn't care enough to make it perfect because LZW was the interesting part and that worked.

Re: LZW and GIF explained

#13
post #7

My personal favourite GIF-related explainer: * "What's In A GIF": https://www.matthewflickinger.com/lab/whatsinagif/ It's a five part explanation that includes both great visualisations and bespoke analysis tools[2]. Here's a direct link to the section on LZW compression[0]: * https://www.matthewflickinger.com/lab/whatsinagif/lzw_image_... [0] Which somewhat confusingly credits "John Barkaus's LZW and GIF Explained"…

Speak of the devil! I also cited Matthew's specific blog post in my LZW GIF encoder implementation: https://github.com/alexqfredrickson/LzwGifTools

Re: LZW and GIF explained

#14
post #4

I found out the other day that zstd supports dictionary compression [0]. It's a pretty neat concept: you can "train" a dictionary on your corpus of text, and use this dictionary to compress subsequent documents. This is really useful if you have a lot of small documents with a similar distribution of characters. You only have to transmit the dictionary once over the wire once, and then clients can get great compressi…

Lichess is open source and has a very clever custom pgn compression. They analyze the chess position and use various features to determine how likely various moves are, then use that distribution to encode the move.

Re: LZW and GIF explained

#15
post #13
post #7

My personal favourite GIF-related explainer: * "What's In A GIF": https://www.matthewflickinger.com/lab/whatsinagif/ It's a five part explanation that includes both great visualisations and bespoke analysis tools[2]. Here's a direct link to the section on LZW compression[0]: * https://www.matthewflickinger.com/lab/whatsinagif/lzw_image_... [0] Which somewhat confusingly credits "John Barkaus's LZW and GIF Explained"…

Speak of the devil! I also cited Matthew's specific blog post in my LZW GIF encoder implementation: https://github.com/alexqfredrickson/LzwGifTools

Understandably, it's such a great resource! :)

Re: LZW and GIF explained

#16
post #13
post #7

My personal favourite GIF-related explainer: * "What's In A GIF": https://www.matthewflickinger.com/lab/whatsinagif/ It's a five part explanation that includes both great visualisations and bespoke analysis tools[2]. Here's a direct link to the section on LZW compression[0]: * https://www.matthewflickinger.com/lab/whatsinagif/lzw_image_... [0] Which somewhat confusingly credits "John Barkaus's LZW and GIF Explained"…

Speak of the devil! I also cited Matthew's specific blog post in my LZW GIF encoder implementation: https://github.com/alexqfredrickson/LzwGifTools

Also, nifty: https://github.com/alexqfredrickson/vcvj :)

(I've done some VJing in my time, so it's always cool to see related projects--I particularly like the effect on the ping-pong ball in the examples with its bounce path trail. :) )

Post reply on HN