feat: make icons scale using SCALE_SMOOTH

This commit is contained in:
Paco Ito
2022-02-23 19:52:41 +00:00
committed by Michael Kamensky
parent 6f15f7c618
commit 6b24d956f6
3 changed files with 15 additions and 34 deletions

View File

@@ -463,7 +463,7 @@ public class FSkin {
} }
private void updateColor() { private void updateColor() {
tempCoords = skinProp.getCoords(); int[] tempCoords = skinProp.getCoords();
x0 = tempCoords[0]; x0 = tempCoords[0];
y0 = tempCoords[1]; y0 = tempCoords[1];
@@ -549,7 +549,7 @@ public class FSkin {
* @param s0   An address in the hashmap, derived from FSkinProp enum * @param s0   An address in the hashmap, derived from FSkinProp enum
*/ */
private static void setImage(final FSkinProp s0, final boolean scale) { private static void setImage(final FSkinProp s0, final boolean scale) {
tempCoords = s0.getCoords(); int[] tempCoords = s0.getCoords();
x0 = tempCoords[0]; x0 = tempCoords[0];
y0 = tempCoords[1]; y0 = tempCoords[1];
w0 = tempCoords[2]; w0 = tempCoords[2];
@@ -560,7 +560,7 @@ public class FSkin {
final BufferedImage bi0 = img.getSubimage(x0, y0, w0, h0); final BufferedImage bi0 = img.getSubimage(x0, y0, w0, h0);
if (scale && newW != 0) { if (scale && newW != 0) {
setImage(s0, bi0.getScaledInstance(newW, newH, Image.SCALE_AREA_AVERAGING)); setImage(s0, bi0.getScaledInstance(newW, newH, Image.SCALE_SMOOTH));
} }
else { else {
setImage(s0, bi0); setImage(s0, bi0);
@@ -569,8 +569,8 @@ public class FSkin {
protected Image image; protected Image image;
protected ImageIcon imageIcon; protected ImageIcon imageIcon;
protected HashMap<String, SkinImage> scaledImages; protected HashMap<String, SkinImage> scaledImages = new HashMap<>();
private HashMap<String, SkinCursor> cursors; private HashMap<String, SkinCursor> cursors = new HashMap<>();
private SkinImage(final Image image0) { private SkinImage(final Image image0) {
this.image = image0; this.image = image0;
@@ -589,9 +589,6 @@ public class FSkin {
} }
public SkinImage resize(final int w, final int h) { public SkinImage resize(final int w, final int h) {
if (this.scaledImages == null) {
this.scaledImages = new HashMap<>();
}
final String key = w + "x" + h; final String key = w + "x" + h;
SkinImage scaledImage = this.scaledImages.get(key); SkinImage scaledImage = this.scaledImages.get(key);
if (scaledImage == null) { if (scaledImage == null) {
@@ -603,11 +600,13 @@ public class FSkin {
} }
public boolean save(final String path, final int w, final int h) { public boolean save(final String path, final int w, final int h) {
final Image scaledImage = this.image.getScaledInstance(w, h, Image.SCALE_SMOOTH);
final BufferedImage resizedImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); final BufferedImage resizedImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
final Graphics2D g2d = resizedImage.createGraphics(); final Graphics2D g2d = resizedImage.createGraphics();
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2d.drawImage(this.image, 0, 0, w, h, 0, 0, this.getWidth(), this.getHeight(), null); g2d.drawImage(scaledImage, 0, 0, null);
g2d.dispose(); g2d.dispose();
final File outputfile = new File(path); final File outputfile = new File(path);
@@ -624,9 +623,6 @@ public class FSkin {
return scale(scale, scale); return scale(scale, scale);
} }
public SkinImage scale(final double scaleX, final double scaleY) { public SkinImage scale(final double scaleX, final double scaleY) {
if (this.scaledImages == null) {
this.scaledImages = new HashMap<>();
}
final String key = scaleX + "|" + scaleY; final String key = scaleX + "|" + scaleY;
SkinImage scaledImage = this.scaledImages.get(key); SkinImage scaledImage = this.scaledImages.get(key);
if (scaledImage == null) { if (scaledImage == null) {
@@ -638,8 +634,6 @@ public class FSkin {
} }
protected void updateScaledImages() { protected void updateScaledImages() {
if (this.scaledImages == null) { return; }
for (final Entry<String, SkinImage> i : this.scaledImages.entrySet()) { for (final Entry<String, SkinImage> i : this.scaledImages.entrySet()) {
String[] dims = i.getKey().split("x"); String[] dims = i.getKey().split("x");
if (dims.length == 2) { //static scale if (dims.length == 2) { //static scale
@@ -653,14 +647,7 @@ public class FSkin {
} }
protected void createResizedImage(final SkinImage baseImage, final int w, final int h) { protected void createResizedImage(final SkinImage baseImage, final int w, final int h) {
final BufferedImage resizedImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); this.changeImage(baseImage.image.getScaledInstance(w, h, Image.SCALE_SMOOTH), null);
final Graphics2D g2d = resizedImage.createGraphics();
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2d.drawImage(baseImage.image, 0, 0, w, h, 0, 0, baseImage.getWidth(), baseImage.getHeight(), null);
g2d.dispose();
this.changeImage(resizedImage, null);
} }
private void createScaledImage(final SkinImage baseImage, final double scaleX, final double scaleY) { private void createScaledImage(final SkinImage baseImage, final double scaleX, final double scaleY) {
@@ -668,9 +655,6 @@ public class FSkin {
} }
private SkinCursor toCursor(final int hotSpotX, final int hotSpotY, final String name) { private SkinCursor toCursor(final int hotSpotX, final int hotSpotY, final String name) {
if (this.cursors == null) {
this.cursors = new HashMap<>();
}
final String key = hotSpotX + "|" + hotSpotY + "|" + name; final String key = hotSpotX + "|" + hotSpotY + "|" + name;
SkinCursor cursor = this.cursors.get(key); SkinCursor cursor = this.cursors.get(key);
if (cursor == null) { if (cursor == null) {
@@ -682,8 +666,6 @@ public class FSkin {
} }
private void updateCursors() { private void updateCursors() {
if (this.cursors == null) { return; }
for (final SkinCursor cursor : this.cursors.values()) { for (final SkinCursor cursor : this.cursors.values()) {
cursor.updateCursor(this.image); cursor.updateCursor(this.image);
} }
@@ -778,7 +760,7 @@ public class FSkin {
} }
private static void setIcon(final FSkinProp s0) { private static void setIcon(final FSkinProp s0) {
tempCoords = s0.getCoords(); int[] tempCoords = s0.getCoords();
x0 = tempCoords[0]; x0 = tempCoords[0];
y0 = tempCoords[1]; y0 = tempCoords[1];
w0 = tempCoords[2]; w0 = tempCoords[2];
@@ -1111,7 +1093,6 @@ public class FSkin {
bimDefaultAvatars, bimPreferredAvatars, bimTrophies, bimAbilities, bimManaIcons, bimPhyrexian, bimDefaultSleeve, bimDefaultAvatars, bimPreferredAvatars, bimTrophies, bimAbilities, bimManaIcons, bimPhyrexian, bimDefaultSleeve,
bimDefaultSleeve2, bimDefaultDeckbox, bimPrefferedSetLogo, bimDefaultWatermark, bimDefaultDraftRank; bimDefaultSleeve2, bimDefaultDeckbox, bimPrefferedSetLogo, bimDefaultWatermark, bimDefaultDraftRank;
private static int x0, y0, w0, h0, newW, newH, preferredW, preferredH; private static int x0, y0, w0, h0, newW, newH, preferredW, preferredH;
private static int[] tempCoords;
private static int defaultFontSize = 12; private static int defaultFontSize = 12;
private static boolean loaded = false; private static boolean loaded = false;
@@ -1288,7 +1269,7 @@ public class FSkin {
bimQuestDraftDeck = ImageIO.read(f8); bimQuestDraftDeck = ImageIO.read(f8);
FView.SINGLETON_INSTANCE.incrementSplashProgessBar(++p); FView.SINGLETON_INSTANCE.incrementSplashProgessBar(++p);
bimFavIcon = ImageIO.read(f9); bimFavIcon = ImageIO.read(f9);
FView.SINGLETON_INSTANCE.incrementSplashProgessBar(++p);
if (f5.exists()) { bimPreferredAvatars = ImageIO.read(f5); } if (f5.exists()) { bimPreferredAvatars = ImageIO.read(f5); }
FView.SINGLETON_INSTANCE.incrementSplashProgessBar(++p); FView.SINGLETON_INSTANCE.incrementSplashProgessBar(++p);
@@ -1538,7 +1519,7 @@ public class FSkin {
} }
private static BufferedImage testPreferredSprite(final FSkinProp s0) { private static BufferedImage testPreferredSprite(final FSkinProp s0) {
tempCoords = s0.getCoords(); int[] tempCoords = s0.getCoords();
x0 = tempCoords[0]; x0 = tempCoords[0];
y0 = tempCoords[1]; y0 = tempCoords[1];
w0 = tempCoords[2]; w0 = tempCoords[2];
@@ -1653,7 +1634,7 @@ public class FSkin {
} }
private static void setImage(final FSkinProp s0, final BufferedImage bim) { private static void setImage(final FSkinProp s0, final BufferedImage bim) {
tempCoords = s0.getCoords(); int[] tempCoords = s0.getCoords();
x0 = tempCoords[0]; x0 = tempCoords[0];
y0 = tempCoords[1]; y0 = tempCoords[1];
w0 = tempCoords[2]; w0 = tempCoords[2];

View File

@@ -445,7 +445,7 @@ public class FNavigationBar extends FTitleBarBase {
public void setIcon(final Icon icon) { public void setIcon(final Icon icon) {
final ImageIcon imageIcon = ReflectionUtil.safeCast(icon, ImageIcon.class); final ImageIcon imageIcon = ReflectionUtil.safeCast(icon, ImageIcon.class);
if (imageIcon != null) { if (imageIcon != null) {
super.setIcon(new ImageIcon(imageIcon.getImage().getScaledInstance(20, 20, Image.SCALE_AREA_AVERAGING))); super.setIcon(new ImageIcon(imageIcon.getImage().getScaledInstance(20, 20, Image.SCALE_SMOOTH)));
} }
else { else {
super.setIcon((Icon)null); super.setIcon((Icon)null);

View File

@@ -44,7 +44,7 @@ public class FTitleBar extends FTitleBarBase {
@Override @Override
public void setIconImage(Image image) { public void setIconImage(Image image) {
if (image != null) { if (image != null) {
this.lblTitle.setIcon(new ImageIcon(image.getScaledInstance(16, 16, Image.SCALE_AREA_AVERAGING))); this.lblTitle.setIcon(new ImageIcon(image.getScaledInstance(16, 16, Image.SCALE_SMOOTH)));
} }
else { else {
this.lblTitle.setIcon((ImageIcon)null); this.lblTitle.setIcon((ImageIcon)null);