I'm trying to implement the Floyd-Steinberg algorithm in java ,but i still have some errors?! in my code that i cant solve.Maybe some of you have an advise how i can solve this.
Here is the method
public DitheringGUI dith(String fileName) {
DitheringGUI g = new DitheringGUI(fileName);
for(int y = 0 ; y<g.img.getHeight();y++){
for(int x = 0 ; x < g.img.getWidth();x++){
Color oldColor = g.img.getColor(x, y);
Color newColor = palette(oldColor);
g.img.set(x, y, newColor);
int quant_Error = oldColor.getRed() - newColor.getRed();
if(x+1 < g.img.getWidth()) {
g.img.set(x+1,y,new Color( g.img.getColor(x+1, y).getRed()+quant_Error*(7/16),
g.img.getColor(x+1, y).getRed()+quant_Error*(7/16),
g.img.getColor(x+1, y).getRed()+quant_Error*(7/16)));
}
if(x-1 >=0 && y+1 <g.img.getHeight()){
g.img.set(x-1,y+1,new Color( g.img.getColor(x-1, y+1).getRed()+quant_Error*(3/16),
g.img.getColor(x-1, y+1).getRed()+quant_Error*(3/16),
g.img.getColor(x-1, y+1).getRed()+quant_Error*(3/16)));
}
if(y+1 < g.img.getHeight()){
g.img.set(x,y+1,new Color( g.img.getColor(x, y+1).getRed()+quant_Error*(5/16),
g.img.getColor(x, y+1).getRed()+quant_Error*(5/16),
g.img.getColor(x, y+1).getRed()+quant_Error*(5/16)));
}
if(x+1 < g.img.getWidth() && y+1 < g.img.getHeight()){
g.img.set(x+1,y+1,new Color( g.img.getColor(x+1, y+1).getRed()+quant_Error*(1/16),
g.img.getColor(x+1, y+1).getRed()+quant_Error*(1/16),
g.img.getColor(x+1, y+1).getRed()+quant_Error*(1/16)));
}
}
}
return g;
}
the actual problem is that it is just black and white and not dithered,meaning there are no gray-scalings.
My input is this: http://www.directupload.net/file/d/3985/spd2k9wq.png
My output is: http://www.directupload.net/file/d/3985/s24rq7qo.png
Notice that the "dithered" image is over-dithered and is nearly black.