From 16950bf8f2c29d7e80e31a9fd0e7cb149e4c6a6f Mon Sep 17 00:00:00 2001 From: OnlyBMan <27742182+OnlyBMan@users.noreply.github.com> Date: Sat, 14 Dec 2019 21:12:12 -0500 Subject: [PATCH 1/3] Update SkinProvider.java Fix OptiFine capes and downscales banner capes so they work on PE too. --- .../connector/utils/SkinProvider.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/utils/SkinProvider.java b/connector/src/main/java/org/geysermc/connector/utils/SkinProvider.java index b2634e3be..2b9d9a77b 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/SkinProvider.java +++ b/connector/src/main/java/org/geysermc/connector/utils/SkinProvider.java @@ -164,11 +164,17 @@ public class SkinProvider { BufferedImage image = ImageIO.read(new URL(imageUrl)); Geyser.getLogger().debug("Downloaded " + imageUrl); - if (cape) { + if (cape && image.getWidth() <= 64) { BufferedImage newImage = new BufferedImage(64, 32, BufferedImage.TYPE_INT_RGB); - Graphics g = newImage.createGraphics(); - g.drawImage(image, 0, 0, 64, 32, null); + g.drawImage(image, 0, 0, image.getWidth(), image.getHeight(), null); + g.dispose(); + image = newImage; + } + else if(cape && image.getWidth() >= 64 && image.getWidth() <= 128) { + BufferedImage newImage = new BufferedImage(64, 32, BufferedImage.TYPE_INT_RGB); + Graphics g = newImage.createGraphics(); + g.drawImage(scale(image), 0, 0, scale(image).getWidth(), scale(image).getHeight(), null); g.dispose(); image = newImage; } @@ -193,6 +199,15 @@ public class SkinProvider { } } + private static BufferedImage scale (BufferedImage bufferedImage) { + BufferedImage resized = new BufferedImage(bufferedImage.getWidth() / 2, bufferedImage.getHeight() / 2, BufferedImage.TYPE_INT_RGB); + Graphics2D g2 = resized.createGraphics(); + g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); + g2.drawImage(bufferedImage, 0, 0, bufferedImage.getWidth() / 2, bufferedImage.getHeight() / 2, null); + g2.dispose(); + return resized; + } + public static T getOrDefault(CompletableFuture future, T defaultValue, int timeoutInSeconds) { try { return future.get(timeoutInSeconds, TimeUnit.SECONDS); From 203b3b9d4623355bec24546279a422867f48ecb5 Mon Sep 17 00:00:00 2001 From: OnlyBMan <27742182+OnlyBMan@users.noreply.github.com> Date: Sun, 15 Dec 2019 19:24:00 -0500 Subject: [PATCH 2/3] Update SkinProvider.java Instead of calling the scale method 3 times, just used a cached scaled image --- .../main/java/org/geysermc/connector/utils/SkinProvider.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/connector/src/main/java/org/geysermc/connector/utils/SkinProvider.java b/connector/src/main/java/org/geysermc/connector/utils/SkinProvider.java index 2b9d9a77b..07693de7d 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/SkinProvider.java +++ b/connector/src/main/java/org/geysermc/connector/utils/SkinProvider.java @@ -162,6 +162,7 @@ public class SkinProvider { private static byte[] requestImage(String imageUrl, boolean cape) throws Exception { BufferedImage image = ImageIO.read(new URL(imageUrl)); + BufferedImage scale = scale(image); Geyser.getLogger().debug("Downloaded " + imageUrl); if (cape && image.getWidth() <= 64) { @@ -174,7 +175,7 @@ public class SkinProvider { else if(cape && image.getWidth() >= 64 && image.getWidth() <= 128) { BufferedImage newImage = new BufferedImage(64, 32, BufferedImage.TYPE_INT_RGB); Graphics g = newImage.createGraphics(); - g.drawImage(scale(image), 0, 0, scale(image).getWidth(), scale(image).getHeight(), null); + g.drawImage(scale, 0, 0, scale.getWidth(), scale.getHeight(), null); g.dispose(); image = newImage; } From afab21695a5fee3e2e32c9090f1706d341048875 Mon Sep 17 00:00:00 2001 From: OnlyBMan <27742182+OnlyBMan@users.noreply.github.com> Date: Mon, 16 Dec 2019 22:26:35 -0500 Subject: [PATCH 3/3] Update SkinProvider.java Remove duplicate code --- .../org/geysermc/connector/utils/SkinProvider.java | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/utils/SkinProvider.java b/connector/src/main/java/org/geysermc/connector/utils/SkinProvider.java index 07693de7d..f3bb4319d 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/SkinProvider.java +++ b/connector/src/main/java/org/geysermc/connector/utils/SkinProvider.java @@ -162,23 +162,16 @@ public class SkinProvider { private static byte[] requestImage(String imageUrl, boolean cape) throws Exception { BufferedImage image = ImageIO.read(new URL(imageUrl)); - BufferedImage scale = scale(image); Geyser.getLogger().debug("Downloaded " + imageUrl); - if (cape && image.getWidth() <= 64) { + if (cape) { + image = image.getWidth() > 64 ? scale(image) : image; BufferedImage newImage = new BufferedImage(64, 32, BufferedImage.TYPE_INT_RGB); Graphics g = newImage.createGraphics(); g.drawImage(image, 0, 0, image.getWidth(), image.getHeight(), null); g.dispose(); image = newImage; } - else if(cape && image.getWidth() >= 64 && image.getWidth() <= 128) { - BufferedImage newImage = new BufferedImage(64, 32, BufferedImage.TYPE_INT_RGB); - Graphics g = newImage.createGraphics(); - g.drawImage(scale, 0, 0, scale.getWidth(), scale.getHeight(), null); - g.dispose(); - image = newImage; - } ByteArrayOutputStream outputStream = new ByteArrayOutputStream(image.getWidth() * 4 + image.getHeight() * 4); try {