Java Code Examples for java.awt.image.DataBuffer#TYPE_DOUBLE

The following examples show how to use java.awt.image.DataBuffer#TYPE_DOUBLE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Canny.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
private WritableRaster createEdgesRaster( int width, int height, int[] pixels ) {
    int dataType = DataBuffer.TYPE_DOUBLE;
    ComponentSampleModel sampleModel = new ComponentSampleModel(dataType, width, height, 1, width, new int[]{0});

    WritableRaster raster = RasterFactory.createWritableRaster(sampleModel, null);
    int index = 0;
    for( int y = 0; y < height; y++ ) {
        for( int x = 0; x < width; x++ ) {
            double value = (double) pixels[index];
            if (value != -1) {
                value = HMConstants.doubleNovalue;
            } else {
                value = 1.0;
            }
            raster.setSample(x, y, 0, value);
            index++;
        }
    }
    return raster;
}
 
Example 2
Source File: ColConvTest.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
static String getDTName(int dType) {
    switch(dType) {
        case DataBuffer.TYPE_BYTE:
            return "TYPE_BYTE";
        case DataBuffer.TYPE_DOUBLE:
            return "TYPE_DOUBLE";
        case DataBuffer.TYPE_FLOAT:
            return "TYPE_FLOAT";
        case DataBuffer.TYPE_INT:
            return "TYPE_INT";
        case DataBuffer.TYPE_SHORT:
            return "TYPE_SHORT";
        case DataBuffer.TYPE_USHORT:
            return "TYPE_USHORT";
        case DataBuffer.TYPE_UNDEFINED:
            return "TYPE_UNDEFINED";
    }
    return "UNKNOWN";
}
 
Example 3
Source File: TIFFDecompressor.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Return the number of bits occupied by {@code dataType}
 * which must be one of the {@code DataBuffer} {@code TYPE}s.
 */
private static int getDataTypeSize(int dataType) throws IIOException {
    int dataTypeSize = 0;
    switch(dataType) {
    case DataBuffer.TYPE_BYTE:
        dataTypeSize = 8;
        break;
    case DataBuffer.TYPE_SHORT:
    case DataBuffer.TYPE_USHORT:
        dataTypeSize = 16;
        break;
    case DataBuffer.TYPE_INT:
    case DataBuffer.TYPE_FLOAT:
        dataTypeSize = 32;
        break;
    case DataBuffer.TYPE_DOUBLE:
        dataTypeSize = 64;
        break;
    default:
        throw new IIOException("Unknown data type "+dataType);
    }

    return dataTypeSize;
}
 
Example 4
Source File: ColConvTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
static String getDTName(int dType) {
    switch(dType) {
        case DataBuffer.TYPE_BYTE:
            return "TYPE_BYTE";
        case DataBuffer.TYPE_DOUBLE:
            return "TYPE_DOUBLE";
        case DataBuffer.TYPE_FLOAT:
            return "TYPE_FLOAT";
        case DataBuffer.TYPE_INT:
            return "TYPE_INT";
        case DataBuffer.TYPE_SHORT:
            return "TYPE_SHORT";
        case DataBuffer.TYPE_USHORT:
            return "TYPE_USHORT";
        case DataBuffer.TYPE_UNDEFINED:
            return "TYPE_UNDEFINED";
    }
    return "UNKNOWN";
}
 
Example 5
Source File: TIFFDecompressor.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return the number of bits occupied by {@code dataType}
 * which must be one of the {@code DataBuffer} {@code TYPE}s.
 */
private static int getDataTypeSize(int dataType) throws IIOException {
    int dataTypeSize = 0;
    switch(dataType) {
    case DataBuffer.TYPE_BYTE:
        dataTypeSize = 8;
        break;
    case DataBuffer.TYPE_SHORT:
    case DataBuffer.TYPE_USHORT:
        dataTypeSize = 16;
        break;
    case DataBuffer.TYPE_INT:
    case DataBuffer.TYPE_FLOAT:
        dataTypeSize = 32;
        break;
    case DataBuffer.TYPE_DOUBLE:
        dataTypeSize = 64;
        break;
    default:
        throw new IIOException("Unknown data type "+dataType);
    }

    return dataTypeSize;
}
 
Example 6
Source File: Canny.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
private WritableRaster createDoubleWritableRaster( int width, int height, float[] pixels ) {
    int dataType = DataBuffer.TYPE_DOUBLE;
    ComponentSampleModel sampleModel = new ComponentSampleModel(dataType, width, height, 1, width, new int[]{0});

    WritableRaster raster = RasterFactory.createWritableRaster(sampleModel, null);
    int index = 0;
    for( int y = 0; y < height; y++ ) {
        for( int x = 0; x < width; x++ ) {
            raster.setSample(x, y, 0, (double) pixels[index]);
            index++;
        }
    }
    return raster;
}
 
Example 7
Source File: GeneralRenderer.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
static PixelWriter createXorPixelWriter(SunGraphics2D sg2d,
                                        SurfaceData sData)
{
    ColorModel dstCM = sData.getColorModel();

    Object srcPixel = dstCM.getDataElements(sg2d.eargb, null);

    XORComposite comp = (XORComposite)sg2d.getComposite();
    int xorrgb = comp.getXorColor().getRGB();
    Object xorPixel = dstCM.getDataElements(xorrgb, null);

    switch (dstCM.getTransferType()) {
    case DataBuffer.TYPE_BYTE:
        return new XorPixelWriter.ByteData(srcPixel, xorPixel);
    case DataBuffer.TYPE_SHORT:
    case DataBuffer.TYPE_USHORT:
        return new XorPixelWriter.ShortData(srcPixel, xorPixel);
    case DataBuffer.TYPE_INT:
        return new XorPixelWriter.IntData(srcPixel, xorPixel);
    case DataBuffer.TYPE_FLOAT:
        return new XorPixelWriter.FloatData(srcPixel, xorPixel);
    case DataBuffer.TYPE_DOUBLE:
        return new XorPixelWriter.DoubleData(srcPixel, xorPixel);
    default:
        throw new InternalError("Unsupported XOR pixel type");
    }
}
 
Example 8
Source File: RasterUtils.java    From geowave with Apache License 2.0 5 votes vote down vote up
public static RasterDataAdapter createDataAdapterTypeDouble(
    final String coverageName,
    final int numBands,
    final int tileSize,
    final double[] minsPerBand,
    final double[] maxesPerBand,
    final String[] namesPerBand,
    final RasterTileMergeStrategy<?> mergeStrategy) {
  final double[][] noDataValuesPerBand = new double[numBands][];
  final double[] backgroundValuesPerBand = new double[numBands];
  final int[] bitsPerSample = new int[numBands];
  for (int i = 0; i < numBands; i++) {
    noDataValuesPerBand[i] = new double[] {Double.valueOf(Double.NaN)};
    backgroundValuesPerBand[i] = Double.valueOf(Double.NaN);
    bitsPerSample[i] = DataBuffer.getDataTypeSize(DataBuffer.TYPE_DOUBLE);
  }
  final SampleModel sampleModel = createRasterTypeDouble(numBands, tileSize).getSampleModel();
  return new RasterDataAdapter(
      coverageName,
      sampleModel,
      new ComponentColorModel(
          new BogusColorSpace(numBands),
          bitsPerSample,
          false,
          false,
          Transparency.OPAQUE,
          DataBuffer.TYPE_DOUBLE),
      new HashMap<String, String>(),
      tileSize,
      minsPerBand,
      maxesPerBand,
      namesPerBand,
      noDataValuesPerBand,
      backgroundValuesPerBand,
      null,
      false,
      Interpolation.INTERP_NEAREST,
      false,
      mergeStrategy);
}
 
Example 9
Source File: GeneralRenderer.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
static PixelWriter createXorPixelWriter(SunGraphics2D sg2d,
                                        SurfaceData sData)
{
    ColorModel dstCM = sData.getColorModel();

    Object srcPixel = dstCM.getDataElements(sg2d.eargb, null);

    XORComposite comp = (XORComposite)sg2d.getComposite();
    int xorrgb = comp.getXorColor().getRGB();
    Object xorPixel = dstCM.getDataElements(xorrgb, null);

    switch (dstCM.getTransferType()) {
    case DataBuffer.TYPE_BYTE:
        return new XorPixelWriter.ByteData(srcPixel, xorPixel);
    case DataBuffer.TYPE_SHORT:
    case DataBuffer.TYPE_USHORT:
        return new XorPixelWriter.ShortData(srcPixel, xorPixel);
    case DataBuffer.TYPE_INT:
        return new XorPixelWriter.IntData(srcPixel, xorPixel);
    case DataBuffer.TYPE_FLOAT:
        return new XorPixelWriter.FloatData(srcPixel, xorPixel);
    case DataBuffer.TYPE_DOUBLE:
        return new XorPixelWriter.DoubleData(srcPixel, xorPixel);
    default:
        throw new InternalError("Unsupported XOR pixel type");
    }
}
 
Example 10
Source File: GeneralRenderer.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
static PixelWriter createXorPixelWriter(SunGraphics2D sg2d,
                                        SurfaceData sData)
{
    ColorModel dstCM = sData.getColorModel();

    Object srcPixel = dstCM.getDataElements(sg2d.eargb, null);

    XORComposite comp = (XORComposite)sg2d.getComposite();
    int xorrgb = comp.getXorColor().getRGB();
    Object xorPixel = dstCM.getDataElements(xorrgb, null);

    switch (dstCM.getTransferType()) {
    case DataBuffer.TYPE_BYTE:
        return new XorPixelWriter.ByteData(srcPixel, xorPixel);
    case DataBuffer.TYPE_SHORT:
    case DataBuffer.TYPE_USHORT:
        return new XorPixelWriter.ShortData(srcPixel, xorPixel);
    case DataBuffer.TYPE_INT:
        return new XorPixelWriter.IntData(srcPixel, xorPixel);
    case DataBuffer.TYPE_FLOAT:
        return new XorPixelWriter.FloatData(srcPixel, xorPixel);
    case DataBuffer.TYPE_DOUBLE:
        return new XorPixelWriter.DoubleData(srcPixel, xorPixel);
    default:
        throw new InternalError("Unsupported XOR pixel type");
    }
}
 
Example 11
Source File: GeneralRenderer.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
static PixelWriter createXorPixelWriter(SunGraphics2D sg2d,
                                        SurfaceData sData)
{
    ColorModel dstCM = sData.getColorModel();

    Object srcPixel = dstCM.getDataElements(sg2d.eargb, null);

    XORComposite comp = (XORComposite)sg2d.getComposite();
    int xorrgb = comp.getXorColor().getRGB();
    Object xorPixel = dstCM.getDataElements(xorrgb, null);

    switch (dstCM.getTransferType()) {
    case DataBuffer.TYPE_BYTE:
        return new XorPixelWriter.ByteData(srcPixel, xorPixel);
    case DataBuffer.TYPE_SHORT:
    case DataBuffer.TYPE_USHORT:
        return new XorPixelWriter.ShortData(srcPixel, xorPixel);
    case DataBuffer.TYPE_INT:
        return new XorPixelWriter.IntData(srcPixel, xorPixel);
    case DataBuffer.TYPE_FLOAT:
        return new XorPixelWriter.FloatData(srcPixel, xorPixel);
    case DataBuffer.TYPE_DOUBLE:
        return new XorPixelWriter.DoubleData(srcPixel, xorPixel);
    default:
        throw new InternalError("Unsupported XOR pixel type");
    }
}
 
Example 12
Source File: MrsImageInfo.java    From mrgeo with Apache License 2.0 5 votes vote down vote up
private static void printTileType(final MrsPyramidMetadata metadata, PrintStream out)
{
  out.print("Type: ");
  switch (metadata.getTileType())
  {
  case DataBuffer.TYPE_BYTE:
    out.println("byte");
    break;
  case DataBuffer.TYPE_FLOAT:
    out.println("float");
    break;
  case DataBuffer.TYPE_DOUBLE:
    out.println("double");
    break;
  case DataBuffer.TYPE_INT:
    out.println("int");
    break;
  case DataBuffer.TYPE_SHORT:
    out.println("short");
    break;
  case DataBuffer.TYPE_USHORT:
    out.println("unsigned short");
    break;
  default:
    break;
  }
}
 
Example 13
Source File: GeneralRenderer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
static PixelWriter createXorPixelWriter(SunGraphics2D sg2d,
                                        SurfaceData sData)
{
    ColorModel dstCM = sData.getColorModel();

    Object srcPixel = dstCM.getDataElements(sg2d.eargb, null);

    XORComposite comp = (XORComposite)sg2d.getComposite();
    int xorrgb = comp.getXorColor().getRGB();
    Object xorPixel = dstCM.getDataElements(xorrgb, null);

    switch (dstCM.getTransferType()) {
    case DataBuffer.TYPE_BYTE:
        return new XorPixelWriter.ByteData(srcPixel, xorPixel);
    case DataBuffer.TYPE_SHORT:
    case DataBuffer.TYPE_USHORT:
        return new XorPixelWriter.ShortData(srcPixel, xorPixel);
    case DataBuffer.TYPE_INT:
        return new XorPixelWriter.IntData(srcPixel, xorPixel);
    case DataBuffer.TYPE_FLOAT:
        return new XorPixelWriter.FloatData(srcPixel, xorPixel);
    case DataBuffer.TYPE_DOUBLE:
        return new XorPixelWriter.DoubleData(srcPixel, xorPixel);
    default:
        throw new InternalError("Unsupported XOR pixel type");
    }
}
 
Example 14
Source File: GeneralRenderer.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
static PixelWriter createXorPixelWriter(SunGraphics2D sg2d,
                                        SurfaceData sData)
{
    ColorModel dstCM = sData.getColorModel();

    Object srcPixel = dstCM.getDataElements(sg2d.eargb, null);

    XORComposite comp = (XORComposite)sg2d.getComposite();
    int xorrgb = comp.getXorColor().getRGB();
    Object xorPixel = dstCM.getDataElements(xorrgb, null);

    switch (dstCM.getTransferType()) {
    case DataBuffer.TYPE_BYTE:
        return new XorPixelWriter.ByteData(srcPixel, xorPixel);
    case DataBuffer.TYPE_SHORT:
    case DataBuffer.TYPE_USHORT:
        return new XorPixelWriter.ShortData(srcPixel, xorPixel);
    case DataBuffer.TYPE_INT:
        return new XorPixelWriter.IntData(srcPixel, xorPixel);
    case DataBuffer.TYPE_FLOAT:
        return new XorPixelWriter.FloatData(srcPixel, xorPixel);
    case DataBuffer.TYPE_DOUBLE:
        return new XorPixelWriter.DoubleData(srcPixel, xorPixel);
    default:
        throw new InternalError("Unsupported XOR pixel type");
    }
}
 
Example 15
Source File: ImageTypeSpecifier.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public Banded(ColorSpace colorSpace,
              int[] bankIndices,
              int[] bandOffsets,
              int dataType,
              boolean hasAlpha,
              boolean isAlphaPremultiplied) {
    if (colorSpace == null) {
        throw new IllegalArgumentException("colorSpace == null!");
    }
    if (bankIndices == null) {
        throw new IllegalArgumentException("bankIndices == null!");
    }
    if (bandOffsets == null) {
        throw new IllegalArgumentException("bandOffsets == null!");
    }
    if (bankIndices.length != bandOffsets.length) {
        throw new IllegalArgumentException
            ("bankIndices.length != bandOffsets.length!");
    }
    if (dataType != DataBuffer.TYPE_BYTE &&
        dataType != DataBuffer.TYPE_SHORT &&
        dataType != DataBuffer.TYPE_USHORT &&
        dataType != DataBuffer.TYPE_INT &&
        dataType != DataBuffer.TYPE_FLOAT &&
        dataType != DataBuffer.TYPE_DOUBLE) {
        throw new IllegalArgumentException
            ("Bad value for dataType!");
    }
    int numBands = colorSpace.getNumComponents() +
        (hasAlpha ? 1 : 0);
    if (bandOffsets.length != numBands) {
        throw new IllegalArgumentException
            ("bandOffsets.length is wrong!");
    }

    this.colorSpace = colorSpace;
    this.bankIndices = (int[])bankIndices.clone();
    this.bandOffsets = (int[])bandOffsets.clone();
    this.dataType = dataType;
    this.hasAlpha = hasAlpha;
    this.isAlphaPremultiplied = isAlphaPremultiplied;

    this.colorModel =
        ImageTypeSpecifier.createComponentCM(colorSpace,
                                             bankIndices.length,
                                             dataType,
                                             hasAlpha,
                                             isAlphaPremultiplied);

    int w = 1;
    int h = 1;
    this.sampleModel = new BandedSampleModel(dataType,
                                             w, h,
                                             w,
                                             bankIndices,
                                             bandOffsets);
}
 
Example 16
Source File: ImageTypeSpecifier.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
public Banded(ColorSpace colorSpace,
              int[] bankIndices,
              int[] bandOffsets,
              int dataType,
              boolean hasAlpha,
              boolean isAlphaPremultiplied) {
    if (colorSpace == null) {
        throw new IllegalArgumentException("colorSpace == null!");
    }
    if (bankIndices == null) {
        throw new IllegalArgumentException("bankIndices == null!");
    }
    if (bandOffsets == null) {
        throw new IllegalArgumentException("bandOffsets == null!");
    }
    if (bankIndices.length != bandOffsets.length) {
        throw new IllegalArgumentException
            ("bankIndices.length != bandOffsets.length!");
    }
    if (dataType != DataBuffer.TYPE_BYTE &&
        dataType != DataBuffer.TYPE_SHORT &&
        dataType != DataBuffer.TYPE_USHORT &&
        dataType != DataBuffer.TYPE_INT &&
        dataType != DataBuffer.TYPE_FLOAT &&
        dataType != DataBuffer.TYPE_DOUBLE) {
        throw new IllegalArgumentException
            ("Bad value for dataType!");
    }
    int numBands = colorSpace.getNumComponents() +
        (hasAlpha ? 1 : 0);
    if (bandOffsets.length != numBands) {
        throw new IllegalArgumentException
            ("bandOffsets.length is wrong!");
    }

    this.colorSpace = colorSpace;
    this.bankIndices = bankIndices.clone();
    this.bandOffsets = bandOffsets.clone();
    this.dataType = dataType;
    this.hasAlpha = hasAlpha;
    this.isAlphaPremultiplied = isAlphaPremultiplied;

    this.colorModel =
        ImageTypeSpecifier.createComponentCM(colorSpace,
                                             bankIndices.length,
                                             dataType,
                                             hasAlpha,
                                             isAlphaPremultiplied);

    int w = 1;
    int h = 1;
    this.sampleModel = new BandedSampleModel(dataType,
                                             w, h,
                                             w,
                                             bankIndices,
                                             bandOffsets);
}
 
Example 17
Source File: ImageTypeSpecifier.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public Interleaved(ColorSpace colorSpace,
                   int[] bandOffsets,
                   int dataType,
                   boolean hasAlpha,
                   boolean isAlphaPremultiplied) {
    if (colorSpace == null) {
        throw new IllegalArgumentException("colorSpace == null!");
    }
    if (bandOffsets == null) {
        throw new IllegalArgumentException("bandOffsets == null!");
    }
    int numBands = colorSpace.getNumComponents() +
        (hasAlpha ? 1 : 0);
    if (bandOffsets.length != numBands) {
        throw new IllegalArgumentException
            ("bandOffsets.length is wrong!");
    }
    if (dataType != DataBuffer.TYPE_BYTE &&
        dataType != DataBuffer.TYPE_SHORT &&
        dataType != DataBuffer.TYPE_USHORT &&
        dataType != DataBuffer.TYPE_INT &&
        dataType != DataBuffer.TYPE_FLOAT &&
        dataType != DataBuffer.TYPE_DOUBLE) {
        throw new IllegalArgumentException
            ("Bad value for dataType!");
    }
    this.colorSpace = colorSpace;
    this.bandOffsets = (int[])bandOffsets.clone();
    this.dataType = dataType;
    this.hasAlpha = hasAlpha;
    this.isAlphaPremultiplied = isAlphaPremultiplied;

    this.colorModel =
        ImageTypeSpecifier.createComponentCM(colorSpace,
                                             bandOffsets.length,
                                             dataType,
                                             hasAlpha,
                                             isAlphaPremultiplied);

    int minBandOffset = bandOffsets[0];
    int maxBandOffset = minBandOffset;
    for (int i = 0; i < bandOffsets.length; i++) {
        int offset = bandOffsets[i];
        minBandOffset = Math.min(offset, minBandOffset);
        maxBandOffset = Math.max(offset, maxBandOffset);
    }
    int pixelStride = maxBandOffset - minBandOffset + 1;

    int w = 1;
    int h = 1;
    this.sampleModel =
        new PixelInterleavedSampleModel(dataType,
                                        w, h,
                                        pixelStride,
                                        w*pixelStride,
                                        bandOffsets);
}
 
Example 18
Source File: ImageTypeSpecifier.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public Interleaved(ColorSpace colorSpace,
                   int[] bandOffsets,
                   int dataType,
                   boolean hasAlpha,
                   boolean isAlphaPremultiplied) {
    if (colorSpace == null) {
        throw new IllegalArgumentException("colorSpace == null!");
    }
    if (bandOffsets == null) {
        throw new IllegalArgumentException("bandOffsets == null!");
    }
    int numBands = colorSpace.getNumComponents() +
        (hasAlpha ? 1 : 0);
    if (bandOffsets.length != numBands) {
        throw new IllegalArgumentException
            ("bandOffsets.length is wrong!");
    }
    if (dataType != DataBuffer.TYPE_BYTE &&
        dataType != DataBuffer.TYPE_SHORT &&
        dataType != DataBuffer.TYPE_USHORT &&
        dataType != DataBuffer.TYPE_INT &&
        dataType != DataBuffer.TYPE_FLOAT &&
        dataType != DataBuffer.TYPE_DOUBLE) {
        throw new IllegalArgumentException
            ("Bad value for dataType!");
    }
    this.colorSpace = colorSpace;
    this.bandOffsets = (int[])bandOffsets.clone();
    this.dataType = dataType;
    this.hasAlpha = hasAlpha;
    this.isAlphaPremultiplied = isAlphaPremultiplied;

    this.colorModel =
        ImageTypeSpecifier.createComponentCM(colorSpace,
                                             bandOffsets.length,
                                             dataType,
                                             hasAlpha,
                                             isAlphaPremultiplied);

    int minBandOffset = bandOffsets[0];
    int maxBandOffset = minBandOffset;
    for (int i = 0; i < bandOffsets.length; i++) {
        int offset = bandOffsets[i];
        minBandOffset = Math.min(offset, minBandOffset);
        maxBandOffset = Math.max(offset, maxBandOffset);
    }
    int pixelStride = maxBandOffset - minBandOffset + 1;

    int w = 1;
    int h = 1;
    this.sampleModel =
        new PixelInterleavedSampleModel(dataType,
                                        w, h,
                                        pixelStride,
                                        w*pixelStride,
                                        bandOffsets);
}
 
Example 19
Source File: ImageTypeSpecifier.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public Interleaved(ColorSpace colorSpace,
                   int[] bandOffsets,
                   int dataType,
                   boolean hasAlpha,
                   boolean isAlphaPremultiplied) {
    if (colorSpace == null) {
        throw new IllegalArgumentException("colorSpace == null!");
    }
    if (bandOffsets == null) {
        throw new IllegalArgumentException("bandOffsets == null!");
    }
    int numBands = colorSpace.getNumComponents() +
        (hasAlpha ? 1 : 0);
    if (bandOffsets.length != numBands) {
        throw new IllegalArgumentException
            ("bandOffsets.length is wrong!");
    }
    if (dataType != DataBuffer.TYPE_BYTE &&
        dataType != DataBuffer.TYPE_SHORT &&
        dataType != DataBuffer.TYPE_USHORT &&
        dataType != DataBuffer.TYPE_INT &&
        dataType != DataBuffer.TYPE_FLOAT &&
        dataType != DataBuffer.TYPE_DOUBLE) {
        throw new IllegalArgumentException
            ("Bad value for dataType!");
    }
    this.colorSpace = colorSpace;
    this.bandOffsets = (int[])bandOffsets.clone();
    this.dataType = dataType;
    this.hasAlpha = hasAlpha;
    this.isAlphaPremultiplied = isAlphaPremultiplied;

    this.colorModel =
        ImageTypeSpecifier.createComponentCM(colorSpace,
                                             bandOffsets.length,
                                             dataType,
                                             hasAlpha,
                                             isAlphaPremultiplied);

    int minBandOffset = bandOffsets[0];
    int maxBandOffset = minBandOffset;
    for (int i = 0; i < bandOffsets.length; i++) {
        int offset = bandOffsets[i];
        minBandOffset = Math.min(offset, minBandOffset);
        maxBandOffset = Math.max(offset, maxBandOffset);
    }
    int pixelStride = maxBandOffset - minBandOffset + 1;

    int w = 1;
    int h = 1;
    this.sampleModel =
        new PixelInterleavedSampleModel(dataType,
                                        w, h,
                                        pixelStride,
                                        w*pixelStride,
                                        bandOffsets);
}
 
Example 20
Source File: ImageTypeSpecifier.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public Banded(ColorSpace colorSpace,
              int[] bankIndices,
              int[] bandOffsets,
              int dataType,
              boolean hasAlpha,
              boolean isAlphaPremultiplied) {
    if (colorSpace == null) {
        throw new IllegalArgumentException("colorSpace == null!");
    }
    if (bankIndices == null) {
        throw new IllegalArgumentException("bankIndices == null!");
    }
    if (bandOffsets == null) {
        throw new IllegalArgumentException("bandOffsets == null!");
    }
    if (bankIndices.length != bandOffsets.length) {
        throw new IllegalArgumentException
            ("bankIndices.length != bandOffsets.length!");
    }
    if (dataType != DataBuffer.TYPE_BYTE &&
        dataType != DataBuffer.TYPE_SHORT &&
        dataType != DataBuffer.TYPE_USHORT &&
        dataType != DataBuffer.TYPE_INT &&
        dataType != DataBuffer.TYPE_FLOAT &&
        dataType != DataBuffer.TYPE_DOUBLE) {
        throw new IllegalArgumentException
            ("Bad value for dataType!");
    }
    int numBands = colorSpace.getNumComponents() +
        (hasAlpha ? 1 : 0);
    if (bandOffsets.length != numBands) {
        throw new IllegalArgumentException
            ("bandOffsets.length is wrong!");
    }

    this.colorSpace = colorSpace;
    this.bankIndices = (int[])bankIndices.clone();
    this.bandOffsets = (int[])bandOffsets.clone();
    this.dataType = dataType;
    this.hasAlpha = hasAlpha;
    this.isAlphaPremultiplied = isAlphaPremultiplied;

    this.colorModel =
        ImageTypeSpecifier.createComponentCM(colorSpace,
                                             bankIndices.length,
                                             dataType,
                                             hasAlpha,
                                             isAlphaPremultiplied);

    int w = 1;
    int h = 1;
    this.sampleModel = new BandedSampleModel(dataType,
                                             w, h,
                                             w,
                                             bankIndices,
                                             bandOffsets);
}