diff --git a/forge-gui-desktop/src/main/java/forge/ImageCache.java b/forge-gui-desktop/src/main/java/forge/ImageCache.java index 22317de4636..b52ed21c002 100644 --- a/forge-gui-desktop/src/main/java/forge/ImageCache.java +++ b/forge-gui-desktop/src/main/java/forge/ImageCache.java @@ -206,6 +206,7 @@ public class ImageCache { boolean noBorder = !useArtCrop && !isPreferenceEnabled(ForgePreferences.FPref.UI_RENDER_BLACK_BORDERS); boolean fetcherEnabled = isPreferenceEnabled(ForgePreferences.FPref.UI_ENABLE_ONLINE_IMAGE_FETCHER); boolean isPlaceholder = (original == null) && fetcherEnabled; + String setCode = imageKey.split("/")[0].trim().toUpperCase(); // If the user has indicated that they prefer Forge NOT render a black border, round the image corners // to account for JPEG images that don't have a transparency. @@ -213,7 +214,6 @@ public class ImageCache { // use a quadratic equation to calculate the needed radius from an image dimension int radius; float width = original.getWidth(); - String setCode = imageKey.split("/")[0].trim().toUpperCase(); if (setCode.equals("A")) { // Alpha // radius = 100; // 745 x 1040 // radius = 68; // 488 x 680 @@ -239,6 +239,15 @@ public class ImageCache { original = makeRoundedCorner(original, radius); } + // if image has white corners, get try to crop it out + if (original != null && isWhite(FSkin.getColorFromPixel(original.getRGB(0, 0)))) { + if (!isWhiteBorderSet(setCode)) { + int xSpacing = original.getWidth() / 40; + int ySpacing = original.getHeight() / 57; + original = original.getSubimage(xSpacing, ySpacing, original.getWidth() - (2* xSpacing), original.getHeight() - (2* ySpacing)); + } + } + // No image file exists for the given key so optionally associate with // a default "not available" image, however do not add it to the cache, // as otherwise it's problematic to update if the real image gets fetched. @@ -268,6 +277,15 @@ public class ImageCache { return Pair.of(original, isPlaceholder); } + private static boolean isWhite(Color color) { + return color.getRed() > 200 && color.getBlue() > 200 && color.getGreen() > 200; + } + + private static boolean isWhiteBorderSet(String setCode) { + return setCode.equals("U") || setCode.equals("R") || setCode.equals("4E") || setCode.equals("5E") || + setCode.equals("6E") || setCode.equals("7E") || setCode.equals("8E") || setCode.equals("9E"); + } + // cardView is for Emblem, since there is no paper card for them public static BufferedImage scaleImage(String key, final int width, final int height, boolean useDefaultImage, CardView cardView) { if (StringUtils.isEmpty(key) || (3 > width && -1 != width) || (3 > height && -1 != height)) { diff --git a/forge-gui-desktop/src/main/java/forge/toolbox/FSkin.java b/forge-gui-desktop/src/main/java/forge/toolbox/FSkin.java index 8d66a6ee640..1412034efe3 100644 --- a/forge-gui-desktop/src/main/java/forge/toolbox/FSkin.java +++ b/forge-gui-desktop/src/main/java/forge/toolbox/FSkin.java @@ -1498,7 +1498,7 @@ public class FSkin { * @param pixel * @return */ - private static Color getColorFromPixel(final int pixel) { + public static Color getColorFromPixel(final int pixel) { int r, g, b, a; a = (pixel >> 24) & 0x000000ff; r = (pixel >> 16) & 0x000000ff;