Example usage for java.awt.image DataBuffer getElem

List of usage examples for java.awt.image DataBuffer getElem

Introduction

In this page you can find the example usage for java.awt.image DataBuffer getElem.

Prototype

public int getElem(int i) 

Source Link

Document

Returns the requested data array element from the first (default) bank as an integer.

Usage

From source file:fr.ens.transcriptome.corsen.gui.qt.ResultGraphs.java

private static final byte[] toByte(DataBuffer buffer) {

    if (buffer == null)
        return null;

    final int size = buffer.getSize();

    byte[] result = new byte[size * 4];

    for (int i = 0; i < size; i++) {

        final int val = buffer.getElem(i);
        final int j = i * 4;

        result[j + 3] = (byte) (((val & 0xFF000000) >> 24) & 0xFF);
        result[j + 2] = (byte) (((val & 0x00FF0000) >> 16) & 0xFF);
        result[j + 1] = (byte) (((val & 0x0000FF00) >> 8) & 0xFF);
        result[j] = (byte) (val & 0xFF);
    }//from ww  w  .  j a  va 2  s  .c om

    return result;
}

From source file:RasterDemo.java

public void flipBufferedImage() {
    bi2 = new BufferedImage(bi1.getWidth(), bi1.getHeight(), bi1.getType());

    DataBuffer db1 = bi1.getRaster().getDataBuffer();
    DataBuffer db2 = bi2.getRaster().getDataBuffer();

    for (int i = db1.getSize() - 1, j = 0; i >= 0; --i, j++) {
        db2.setElem(j, db1.getElem(i));
    }//w ww.  ja v  a 2 s .c o  m
}

From source file:com.sat.dbds.vcs.login.LoginStepDef.java

/**
 * This method will try to match images and conclude if
 * the are identical./*from   w  w w  .  j  a v  a 2s. co  m*/
 *
 * @param sourceImage the source image
 * @param targetImage the target image
 * @return true, if successful
 * @throws IOException Signals that an I/O exception has occurred.
 */
boolean doImagesMatch(String sourceImage, String targetImage) throws IOException {

    LogHandler.info("Source image is:" + sourceImage);
    LogHandler.info("Target image is:" + targetImage);

    File fileInput = new File(sourceImage);
    File fileOutPut = new File(targetImage);

    BufferedImage bufFileInput = ImageIO.read(fileInput);
    DataBuffer dataFileInput = bufFileInput.getData().getDataBuffer();
    int sizeFileInput = dataFileInput.getSize();

    BufferedImage bufFileOutPut = ImageIO.read(fileOutPut);
    DataBuffer dataFileOutPut = bufFileOutPut.getData().getDataBuffer();
    int sizeFileOutPut = dataFileOutPut.getSize();

    boolean matchFlag = true;
    if (sizeFileInput == sizeFileOutPut) {
        for (int j = 0; j < sizeFileInput; j++) {
            if (dataFileInput.getElem(j) != dataFileOutPut.getElem(j)) {
                matchFlag = false;
                break;
            }
        }
    } else
        matchFlag = false;

    return matchFlag;
}

From source file:ucar.unidata.idv.ui.ImageGenerator.java

private static boolean isNotBlank(BufferedImage image) {
    // yes, i know this is bonkers. yes, the next step is to try sampling
    // to avoid iterating over each pixel.
    // tests on my linux machine typically find a non-blank pixel within the
    // first 100 iterations, and fewer than 5 retries to get a non-blank
    // *image* (typically 1-2 retries though)
    DataBuffer buf = image.getRaster().getDataBuffer();
    ColorModel model = image.getColorModel();
    boolean result = false;
    int i;/*from w  w  w.ja va  2 s. c  o  m*/
    for (i = 0; i < buf.getSize(); i++) {
        // it's apparently not sufficient to simply grab the value directly;
        // Linux seems to store the "blank" value as -16777216 (-2^24, which
        // makes a lot of sense for images), while on OS X the blank value
        // is simply 0. i suspect the getRGB stuff is a candidate for
        // inlining by the JIT, but profiling is needed.
        int rgb = model.getRGB(buf.getElem(i));
        if (rgb != -16777216) {
            logger.trace("found non-blank value '{}' at index {}", rgb, i);
            result = true;
            break;
        }
    }
    logger.trace("{} iterations to return {}", i, result);
    return result;
}