Search in sources :

Example 61 with DataBufferByte

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

the class VFrapXmlHelper method LoadVFrapDisplayRoi.

// load ROI images
public static void LoadVFrapDisplayRoi(Hashtable<String, Object> hashTable, AnnotatedImageDataset annotatedImages, ROI[] rois) {
    // was roiComposite
    BufferedImage[] displayROI = null;
    // make roi composite
    int[] cmap = new int[256];
    for (int i = 0; i < 256; i += 1) {
        cmap[i] = OverlayEditorPanelJAI.CONTRAST_COLORS[i].getRGB();
        if (i == 0) {
            cmap[i] = new Color(0, 0, 0, 0).getRGB();
        }
    }
    IndexColorModel indexColorModel = new java.awt.image.IndexColorModel(8, cmap.length, cmap, 0, // false means NOT USE alpha
    false, // NO transparent single pixel
    -1, java.awt.image.DataBuffer.TYPE_BYTE);
    displayROI = new BufferedImage[annotatedImages.getImageDataset().getSizeZ()];
    for (int i = 0; i < displayROI.length; i++) {
        displayROI[i] = new BufferedImage(annotatedImages.getImageDataset().getISize().getX(), annotatedImages.getImageDataset().getISize().getY(), BufferedImage.TYPE_BYTE_INDEXED, indexColorModel);
    }
    int xysize = annotatedImages.getImageDataset().getISize().getX() * annotatedImages.getImageDataset().getISize().getY();
    for (int i = 0; i < rois.length; i++) {
        short[] roiBits = rois[i].getBinaryPixelsXYZ(1);
        for (int j = 0; j < roiBits.length; j++) {
            int roiZindex = j / (xysize);
            byte[] roiData = ((DataBufferByte) displayROI[roiZindex].getRaster().getDataBuffer()).getData();
            if (roiBits[j] != 0 && (rois[i].getROIName().equals(AnnotatedImageDataset.VFRAP_ROI_ENUM.ROI_BLEACHED) || roiData[j % xysize] == 0)) {
                roiData[j % xysize] = (byte) (i + 1);
            // if(i!= 0){
            // System.out.println("roi="+i+" j="+j+" j%="+(j%xysize)+" z="+roiZindex+" roidata="+roiData[j%xysize]);
            // }
            }
        }
    }
    hashTable.put("displayROI", displayROI);
}
Also used : Color(java.awt.Color) DataBufferByte(java.awt.image.DataBufferByte) BufferedImage(java.awt.image.BufferedImage) IndexColorModel(java.awt.image.IndexColorModel)

Example 62 with DataBufferByte

use of java.awt.image.DataBufferByte in project jlineup by otto-de.

the class ImageService method bufferedImagesEqualQuick.

// A very fast byte buffer based image comparison for images containing INT or BYTE type representations
public static boolean bufferedImagesEqualQuick(BufferedImage image1, BufferedImage image2) {
    DataBuffer dataBuffer1 = image1.getRaster().getDataBuffer();
    DataBuffer dataBuffer2 = image2.getRaster().getDataBuffer();
    if (dataBuffer1 instanceof DataBufferByte && dataBuffer2 instanceof DataBufferByte) {
        DataBufferByte dataBufferBytes1 = (DataBufferByte) dataBuffer1;
        DataBufferByte dataBufferBytes2 = (DataBufferByte) dataBuffer2;
        for (int bank = 0; bank < dataBufferBytes1.getNumBanks(); bank++) {
            byte[] bytes1 = dataBufferBytes1.getData(bank);
            byte[] bytes2 = dataBufferBytes2.getData(bank);
            if (!Arrays.equals(bytes1, bytes2)) {
                return false;
            }
        }
    } else if (dataBuffer1 instanceof DataBufferInt && dataBuffer2 instanceof DataBufferInt) {
        DataBufferInt dataBufferInt1 = (DataBufferInt) dataBuffer1;
        DataBufferInt dataBufferInt2 = (DataBufferInt) dataBuffer2;
        for (int bank = 0; bank < dataBufferInt1.getNumBanks(); bank++) {
            int[] ints1 = dataBufferInt1.getData(bank);
            int[] ints2 = dataBufferInt2.getData(bank);
            if (!Arrays.equals(ints1, ints2)) {
                return false;
            }
        }
    } else {
        return false;
    }
    return true;
}
Also used : DataBufferInt(java.awt.image.DataBufferInt) DataBufferByte(java.awt.image.DataBufferByte) DataBuffer(java.awt.image.DataBuffer)

Example 63 with DataBufferByte

use of java.awt.image.DataBufferByte in project yamcs-studio by yamcs.

the class ValueUtil method toVImage.

/**
 * Converts an AWT BufferedImage to a VImage.
 * <p>
 * Currently, only TYPE_3BYTE_BGR is supported
 *
 * @param image
 *            buffered image
 * @return a new image
 */
public static VImage toVImage(BufferedImage image) {
    if (image.getType() != BufferedImage.TYPE_3BYTE_BGR) {
        BufferedImage newImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_3BYTE_BGR);
        newImage.getGraphics().drawImage(image, 0, 0, null);
        image = newImage;
    }
    byte[] buffer = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
    return ValueFactory.newVImage(image.getHeight(), image.getWidth(), buffer);
}
Also used : DataBufferByte(java.awt.image.DataBufferByte) BufferedImage(java.awt.image.BufferedImage)

Example 64 with DataBufferByte

use of java.awt.image.DataBufferByte in project yamcs-studio by yamcs.

the class ValueUtil method toImage.

/**
 * Converts a VImage to an AWT BufferedImage, so that it can be displayed. The content of the vImage buffer is
 * copied, so further changes to the VImage will not modify the BufferedImage.
 *
 * @param vImage
 *            the image to be converted
 * @return a new BufferedImage
 */
public static BufferedImage toImage(VImage vImage) {
    if (vImage.getVImageType() == VImageType.TYPE_3BYTE_BGR) {
        BufferedImage image = new BufferedImage(vImage.getWidth(), vImage.getHeight(), BufferedImage.TYPE_3BYTE_BGR);
        ListNumber data = vImage.getData();
        for (int i = 0; i < data.size(); i++) {
            ((DataBufferByte) image.getRaster().getDataBuffer()).getData()[i] = data.getByte(i);
        }
        return image;
    } else {
        throw new UnsupportedOperationException("No support for creating a BufferedImage from Image Type: " + vImage.getVImageType());
    }
}
Also used : ListNumber(org.diirt.util.array.ListNumber) DataBufferByte(java.awt.image.DataBufferByte) BufferedImage(java.awt.image.BufferedImage)

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