Example usage for java.awt.image DataBuffer TYPE_INT

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

Introduction

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

Prototype

int TYPE_INT

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

Click Source Link

Document

Tag for int data.

Usage

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 w w  .  j  av  a 2  s  . 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:GraphicsUtil.java

public static boolean is_INT_PACK_Data(SampleModel sm, boolean requireAlpha) {
    // Check ColorModel is of type DirectColorModel
    if (!(sm instanceof SinglePixelPackedSampleModel))
        return false;

    // Check transfer type
    if (sm.getDataType() != DataBuffer.TYPE_INT)
        return false;

    SinglePixelPackedSampleModel sppsm;
    sppsm = (SinglePixelPackedSampleModel) sm;

    int[] masks = sppsm.getBitMasks();
    if (masks.length == 3) {
        if (requireAlpha)
            return false;
    } else if (masks.length != 4)
        return false;

    if (masks[0] != 0x00ff0000)
        return false;
    if (masks[1] != 0x0000ff00)
        return false;
    if (masks[2] != 0x000000ff)
        return false;
    if ((masks.length == 4) && (masks[3] != 0xff000000))
        return false;

    return true;/*from  ww  w  .j  a  v a2  s  .c  om*/
}

From source file:BlendCompositeDemo.java

private static boolean checkComponentsOrder(ColorModel cm) {
    if (cm instanceof DirectColorModel && cm.getTransferType() == DataBuffer.TYPE_INT) {
        DirectColorModel directCM = (DirectColorModel) cm;

        return directCM.getRedMask() == 0x00FF0000 && directCM.getGreenMask() == 0x0000FF00
                && directCM.getBlueMask() == 0x000000FF
                && (directCM.getNumComponents() != 4 || directCM.getAlphaMask() == 0xFF000000);
    }//from w w w.  j a  v  a  2s  .c  o  m

    return false;
}

From source file:PngEncoder.java

/**
 * Creates a PNG encoder for an image.//from   w w  w.j  av a2  s.  co  m
 *
 * @param image the image to be encoded
 * @param encodeAlpha true if the image's alpha channel should be encoded
 * @param filter The filter to be applied to the image data, one of the 
 *        following values:
 *        <ul>
 *        <li>SUB_FILTER</li>
 *        <li>UP_FILTER</li>
 *        <li>AVERAGE_FILTER</li>
 *        <li>PAETH_FILTER</li>
 *        </ul>
 *        If a null value is specified, no filtering will be performed.
 * @param compressionLevel the deflater compression level that will be used
 *        for compressing the image data:  Valid values range from 0 to 9.
 *        Higher values result in smaller files and therefore decrease
 *        network traffic, but require more CPU time to encode.  The normal
 *        compromise value is 3.
 */
public PngEncoder(Image image, boolean encodeAlpha, Filter filter, int compressionLevel) {
    super();

    this.image = ImageToBufferedImage.toBufferedImage(image);
    this.filter = filter;
    this.compressionLevel = compressionLevel;

    width = this.image.getWidth(null);
    height = this.image.getHeight(null);
    raster = this.image.getRaster();
    transferType = raster.getTransferType();

    // Establish storage information
    int dataBytes = raster.getNumDataElements();
    if (transferType == DataBuffer.TYPE_BYTE && dataBytes == 4) {
        outputBpp = encodeAlpha ? 4 : 3;
        inputBpp = 4;
        translator = new ByteTranslator();
    } else if (transferType == DataBuffer.TYPE_BYTE && dataBytes == 3) {
        outputBpp = 3;
        inputBpp = 3;
        encodeAlpha = false;
        translator = new ByteTranslator();
    } else if (transferType == DataBuffer.TYPE_INT && dataBytes == 1) {
        outputBpp = encodeAlpha ? 4 : 3;
        inputBpp = 4;
        translator = new IntTranslator();
    } else if (transferType == DataBuffer.TYPE_BYTE && dataBytes == 1) {
        throw new UnsupportedOperationException("Encoding indexed-color images not yet supported.");
    } else {
        throw new IllegalArgumentException("Cannot determine appropriate bits-per-pixel for provided image.");
    }
}

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 ww  . j  av  a  2 s.c  o m
            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:/*w  ww. j ava2  s  . c om*/
            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:/*w  ww  . j  av a  2  s. 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:/*from  w w  w.  ja v a2 s .  com*/
            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}.
 * /*from  www  . j  a  v a  2  s .  com*/
 * @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);
}