Example usage for java.awt.image ComponentSampleModel getBandOffsets

List of usage examples for java.awt.image ComponentSampleModel getBandOffsets

Introduction

In this page you can find the example usage for java.awt.image ComponentSampleModel getBandOffsets.

Prototype

public final int[] getBandOffsets() 

Source Link

Document

Returns the band offset for all bands.

Usage

From source file:GraphicsUtil.java

protected static void mult_BYTE_COMP_Data(WritableRaster wr) {
    // System.out.println("Multiply Int: " + wr);

    ComponentSampleModel csm;
    csm = (ComponentSampleModel) wr.getSampleModel();

    final int width = wr.getWidth();

    final int scanStride = csm.getScanlineStride();
    final int pixStride = csm.getPixelStride();
    final int[] bandOff = csm.getBandOffsets();

    DataBufferByte db = (DataBufferByte) wr.getDataBuffer();
    final int base = (db.getOffset() + csm.getOffset(wr.getMinX() - wr.getSampleModelTranslateX(),
            wr.getMinY() - wr.getSampleModelTranslateY()));

    int a = 0;/*  w  w  w. j  av a  2s  . com*/
    int aOff = bandOff[bandOff.length - 1];
    int bands = bandOff.length - 1;
    int b, i;

    // Access the pixel data array
    final byte pixels[] = db.getBankData()[0];
    for (int y = 0; y < wr.getHeight(); y++) {
        int sp = base + y * scanStride;
        final int end = sp + width * pixStride;
        while (sp < end) {
            a = pixels[sp + aOff] & 0xFF;
            if (a != 0xFF)
                for (b = 0; b < bands; b++) {
                    i = sp + bandOff[b];
                    pixels[i] = (byte) (((pixels[i] & 0xFF) * a) >> 8);
                }
            sp += pixStride;
        }
    }
}

From source file:GraphicsUtil.java

protected static void divide_BYTE_COMP_Data(WritableRaster wr) {
    // System.out.println("Multiply Int: " + wr);

    ComponentSampleModel csm;
    csm = (ComponentSampleModel) wr.getSampleModel();

    final int width = wr.getWidth();

    final int scanStride = csm.getScanlineStride();
    final int pixStride = csm.getPixelStride();
    final int[] bandOff = csm.getBandOffsets();

    DataBufferByte db = (DataBufferByte) wr.getDataBuffer();
    final int base = (db.getOffset() + csm.getOffset(wr.getMinX() - wr.getSampleModelTranslateX(),
            wr.getMinY() - wr.getSampleModelTranslateY()));

    int a = 0;/*from w w  w .  j  ava2  s.  c  o m*/
    int aOff = bandOff[bandOff.length - 1];
    int bands = bandOff.length - 1;
    int b, i;
    // Access the pixel data array
    final byte pixels[] = db.getBankData()[0];
    for (int y = 0; y < wr.getHeight(); y++) {
        int sp = base + y * scanStride;
        final int end = sp + width * pixStride;
        while (sp < end) {
            a = pixels[sp + aOff] & 0xFF;
            if (a == 0) {
                for (b = 0; b < bands; b++)
                    pixels[sp + bandOff[b]] = (byte) 0xFF;
            } else if (a < 255) {
                int aFP = (0x00FF0000 / a);
                for (b = 0; b < bands; b++) {
                    i = sp + bandOff[b];
                    pixels[i] = (byte) (((pixels[i] & 0xFF) * aFP) >>> 16);
                }
            }
            sp += pixStride;
        }
    }
}

From source file:GraphicsUtil.java

protected static void mult_BYTE_COMP_Data(WritableRaster wr) {
    // System.out.println("Multiply Int: " + wr);

    ComponentSampleModel csm;
    csm = (ComponentSampleModel) wr.getSampleModel();

    final int width = wr.getWidth();

    final int scanStride = csm.getScanlineStride();
    final int pixStride = csm.getPixelStride();
    final int[] bandOff = csm.getBandOffsets();

    DataBufferByte db = (DataBufferByte) wr.getDataBuffer();
    final int base = (db.getOffset() + csm.getOffset(wr.getMinX() - wr.getSampleModelTranslateX(),
            wr.getMinY() - wr.getSampleModelTranslateY()));

    int aOff = bandOff[bandOff.length - 1];
    int bands = bandOff.length - 1;

    // Access the pixel data array
    final byte[] pixels = db.getBankData()[0];
    for (int y = 0; y < wr.getHeight(); y++) {
        int sp = base + y * scanStride;
        final int end = sp + width * pixStride;
        while (sp < end) {
            int a = pixels[sp + aOff] & 0xFF;
            if (a != 0xFF)
                for (int b = 0; b < bands; b++) {
                    int i = sp + bandOff[b];
                    pixels[i] = (byte) (((pixels[i] & 0xFF) * a) >> 8);
                }//from ww  w. j a  v a2s .c o m
            sp += pixStride;
        }
    }
}

From source file:GraphicsUtil.java

protected static void divide_BYTE_COMP_Data(WritableRaster wr) {
    // System.out.println("Multiply Int: " + wr);

    ComponentSampleModel csm;
    csm = (ComponentSampleModel) wr.getSampleModel();

    final int width = wr.getWidth();

    final int scanStride = csm.getScanlineStride();
    final int pixStride = csm.getPixelStride();
    final int[] bandOff = csm.getBandOffsets();

    DataBufferByte db = (DataBufferByte) wr.getDataBuffer();
    final int base = (db.getOffset() + csm.getOffset(wr.getMinX() - wr.getSampleModelTranslateX(),
            wr.getMinY() - wr.getSampleModelTranslateY()));

    int aOff = bandOff[bandOff.length - 1];
    int bands = bandOff.length - 1;

    // Access the pixel data array
    final byte[] pixels = db.getBankData()[0];
    for (int y = 0; y < wr.getHeight(); y++) {
        int sp = base + y * scanStride;
        final int end = sp + width * pixStride;
        while (sp < end) {
            int a = pixels[sp + aOff] & 0xFF;
            if (a == 0) {
                for (int b = 0; b < bands; b++)
                    pixels[sp + bandOff[b]] = (byte) 0xFF;
            } else if (a < 255) { // this does NOT include a == 255 (0xff) !
                int aFP = (0x00FF0000 / a);
                for (int b = 0; b < bands; b++) {
                    int i = sp + bandOff[b];
                    pixels[i] = (byte) (((pixels[i] & 0xFF) * aFP) >>> 16);
                }//from  w w w .jav  a  2  s  .  c  o m
            }
            sp += pixStride;
        }
    }
}

From source file:org.geoserver.jai.ConcurrentTileFactory.java

static long getBufferSizeCSM(ComponentSampleModel csm) {
    int[] bandOffsets = csm.getBandOffsets();
    int maxBandOff = bandOffsets[0];
    for (int i = 1; i < bandOffsets.length; i++)
        maxBandOff = Math.max(maxBandOff, bandOffsets[i]);

    long size = 0;
    if (maxBandOff >= 0)
        size += maxBandOff + 1;/*from   w w  w  . j av  a2  s  .  com*/
    int pixelStride = csm.getPixelStride();
    if (pixelStride > 0)
        size += pixelStride * (csm.getWidth() - 1);
    int scanlineStride = csm.getScanlineStride();
    if (scanlineStride > 0)
        size += scanlineStride * (csm.getHeight() - 1);
    return size;
}