dithering_algorithms icon indicating copy to clipboard operation
dithering_algorithms copied to clipboard

problem on Android Mode, and Fixed

Open PandaBalls opened this issue 9 years ago • 0 comments

while using dithering method on processing Android mode. catch wrong of PImage.set(). You can't use any calculate in PImage.set(). so i fixed like this:

public PImage imgDithering(PImage src) { int s = 1; for (int x = s; x < src.width-s; x+=s) { for (int y = s; y < src.height-s; y+=s) { color oldpixel = src.get(x, y); color newpixel = findClosestColor(oldpixel); float quant_error = brightness(oldpixel) - brightness(newpixel); color oldpixel1 = src.get(x+s, y); color oldpixel2 = src.get(x-s, y+s); color oldpixel3 = src.get(x, y+s); color oldpixel4 = src.get(x+s, y+s); color newpixel1 = color(brightness(oldpixel1)+7.0/16 * quant_error); color newpixel2 = color(brightness(oldpixel2) + 3.0/16 * quant_error); color newpixel3 = color(brightness(oldpixel3) + 3.0/16 * quant_error); color newpixel4 = color(brightness(oldpixel4) + 3.0/16 * quant_error);

    src.set(x, y, newpixel);
    int xnew = x+s;
    src.set(xnew, y, newpixel1);
    xnew = x-s;
    int ynew = y+s;
    src.set(xnew, ynew, newpixel2);
    ynew = y+s;
    src.set(x, ynew, newpixel3 );
    xnew = x+s;
    ynew = y+s;
    src.set(xnew, ynew, newpixel4);

}

} src.updatePixels(); return src; }

color findClosestColor(color c) { color r;

if (brightness(c) < 128) { r = color(0); } else { r = color(255); } return r; }

PandaBalls avatar Sep 21 '16 05:09 PandaBalls