Search in sources :

Example 56 with DataBufferByte

use of java.awt.image.DataBufferByte 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 57 with DataBufferByte

use of java.awt.image.DataBufferByte in project vcell by virtualcell.

the class FormatSpecificSpecs method getVideoMediaSample.

public static VideoMediaSample getVideoMediaSample(int width, int height, int sampleDuration, boolean isGrayScale, int compressionType, float compressionQuality, int[] argbData) throws Exception {
    if (isGrayScale) {
        // convert 32bit to 8bit
        BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);
        byte[] buffer = ((DataBufferByte) bufferedImage.getRaster().getDataBuffer()).getData();
        for (int i = 0; i < buffer.length; i++) {
            buffer[i] = (byte) (argbData[i] & 0x000000FF);
        }
        if (compressionType == FormatSpecificSpecs.CODEC_JPEG) {
            return FormatSpecificSpecs.encodeJPEG(bufferedImage, compressionQuality, width, height, sampleDuration, Byte.SIZE, true);
        } else {
            return new VideoMediaSampleRaw(width, height, sampleDuration, buffer, 8, true);
        }
    }
    if (compressionType == FormatSpecificSpecs.CODEC_JPEG) {
        BufferedImage bufferedImage = null;
        bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        System.arraycopy(argbData, 0, ((DataBufferInt) bufferedImage.getRaster().getDataBuffer()).getData(), 0, argbData.length);
        return FormatSpecificSpecs.encodeJPEG(bufferedImage, compressionQuality, width, height, sampleDuration, Integer.SIZE, false);
    } else {
        ByteArrayOutputStream sampleBytes = new ByteArrayOutputStream();
        DataOutputStream sampleData = new DataOutputStream(sampleBytes);
        for (int j = 0; j < argbData.length; j++) {
            sampleData.writeInt(argbData[j]);
        }
        sampleData.close();
        byte[] bytes = sampleBytes.toByteArray();
        return new VideoMediaSampleRaw(width, height, sampleDuration, bytes, Integer.SIZE, false);
    }
}
Also used : DataOutputStream(java.io.DataOutputStream) VideoMediaSampleRaw(cbit.vcell.export.gloworm.quicktime.VideoMediaSampleRaw) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataBufferByte(java.awt.image.DataBufferByte) BufferedImage(java.awt.image.BufferedImage)

Example 58 with DataBufferByte

use of java.awt.image.DataBufferByte in project vcell by virtualcell.

the class GeometryThumbnailImageFactoryAWT method getImage.

private static BufferedImage getImage(IndexColorModel indexColorModel, byte[] imageIndiciesIntoPalette, int width, int height) {
    BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_INDEXED, indexColorModel);
    WritableRaster raster = bufferedImage.getRaster();
    DataBufferByte dataBuffer = (DataBufferByte) raster.getDataBuffer();
    System.arraycopy(imageIndiciesIntoPalette, 0, dataBuffer.getData(), 0, imageIndiciesIntoPalette.length);
    return bufferedImage;
}
Also used : WritableRaster(java.awt.image.WritableRaster) DataBufferByte(java.awt.image.DataBufferByte) BufferedImage(java.awt.image.BufferedImage)

Example 59 with DataBufferByte

use of java.awt.image.DataBufferByte in project vcell by virtualcell.

the class OverlayEditorPanelJAI method createHighlightImageFromROI.

/**
 * Method createHighlightImageFromROI.
 * @return BufferedImage
 */
private BufferedImage createHighlightImageFromROI(ROI highlightImageROI) {
    UShortImage roiImage = highlightImageROI.getRoiImages()[getRoiImageIndex()];
    int width = roiImage.getNumX();
    int height = roiImage.getNumY();
    BufferedImage hiLiteImage = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_INDEXED, getHiliteColorModel());
    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)

Example 60 with DataBufferByte

use of java.awt.image.DataBufferByte in project vcell by virtualcell.

the class OverlayEditorPanelJAI method updateLabel.

/**
 * Updates cursor probe label. * @param x int
 * @param y int
 */
private void updateLabel(int inx, int iny) {
    if (imageDataset == null) {
        return;
    }
    float zoom = imagePane.getZoom();
    if ((inx / zoom) >= imageDataset.getISize().getX() || (iny / zoom) >= imageDataset.getISize().getY()) {
        inx = -1;
        iny = -1;
    }
    int x = (int) (inx / zoom);
    int y = (int) (iny / zoom);
    UShortImage[] images = imageDataset.getAllImages();
    sb.setLength(0);
    boolean bMultipleZ = imageDataset.getSizeZ() > 1;
    if (bMultipleZ) {
        sb.append("; Z=");
        sb.append(getZ() + 1);
        sb.append("/");
        sb.append(imageDataset.getSizeZ());
        if (calcCoords != null) {
            sb.append(" " + NumberUtils.formatNumber(calcCoords.calcZ(getZ()), 6) + "/" + NumberUtils.formatNumber(calcCoords.extentZ(), 6));
        }
    }
    if (imageDataset.getSizeT() > 1) {
        sb.append((bMultipleZ ? "; " : "") + "T=");
        sb.append(imageDataset.getImageTimeStamps()[getT()]);
    }
    int w = imageDataset == null ? -1 : imageDataset.getISize().getX();
    int h = imageDataset == null ? -1 : imageDataset.getISize().getY();
    if (x >= w)
        x = w - 1;
    if (y >= h)
        y = h - 1;
    if (x >= 0 && y >= 0 && inx >= 0 && iny >= 0 && x < imageDataset.getISize().getX() && y < imageDataset.getISize().getY()) {
        if (images.length > 1)
            sb.append("; ");
        sb.append("X=");
        sb.append(x);
        if (w > 0) {
            sb.append("/");
            sb.append(w);
            if (calcCoords != null) {
                sb.append(" " + NumberUtils.formatNumber(calcCoords.calcX(inx), 6) + "/" + NumberUtils.formatNumber(calcCoords.extentX(), 6));
            }
        }
        sb.append("; Y=");
        sb.append(y);
        if (h > 0) {
            sb.append("/");
            sb.append(h);
            if (calcCoords != null) {
                sb.append(" " + NumberUtils.formatNumber(calcCoords.calcY(iny), 6) + "/" + NumberUtils.formatNumber(calcCoords.extentY(), 6));
            }
        }
        sb.append("; zoom(" + NumberUtils.formatNumber(imagePane.getZoom(), 3) + ")");
        sb.append("; contr(" + imagePane.getContrastDescription() + ")");
        if (imageDataset != null) {
            short[] pix = null;
            try {
                pix = new short[imageDataset.getSizeC()];
                for (int i = 0; i < pix.length; i++) {
                    pix[i] = imageDataset.getImage(getZ(), i, getT()).getPixel(x, y, 0);
                }
            } catch (Exception e) {
                pix = null;
                e.printStackTrace();
            // do nothing
            }
            sb.append("; value(img)" + (isOriginalValueScaled() ? "(scld)" : ""));
            if (pix != null) {
                if (histogramPanel.isVisible()) {
                    histogramPanel.setSpecialValue((int) (pix[0] & 0x0000FFFF));
                }
                sb.append(pix.length > 1 ? "s=(" : "=");
                for (int i = 0; i < pix.length; i++) {
                    if (i > 0)
                        sb.append(", ");
                    sb.append((int) (pix[i] & 0x0000FFFF));
                }
                if (pix.length > 1)
                    sb.append(")");
            } else {
                sb.append(" error");
            }
            if (isOriginalValueScaled()) {
                sb.append("; value(img)(orig)");
                if (pix != null) {
                    sb.append(pix.length > 1 ? "s=(" : "=");
                    for (int i = 0; i < pix.length; i++) {
                        if (i > 0)
                            sb.append(", ");
                        sb.append(NumberUtils.formatNumber((((int) (pix[i] & 0x0000FFFF)) - originalOffsetFactor) / originalScaleFactor, 6));
                    }
                    if (pix.length > 1)
                        sb.append(")");
                } else {
                    sb.append(" error");
                }
            }
        }
        if (allROICompositeImageArr != null) {
            // System.out.println(getZ()+" "+x+" "+y);
            DataBufferByte dataBufferByte = (DataBufferByte) (allROICompositeImageArr[getZ()].getRaster().getDataBuffer());
            sb.append(" val(roi)=" + dataBufferByte.getData()[y * allROICompositeImageArr[0].getWidth() + x]);
        }
    } else {
        sb.append((sb.length() != 0 ? "; " : "") + "zoom(" + NumberUtils.formatNumber(imagePane.getZoom(), 3) + ")");
        sb.append("; contr(" + imagePane.getContrastDescription() + ")");
        if (histogramPanel.isVisible()) {
            histogramPanel.setSpecialValue(null);
        }
    }
    sb.append(" ");
    textLabel.setText(sb.toString());
}
Also used : UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) DataBufferByte(java.awt.image.DataBufferByte) Point(java.awt.Point) UtilCancelException(org.vcell.util.UtilCancelException) UserCancelException(org.vcell.util.UserCancelException)

Aggregations

DataBufferByte (java.awt.image.DataBufferByte)64 BufferedImage (java.awt.image.BufferedImage)38 Point (java.awt.Point)36 WritableRaster (java.awt.image.WritableRaster)18 DataBufferInt (java.awt.image.DataBufferInt)14 DataBuffer (java.awt.image.DataBuffer)13 DataBufferShort (java.awt.image.DataBufferShort)10 UShortImage (cbit.vcell.VirtualMicroscopy.UShortImage)8 Rectangle (java.awt.Rectangle)8 SampleModel (java.awt.image.SampleModel)8 DataBufferUShort (java.awt.image.DataBufferUShort)7 IndexColorModel (java.awt.image.IndexColorModel)7 MultiPixelPackedSampleModel (java.awt.image.MultiPixelPackedSampleModel)7 Graphics2D (java.awt.Graphics2D)6 ComponentSampleModel (java.awt.image.ComponentSampleModel)6 UserCancelException (org.vcell.util.UserCancelException)6 UtilCancelException (org.vcell.util.UtilCancelException)6 SinglePixelPackedSampleModel (java.awt.image.SinglePixelPackedSampleModel)5 Hashtable (java.util.Hashtable)5 VCImage (cbit.image.VCImage)4