From 328954b256bbd1c3c210820617927ed4219d62d4 Mon Sep 17 00:00:00 2001 From: Michael Primm Date: Fri, 22 Dec 2023 11:08:10 -0600 Subject: [PATCH] Handle bogus gamma correction on new GRAY texturepack images --- .../src/main/java/org/dynmap/hdmap/TexturePack.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/DynmapCore/src/main/java/org/dynmap/hdmap/TexturePack.java b/DynmapCore/src/main/java/org/dynmap/hdmap/TexturePack.java index 57cbb904..d284a54e 100644 --- a/DynmapCore/src/main/java/org/dynmap/hdmap/TexturePack.java +++ b/DynmapCore/src/main/java/org/dynmap/hdmap/TexturePack.java @@ -1273,7 +1273,17 @@ public class TexturePack { imgs[idx].width = img.getWidth(); imgs[idx].height = img.getHeight(); imgs[idx].argb = new int[imgs[idx].width * imgs[idx].height]; - img.getRGB(0, 0, imgs[idx].width, imgs[idx].height, imgs[idx].argb, 0, imgs[idx].width); + if (img.getType() == BufferedImage.TYPE_BYTE_GRAY) { // We don't want alpha correction, apparently + float[] buffer = new float[imgs[idx].width * imgs[idx].height]; + img.getData().getPixels(0, 0, imgs[idx].width, imgs[idx].height, buffer); + for (int i = 0; i < imgs[idx].argb.length; i++) { + int v = (int) buffer[i]; + imgs[idx].argb[i] = 0xFF000000 | (v << 16) | (v << 8) | v; + } + } + else { + img.getRGB(0, 0, imgs[idx].width, imgs[idx].height, imgs[idx].argb, 0, imgs[idx].width); + } img.flush(); imgs[idx].isLoaded = true; }