* </p>
* @return a Buffered Image
*/
public static BufferedImage convertToAWT(ImageData data) {
ColorModel colorModel = null;
PaletteData palette = data.palette;
if (palette.isDirect) {
// no alpha data?
if(data.alphaData==null) {
colorModel = new DirectColorModel(32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
BufferedImage bufferedImage = new BufferedImage(colorModel,
colorModel.createCompatibleWritableRaster(data.width, data.height),
false, null);
WritableRaster raster = bufferedImage.getRaster();
int[] pixelArray = new int[4];
for (int y = 0; y < data.height; y++) {
for (int x = 0; x < data.width; x++) {
int pixel = data.getPixel(x, y);
RGB rgb = palette.getRGB(pixel);
pixelArray[0] = rgb.red;
pixelArray[1] = rgb.green;
pixelArray[2] = rgb.blue;
if (pixel == data.transparentPixel) {
pixelArray[3]=0; // transparent
}
else {
pixelArray[3]=255; // opaque
}
raster.setPixels(x, y, 1, 1, pixelArray);
}
}
int w = bufferedImage.getWidth();
int h = bufferedImage.getHeight();
Raster ras = bufferedImage.getData();
for( int i = 0; i < w; i++ ) {
for( int j = 0; j < h; j++ ) {
double[] pixel = ras.getPixel(i, j, new double[4]);
}
}
return bufferedImage;
}
// image has alpha data, preserve it
else {
colorModel = new DirectColorModel(32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
BufferedImage bufferedImage = new BufferedImage(colorModel,
colorModel.createCompatibleWritableRaster(data.width, data.height),
false, null);
WritableRaster raster = bufferedImage.getRaster();
int[] pixelArray = new int[4];
for (int y = 0; y < data.height; y++) {
for (int x = 0; x < data.width; x++) {
int pixel = data.getPixel(x, y);
RGB rgb = palette.getRGB(pixel);
pixelArray[0] = rgb.red;
pixelArray[1] = rgb.green;
pixelArray[2] = rgb.blue;
pixelArray[3]=data.getAlpha(x,y);
raster.setPixels(x, y, 1, 1, pixelArray);
}
}
return bufferedImage;
}
//la paleta swt no es directa �?�?�?
// ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_sRGB);
// colorModel = new DirectColorModel(colorSpace, data.depth, palette.redMask,
// palette.greenMask, palette.blueMask, 0, false, DataBuffer.TYPE_INT);
//// colorModel = new DirectColorModel(data.depth, palette.redMask,
//// palette.greenMask, palette.blueMask);
// BufferedImage bufferedImage = new BufferedImage(colorModel,
// colorModel.createCompatibleWritableRaster(data.width,
// data.height), false, null);
// WritableRaster raster = bufferedImage.getRaster();
// int[] pixelArray = new int[3];
// for (int y = 0; y < data.height; y++) {
// for (int x = 0; x < data.width; x++) {
// int pixel = data.getPixel(x, y);
// RGB rgb = palette.getRGB(pixel);
// pixelArray[0] = rgb.red;
// pixelArray[1] = rgb.green;
// pixelArray[2] = rgb.blue;
// raster.setPixels(x, y, 1, 1, pixelArray);
// }
// }
// return bufferedImage;
} else {
RGB[] rgbs = palette.getRGBs();
byte[] red = new byte[rgbs.length];
byte[] green = new byte[rgbs.length];
byte[] blue = new byte[rgbs.length];
for (int i = 0; i < rgbs.length; i++) {
RGB rgb = rgbs[i];