home *** CD-ROM | disk | FTP | other *** search
- From: garyo@masscomp.UUCP (Gary Oberbrunner)
- Newsgroups: comp.graphics
- Subject: Re: Advanced Dither Needed
- Summary: Floyd-Steinberg Dither explained
- Date: 7 Jan 88 03:03:58 GMT
- Organization: MASSCOMP - Westford, Ma
-
- In article <3703@ames.arpa> watson@ames.UUCP (John S. Watson) writes:
- > I'm looking for either references to, or code for a really
- >nice color dithering algorithm. The algorithm produces 8-bit dithered
- >images that are almost indistinguishable from the original 24-bit images.
-
- Floyd & Steinberg's dithering algorithm is described in the following paper:
-
- Floyd, R.W. and Steinberg, L. "An Adaptive Algorithm for Spatial Gray Scale."
- SID 75m Int. Symp. Dig. Tech. Papers (1975), p. 36.
-
- I don't actually have this paper, just a reference to it in Heckbert's "Color
- Image Quantization for Frame Buffer Display (Siggraph proceedings, 1982,
- p. 297). You probably want to check this paper out too.
- But the way F/S dither works is like this (it's so simple...)
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- First you come up with a color map - use uniform segmentation for speed or
- Heckbert's method for quality. Then you work from the top left to the bottom
- right of the image (pixel order), as follows:
-
- Find the closest match in the color map to the true pixel color.
- Use that color map entry to represent that pixel.
-
- Compute the r,g,b error resulting from the above approximation.
-
- Add 3/8 of that error to the pixel to the right, and 3/8 to the pixel
- below the current pixel. The remaining 1/4 goes to the pixel diagonally
- below. Don't forget to clip the rgb, as well as check your boundary
- conditions.
-
- And that's it - compute the next pixel! No dither maps, no muss no fuss no
- bother. And it's real fast since you can do the 3/8 and 1/4 by shifting.
- On some images it can help to add some random noise; for instance if you
- have a smooth (flat-shaded) surface that's just below one of the colors in
- the map, the error will build up slowly until you get a line of brighter
- color somewhere in the surface. A bit o' noise gets rid of that line nicely.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- Of course choosing the color map is the fun part. :-) :-)
-
- Gary Oberbrunner
-
- Here is a hack C program which implements both Heckbert's algorithm and F/S
- dither (no claims of any kind are made for this program - in fact this article
- ended above with my name, and this is all line nois)@(#*&...
- No seriously, this code needs real help - it was written for a one-shot deal,
- and it is very inefficient in many places. But it does work ok.
- The worst part is where every possible color mapping is computed - SLOW!
- And Remap() ain't a speed-demon either, but that's where Floyd et. al.
- come in...
- Enjoy (watch out for possible signature at end...)
-
- ----------------------------------------------------------------------------
- Remember, -Truth is not beauty;
- Information is not knowledge; / Beauty is not love; Gary Oberbrunner
- Knowledge is not wisdom; / Love is not music; ...!masscomp!garyo
- Wisdom is not truth; ----/ Music is the best. - FZ
- ----------------------------------------------------------------------------
- # Files that go with this:
- # quantize.c (most everything in here)
- # split.c (the color-space-splitting algorithm)
- # quantize.h (structs & externs)
- # std.h (my "gotta have it" stuff)
-