use of java.awt.image.WritableRaster in project vcell by virtualcell.
the class OverlayEditorPanelJAI method createUnderlyingImage.
/**
* Method createUnderlyingImage.
* @param image UShortImage
* @return BufferedImage
*/
private BufferedImage createUnderlyingImage(UShortImage image) {
short[] pixels = image.getPixels();
WritableRaster raster = greyIndexColorModel.createCompatibleWritableRaster(image.getNumX(), image.getNumY());
byte[] byteData = ((DataBufferByte) raster.getDataBuffer()).getData();
if (allPixelValuesRange.getScaleFactor() >= 1) {
for (int i = 0; i < byteData.length; i++) {
byteData[i] = (byte) (pixels[i] & 0x0000FFFF);
}
} else {
for (int i = 0; i < byteData.length; i++) {
byteData[i] = (byte) ((pixels[i] & 0x0000FFFF) * allPixelValuesRange.getScaleFactor());
}
}
BufferedImage result = new BufferedImage(greyIndexColorModel, raster, false, null);
return result;
}
use of java.awt.image.WritableRaster in project vcell by virtualcell.
the class OverlayImageDisplayJAI method computeComposite.
private BufferedImage computeComposite(RenderedImage contrastEnhancedUnderlyingImage) {
// Improve memory use by saving 1 composite image in hash and re-use if sizes don't change
Rectangle imageSizeRect = new Rectangle(0, 0, contrastEnhancedUnderlyingImage.getWidth(), contrastEnhancedUnderlyingImage.getHeight());
BufferedImage result = compositeHash.get(imageSizeRect);
if (result == null) {
compositeHash.clear();
DirectColorModel dcm = new DirectColorModel(32, 0x00FF0000, 0x0000FF00, 0x000000FF);
WritableRaster newOverlayRaster = dcm.createCompatibleWritableRaster(imageSizeRect.width, imageSizeRect.height);
result = new BufferedImage(dcm, newOverlayRaster, false, null);
compositeHash.put(imageSizeRect, result);
}
try {
int[] newOverlayRasterInts = ((DataBufferInt) result.getRaster().getDataBuffer()).getData();
byte[] contrastUnderlayBytes = ((DataBufferByte) contrastEnhancedUnderlyingImage.getData().getDataBuffer()).getData();
byte[] roiBytes = (allROICompositeImage == null ? null : ((DataBufferByte) allROICompositeImage.getData().getDataBuffer()).getData());
byte[] highlightBytes = (highlightImage == null ? null : ((DataBufferByte) highlightImage.getData().getDataBuffer()).getData());
if (roiBytes != null && roiBytes.length != contrastUnderlayBytes.length) {
return result;
}
if (highlightBytes != null && highlightBytes.length != contrastUnderlayBytes.length) {
return result;
}
int index = 0;
for (int Y = 0; Y < contrastEnhancedUnderlyingImage.getHeight(); Y++) {
for (int X = 0; X < contrastEnhancedUnderlyingImage.getWidth(); X++) {
// if(roiBytes[index] != 0){
// System.out.println("X "+X+" Y "+Y+
// " roi="+(0x000000FF&roiBytes[index])+
// " under="+(underlayBytes[index]&0x000000FF)+
// " color="+Hex.toString(blendARGB[roiBytes[index]&0x000000FF][underlayBytes[index]&0x000000FF]));
// }
newOverlayRasterInts[index] = blendARGB[(highlightBytes == null ? 0 : (highlightBytes[index] == 0 ? 0 : 1))][(roiBytes == null ? 0 : roiBytes[index] & 0x000000FF)][contrastUnderlayBytes[index] & 0x000000FF];
index++;
}
}
} catch (Exception e) {
e.printStackTrace();
// ignore, try to display what you have
}
return result;
}
use of java.awt.image.WritableRaster in project yamcs-studio by yamcs.
the class AWT2SWTImageConverter method convertToSWT.
static ImageData convertToSWT(BufferedImage bufferedImage) {
if (bufferedImage.getColorModel() instanceof DirectColorModel) {
DirectColorModel colorModel = (DirectColorModel) bufferedImage.getColorModel();
PaletteData palette = new PaletteData(colorModel.getRedMask(), colorModel.getGreenMask(), colorModel.getBlueMask());
ImageData data = new ImageData(bufferedImage.getWidth(), bufferedImage.getHeight(), colorModel.getPixelSize(), palette);
for (int y = 0; y < data.height; y++) {
for (int x = 0; x < data.width; x++) {
int rgb = bufferedImage.getRGB(x, y);
int pixel = palette.getPixel(new RGB((rgb >> 16) & 0xFF, (rgb >> 8) & 0xFF, rgb & 0xFF));
data.setPixel(x, y, pixel);
}
}
return data;
} else if (bufferedImage.getColorModel() instanceof IndexColorModel) {
IndexColorModel colorModel = (IndexColorModel) bufferedImage.getColorModel();
int size = colorModel.getMapSize();
byte[] reds = new byte[size];
byte[] greens = new byte[size];
byte[] blues = new byte[size];
colorModel.getReds(reds);
colorModel.getGreens(greens);
colorModel.getBlues(blues);
RGB[] rgbs = new RGB[size];
for (int i = 0; i < rgbs.length; i++) {
rgbs[i] = new RGB(reds[i] & 0xFF, greens[i] & 0xFF, blues[i] & 0xFF);
}
PaletteData palette = new PaletteData(rgbs);
ImageData data = new ImageData(bufferedImage.getWidth(), bufferedImage.getHeight(), colorModel.getPixelSize(), palette);
data.transparentPixel = colorModel.getTransparentPixel();
WritableRaster raster = bufferedImage.getRaster();
int[] pixelArray = new int[1];
for (int y = 0; y < data.height; y++) {
for (int x = 0; x < data.width; x++) {
raster.getPixel(x, y, pixelArray);
data.setPixel(x, y, pixelArray[0]);
}
}
return data;
}
return null;
}
use of java.awt.image.WritableRaster in project yamcs-studio by yamcs.
the class AWT2SWTImageConverter method convertToAWT.
static BufferedImage convertToAWT(ImageData data) {
ColorModel colorModel = null;
PaletteData palette = data.palette;
if (palette.isDirect) {
colorModel = new DirectColorModel(data.depth, palette.redMask, palette.greenMask, palette.blueMask);
BufferedImage bufferedImage = new BufferedImage(colorModel, colorModel.createCompatibleWritableRaster(data.width, data.height), false, null);
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);
bufferedImage.setRGB(x, y, rgb.red << 16 | rgb.green << 8 | rgb.blue);
}
}
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];
red[i] = (byte) rgb.red;
green[i] = (byte) rgb.green;
blue[i] = (byte) rgb.blue;
}
if (data.transparentPixel != -1) {
colorModel = new IndexColorModel(data.depth, rgbs.length, red, green, blue, data.transparentPixel);
} else {
colorModel = new IndexColorModel(data.depth, rgbs.length, red, green, blue);
}
BufferedImage bufferedImage = new BufferedImage(colorModel, colorModel.createCompatibleWritableRaster(data.width, data.height), false, null);
WritableRaster raster = bufferedImage.getRaster();
int[] pixelArray = new int[1];
for (int y = 0; y < data.height; y++) {
for (int x = 0; x < data.width; x++) {
int pixel = data.getPixel(x, y);
pixelArray[0] = pixel;
raster.setPixel(x, y, pixelArray);
}
}
return bufferedImage;
}
}
use of java.awt.image.WritableRaster in project processdash by dtuma.
the class TeamMemberTimeCellRenderer method getGradient.
/** Construct a Paint that can be used to fade to the background color.
*/
protected Paint getGradient() {
Color backgroundColor = getBackground();
BufferedImage i = new BufferedImage(gradientWidth, 1, BufferedImage.TYPE_INT_ARGB);
WritableRaster alpha = i.getAlphaRaster();
for (int x = gradientWidth; x-- > 0; ) {
i.setRGB(x, 0, backgroundColor.getRGB());
double sample = gradientWidth - x;
sample = sample / gradientWidth;
sample = (1.0 - sample * sample) * 255;
alpha.setSample(x, 0, 0, sample);
}
// to perform a quadratic fade instead of a linear fade.
return new TexturePaint(i, new Rectangle(leftBorder, 0, gradientWidth, 1));
}
Aggregations