Example usage for java.awt.image SampleModel getDataType

List of usage examples for java.awt.image SampleModel getDataType

Introduction

In this page you can find the example usage for java.awt.image SampleModel getDataType.

Prototype

public final int getDataType() 

Source Link

Document

Returns the data type of the DataBuffer storing the pixel 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 . ja va  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_BYTE_COMP_Data(SampleModel sm) {
    // Check ColorModel is of type DirectColorModel
    if (!(sm instanceof ComponentSampleModel))
        return false;

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

    return true;//from   ww w .  j  a v a  2s  . com
}

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 w  ww.  j a  v a 2  s .c  o  m
}

From source file:org.apache.xmlgraphics.image.codec.png.PNGImageDecoder.java

/**
 * A convenience method to create an instance of
 * <code>ComponentColorModel</code> suitable for use with the given
 * <code>SampleModel</code>. The <code>SampleModel</code> should have a data
 * type of <code>DataBuffer.TYPE_BYTE</code>, <code>TYPE_USHORT</code>, or
 * <code>TYPE_INT</code> and between 1 and 4 bands. Depending on the number
 * of bands of the <code>SampleModel</code>, either a gray, gray+alpha, rgb,
 * or rgb+alpha <code>ColorModel</code> is returned.
 *///from   w  ww  .  j  a va 2  s .  co m
public static ColorModel createComponentColorModel(final SampleModel sm) {
    final int type = sm.getDataType();
    final int bands = sm.getNumBands();
    ComponentColorModel cm = null;

    if (type == DataBuffer.TYPE_BYTE) {
        switch (bands) {
        case 1:
            cm = colorModelGray8;
            break;
        case 2:
            cm = colorModelGrayAlpha8;
            break;
        case 3:
            cm = colorModelRGB8;
            break;
        case 4:
            cm = colorModelRGBA8;
            break;
        }
    } else if (type == DataBuffer.TYPE_USHORT) {
        switch (bands) {
        case 1:
            cm = colorModelGray16;
            break;
        case 2:
            cm = colorModelGrayAlpha16;
            break;
        case 3:
            cm = colorModelRGB16;
            break;
        case 4:
            cm = colorModelRGBA16;
            break;
        }
    } else if (type == DataBuffer.TYPE_INT) {
        switch (bands) {
        case 1:
            cm = colorModelGray32;
            break;
        case 2:
            cm = colorModelGrayAlpha32;
            break;
        case 3:
            cm = colorModelRGB32;
            break;
        case 4:
            cm = colorModelRGBA32;
            break;
        }
    }

    return cm;
}

From source file:org.geoserver.catalog.CoverageViewReader.java

public CoverageViewReader(GridCoverage2DReader delegate, CoverageView coverageView, CoverageInfo coverageInfo,
        Hints hints) {/*from w  w w.ja v a2s  .  c  o m*/
    this.coverageName = coverageView.getName();
    this.delegate = delegate;
    this.coverageView = coverageView;
    this.coverageInfo = coverageInfo;
    this.hints = hints;
    // Refactor this once supporting heterogeneous elements
    referenceName = coverageView.getBand(0).getInputCoverageBands().get(0).getCoverageName();
    if (this.hints != null && this.hints.containsKey(Hints.GRID_COVERAGE_FACTORY)) {
        final Object factory = this.hints.get(Hints.GRID_COVERAGE_FACTORY);
        if (factory != null && factory instanceof GridCoverageFactory) {
            this.coverageFactory = (GridCoverageFactory) factory;
        }
    }
    if (this.coverageFactory == null) {
        this.coverageFactory = CoverageFactoryFinder.getGridCoverageFactory(this.hints);
    }
    ImageLayout layout;
    try {
        layout = delegate.getImageLayout(referenceName);
        List<CoverageBand> bands = coverageView.getCoverageBands();
        SampleModel originalSampleModel = layout.getSampleModel(null);
        SampleModel sampleModel = RasterFactory.createBandedSampleModel(originalSampleModel.getDataType(),
                originalSampleModel.getWidth(), originalSampleModel.getHeight(), bands.size());

        ColorModel colorModel = ImageIOUtilities.createColorModel(sampleModel);
        this.imageLayout = new ImageLayout2(layout.getMinX(null), layout.getMinY(null),
                originalSampleModel.getWidth(), originalSampleModel.getHeight());
        imageLayout.setSampleModel(sampleModel);
        imageLayout.setColorModel(colorModel);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}