Search in sources :

Example 66 with IndexColorModel

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;
}
Also used : UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) DataBufferByte(java.awt.image.DataBufferByte) Point(java.awt.Point) BufferedImage(java.awt.image.BufferedImage) IndexColorModel(java.awt.image.IndexColorModel)

Example 67 with IndexColorModel

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;
}
Also used : ImageStatistics(cbit.vcell.VirtualMicroscopy.Image.ImageStatistics) DataBufferByte(java.awt.image.DataBufferByte) Point(java.awt.Point) BufferedImage(java.awt.image.BufferedImage) IndexColorModel(java.awt.image.IndexColorModel)

Example 68 with IndexColorModel

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;
}
Also used : IndexColorModel(java.awt.image.IndexColorModel)

Example 69 with IndexColorModel

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());
    }
}
Also used : ColorModel(java.awt.image.ColorModel) DirectColorModel(java.awt.image.DirectColorModel) IndexColorModel(java.awt.image.IndexColorModel) DirectColorModel(java.awt.image.DirectColorModel) PixelGrabber(java.awt.image.PixelGrabber) IOException(java.io.IOException) IndexColorModel(java.awt.image.IndexColorModel)

Example 70 with IndexColorModel

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;
}
Also used : ImageIcon(javax.swing.ImageIcon) VCPixelClass(cbit.image.VCPixelClass) VCImage(cbit.image.VCImage) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) ThumbnailImage(cbit.image.ThumbnailImage) IndexColorModel(java.awt.image.IndexColorModel) IndexColorModel(java.awt.image.IndexColorModel)

Aggregations

IndexColorModel (java.awt.image.IndexColorModel)74 ColorModel (java.awt.image.ColorModel)30 BufferedImage (java.awt.image.BufferedImage)29 DirectColorModel (java.awt.image.DirectColorModel)17 Point (java.awt.Point)14 WritableRaster (java.awt.image.WritableRaster)12 SampleModel (java.awt.image.SampleModel)10 ComponentColorModel (java.awt.image.ComponentColorModel)8 Rectangle (java.awt.Rectangle)7 DataBufferByte (java.awt.image.DataBufferByte)7 MultiPixelPackedSampleModel (java.awt.image.MultiPixelPackedSampleModel)7 Raster (java.awt.image.Raster)7 ComponentSampleModel (java.awt.image.ComponentSampleModel)6 Graphics2D (java.awt.Graphics2D)5 ColorSpace (java.awt.color.ColorSpace)5 Color (java.awt.Color)4 Graphics (java.awt.Graphics)4 ICC_ColorSpace (java.awt.color.ICC_ColorSpace)4 SinglePixelPackedSampleModel (java.awt.image.SinglePixelPackedSampleModel)4 IOException (java.io.IOException)4