Fix: Better scaling of vic-20 screenshots

This commit is contained in:
lantzelot-swe 2021-01-04 23:12:35 +01:00
parent d63d4d6d64
commit 8c5727a617
3 changed files with 30 additions and 15 deletions

View File

@ -66,7 +66,7 @@ public class ScreenshotsPanel extends JPanel
private ImageIcon warningIcon = new ImageIcon(getClass().getResource("/se/lantz/warning-icon.png"));
private String editTooltip =
"<html>Optimal resolution for the carousel is 320x200.<br>Press to crop the image to this size (the border will be removed).<br>Otherwise it will be resized when saving which might make it blurry.</html>";
"<html>Optimal resolution for the carousel is 320x200.<br>Press to crop the image to this size (the border will be removed).<br>It will be resized when saving but it might make it blurry.</html>";
private boolean gamesFileUpdated = false;
FileNameExtensionFilter imagefilter =
@ -138,7 +138,7 @@ public class ScreenshotsPanel extends JPanel
if (!coverImage.equals(currentCoverImage))
{
logger.debug("SETTING NEW COVER IMAGE");
Image newImage = coverImage.getScaledInstance(130, 200, Image.SCALE_DEFAULT);
Image newImage = coverImage.getScaledInstance(130, 200, Image.SCALE_SMOOTH);
getCoverImageLabel().setIcon(new ImageIcon(newImage));
currentCoverImage = coverImage;
}
@ -164,8 +164,7 @@ public class ScreenshotsPanel extends JPanel
if (!screen1Image.equals(currentScreen1Image))
{
logger.debug("SETTING SCREEN 1 IMAGE");
Image newImage = screen1Image.getScaledInstance(320, 200, Image.SCALE_DEFAULT);
getScreen1ImageLabel().setIcon(new ImageIcon(newImage));
getScreen1ImageLabel().setIcon(new ImageIcon(FileManager.scaleImageTo320x200(screen1Image)));
setEditButtonVisibilityAndResolution(screen1Image, getResolution1Label(), getEdit1Button());
currentScreen1Image = screen1Image;
}
@ -192,8 +191,7 @@ public class ScreenshotsPanel extends JPanel
if (!screen2Image.equals(currentScreen2Image))
{
logger.debug("SETTING SCREEN 2 IMAGE");
Image newImage = screen2Image.getScaledInstance(320, 200, Image.SCALE_DEFAULT);
getScreen2ImageLabel().setIcon(new ImageIcon(newImage));
getScreen2ImageLabel().setIcon(new ImageIcon(FileManager.scaleImageTo320x200(screen2Image)));
setEditButtonVisibilityAndResolution(screen2Image, getResolution2Label(), getEdit2Button());
currentScreen2Image = screen2Image;
}
@ -229,7 +227,7 @@ public class ScreenshotsPanel extends JPanel
try
{
BufferedImage image = ImageIO.read(imagefile);
Image newImage = image.getScaledInstance(130, 200, Image.SCALE_DEFAULT);
Image newImage = image.getScaledInstance(130, 200, Image.SCALE_SMOOTH);
getCoverImageLabel().setIcon(new ImageIcon(newImage));
}
catch (IOException e)
@ -253,7 +251,7 @@ public class ScreenshotsPanel extends JPanel
try
{
image = ImageIO.read(imagefile);
Image newImage = image.getScaledInstance(320, 200, Image.SCALE_DEFAULT);
Image newImage = image.getScaledInstance(320, 200, Image.SCALE_SMOOTH);
screenLabel.setIcon(new ImageIcon(newImage));
setEditButtonVisibilityAndResolution(image, resolutionLabel, editButton);
}
@ -621,7 +619,7 @@ public class ScreenshotsPanel extends JPanel
try
{
returnImage = ImageIO.read(files[0]);
Image newImage = returnImage.getScaledInstance(135, 200, Image.SCALE_DEFAULT);
Image newImage = returnImage.getScaledInstance(130, 200, Image.SCALE_SMOOTH);
imageLabel.setIcon(new ImageIcon(newImage));
}
catch (IOException e)
@ -643,8 +641,7 @@ public class ScreenshotsPanel extends JPanel
returnImage = ImageIO.read(files[0]);
setEditButtonVisibility(returnImage, editButton);
Image newImage = returnImage.getScaledInstance(320, 200, Image.SCALE_DEFAULT);
imageLabel.setIcon(new ImageIcon(newImage));
imageLabel.setIcon(new ImageIcon(FileManager.scaleImageTo320x200(returnImage)));
}
catch (IOException e)
{

View File

@ -333,7 +333,7 @@ public class MobyGamesOptionsPanel extends JPanel
scraper.connectScraper(urlTextField.getText());
getConnectionStatusLabel().setText("Connection status: OK");
getConnectionStatusLabel().setIcon(new ImageIcon(this.getClass().getResource("/se/lantz/check.png")));
enableCheckBoxes(true);
okButton.setEnabled(true);
MobyGamesOptionsPanel.this.setCursor(defaultCursor);
SwingUtilities.invokeLater(() -> SwingUtilities.getRootPane(connectButton).setDefaultButton(okButton));

View File

@ -86,7 +86,7 @@ public class FileManager
{
try
{
Image coverToSave = cover.getScaledInstance(122, 175, Image.SCALE_DEFAULT);
Image coverToSave = cover.getScaledInstance(122, 175, Image.SCALE_SMOOTH);
BufferedImage copyOfImage =
new BufferedImage(coverToSave.getWidth(null), coverToSave.getHeight(null), BufferedImage.TYPE_INT_RGB);
Graphics g = copyOfImage.createGraphics();
@ -783,17 +783,23 @@ public class FileManager
public static BufferedImage scaleImageTo320x200(BufferedImage originalImage)
{
BufferedImage returnImage = originalImage;
if (originalImage.getWidth() >= 544 && originalImage.getHeight() >= 284)
{
//Standard VIC-20 screenshot from Vice. This is best scaled by first cropping to 448x280
returnImage = cropImageTo448x280(originalImage);
}
if (originalImage.getWidth() != 320 || originalImage.getHeight() != 200)
{
// Scale to right size.
Image newImage = originalImage.getScaledInstance(320, 200, Image.SCALE_DEFAULT);
Image newImage = returnImage.getScaledInstance(320, 200, Image.SCALE_SMOOTH);
BufferedImage copyOfImage =
new BufferedImage(newImage.getWidth(null), newImage.getHeight(null), BufferedImage.TYPE_INT_RGB);
Graphics g = copyOfImage.createGraphics();
g.drawImage(newImage, 0, 0, null);
return copyOfImage;
}
return originalImage;
return returnImage;
}
public static BufferedImage cropImageTo320x200(BufferedImage originalImage)
@ -807,4 +813,16 @@ public class FileManager
g.drawImage(newImage, 0, 0, null);
return newImage;
}
private static BufferedImage cropImageTo448x280(BufferedImage originalImage)
{
// Crop to right size for Vic-20: Remove the border to fit nicely in the carousel.
BufferedImage newImage = originalImage
.getSubimage((originalImage.getWidth() - 448) / 2, ((originalImage.getHeight() - 280) / 2) - 1, 448, 280);
BufferedImage copyOfImage =
new BufferedImage(newImage.getWidth(), newImage.getHeight(), BufferedImage.TYPE_INT_RGB);
Graphics g = copyOfImage.createGraphics();
g.drawImage(newImage, 0, 0, null);
return newImage;
}
}