I'm currently trying to implement the Floyd-Steinberg-Dithering algorithm in Java. After a few failed attempts I came across a question after reading the pseudocode listed on Wikipedia.
for each y from top to bottom
for each x from left to right
oldpixel := pixel[x][y]
newpixel := find_closest_palette_color(oldpixel)
pixel[x][y] := newpixel
quant_error := oldpixel - newpixel
pixel[x+1][y ] := pixel[x+1][y ] + 7/16 * quant_error
pixel[x-1][y+1] := pixel[x-1][y+1] + 3/16 * quant_error
pixel[x ][y+1] := pixel[x ][y+1] + 5/16 * quant_error
pixel[x+1][y+1] := pixel[x+1][y+1] + 1/16 * quant_error
What I'm trying to achieve is squishing the image into a 16 color palette. After adding the error the pixels however, don't I create completely new colors that don't even exist in the palette?
But would forcing the entire image back into the color palette at the end suffice to make this work?
Thanks in advance!