|
CONTENTS Home Projects More Projects Resume Computer Skills Music Links To Friends Pictures About Mike Random Link |
Compression RoutinesRelated pages on www.mikekohn.net: SSE Image Processing, GIF, TIFF, BMP/RLE, JPEG, AVI, kunzip, gif2avi, Ringtone Tools, yuv2rgb Contents BMP/RLE GIF/LZW ZIP/DEFLATE TIFF JPEG AVI .anm One of my dorky computer interests happens to be compression schemes and file formats. For anyone who doesn't know, data compression is basically where you take a file and make it use less disk space. Later you can take that file and run it through a decompressor program to get your original full sized file back. When I was working at Direct-Data I got to write decompression routines for LZW, static Huffman for TIFF, and CCITT Group 4 for TIFF. I've also done RLE4 and RLE8 for BMP decompression which I added to Ringtone Tools and RLE compression which I have in my gif2avi for MandelServer. I also took some time at home to rewrite my LZW compressor/decompressor for GIF files and DEFLATE for ZIP files. In the future I plan to rewrite code for decompressing TIFF files for my own use and possibly JPEG files. If you have any questions or such about the programs on this page feel free to email me. BMP/RLE (Run Length Encoding) Compression For information on BMP/RLE check my BMP/RLE page. GIF and LZW Compression/Decompression I created a library for lzw decompressing and compressing GIF images. More info on the library is here on of my libkohn_gif page. Deflate (Huffman/LZ77) Decompression DEFLATE is a common compression algorithm used in PNG image files, ZIP file archives, and gzip. I wrote some DEFLATE compression routines and stuffed them in a library for unzipping ZIP files. If you are interested in seeing what I did with deflate click here to go to the Kunzip project page. TIFF and Huffman/CCITT Group 3,4 Compression All information and sample source code I've written for TIFF is on my TIFF page.I wrote a JPEG decompression routine and a DCT analysis program. The code can be found on my JPEG page. Here is a small program I wrote called readavi which can be used to parse avi files and output their headers. A long time ago there was a file format called .anm (actually,
I think there were a few different file formats called .anm, so
this might not be what you're looking for). I've only ever seen
one file that uses this .anm format (gusher.anm), since it was
kinda legendary around my friends I decided to make a Java player
for it. The first step tho was to make an anm2gif program just to
see if I could figure out the format of the file since I had no
specs on it. Anyway, using this program
you can turn these old .anm files into gif's and then use
the gif2avi that I made to
make it an avi (may take some source code tweaks.. I don't remember).
I did get the Java player working too if anyone is interested in that :).
Compressing Pixel Differences Since compression algorithms such as lzw or deflate work by reducing redundancy, I came up with this idea to make photographic images compress better with them. Unfortunately, I didn't realize that the PNG file format already does at least part of this :). Anyway, my two ideas were this: 1) instead of compressing the colors themselves, compress the differences in color between pixels next to each other and 2) compress red, green, and blue parts of a pixel seperate from each other. The theory behind compressing the differences in colors is in a photographic image, there are a lot of gradients. Anyway, if you had an image where the pixel values from left to right were (120,122,124,126) if these values were "compressed" with lzw or such, the file size could not be made smaller. However, if the differences in pixel values were compressed (-120,2,2,2) this has a lot of redundancy. Now the reason for compressing the red, green, and blue parts of a color image separate.... maybe I'll explain my idea on that later. Either way, I tried it on these two images: alligator.jpeg and alligator-gray.jpeg. This image was originally a large jpeg from a digital camera that I shrunk down to 400x240 and turned into a bmp. I also turned it into a PNG and GIF to compare file sizes with those. Anyway, here are the results: Update: I changed compression algorithms from lzw to zlib's deflate (using the default compression of 6)
The results of this test prove that my theory does work on at least this image. The RAW-DIFF column creates a file smaller than the original. However, it's interesting to note that the "compressed" image is bigger than the RAW (or BMP) image. Also interesting to note that the PNG images are smaller than the RAW or BMP. When I saw this, I wondered if my LZW routines were flawed so I made a GIF from the gray-scale image which ended up to be a similar size as the non-diff version. One thing to note: the LZW I used for here currently is identical to GIF except I removed a stupidity in GIF which wraps the compressed data in 255 byte frames (thus should reduce the file size by around 1/255 :). Anyway, I think this test also shows that DEFLATE/INFLATE (the compression used in PNG) is far superior to LZW.
|