forked from External/mage
[refactoring][minor] Replaced all tabs with four spaces.
This commit is contained in:
parent
e646e4768d
commit
239a4fb100
2891 changed files with 79411 additions and 79411 deletions
|
|
@ -56,123 +56,123 @@ import java.awt.Rectangle;
|
|||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class ImageHelper {
|
||||
protected static HashMap<String, BufferedImage> images = new HashMap<String, BufferedImage>();
|
||||
protected static HashMap<String, BufferedImage> backgrounds = new HashMap<String, BufferedImage>();
|
||||
protected static HashMap<String, BufferedImage> images = new HashMap<String, BufferedImage>();
|
||||
protected static HashMap<String, BufferedImage> backgrounds = new HashMap<String, BufferedImage>();
|
||||
|
||||
public static BufferedImage loadImage(String ref, int width, int height) {
|
||||
BufferedImage image = loadImage(ref);
|
||||
if (image != null)
|
||||
return scaleImage(image, width, height);
|
||||
return null;
|
||||
}
|
||||
public static BufferedImage loadImage(String ref, int width, int height) {
|
||||
BufferedImage image = loadImage(ref);
|
||||
if (image != null)
|
||||
return scaleImage(image, width, height);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ref - image name
|
||||
* @param height - height after scaling
|
||||
* @return a scaled image that preserves the original aspect ratio, with a specified height
|
||||
*/
|
||||
public static BufferedImage loadImage(String ref, int height) {
|
||||
BufferedImage image = loadImage(ref);
|
||||
if (image != null)
|
||||
return scaleImage(image, height);
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param ref - image name
|
||||
* @param height - height after scaling
|
||||
* @return a scaled image that preserves the original aspect ratio, with a specified height
|
||||
*/
|
||||
public static BufferedImage loadImage(String ref, int height) {
|
||||
BufferedImage image = loadImage(ref);
|
||||
if (image != null)
|
||||
return scaleImage(image, height);
|
||||
return null;
|
||||
}
|
||||
|
||||
public static BufferedImage loadImage(String ref) {
|
||||
if (!images.containsKey(ref)) {
|
||||
try {
|
||||
images.put(ref, ImageIO.read(ImageHelper.class.getResourceAsStream(ref)));
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return images.get(ref);
|
||||
}
|
||||
public static BufferedImage loadImage(String ref) {
|
||||
if (!images.containsKey(ref)) {
|
||||
try {
|
||||
images.put(ref, ImageIO.read(ImageHelper.class.getResourceAsStream(ref)));
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return images.get(ref);
|
||||
}
|
||||
|
||||
public static BufferedImage getBackground(CardView card, String backgroundName) {
|
||||
if (backgrounds.containsKey(backgroundName)) {
|
||||
return backgrounds.get(backgroundName);
|
||||
}
|
||||
|
||||
BufferedImage background = new BufferedImage(FRAME_MAX_WIDTH, FRAME_MAX_HEIGHT, BufferedImage.TYPE_INT_RGB);
|
||||
backgrounds.put(backgroundName, background);
|
||||
return background;
|
||||
}
|
||||
public static BufferedImage getBackground(CardView card, String backgroundName) {
|
||||
if (backgrounds.containsKey(backgroundName)) {
|
||||
return backgrounds.get(backgroundName);
|
||||
}
|
||||
|
||||
BufferedImage background = new BufferedImage(FRAME_MAX_WIDTH, FRAME_MAX_HEIGHT, BufferedImage.TYPE_INT_RGB);
|
||||
backgrounds.put(backgroundName, background);
|
||||
return background;
|
||||
}
|
||||
|
||||
|
||||
public static BufferedImage scaleImage(BufferedImage image, int width, int height) {
|
||||
BufferedImage scaledImage = image;
|
||||
int w = image.getWidth();
|
||||
int h = image.getHeight();
|
||||
do {
|
||||
w /= 2;
|
||||
h /= 2;
|
||||
if (w < width || h < height) {
|
||||
w = width;
|
||||
h = height;
|
||||
}
|
||||
BufferedImage newImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D graphics2D = newImage.createGraphics();
|
||||
graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
||||
graphics2D.drawImage(scaledImage, 0, 0, w, h, null);
|
||||
graphics2D.dispose();
|
||||
scaledImage = newImage;
|
||||
} while (w != width || h != height);
|
||||
return scaledImage;
|
||||
}
|
||||
public static BufferedImage scaleImage(BufferedImage image, int width, int height) {
|
||||
BufferedImage scaledImage = image;
|
||||
int w = image.getWidth();
|
||||
int h = image.getHeight();
|
||||
do {
|
||||
w /= 2;
|
||||
h /= 2;
|
||||
if (w < width || h < height) {
|
||||
w = width;
|
||||
h = height;
|
||||
}
|
||||
BufferedImage newImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D graphics2D = newImage.createGraphics();
|
||||
graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
||||
graphics2D.drawImage(scaledImage, 0, 0, w, h, null);
|
||||
graphics2D.dispose();
|
||||
scaledImage = newImage;
|
||||
} while (w != width || h != height);
|
||||
return scaledImage;
|
||||
}
|
||||
|
||||
public static BufferedImage scaleImage(BufferedImage image, int height) {
|
||||
double ratio = height / (double)image.getHeight();
|
||||
int width = (int) (image.getWidth() * ratio);
|
||||
return scaleImage(image, width, height);
|
||||
}
|
||||
public static BufferedImage scaleImage(BufferedImage image, int height) {
|
||||
double ratio = height / (double)image.getHeight();
|
||||
int width = (int) (image.getWidth() * ratio);
|
||||
return scaleImage(image, width, height);
|
||||
}
|
||||
|
||||
public static MemoryImageSource rotate(Image image, CardDimensions dimensions) {
|
||||
int buffer[] = new int[dimensions.frameWidth * dimensions.frameHeight];
|
||||
int rotate[] = new int[dimensions.frameHeight * dimensions.frameWidth];
|
||||
PixelGrabber grabber = new PixelGrabber(image, 0, 0, dimensions.frameWidth, dimensions.frameHeight, buffer, 0, dimensions.frameWidth);
|
||||
try {
|
||||
grabber.grabPixels();
|
||||
}
|
||||
catch(InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
for(int y = 0; y < dimensions.frameHeight; y++) {
|
||||
for(int x = 0; x < dimensions.frameWidth; x++) {
|
||||
rotate[((dimensions.frameWidth - x - 1) *dimensions.frameHeight)+y] = buffer[(y*dimensions.frameWidth)+x];
|
||||
}
|
||||
}
|
||||
public static MemoryImageSource rotate(Image image, CardDimensions dimensions) {
|
||||
int buffer[] = new int[dimensions.frameWidth * dimensions.frameHeight];
|
||||
int rotate[] = new int[dimensions.frameHeight * dimensions.frameWidth];
|
||||
PixelGrabber grabber = new PixelGrabber(image, 0, 0, dimensions.frameWidth, dimensions.frameHeight, buffer, 0, dimensions.frameWidth);
|
||||
try {
|
||||
grabber.grabPixels();
|
||||
}
|
||||
catch(InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
for(int y = 0; y < dimensions.frameHeight; y++) {
|
||||
for(int x = 0; x < dimensions.frameWidth; x++) {
|
||||
rotate[((dimensions.frameWidth - x - 1) *dimensions.frameHeight)+y] = buffer[(y*dimensions.frameWidth)+x];
|
||||
}
|
||||
}
|
||||
|
||||
return new MemoryImageSource(dimensions.frameHeight, dimensions.frameWidth, rotate, 0, dimensions.frameHeight);
|
||||
return new MemoryImageSource(dimensions.frameHeight, dimensions.frameWidth, rotate, 0, dimensions.frameHeight);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static void drawCosts(List<String> costs, Graphics2D g, int xOffset, int yOffset, ImageObserver o) {
|
||||
if (costs.size() > 0) {
|
||||
int costLeft = xOffset;
|
||||
for (int i = costs.size() - 1; i >= 0; i--) {
|
||||
String symbol = costs.get(i);
|
||||
g.drawString(symbol, costLeft, yOffset + SYMBOL_MAX_SPACE);
|
||||
costLeft -= SYMBOL_MAX_SPACE + 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void drawCosts(List<String> costs, Graphics2D g, int xOffset, int yOffset, ImageObserver o) {
|
||||
if (costs.size() > 0) {
|
||||
int costLeft = xOffset;
|
||||
for (int i = costs.size() - 1; i >= 0; i--) {
|
||||
String symbol = costs.get(i);
|
||||
g.drawString(symbol, costLeft, yOffset + SYMBOL_MAX_SPACE);
|
||||
costLeft -= SYMBOL_MAX_SPACE + 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an image scaled to the size appropriate for the card picture
|
||||
* panel
|
||||
*/
|
||||
public static BufferedImage getResizedImage(BufferedImage original, int width, int height) {
|
||||
ResampleOp resampleOp = new ResampleOp(width, height);
|
||||
BufferedImage image = resampleOp.filter(original, null);
|
||||
return image;
|
||||
}
|
||||
/**
|
||||
* Returns an image scaled to the size appropriate for the card picture
|
||||
* panel
|
||||
*/
|
||||
public static BufferedImage getResizedImage(BufferedImage original, int width, int height) {
|
||||
ResampleOp resampleOp = new ResampleOp(width, height);
|
||||
BufferedImage image = resampleOp.filter(original, null);
|
||||
return image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an image scaled to fit width
|
||||
* panel
|
||||
*/
|
||||
/**
|
||||
* Returns an image scaled to fit width
|
||||
* panel
|
||||
*/
|
||||
public static BufferedImage getResizedImage(BufferedImage original, int width) {
|
||||
if (width != original.getWidth()) {
|
||||
double ratio = width / (double) original.getWidth();
|
||||
|
|
@ -183,33 +183,33 @@ public class ImageHelper {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an image scaled to the needed size
|
||||
*/
|
||||
/**
|
||||
* Returns an image scaled to the needed size
|
||||
*/
|
||||
public static BufferedImage getResizedImage(BufferedImage original, Rectangle sizeNeed) {
|
||||
ResampleOp resampleOp = new ResampleOp(sizeNeed.width, sizeNeed.height);
|
||||
BufferedImage image = resampleOp.filter(original, null);
|
||||
return image;
|
||||
}
|
||||
ResampleOp resampleOp = new ResampleOp(sizeNeed.width, sizeNeed.height);
|
||||
BufferedImage image = resampleOp.filter(original, null);
|
||||
return image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get image using relative path in resources.
|
||||
* @param path
|
||||
* @return
|
||||
*/
|
||||
public static Image getImageFromResources(String path) {
|
||||
InputStream stream;
|
||||
stream = UI.class.getResourceAsStream(path);
|
||||
if (stream == null) {
|
||||
throw new IllegalArgumentException("Couldn't find image in resources: " + path);
|
||||
}
|
||||
/**
|
||||
* Get image using relative path in resources.
|
||||
* @param path
|
||||
* @return
|
||||
*/
|
||||
public static Image getImageFromResources(String path) {
|
||||
InputStream stream;
|
||||
stream = UI.class.getResourceAsStream(path);
|
||||
if (stream == null) {
|
||||
throw new IllegalArgumentException("Couldn't find image in resources: " + path);
|
||||
}
|
||||
|
||||
try {
|
||||
BufferedImage image = ImageIO.read(stream);
|
||||
return image;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
BufferedImage image = ImageIO.read(stream);
|
||||
return image;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue