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 javax.swing.Icon;
00026 import javax.swing.ImageIcon;
00027 import org.jetbrains.annotations.NotNull;
00028
00033 public class ImageScale8d {
00034
00038 @NotNull
00039 private final int[] srcData;
00040
00044 private final int width;
00045
00049 private final int height;
00050
00055 public ImageScale8d(@NotNull final Icon srcImageIcon) {
00056 width = srcImageIcon.getIconWidth();
00057 height = srcImageIcon.getIconHeight();
00058
00059 srcData = new int[width*height];
00060 final BufferedImage srcBufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
00061 srcImageIcon.paintIcon(null, srcBufferedImage.getGraphics(), 0, 0);
00062 srcBufferedImage.getRGB(0, 0, width, height, srcData, 0, width);
00063 }
00064
00070 @NotNull
00071 public ImageIcon getScaledImage() {
00072 final RawScale8d scaler = new RawScale8d(srcData, width, height);
00073
00074 final BufferedImage image = new BufferedImage(width/8, height/8, BufferedImage.TYPE_INT_ARGB);
00075 image.setRGB(0, 0, width/8, height/8, scaler.getScaledData(), 0, width/8);
00076
00077 return new ImageIcon(image);
00078 }
00079
00080 }