I just found this on the wikipedia page for ordered dithering and have been following the explanation in order to produce this effect myself. The algorithm producing the effect from this matrix is as closely resemblant of that explained in the wikipedia page and is as follows:

This is just the method that reduces the amount of colours available in each channel:

1 2 3

privateintclosestCol(intc, intb) {returnc / b * b;}

The above code simply adds the corresponding value from the threshold matrix to the image data and then attempts to find the nearest colour to it after rounding. The issue is that the dither values are quite high and saturate the channel of the pixel. I've tried averaging the channel colour with the corresponding dither value but that makes the screen far darker than it should be. Is there a detail that I'm missing whereby it adds the effect without harshly altering the tone of the image?

The closest colour rounding seems to actually be working before adding the threshold. As the colour's stored as an integer it performs the division first and rounds that result and then multiplies. So the end value is actually floored to the nearest 64 in this case. For example:

140 / 64 * 642 * 64= 128

So 140 becomes 128 when floored to the nearest 64. Sorry if I'm teaching you how to suck eggs, I'm just making sure.

Oh right order of precedence. I never write code that way since you can't tell what you meant by it. ie a/b*b or did you mean a/(b*b). So i would write (a/b)*b.

Note that you get a different result from (b*a)/b too. So best be explicit. Brackets don't hurt anyone.

So yea I think the normalization in the wiki is the problem. Note the matrices they show are normalized to be less than 1. So its just not clear what range colors are suppose to take. Well not without more work.

I have no special talents. I am only passionately curious.--Albert Einstein

To sort of back that up. Note that if a value is overflowing before a call to closestCol, it can still be overflowing after. So it seems the dithering values should be a portion of between color range.

I have no special talents. I am only passionately curious.--Albert Einstein

Yeah the threshold values range from 1-64, so presumably it breaches its respective channel fairly often which explains the artifacts, but I'm not entirely sure how to normalise the threshold value. I've tried dividing the value by 64, which is the highest value that is held in the matrix, although I'm working in whole numbers and only one instance would yield 1 and the rest would be 0.

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org