Cache resized and rotated images

RotatedResizedImageCache and MultiRotatedResizedImageCache contain the caching
machinery.

A cache of rotated and resized images is added to ImageCache, and is used by
the resizing functions there.

All the resizing and rotation functions in ImageHelper are redirected to the
ones in ImageCache.

This is slightly inefficient because it will cache some calls that are never
repeated, but it prevents developers from mistakenly using uncached functions
when calls are repeated, seriously impacting performance.

Also resizing functions that only take a width or an height have been removed,
and their calls fixed to provide the other dimension. It's still possible to
specify -1 as width or height to ignore constraints in that dimension, though.

Greatly speeds up UI performance.
This commit is contained in:
draxdyn 2016-06-01 17:05:28 +02:00
parent 1999dfe5c0
commit e3d84ca212
9 changed files with 179 additions and 157 deletions

View file

@ -598,13 +598,7 @@ public class MageActionCallback implements ActionCallback {
private void displayCardInfo(MageCard mageCard, Image image, BigCard bigCard) {
if (image != null && image instanceof BufferedImage) {
// XXX: scaled to fit width
if (mageCard.getOriginal().isToRotate() && bigCard.getWidth() > bigCard.getHeight()) {
image = ImageHelper.getResizedImage((BufferedImage) image, bigCard.getHeight());
image = ImageHelper.rotate((BufferedImage) image, Math.toRadians(90));
} else {
image = ImageHelper.getResizedImage((BufferedImage) image, bigCard.getWidth());
}
bigCard.setCard(mageCard.getOriginal().getId(), enlargeMode, image, mageCard.getOriginal().getRules());
bigCard.setCard(mageCard.getOriginal().getId(), enlargeMode, image, mageCard.getOriginal().getRules(), mageCard.getOriginal().isToRotate());
// if it's an ability, show only the ability text as overlay
if (mageCard.getOriginal().isAbility() && enlargeMode.equals(EnlargeMode.NORMAL)) {
bigCard.showTextComponent();