From e9fa275002708fa9081491a49723b8fd5193a795 Mon Sep 17 00:00:00 2001 From: Liam Date: Thu, 11 Apr 2024 03:51:21 +0100 Subject: [PATCH] cleanup isometric skin renderer --- .../java/cc.fascinated/common/ImageUtils.java | 2 ++ .../java/cc.fascinated/model/player/Skin.java | 4 ++-- .../{SkinPartRenderer.java => SkinRenderer.java} | 2 +- .../service/skin/impl/FlatRenderer.java | 15 +++------------ .../service/skin/impl/IsometricHeadRenderer.java | 4 ++-- 5 files changed, 10 insertions(+), 17 deletions(-) rename src/main/java/cc.fascinated/service/skin/{SkinPartRenderer.java => SkinRenderer.java} (98%) diff --git a/src/main/java/cc.fascinated/common/ImageUtils.java b/src/main/java/cc.fascinated/common/ImageUtils.java index 1a4342b..565425c 100644 --- a/src/main/java/cc.fascinated/common/ImageUtils.java +++ b/src/main/java/cc.fascinated/common/ImageUtils.java @@ -1,11 +1,13 @@ package cc.fascinated.common; import jakarta.validation.constraints.NotNull; +import lombok.extern.log4j.Log4j2; import java.awt.*; import java.awt.geom.AffineTransform; import java.awt.image.BufferedImage; +@Log4j2 public class ImageUtils { /** diff --git a/src/main/java/cc.fascinated/model/player/Skin.java b/src/main/java/cc.fascinated/model/player/Skin.java index 4826896..3358e47 100644 --- a/src/main/java/cc.fascinated/model/player/Skin.java +++ b/src/main/java/cc.fascinated/model/player/Skin.java @@ -3,7 +3,7 @@ package cc.fascinated.model.player; import cc.fascinated.common.PlayerUtils; import cc.fascinated.config.Config; import cc.fascinated.exception.impl.BadRequestException; -import cc.fascinated.service.skin.SkinPartRenderer; +import cc.fascinated.service.skin.SkinRenderer; import cc.fascinated.service.skin.impl.FlatRenderer; import cc.fascinated.service.skin.impl.IsometricHeadRenderer; import com.fasterxml.jackson.annotation.JsonIgnore; @@ -101,7 +101,7 @@ public class Skin { /** * The skin part parser for the part. */ - private final SkinPartRenderer skinPartParser; + private final SkinRenderer skinPartParser; /** * Gets the name of the part. diff --git a/src/main/java/cc.fascinated/service/skin/SkinPartRenderer.java b/src/main/java/cc.fascinated/service/skin/SkinRenderer.java similarity index 98% rename from src/main/java/cc.fascinated/service/skin/SkinPartRenderer.java rename to src/main/java/cc.fascinated/service/skin/SkinRenderer.java index 72b5dfe..be21246 100644 --- a/src/main/java/cc.fascinated/service/skin/SkinPartRenderer.java +++ b/src/main/java/cc.fascinated/service/skin/SkinRenderer.java @@ -13,7 +13,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @AllArgsConstructor @Getter @Log4j2 -public abstract class SkinPartRenderer { +public abstract class SkinRenderer { /** * Gets the skin part image. diff --git a/src/main/java/cc.fascinated/service/skin/impl/FlatRenderer.java b/src/main/java/cc.fascinated/service/skin/impl/FlatRenderer.java index 7affb41..51024ea 100644 --- a/src/main/java/cc.fascinated/service/skin/impl/FlatRenderer.java +++ b/src/main/java/cc.fascinated/service/skin/impl/FlatRenderer.java @@ -1,18 +1,16 @@ package cc.fascinated.service.skin.impl; import cc.fascinated.model.player.Skin; -import cc.fascinated.service.skin.SkinPartRenderer; +import cc.fascinated.service.skin.SkinRenderer; import lombok.Getter; import lombok.extern.log4j.Log4j2; -import javax.imageio.ImageIO; import java.awt.*; import java.awt.geom.AffineTransform; import java.awt.image.BufferedImage; -import java.io.ByteArrayOutputStream; @Getter @Log4j2 -public class FlatRenderer extends SkinPartRenderer { +public class FlatRenderer extends SkinRenderer { /** * The x and y position of the part. @@ -49,14 +47,7 @@ public class FlatRenderer extends SkinPartRenderer { graphics.setTransform(AffineTransform.getScaleInstance(scale, scale)); graphics.drawImage(this.getSkinPart(skin, this.x, this.y, this.widthAndHeight, this.widthAndHeight, 1), 0, 0, null); - try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { - ImageIO.write(outputImage, "png", outputStream); - // Cleanup - outputStream.flush(); - graphics.dispose(); - log.info("Successfully got {} part bytes for {}", partName, skin.getUrl()); - return outputStream.toByteArray(); - } + return super.getBytes(outputImage, skin, partName); } catch (Exception ex) { log.error("Failed to get {} part bytes for {}", partName, skin.getUrl(), ex); throw new RuntimeException("Failed to get " + partName + " part for " + skin.getUrl()); diff --git a/src/main/java/cc.fascinated/service/skin/impl/IsometricHeadRenderer.java b/src/main/java/cc.fascinated/service/skin/impl/IsometricHeadRenderer.java index 1ed3511..3035808 100644 --- a/src/main/java/cc.fascinated/service/skin/impl/IsometricHeadRenderer.java +++ b/src/main/java/cc.fascinated/service/skin/impl/IsometricHeadRenderer.java @@ -2,7 +2,7 @@ package cc.fascinated.service.skin.impl; import cc.fascinated.common.ImageUtils; import cc.fascinated.model.player.Skin; -import cc.fascinated.service.skin.SkinPartRenderer; +import cc.fascinated.service.skin.SkinRenderer; import lombok.Getter; import lombok.extern.log4j.Log4j2; @@ -11,7 +11,7 @@ import java.awt.geom.AffineTransform; import java.awt.image.BufferedImage; @Getter @Log4j2 -public class IsometricHeadRenderer extends SkinPartRenderer { +public class IsometricHeadRenderer extends SkinRenderer { private static final double SKEW_A = 26d / 45d; // 0.57777777 private static final double SKEW_B = SKEW_A * 2d; // 1.15555555