00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 package com.realtime.crossfire.jxclient.faces;
00023
00024 import java.awt.image.BufferedImage;
00025 import java.io.File;
00026 import javax.swing.Icon;
00027 import javax.swing.ImageIcon;
00028 import org.jetbrains.annotations.NotNull;
00029
00034 public class ImageScale2x {
00035
00039 @NotNull
00040 private final int[] srcData;
00041
00045 private final int width;
00046
00050 private final int height;
00051
00056 public ImageScale2x(@NotNull final Icon srcImageIcon) {
00057 width = srcImageIcon.getIconWidth();
00058 height = srcImageIcon.getIconHeight();
00059
00060 srcData = new int[width*height];
00061 final BufferedImage srcBufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
00062 srcImageIcon.paintIcon(null, srcBufferedImage.getGraphics(), 0, 0);
00063 srcBufferedImage.getRGB(0, 0, width, height, srcData, 0, width);
00064 }
00065
00071 @NotNull
00072 public ImageIcon getScaledImage() {
00073 final RawScale2x scaler = new RawScale2x(srcData, width, height);
00074
00075 final BufferedImage image = new BufferedImage(width*2, height*2, BufferedImage.TYPE_INT_ARGB);
00076 image.setRGB(0, 0, width*2, height*2, scaler.getScaledData(), 0, width*2);
00077
00078 return new ImageIcon(image);
00079 }
00080
00085 public static void main(@NotNull final String[] args) {
00086 final String srcFile = "randam_orig.png";
00087 System.out.println("Reading: "+srcFile);
00088 final ImageIcon src = new ImageIcon(srcFile);
00089 final ImageScale2x scaler = new ImageScale2x(src);
00090 final Icon out = scaler.getScaledImage();
00091
00092 final String outFile = srcFile.substring(0, srcFile.length()-4)+"2x.png";
00093 System.out.println("Writing: "+outFile);
00094 final FileCache fileCache = new FileCache(new File("cache"));
00095 fileCache.save(outFile, 0, out);
00096 }
00097
00098 }