13
0

Update stuff
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
yoyosource 2022-03-27 01:17:18 +01:00
Ursprung c1236dbc0e
Commit ebf4ae4219

Datei anzeigen

@ -43,6 +43,10 @@ public class CustomMap {
throw new IllegalArgumentException("Image height must be a multiple of 128"); throw new IllegalArgumentException("Image height must be a multiple of 128");
} }
final double multiplier1 = 7 / 16.0;
final double multiplier2 = 3 / 16.0;
final double multiplier3 = 5 / 16.0;
final double multiplier4 = 1 / 16.0;
WritableRaster raster = image.getRaster(); WritableRaster raster = image.getRaster();
int numBands = raster.getNumBands(); int numBands = raster.getNumBands();
int[] pixels = raster.getPixels(0, 0, image.getWidth(), image.getHeight(), new int[image.getWidth() * image.getHeight() * numBands]); int[] pixels = raster.getPixels(0, 0, image.getWidth(), image.getHeight(), new int[image.getWidth() * image.getHeight() * numBands]);
@ -60,23 +64,23 @@ public class CustomMap {
int quantErrorGreen = green - nearest.getGreen(); int quantErrorGreen = green - nearest.getGreen();
int quantErrorBlue = blue - nearest.getBlue(); int quantErrorBlue = blue - nearest.getBlue();
if (x < image.getWidth() - 1) { if (x < image.getWidth() - 1) {
pixels[(y * image.getWidth() + x + 1) * numBands] = clamp(pixels[(y * image.getWidth() + x + 1) * numBands] + quantErrorRed * 7 / 16); pixels[(y * image.getWidth() + x + 1) * numBands] = clamp((int) (pixels[(y * image.getWidth() + x + 1) * numBands] + quantErrorRed * multiplier1));
pixels[(y * image.getWidth() + x + 1) * numBands + 1] = clamp(pixels[(y * image.getWidth() + x + 1) * numBands + 1] + quantErrorGreen * 7 / 16); pixels[(y * image.getWidth() + x + 1) * numBands + 1] = clamp((int) (pixels[(y * image.getWidth() + x + 1) * numBands + 1] + quantErrorGreen * multiplier1));
pixels[(y * image.getWidth() + x + 1) * numBands + 2] = clamp(pixels[(y * image.getWidth() + x + 1) * numBands + 2] + quantErrorBlue * 7 / 16); pixels[(y * image.getWidth() + x + 1) * numBands + 2] = clamp((int) (pixels[(y * image.getWidth() + x + 1) * numBands + 2] + quantErrorBlue * multiplier1));
} }
if (x > 0) { if (x > 0) {
pixels[(y * image.getWidth() + x - 1) * numBands] = clamp(pixels[(y * image.getWidth() + x - 1) * numBands] + quantErrorRed * 3 / 16); pixels[(y * image.getWidth() + x - 1) * numBands] = clamp((int) (pixels[(y * image.getWidth() + x - 1) * numBands] + quantErrorRed * multiplier2));
pixels[(y * image.getWidth() + x - 1) * numBands + 1] = clamp(pixels[(y * image.getWidth() + x - 1) * numBands + 1] + quantErrorGreen * 3 / 16); pixels[(y * image.getWidth() + x - 1) * numBands + 1] = clamp((int) (pixels[(y * image.getWidth() + x - 1) * numBands + 1] + quantErrorGreen * multiplier2));
pixels[(y * image.getWidth() + x - 1) * numBands + 2] = clamp(pixels[(y * image.getWidth() + x - 1) * numBands + 2] + quantErrorBlue * 3 / 16); pixels[(y * image.getWidth() + x - 1) * numBands + 2] = clamp((int) (pixels[(y * image.getWidth() + x - 1) * numBands + 2] + quantErrorBlue * multiplier2));
} }
if (y < image.getHeight() - 1) { if (y < image.getHeight() - 1) {
pixels[((y + 1) * image.getWidth() + x) * numBands] = clamp(pixels[((y + 1) * image.getWidth() + x) * numBands] + quantErrorRed * 5 / 16); pixels[((y + 1) * image.getWidth() + x) * numBands] = clamp((int) (pixels[((y + 1) * image.getWidth() + x) * numBands] + quantErrorRed * multiplier3));
pixels[((y + 1) * image.getWidth() + x) * numBands + 1] = clamp(pixels[((y + 1) * image.getWidth() + x) * numBands + 1] + quantErrorGreen * 5 / 16); pixels[((y + 1) * image.getWidth() + x) * numBands + 1] = clamp((int) (pixels[((y + 1) * image.getWidth() + x) * numBands + 1] + quantErrorGreen * multiplier3));
pixels[((y + 1) * image.getWidth() + x) * numBands + 2] = clamp(pixels[((y + 1) * image.getWidth() + x) * numBands + 2] + quantErrorBlue * 5 / 16); pixels[((y + 1) * image.getWidth() + x) * numBands + 2] = clamp((int) (pixels[((y + 1) * image.getWidth() + x) * numBands + 2] + quantErrorBlue * multiplier3));
if (x < image.getWidth() - 1) { if (x < image.getWidth() - 1) {
pixels[((y + 1) * image.getWidth() + x + 1) * numBands] = clamp(pixels[((y + 1) * image.getWidth() + x + 1) * numBands] + quantErrorRed / 16); pixels[((y + 1) * image.getWidth() + x + 1) * numBands] = clamp((int) (pixels[((y + 1) * image.getWidth() + x + 1) * numBands] + quantErrorRed * multiplier4));
pixels[((y + 1) * image.getWidth() + x + 1) * numBands + 1] = clamp(pixels[((y + 1) * image.getWidth() + x + 1) * numBands + 1] + quantErrorGreen / 16); pixels[((y + 1) * image.getWidth() + x + 1) * numBands + 1] = clamp((int) (pixels[((y + 1) * image.getWidth() + x + 1) * numBands + 1] + quantErrorGreen * multiplier4));
pixels[((y + 1) * image.getWidth() + x + 1) * numBands + 2] = clamp(pixels[((y + 1) * image.getWidth() + x + 1) * numBands + 2] + quantErrorBlue / 16); pixels[((y + 1) * image.getWidth() + x + 1) * numBands + 2] = clamp((int) (pixels[((y + 1) * image.getWidth() + x + 1) * numBands + 2] + quantErrorBlue * multiplier4));
} }
} }
} }