Example usage for java.awt.image ColorModel getPixelSize

List of usage examples for java.awt.image ColorModel getPixelSize

Introduction

In this page you can find the example usage for java.awt.image ColorModel getPixelSize.

Prototype

public int getPixelSize() 

Source Link

Document

Returns the number of bits per pixel described by this ColorModel .

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  ww  .  j  a  v  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:omr.jai.TestImage3.java

/**
 * Check if the image format (and especially its color model) is
 * properly handled by Audiveris./*from   w w  w .ja  v  a 2 s  .  c o  m*/
 *
 * @throws ImageFormatException is the format is not supported
 */
private void checkImageFormat()
{
    // Check nb of bands
    int numBands = image.getSampleModel().getNumBands();
    if (numBands != 1) {
        if (numBands == 3) {
            image = colorToGray(image);
        } else {
            throw new RuntimeException
                ("Unsupported sample model" +
                 " numBands=" + numBands);
        }
    }

    // Check pixel size
    ColorModel colorModel = image.getColorModel();
    int pixelSize = colorModel.getPixelSize();
    if (pixelSize != 8) {
        System.out.println("pixelSize=" + pixelSize +
                " colorModel=" + colorModel);
        image = grayToGray256(image);
    }
}

From source file:lucee.runtime.img.Image.java

public Struct info() throws ExpressionException {
    if (sctInfo != null)
        return sctInfo;

    Struct sctInfo = new StructImpl(), sct;

    sctInfo.setEL("height", new Double(getHeight()));
    sctInfo.setEL("width", new Double(getWidth()));
    sctInfo.setEL("source", source == null ? "" : source.getAbsolutePath());
    //sct.setEL("mime_type",getMimeType());

    ColorModel cm = image().getColorModel();
    sct = new StructImpl();
    sctInfo.setEL("colormodel", sct);

    sct.setEL("alpha_channel_support", Caster.toBoolean(cm.hasAlpha()));
    sct.setEL("alpha_premultiplied", Caster.toBoolean(cm.isAlphaPremultiplied()));
    sct.setEL("transparency", toStringTransparency(cm.getTransparency()));
    sct.setEL("pixel_size", Caster.toDouble(cm.getPixelSize()));
    sct.setEL("num_components", Caster.toDouble(cm.getNumComponents()));
    sct.setEL("num_color_components", Caster.toDouble(cm.getNumColorComponents()));
    sct.setEL("colorspace", toStringColorSpace(cm.getColorSpace()));

    //bits_component
    int[] bitspercomponent = cm.getComponentSize();
    Array arr = new ArrayImpl();
    Double value;// www.ja  va 2 s . co  m
    for (int i = 0; i < bitspercomponent.length; i++) {
        sct.setEL("bits_component_" + (i + 1), value = new Double(bitspercomponent[i]));
        arr.appendEL(value);
    }
    sct.setEL("bits_component", arr);

    // colormodel_type
    if (cm instanceof ComponentColorModel)
        sct.setEL("colormodel_type", "ComponentColorModel");
    else if (cm instanceof IndexColorModel)
        sct.setEL("colormodel_type", "IndexColorModel");
    else if (cm instanceof PackedColorModel)
        sct.setEL("colormodel_type", "PackedColorModel");
    else
        sct.setEL("colormodel_type", ListUtil.last(cm.getClass().getName(), '.'));

    getMetaData(sctInfo);

    ImageMeta.addInfo(format, source, sctInfo);

    this.sctInfo = sctInfo;
    return sctInfo;
}