use of java.awt.image.IndexColorModel in project vcell by virtualcell.
the class VFrap_OverlayEditorPanelJAI method createHighlightImageFromROI.
/**
* Method createHighlightImageFromROI.
* @return BufferedImage
*/
private BufferedImage createHighlightImageFromROI() {
int[] cmap = new int[256];
// colormap (grayscale)
for (int i = 0; i < 256; i += 1) {
if (i != 0) {
cmap[i] = 0xFF000000 | highlightColor.getRGB();
} else {
cmap[1] = 0xFF000000;
}
}
IndexColorModel indexColorModel = new java.awt.image.IndexColorModel(8, cmap.length, cmap, 0, false, /*false means NOT USE alpha*/
-1, /*NO transparent single pixel*/
java.awt.image.DataBuffer.TYPE_BYTE);
UShortImage roiImage = roi.getRoiImages()[getRoiImageIndex()];
int width = roiImage.getNumX();
int height = roiImage.getNumY();
BufferedImage hiLiteImage = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_INDEXED, indexColorModel);
byte[] hiLiteArr = ((DataBufferByte) hiLiteImage.getRaster().getDataBuffer()).getData();
for (int i = 0; i < roiImage.getPixels().length; i++) {
hiLiteArr[i] = (roiImage.getPixels()[i] != 0 ? (byte) highlightColor.getRed() : 0);
}
return hiLiteImage;
}
use of java.awt.image.IndexColorModel in project vcell by virtualcell.
the class VFrap_OverlayEditorPanelJAI method createUnderlyingImage.
/**
* Method createUnderlyingImage.
* @param image UShortImage
* @return BufferedImage
*/
private BufferedImage createUnderlyingImage(UShortImage image) {
int[] cmap = new int[256];
// colormap (grayscale)
for (int i = 0; i < 256; i += 1) {
int iv = (0x000000FF & i);
cmap[i] = 0xFF000000 | iv << 16 | iv << 8 | i;
}
IndexColorModel indexColorModel = new java.awt.image.IndexColorModel(8, cmap.length, cmap, 0, false, /*false means NOT USE alpha*/
-1, /*NO transparent single pixel*/
java.awt.image.DataBuffer.TYPE_BYTE);
int width = image.getNumX();
int height = image.getNumY();
ImageStatistics imageStats = image.getImageStatistics();
short[] pixels = image.getPixels();
BufferedImage underImage = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_INDEXED, indexColorModel);
byte[] byteData = ((DataBufferByte) underImage.getRaster().getDataBuffer()).getData();
for (int i = 0; i < byteData.length; i++) {
byteData[i] = (imageStats.maxValue < SHORT_TO_BYTE_FACTOR ? (byte) pixels[i] : (byte) (((pixels[i] & 0x0000FFFF)) / SHORT_TO_BYTE_FACTOR));
}
return underImage;
}
use of java.awt.image.IndexColorModel in project vcell by virtualcell.
the class NativeImage method createRGBAPixels.
/**
* This method was created in VisualAge.
* @return int[]
*/
private int[] createRGBAPixels() throws Exception {
createPixels();
if (newRGBAPixels != null) {
return newRGBAPixels;
}
// Get rgb colors from index color pixels
IndexColorModel colorModel = getIndexColorModel();
int[] tryRGBAPixels = new int[newIndexPixels.length];
for (int c = 0; c < tryRGBAPixels.length; c += 1) {
tryRGBAPixels[c] = colorModel.getRGB((int) (0xFF & newIndexPixels[c]));
}
newRGBAPixels = tryRGBAPixels;
return newRGBAPixels;
}
use of java.awt.image.IndexColorModel in project vcell by virtualcell.
the class NativeImage method createPixels.
/**
* This method was created in VisualAge.
* @return byte[]
*/
private void createPixels() throws Exception {
if (bPixelsExist()) {
return;
}
PixelGrabber pg = new PixelGrabber(getJavaImage(), 0, 0, getSize().getX(), getSize().getX(), false);
if (!pg.grabPixels()) {
throw new Exception("Error getting pixels, status = " + pg.getStatus());
}
Object pixels = pg.getPixels();
ColorModel colorModel = null;
while (colorModel == null) {
colorModel = pg.getColorModel();
}
if ((pixels instanceof int[]) && (colorModel instanceof DirectColorModel)) {
newRGBAPixels = (int[]) pixels;
} else if ((pixels instanceof byte[]) && (colorModel instanceof IndexColorModel)) {
newIndexPixels = (byte[]) pixels;
IndexColorModel indexColorModel = (IndexColorModel) colorModel;
int colorMapSize = indexColorModel.getMapSize();
byte[] temp_colorMap = new byte[colorMapSize * IndexColorMap.RGB_PACK_SIZE];
byte[] reds = new byte[colorMapSize];
indexColorModel.getReds(reds);
byte[] greens = new byte[colorMapSize];
indexColorModel.getGreens(greens);
byte[] blues = new byte[colorMapSize];
indexColorModel.getBlues(blues);
for (int c = 0; c < colorMapSize; c += 1) {
// make packed R,G,B array for ColorIndexModel
int packCount = c * IndexColorMap.RGB_PACK_SIZE;
temp_colorMap[packCount] = reds[c];
temp_colorMap[packCount + 1] = greens[c];
temp_colorMap[packCount + 2] = blues[c];
}
colorMap = new IndexColorMap(temp_colorMap);
} else {
throw new Exception("Unknown combination of data type=" + pixels.getClass().toString() + " and ColorModel=" + colorModel.getClass().toString());
}
}
use of java.awt.image.IndexColorModel in project vcell by virtualcell.
the class GeometryThumbnailImageFactoryAWT method getThumbnailImage.
public ThumbnailImage getThumbnailImage(GeometrySpec geometrySpec) throws ImageException {
int REAL_SAMPLE_X = 0;
int REAL_SAMPLE_Y = 0;
if (geometrySpec.getDimension() > 0) {
// Calc Scaling parameters
double srcScaleX = SAMPLED_GEOM_SIZE_MAX / geometrySpec.getExtent().getX();
double srcScaleY = SAMPLED_GEOM_SIZE_MAX / geometrySpec.getExtent().getY();
if (srcScaleX < srcScaleY) {
REAL_SAMPLE_X = SAMPLED_GEOM_SIZE_MAX;
REAL_SAMPLE_Y = Math.max((int) (srcScaleX * geometrySpec.getExtent().getY()), 1);
} else {
REAL_SAMPLE_Y = SAMPLED_GEOM_SIZE_MAX;
REAL_SAMPLE_X = Math.max((int) (srcScaleY * geometrySpec.getExtent().getX()), 1);
}
}
if (geometrySpec.getDimension() > 0) {
BufferedImage brightImage = new BufferedImage(REAL_SAMPLE_X, REAL_SAMPLE_Y, BufferedImage.TYPE_INT_RGB);
Graphics2D brightG2D = brightImage.createGraphics();
brightG2D.setColor(java.awt.Color.white);
brightG2D.fillRect(0, 0, REAL_SAMPLE_X, REAL_SAMPLE_Y);
VCImage currSampledImage = geometrySpec.getSampledImage().getCurrentValue();
java.awt.image.IndexColorModel handleColorMap = DisplayAdapterService.getHandleColorMap();
byte[] reds = new byte[256];
handleColorMap.getReds(reds);
byte[] greens = new byte[256];
handleColorMap.getGreens(greens);
byte[] blues = new byte[256];
handleColorMap.getBlues(blues);
// Create projections of each subvolume handle
VCPixelClass[] pixClassHandles = currSampledImage.getPixelClasses();
byte[] pixels = currSampledImage.getPixels();
for (int i = 0; i < pixClassHandles.length; i += 1) {
byte[] zBuf = new byte[currSampledImage.getNumX() * currSampledImage.getNumY()];
java.util.Arrays.fill(zBuf, (byte) 0);
// Project z
for (int j = 0; j < pixels.length; j += 1) {
if (pixels[j] == pixClassHandles[i].getPixel()) {
zBuf[j % zBuf.length] = (byte) 1;
}
}
// Scale X-Y
int cmapIndex = (pixClassHandles[i].getPixel() & 0xff);
byte ired = reds[cmapIndex];
byte igrn = greens[cmapIndex];
byte iblu = blues[cmapIndex];
IndexColorModel colorModel = new IndexColorModel(8, 2, new byte[] { 0, ired }, new byte[] { 0, igrn }, new byte[] { 0, iblu }, new byte[] { 0, (byte) (200) });
int width = currSampledImage.getNumX();
int height = currSampledImage.getNumY();
BufferedImage bufferedImage = getImage(colorModel, zBuf, width, height);
ImageIcon theImageIcon = new ImageIcon(bufferedImage.getScaledInstance(REAL_SAMPLE_X, REAL_SAMPLE_Y, Image.SCALE_AREA_AVERAGING));
brightG2D.drawImage(theImageIcon.getImage(), 0, 0, theImageIcon.getImageObserver());
}
int[] rgb = brightImage.getRGB(0, 0, REAL_SAMPLE_X, REAL_SAMPLE_Y, null, 0, REAL_SAMPLE_X);
return new ThumbnailImage(rgb, REAL_SAMPLE_X, REAL_SAMPLE_Y, brightImage);
}
return null;
}
Aggregations