In article <5237@hubcap.clemson.edu> jcocon%hazel.cs.clemson.edu@hubcap.clemson.edu writes: |Has any work been done on displaying 256 grey shades on a monitor with |greater than two grey shades (i.e. black and white + some number of greys)? |It seems that an extension to dither would be a good place to start. So |far as I know, rounding is the norm in hardware (yuck! a good dither looks |better than some 16 grey renderings I've seen!). This program is short, so I though I'd just post it. It uses the PXM file format libraries I posted earlier, but the algorithm is easily separated from the file format details. This program dithers to n levels of grey, default 2, and creates output in the range 0..255 from similar input. ------------------------------------------------------------------------ /* * dither -- use a reduced set of grey values to represent an image * * Copyright (C) 1988 by Dale Schumacher. * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose and without fee is hereby granted, provided * that the above copyright notice appear in all copies and that both that * copyright notice and this permission notice appear in supporting * documentation. This software is provided "as is" without express or * implied warranty. * * * Notes: * * [1] Floyd-Steinberg dither: * I should point out that the actual fractions we used were, assuming * you are at X, moving left to right: * * X 7/16 * 3/16 5/16 1/16 * * Note that the error goes to four neighbors, not three. I think this * will probably do better (at least for black and white) than the * 3/8-3/8-1/4 distribution, at the cost of greater processing. I have * seen the 3/8-3/8-1/4 distribution described as "our" algorithm before, * but I have no idea who the credit really belongs to. * Also, I should add that if you do zig-zag scanning (see my immediately * previous message), it is sufficient (but not quite as good) to send * half the error one pixel ahead (e.g. to the right on lines you scan * left to right), and half one pixel straight down. Again, this is for * black and white; I've not tried it with color. * -- * Lou Steinberg */ static char _Program[] = "dither"; static char _Version[] = "1.3"; static char _Copyright[] = "Copyright 1988 by Dale Schumacher"; #include Discuss this article in the forums
See Also: © 1999-2011 Gamedev.net. All rights reserved. Terms of Use Privacy Policy
|