Example usage for java.awt.image DataBuffer TYPE_DOUBLE

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

Introduction

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

Prototype

int TYPE_DOUBLE

To view the source code for java.awt.image DataBuffer TYPE_DOUBLE.

Click Source Link

Document

Tag for double data.

Usage

From source file:com.bc.ceres.jai.opimage.ReinterpretOpImage.java

private void rescale(Raster sourceRaster, WritableRaster targetRaster, Rectangle targetRectangle) {
    final int sourceDataType = sourceRaster.getSampleModel().getDataType();
    final int targetDataType = targetRaster.getSampleModel().getDataType();
    final PixelAccessor sourceAcc = new PixelAccessor(getSourceImage(0));
    final PixelAccessor targetAcc = new PixelAccessor(this);
    final UnpackedImageData sourcePixels;
    final UnpackedImageData targetPixels;

    sourcePixels = sourceAcc.getPixels(sourceRaster, targetRectangle, sourceDataType, false);
    targetPixels = targetAcc.getPixels(targetRaster, targetRectangle, targetDataType, true);

    switch (sourceDataType) {
    case DataBuffer.TYPE_BYTE:
        if (interpretationType == ReinterpretDescriptor.INTERPRET_BYTE_SIGNED) {
            rescaleSByte(sourcePixels, targetPixels, targetRectangle);
        } else {//from w w  w .j av  a  2 s  .c o m
            rescaleByte(sourcePixels, targetPixels, targetRectangle);
        }
        break;
    case DataBuffer.TYPE_USHORT:
        rescaleUShort(sourcePixels, targetPixels, targetRectangle);
        break;
    case DataBuffer.TYPE_SHORT:
        rescaleShort(sourcePixels, targetPixels, targetRectangle);
        break;
    case DataBuffer.TYPE_INT:
        if (interpretationType == ReinterpretDescriptor.INTERPRET_INT_UNSIGNED) {
            rescaleUInt(sourcePixels, targetPixels, targetRectangle);
        } else {
            rescaleInt(sourcePixels, targetPixels, targetRectangle);
        }
        break;
    case DataBuffer.TYPE_FLOAT:
        rescaleFloat(sourcePixels, targetPixels, targetRectangle);
        break;
    case DataBuffer.TYPE_DOUBLE:
        rescaleDouble(sourcePixels, targetPixels, targetRectangle);
        break;
    }

    targetAcc.setPixels(targetPixels);
}

From source file:it.geosolutions.imageio.plugins.nitronitf.ImageIOUtils.java

/**
 * Returns a generic pixel interleaved WritableRaster
 * /*from w w  w  .java 2  s.com*/
 * @param numElems
 * @param numLines
 * @param bandOffsets
 * @param dataType
 * @return
 */
public static WritableRaster makeGenericPixelInterleavedWritableRaster(int numElems, int numLines, int numBands,
        int dataType) {
    int[] bandOffsets = new int[numBands];
    for (int i = 0; i < numBands; ++i)
        bandOffsets[i] = i;

    DataBuffer d = null;
    if (dataType == DataBuffer.TYPE_BYTE)
        d = new DataBufferByte(numElems * numLines * numBands);
    else if (dataType == DataBuffer.TYPE_SHORT)
        d = new DataBufferShort(numElems * numLines * numBands);
    else if (dataType == DataBuffer.TYPE_USHORT)
        d = new DataBufferUShort(numElems * numLines * numBands);
    else if (dataType == DataBuffer.TYPE_FLOAT)
        d = new DataBufferFloat(numElems * numLines * numBands);
    else if (dataType == DataBuffer.TYPE_DOUBLE)
        d = new DataBufferDouble(numElems * numLines * numBands);
    else
        throw new IllegalArgumentException("Invalid datatype: " + dataType);

    PixelInterleavedSampleModel pism = new PixelInterleavedSampleModel(dataType, numElems, numLines,
            bandOffsets.length, numElems * bandOffsets.length, bandOffsets);

    SunWritableRaster ras = new SunWritableRaster(pism, d, new Point(0, 0));
    return ras;
}

From source file:omr.jai.TestImage3.java

public static void print(PlanarImage pi) {
        // Show the image dimensions and coordinates.
        System.out.print("Image Dimensions: ");
        System.out.print(pi.getWidth() + "x" + pi.getHeight() + " pixels");

        // Remember getMaxX and getMaxY return the coordinate of the next point!
        System.out.println(" (from " + pi.getMinX() + "," + pi.getMinY() + " to " + (pi.getMaxX() - 1) + ","
                + (pi.getMaxY() - 1) + ")");
        if ((pi.getNumXTiles() != 1) || (pi.getNumYTiles() != 1)) { // Is it tiled?
            // Tiles number, dimensions and coordinates.
            System.out.print("Tiles: ");
            System.out.print(pi.getTileWidth() + "x" + pi.getTileHeight() + " pixels" + " (" + pi.getNumXTiles()
                    + "x" + pi.getNumYTiles() + " tiles)");
            System.out.print(" (from " + pi.getMinTileX() + "," + pi.getMinTileY() + " to " + pi.getMaxTileX() + ","
                    + pi.getMaxTileY() + ")");
            System.out.println(" offset: " + pi.getTileGridXOffset() + "," + pi.getTileGridXOffset());
        }//from   w  ww .j av a 2s.c  o m

        // Display info about the SampleModel of the image.
        SampleModel sm = pi.getSampleModel();
        System.out.println("Number of bands: " + sm.getNumBands());
        System.out.print("Data type: ");
        switch (sm.getDataType()) {
        case DataBuffer.TYPE_BYTE:
            System.out.println("byte");
            break;
        case DataBuffer.TYPE_SHORT:
            System.out.println("short");
            break;
        case DataBuffer.TYPE_USHORT:
            System.out.println("ushort");
            break;
        case DataBuffer.TYPE_INT:
            System.out.println("int");
            break;
        case DataBuffer.TYPE_FLOAT:
            System.out.println("float");
            break;
        case DataBuffer.TYPE_DOUBLE:
            System.out.println("double");
            break;
        case DataBuffer.TYPE_UNDEFINED:
            System.out.println("undefined");
            break;
        }

        // Display info about the ColorModel of the image.
        ColorModel cm = pi.getColorModel();
        if (cm != null) {
            System.out.println("Number of color components: " + cm.getNumComponents());
            System.out.println("Bits per pixel: " + cm.getPixelSize());
            System.out.print("Image Transparency: ");
            switch (cm.getTransparency()) {
            case Transparency.OPAQUE:
                System.out.println("opaque");
                break;
            case Transparency.BITMASK:
                System.out.println("bitmask");
                break;
            case Transparency.TRANSLUCENT:
                System.out.println("translucent");
                break;
            }
        } else
            System.out.println("No color model.");
    }

From source file:it.geosolutions.imageio.plugins.nitronitf.ImageIOUtils.java

/**
 * Utility method for creating a BufferedImage from a source raster Currently only Float->Byte and Byte->Byte are supported. Will throw an
 * {@link UnsupportedOperationException} if the conversion is not supported.
 * // w  w w.ja va 2 s. c  om
 * @param raster
 * @param imageType
 * @return
 */
public static BufferedImage rasterToBufferedImage(Raster raster, ImageTypeSpecifier imageType) {
    if (imageType == null) {
        if (raster.getDataBuffer().getDataType() == DataBuffer.TYPE_BYTE)
            imageType = ImageTypeSpecifier.createGrayscale(8, DataBuffer.TYPE_BYTE, false);
        else
            throw new IllegalArgumentException("unable to dynamically determine the imageType");
    }
    // create a new buffered image, for display
    BufferedImage bufImage = imageType.createBufferedImage(raster.getWidth(), raster.getHeight());

    if (raster.getDataBuffer().getDataType() == DataBuffer.TYPE_USHORT
            && bufImage.getRaster().getDataBuffer().getDataType() == DataBuffer.TYPE_BYTE) {
        // convert short pixels to bytes
        short[] shortData = ((DataBufferUShort) raster.getDataBuffer()).getData();
        byte[] byteData = ((DataBufferByte) bufImage.getWritableTile(0, 0).getDataBuffer()).getData();
        ImageIOUtils.shortToByteBuffer(shortData, byteData, 1, raster.getNumBands());
    } else if (raster.getDataBuffer().getDataType() == DataBuffer.TYPE_FLOAT
            && bufImage.getRaster().getDataBuffer().getDataType() == DataBuffer.TYPE_BYTE) {
        // convert float pixels to bytes
        float[] floatData = ((DataBufferFloat) raster.getDataBuffer()).getData();
        byte[] byteData = ((DataBufferByte) bufImage.getWritableTile(0, 0).getDataBuffer()).getData();
        ImageIOUtils.floatToByteBuffer(floatData, byteData, 1, raster.getNumBands());
    } else if (raster.getDataBuffer().getDataType() == DataBuffer.TYPE_DOUBLE
            && bufImage.getRaster().getDataBuffer().getDataType() == DataBuffer.TYPE_BYTE) {
        // convert double pixels to bytes
        double[] doubleData = ((DataBufferDouble) raster.getDataBuffer()).getData();
        byte[] byteData = ((DataBufferByte) bufImage.getWritableTile(0, 0).getDataBuffer()).getData();
        ImageIOUtils.doubleToByteBuffer(doubleData, byteData, 1, raster.getNumBands());
    } else if ((raster.getDataBuffer().getDataType() == DataBuffer.TYPE_BYTE
            && bufImage.getRaster().getDataBuffer().getDataType() == DataBuffer.TYPE_BYTE)
            || (raster.getDataBuffer().getDataType() == DataBuffer.TYPE_USHORT
                    && bufImage.getRaster().getDataBuffer().getDataType() == DataBuffer.TYPE_USHORT)
            || (raster.getDataBuffer().getDataType() == DataBuffer.TYPE_SHORT
                    && bufImage.getRaster().getDataBuffer().getDataType() == DataBuffer.TYPE_SHORT)) {
        bufImage.setData(raster);
    } else {
        throw new UnsupportedOperationException(
                "Unable to convert raster type to bufferedImage type: " + raster.getDataBuffer().getDataType()
                        + " ==> " + bufImage.getRaster().getDataBuffer().getDataType());
    }
    return bufImage;
}

From source file:it.geosolutions.jaiext.range.RangeTest.java

@Test
public void testRangeTimeByte1or2Points() {
    if (!SINGLE_POINT) {
        switch (TEST_SELECTOR) {
        case DataBuffer.TYPE_BYTE:
            testRangeTimeByte(rangeB2bounds, SINGLE_POINT);
            break;
        case DataBuffer.TYPE_SHORT:
            testRangeTimeShort(rangeS2bounds, SINGLE_POINT);
            break;
        case DataBuffer.TYPE_INT:
            testRangeTimeInteger(rangeI2bounds, SINGLE_POINT);
            break;
        case DataBuffer.TYPE_FLOAT:
            testRangeTimeFloat(rangeF2bounds, SINGLE_POINT);
            break;
        case DataBuffer.TYPE_DOUBLE:
            testRangeTimeDouble(rangeD2bounds, SINGLE_POINT);
            break;
        default://from w w w.jav a  2  s . c om
            throw new IllegalArgumentException("Wrong data type");
        }
    } else {
        switch (TEST_SELECTOR) {
        case DataBuffer.TYPE_BYTE:
            testRangeTimeByte(rangeBpoint, SINGLE_POINT);
            break;
        case DataBuffer.TYPE_SHORT:
            testRangeTimeShort(rangeSpoint, SINGLE_POINT);
            break;
        case DataBuffer.TYPE_INT:
            testRangeTimeInteger(rangeIpoint, SINGLE_POINT);
            break;
        case DataBuffer.TYPE_FLOAT:
            testRangeTimeFloat(rangeFpoint, SINGLE_POINT);
            break;
        case DataBuffer.TYPE_DOUBLE:
            testRangeTimeDouble(rangeDpoint, SINGLE_POINT);
            break;
        default:
            throw new IllegalArgumentException("Wrong data type");
        }
    }
}

From source file:it.geosolutions.jaiext.range.RangeTest.java

@Test
public void testJaiToolsRangeTimeByte1or2Points() {
    if (!SINGLE_POINT) {
        switch (TEST_SELECTOR) {
        case DataBuffer.TYPE_BYTE:
            testJaiToolsRangeTime(rangeJTB, SINGLE_POINT, arrayBtest);
            break;
        case DataBuffer.TYPE_SHORT:
            testJaiToolsRangeTime(rangeJTS, SINGLE_POINT, arrayStest);
            break;
        case DataBuffer.TYPE_INT:
            testJaiToolsRangeTime(rangeJTI, SINGLE_POINT, arrayItest);
            break;
        case DataBuffer.TYPE_FLOAT:
            testJaiToolsRangeTime(rangeJTF, SINGLE_POINT, arrayFtest);
            break;
        case DataBuffer.TYPE_DOUBLE:
            testJaiToolsRangeTime(rangeJTD, SINGLE_POINT, arrayDtest);
            break;
        default:/*from  w  w  w  .  j a  v  a 2  s  .  c  o  m*/
            throw new IllegalArgumentException("Wrong data type");
        }
    } else {
        switch (TEST_SELECTOR) {
        case DataBuffer.TYPE_BYTE:
            testJaiToolsRangeTime(rangeJTBpoint, SINGLE_POINT, arrayBtest);
            break;
        case DataBuffer.TYPE_SHORT:
            testJaiToolsRangeTime(rangeJTSpoint, SINGLE_POINT, arrayStest);
            break;
        case DataBuffer.TYPE_INT:
            testJaiToolsRangeTime(rangeJTIpoint, SINGLE_POINT, arrayItest);
            break;
        case DataBuffer.TYPE_FLOAT:
            testJaiToolsRangeTime(rangeJTFpoint, SINGLE_POINT, arrayFtest);
            break;
        case DataBuffer.TYPE_DOUBLE:
            testJaiToolsRangeTime(rangeJTDpoint, SINGLE_POINT, arrayDtest);
            break;
        default:
            throw new IllegalArgumentException("Wrong data type");
        }
    }
}

From source file:it.geosolutions.jaiext.range.RangeTest.java

@Test
public void testJAIRangeTimeByte1or2Points() {
    if (!SINGLE_POINT) {
        switch (TEST_SELECTOR) {
        case DataBuffer.TYPE_BYTE:
            testJAIRangeTime(rangeJAIB, SINGLE_POINT, arrayBtest);
            break;
        case DataBuffer.TYPE_SHORT:
            testJAIRangeTime(rangeJAIS, SINGLE_POINT, arrayStest);
            break;
        case DataBuffer.TYPE_INT:
            testJAIRangeTime(rangeJAII, SINGLE_POINT, arrayItest);
            break;
        case DataBuffer.TYPE_FLOAT:
            testJAIRangeTime(rangeJAIF, SINGLE_POINT, arrayFtest);
            break;
        case DataBuffer.TYPE_DOUBLE:
            testJAIRangeTime(rangeJAID, SINGLE_POINT, arrayDtest);
            break;
        default:/*from w ww .j  a va  2s .  c  o m*/
            throw new IllegalArgumentException("Wrong data type");
        }
    } else {
        switch (TEST_SELECTOR) {
        case DataBuffer.TYPE_BYTE:
            testJAIRangeTime(rangeJAIBpoint, SINGLE_POINT, arrayBtest);
            break;
        case DataBuffer.TYPE_SHORT:
            testJAIRangeTime(rangeJAISpoint, SINGLE_POINT, arrayStest);
            break;
        case DataBuffer.TYPE_INT:
            testJAIRangeTime(rangeJAIIpoint, SINGLE_POINT, arrayItest);
            break;
        case DataBuffer.TYPE_FLOAT:
            testJAIRangeTime(rangeJAIFpoint, SINGLE_POINT, arrayFtest);
            break;
        case DataBuffer.TYPE_DOUBLE:
            testJAIRangeTime(rangeJAIDpoint, SINGLE_POINT, arrayDtest);
            break;
        default:
            throw new IllegalArgumentException("Wrong data type");
        }
    }
}

From source file:it.geosolutions.jaiext.range.RangeTest.java

@Test
public void testApacheCommonRangeTimeByte1or2Points() {

    if (!SINGLE_POINT) {
        switch (TEST_SELECTOR) {
        case DataBuffer.TYPE_BYTE:
            testApacheCommonsRangeTime(rangeCommonsB, SINGLE_POINT, arrayBtest);
            break;
        case DataBuffer.TYPE_SHORT:
            testApacheCommonsRangeTime(rangeCommonsS, SINGLE_POINT, arrayStest);
            break;
        case DataBuffer.TYPE_INT:
            testApacheCommonsRangeTime(rangeCommonsI, SINGLE_POINT, arrayItest);
            break;
        case DataBuffer.TYPE_FLOAT:
            testApacheCommonsRangeTime(rangeCommonsF, SINGLE_POINT, arrayFtest);
            break;
        case DataBuffer.TYPE_DOUBLE:
            testApacheCommonsRangeTime(rangeCommonsD, SINGLE_POINT, arrayDtest);
            break;
        default:/*  w w  w.  j  a va2  s . c o  m*/
            throw new IllegalArgumentException("Wrong data type");
        }
    } else {
        switch (TEST_SELECTOR) {
        case DataBuffer.TYPE_BYTE:
            testApacheCommonsRangeTime(rangeCommonsBpoint, SINGLE_POINT, arrayBtest);
            break;
        case DataBuffer.TYPE_SHORT:
            testApacheCommonsRangeTime(rangeCommonsSpoint, SINGLE_POINT, arrayStest);
            break;
        case DataBuffer.TYPE_INT:
            testApacheCommonsRangeTime(rangeCommonsIpoint, SINGLE_POINT, arrayItest);
            break;
        case DataBuffer.TYPE_FLOAT:
            testApacheCommonsRangeTime(rangeCommonsFpoint, SINGLE_POINT, arrayFtest);
            break;
        case DataBuffer.TYPE_DOUBLE:
            testApacheCommonsRangeTime(rangeCommonsDpoint, SINGLE_POINT, arrayDtest);
            break;
        default:
            throw new IllegalArgumentException("Wrong data type");
        }
    }
}

From source file:eu.udig.catalog.jgrass.utils.JGrassCatalogUtilities.java

/**
 * Creates a {@link WritableRaster writable raster}.
 * /* ww w .  j  a  v a 2  s  .c  om*/
 * @param width width of the raster to create.
 * @param height height of the raster to create.
 * @param dataClass data type for the raster. If <code>null</code>, defaults to double.
 * @param sampleModel the samplemodel to use. If <code>null</code>, defaults to 
 *                  <code>new ComponentSampleModel(dataType, width, height, 1, width, new int[]{0});</code>.
 * @param value value to which to set the raster to. If null, the default of the raster creation is 
 *                  used, which is 0.
 * @return a {@link WritableRaster writable raster}.
 */
public static WritableRaster createDoubleWritableRaster(int width, int height, Class<?> dataClass,
        SampleModel sampleModel, Double value) {
    int dataType = DataBuffer.TYPE_DOUBLE;
    if (dataClass != null) {
        if (dataClass.isAssignableFrom(Integer.class)) {
            dataType = DataBuffer.TYPE_INT;
        } else if (dataClass.isAssignableFrom(Float.class)) {
            dataType = DataBuffer.TYPE_FLOAT;
        } else if (dataClass.isAssignableFrom(Byte.class)) {
            dataType = DataBuffer.TYPE_BYTE;
        }
    }
    if (sampleModel == null) {
        sampleModel = new ComponentSampleModel(dataType, width, height, 1, width, new int[] { 0 });
    }

    WritableRaster raster = RasterFactory.createWritableRaster(sampleModel, null);
    if (value != null) {
        // autobox only once
        double v = value;

        for (int y = 0; y < height; y++) {
            for (int x = 0; x < width; x++) {
                raster.setSample(x, y, 0, v);
            }
        }
    }
    return raster;
}

From source file:it.geosolutions.jaiext.range.RangeTest.java

private void checkRangeConversion(Range range) {
    checkRangeConversion(range, DataBuffer.TYPE_BYTE);
    checkRangeConversion(range, DataBuffer.TYPE_DOUBLE);
    checkRangeConversion(range, DataBuffer.TYPE_FLOAT);
    checkRangeConversion(range, DataBuffer.TYPE_INT);
    checkRangeConversion(range, DataBuffer.TYPE_SHORT);
    checkRangeConversion(range, DataBuffer.TYPE_USHORT);
}