Merge pull request #112 from OnlyBMan/master

Update SkinProvider.java
This commit is contained in:
Redned 2019-12-18 20:43:32 -06:00 committed by GitHub
commit 42ac37fe40
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -165,10 +165,10 @@ public class SkinProvider {
Geyser.getLogger().debug("Downloaded " + imageUrl); Geyser.getLogger().debug("Downloaded " + imageUrl);
if (cape) { if (cape) {
image = image.getWidth() > 64 ? scale(image) : image;
BufferedImage newImage = new BufferedImage(64, 32, BufferedImage.TYPE_INT_RGB); BufferedImage newImage = new BufferedImage(64, 32, BufferedImage.TYPE_INT_RGB);
Graphics g = newImage.createGraphics(); Graphics g = newImage.createGraphics();
g.drawImage(image, 0, 0, 64, 32, null); g.drawImage(image, 0, 0, image.getWidth(), image.getHeight(), null);
g.dispose(); g.dispose();
image = newImage; image = newImage;
} }
@ -193,6 +193,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> T getOrDefault(CompletableFuture<T> future, T defaultValue, int timeoutInSeconds) { public static <T> T getOrDefault(CompletableFuture<T> future, T defaultValue, int timeoutInSeconds) {
try { try {
return future.get(timeoutInSeconds, TimeUnit.SECONDS); return future.get(timeoutInSeconds, TimeUnit.SECONDS);