mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 11:48:02 +00:00
Merge branch 'white-corners' into 'master'
Crop out white corners when importing images Closes #1965 See merge request core-developers/forge!5326
This commit is contained in:
@@ -206,6 +206,7 @@ public class ImageCache {
|
|||||||
boolean noBorder = !useArtCrop && !isPreferenceEnabled(ForgePreferences.FPref.UI_RENDER_BLACK_BORDERS);
|
boolean noBorder = !useArtCrop && !isPreferenceEnabled(ForgePreferences.FPref.UI_RENDER_BLACK_BORDERS);
|
||||||
boolean fetcherEnabled = isPreferenceEnabled(ForgePreferences.FPref.UI_ENABLE_ONLINE_IMAGE_FETCHER);
|
boolean fetcherEnabled = isPreferenceEnabled(ForgePreferences.FPref.UI_ENABLE_ONLINE_IMAGE_FETCHER);
|
||||||
boolean isPlaceholder = (original == null) && fetcherEnabled;
|
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
|
// 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.
|
// 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
|
// use a quadratic equation to calculate the needed radius from an image dimension
|
||||||
int radius;
|
int radius;
|
||||||
float width = original.getWidth();
|
float width = original.getWidth();
|
||||||
String setCode = imageKey.split("/")[0].trim().toUpperCase();
|
|
||||||
if (setCode.equals("A")) { // Alpha
|
if (setCode.equals("A")) { // Alpha
|
||||||
// radius = 100; // 745 x 1040
|
// radius = 100; // 745 x 1040
|
||||||
// radius = 68; // 488 x 680
|
// radius = 68; // 488 x 680
|
||||||
@@ -239,6 +239,15 @@ public class ImageCache {
|
|||||||
original = makeRoundedCorner(original, radius);
|
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
|
// 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,
|
// 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.
|
// 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);
|
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
|
// 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) {
|
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)) {
|
if (StringUtils.isEmpty(key) || (3 > width && -1 != width) || (3 > height && -1 != height)) {
|
||||||
|
|||||||
@@ -1498,7 +1498,7 @@ public class FSkin {
|
|||||||
* @param pixel
|
* @param pixel
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private static Color getColorFromPixel(final int pixel) {
|
public static Color getColorFromPixel(final int pixel) {
|
||||||
int r, g, b, a;
|
int r, g, b, a;
|
||||||
a = (pixel >> 24) & 0x000000ff;
|
a = (pixel >> 24) & 0x000000ff;
|
||||||
r = (pixel >> 16) & 0x000000ff;
|
r = (pixel >> 16) & 0x000000ff;
|
||||||
|
|||||||
Reference in New Issue
Block a user