code for DITHERING
code for DITHERING
Okie tay.
Well, the best way is to do something relative to this.
Generate a lookup table of possible color combinations.
Grayscale: 0,1,2,3,4
Assign them color values.
Colorz(0).red=&h00
Colorz(0).grn=&h00
Colorz(0).blu=&h00
Colorz(1).red=&h07
Colorz(1).grn=&h07
Colorz(1).blu=&h07
That's generic and needs to be tuned. You simply make a gradient from black into gray to white at various stages. As few as possible.
Write code to dither correctly based on the binary compiment of the pixel address in x and y.
Pseudocode in PLC type notation.
(Looks like an old flowchart if you look at the symbols.)
() Begin program
[] Load image
[] Generate lookup table with target colors
{} (loop function)
<> Is color within range of one of target colors (use SQR root of ..)
y[] Draw pixel
<> is final pixel color on or off in dither pattern?
y[] Draw monochrome pixel
n[] Leave pixel off
n[] cycle through colors until most approximate match is found
endof{} loop
So you see, if you make a target set of colors, a very wide gradient in as few choices as possible, then you can set the target pixels to be either on or off, but it must test against the pattern in the gradient for the designated color.
You have dots like this for off
~~
~~
(blank)
You have dots for on
XX
XX
You have dots for 25% on
X~
~~
You have dots for 50% on
X~
~X
You have dots for 75% on
XX
~X
So, if you give it target colors to match to, simply grayscale RGB colors, they will match down to the target colors, which are monochrome only bit patterns, then for each pixel you draw, (one pixel at a time), make sure it fits in either the ON or the OFF pattern of the pseudo pixel of monochrome-ness, and you will end up with a dithered, 1bpps, (not perfect mind you but it works), image of awesomeness.
Kiyote!
BTW, I work in either PLC flowchart psuedocode or fully working examples of either QBasic or FreeBasic, nothing in between. I hate half-alive stillborn examples of code you can't even run. I post either something metaphysical, or the real deal.