Advanced card image loading: thumbnails (slow on first run). Updated mage-card-plugin. Disabled foil cards.

This commit is contained in:
magenoxx 2011-05-11 17:17:15 +04:00
parent 539cf2552f
commit 6e3a7ede39
6 changed files with 52 additions and 9 deletions

View file

@ -126,7 +126,7 @@ public class BigCard extends JComponent {
@Override @Override
public void paintComponent(Graphics graphics) { public void paintComponent(Graphics graphics) {
if (foilState) { /*if (foilState) {
if (source != null) { if (source != null) {
synchronized (BigCard.class) { synchronized (BigCard.class) {
if (source != null) { if (source != null) {
@ -138,6 +138,9 @@ public class BigCard extends JComponent {
if (bigImage != null) { if (bigImage != null) {
graphics.drawImage(bigImage, 0, 0, this); graphics.drawImage(bigImage, 0, 0, this);
} }
}*/
if (bigImage != null) {
graphics.drawImage(bigImage, 0, 0, this);
} }
super.paintComponent(graphics); super.paintComponent(graphics);
} }
@ -154,7 +157,7 @@ public class BigCard extends JComponent {
} }
public void setFoil(boolean foil) { public void setFoil(boolean foil) {
if (foilThread == null) { /*if (foilThread == null) {
synchronized (this) { synchronized (this) {
if (foilThread == null) { if (foilThread == null) {
foilThread = getFoilThread(); foilThread = getFoilThread();
@ -171,6 +174,7 @@ public class BigCard extends JComponent {
} }
} }
} }
*/
repaint(); repaint();
} }

View file

@ -90,6 +90,7 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener,
i.remove(); i.remove();
} }
} }
System.gc();
drawCards(sortBy, piles); drawCards(sortBy, piles);
this.setVisible(true); this.setVisible(true);
} }
@ -189,10 +190,12 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener,
if (comp instanceof Card) { if (comp instanceof Card) {
if (((Card)comp).getCardId().equals(cardId)) { if (((Card)comp).getCardId().equals(cardId)) {
remove(comp); remove(comp);
comp = null;
} }
} else if (comp instanceof MageCard) { } else if (comp instanceof MageCard) {
if (((MageCard)comp).getOriginal().getId().equals(cardId)) { if (((MageCard)comp).getOriginal().getId().equals(cardId)) {
remove(comp); remove(comp);
comp = null;
} }
} }
} }

View file

@ -149,8 +149,7 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
public void run() { public void run() {
try { try {
tappedAngle = isTapped() ? CardPanel.TAPPED_ANGLE : 0; tappedAngle = isTapped() ? CardPanel.TAPPED_ANGLE : 0;
BufferedImage srcImage = ImageCache.getImageOriginal(gameCard); BufferedImage srcImage = ImageCache.getThumbnail(gameCard);
srcImage = ImageCache.getNormalSizeImage(srcImage);
if (srcImage != null) { if (srcImage != null) {
hasImage = true; hasImage = true;
setText(gameCard); setText(gameCard);
@ -199,12 +198,12 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
public void setFoil(boolean foil) { public void setFoil(boolean foil) {
this.isFoil = foil; this.isFoil = foil;
if (foil) { if (foil) {
BufferedImage source = BufferedImageBuilder.bufferImage(imagePanel.getSrcImage()); /*BufferedImage source = BufferedImageBuilder.bufferImage(imagePanel.getSrcImage());
HueFilter filter = FilterFactory.getHueFilter(); HueFilter filter = FilterFactory.getHueFilter();
filter.setHue(0.1f); filter.setHue(0.1f);
BufferedImage dest = filter.filter(source, null); BufferedImage dest = filter.filter(source, null);
imagePanel.setImage(dest); imagePanel.setImage(dest);
imagePanel.repaint(); imagePanel.repaint();*/
/* /*
Thread thread = new Thread(new Runnable() { Thread thread = new Thread(new Runnable() {

View file

@ -11,6 +11,7 @@ public class Constants {
public static final String RESOURCE_PATH_SET_SMALL = RESOURCE_PATH_SET + File.separator + "small" + File.separator; public static final String RESOURCE_PATH_SET_SMALL = RESOURCE_PATH_SET + File.separator + "small" + File.separator;
public static final Rectangle CARD_SIZE_FULL = new Rectangle(101, 149); public static final Rectangle CARD_SIZE_FULL = new Rectangle(101, 149);
public static final Rectangle THUMBNAIL_SIZE_FULL = new Rectangle(102, 146);
public interface IO { public interface IO {
public static final String imageBaseDir = "plugins" + File.separator + "images" + File.separator; public static final String imageBaseDir = "plugins" + File.separator + "images" + File.separator;

View file

@ -52,6 +52,11 @@ public class ImageCache {
imageCache = new MapMaker().softValues().makeComputingMap(new Function<String, BufferedImage>() { imageCache = new MapMaker().softValues().makeComputingMap(new Function<String, BufferedImage>() {
public BufferedImage apply(String key) { public BufferedImage apply(String key) {
try { try {
boolean thumbnail = false;
if (key.endsWith("#thumb")) {
thumbnail = true;
key = key.replace("#thumb", "");
}
Matcher m = KEY_PATTERN.matcher(key); Matcher m = KEY_PATTERN.matcher(key);
if (m.matches()) { if (m.matches()) {
@ -66,8 +71,21 @@ public class ImageCache {
if (path == null) return null; if (path == null) return null;
File file = new File(path); File file = new File(path);
if (thumbnail && path.endsWith(".jpg")) {
String thumbnailPath = path.replace(".jpg", ".thumb.jpg");
File thumbnailFile = new File(thumbnailPath);
if (thumbnailFile.exists()) {
log.info("loading thumbnail for " + key + ", path="+thumbnailPath);
return loadImage(thumbnailFile);
} else {
BufferedImage image = loadImage(file); BufferedImage image = loadImage(file);
return image; if (image == null) return null;
log.info("creating thumbnail for " + key);
return makeThumbnail(image, thumbnailPath);
}
} else {
return loadImage(file);
}
} else { } else {
throw new RuntimeException( throw new RuntimeException(
"Requested image doesn't fit the requirement for key (<cardname>#<setname>#<collectorID>): " + key); "Requested image doesn't fit the requirement for key (<cardname>#<setname>#<collectorID>): " + key);
@ -82,6 +100,12 @@ public class ImageCache {
}); });
} }
public static BufferedImage getThumbnail(CardView card) {
String key = getKey(card) + "#thumb";
//log.debug("#key: " + key);
return getImage(key);
}
public static BufferedImage getImageOriginal(CardView card) { public static BufferedImage getImageOriginal(CardView card) {
String key = getKey(card); String key = getKey(card);
//log.debug("#key: " + key); //log.debug("#key: " + key);
@ -140,6 +164,18 @@ public class ImageCache {
return image; return image;
} }
public static BufferedImage makeThumbnail(BufferedImage original, String path) {
BufferedImage image = getResizedImage(original, Constants.THUMBNAIL_SIZE_FULL);
File imagePath = new File(path);
try {
log.info("thumbnail path:"+path);
ImageIO.write(image, "jpg", imagePath);
} catch (Exception e) {
log.error(e,e);
}
return image;
}
/** /**
* Returns an image scaled to the size given * Returns an image scaled to the size given
*/ */