Java Code Examples for java.awt.color.ColorSpace#getNumComponents()

The following examples show how to use java.awt.color.ColorSpace#getNumComponents() . 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: ComponentColorModel.java    From jdk-1.7-annotated with Apache License 2.0 6 votes vote down vote up
private static int[] bitsArrayHelper(int[] origBits,
                                     int transferType,
                                     ColorSpace colorSpace,
                                     boolean hasAlpha) {
    switch(transferType) {
        case DataBuffer.TYPE_BYTE:
        case DataBuffer.TYPE_USHORT:
        case DataBuffer.TYPE_INT:
            if (origBits != null) {
                return origBits;
            }
            break;
        default:
            break;
    }
    int numBits = DataBuffer.getDataTypeSize(transferType);
    int numComponents = colorSpace.getNumComponents();
    if (hasAlpha) {
        ++numComponents;
    }
    int[] bits = new int[numComponents];
    for (int i = 0; i < numComponents; i++) {
        bits[i] = numBits;
    }
    return bits;
}
 
Example 2
Source File: ComponentColorModel.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
private static int[] bitsArrayHelper(int[] origBits,
                                     int transferType,
                                     ColorSpace colorSpace,
                                     boolean hasAlpha) {
    switch(transferType) {
        case DataBuffer.TYPE_BYTE:
        case DataBuffer.TYPE_USHORT:
        case DataBuffer.TYPE_INT:
            if (origBits != null) {
                return origBits;
            }
            break;
        default:
            break;
    }
    int numBits = DataBuffer.getDataTypeSize(transferType);
    int numComponents = colorSpace.getNumComponents();
    if (hasAlpha) {
        ++numComponents;
    }
    int[] bits = new int[numComponents];
    for (int i = 0; i < numComponents; i++) {
        bits[i] = numBits;
    }
    return bits;
}
 
Example 3
Source File: ComponentColorModel.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private static int[] bitsArrayHelper(int[] origBits,
                                     int transferType,
                                     ColorSpace colorSpace,
                                     boolean hasAlpha) {
    switch(transferType) {
        case DataBuffer.TYPE_BYTE:
        case DataBuffer.TYPE_USHORT:
        case DataBuffer.TYPE_INT:
            if (origBits != null) {
                return origBits;
            }
            break;
        default:
            break;
    }
    int numBits = DataBuffer.getDataTypeSize(transferType);
    int numComponents = colorSpace.getNumComponents();
    if (hasAlpha) {
        ++numComponents;
    }
    int[] bits = new int[numComponents];
    for (int i = 0; i < numComponents; i++) {
        bits[i] = numBits;
    }
    return bits;
}
 
Example 4
Source File: DataConversionTests.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public Context(TestEnvironment env, Result result, ColorSpace cs) {
    this.cs = cs;
    this.env = env;
    this.res = result;

    numComponents = cs.getNumComponents();

    val = new float[numComponents];

    for (int i = 0; i < numComponents; i++) {
        float min = cs.getMinValue(i);
        float max = cs.getMaxValue(i);

        val[i] = 0.5f * (max - min);
    }

    rgb = new float[]{0.5f, 0.5f, 0.5f};
    cie = new float[]{0.5f, 0.5f, 0.5f};
}
 
Example 5
Source File: DataConversionTests.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public Context(TestEnvironment env, Result result, ColorSpace cs) {
    this.cs = cs;
    this.env = env;
    this.res = result;

    numComponents = cs.getNumComponents();

    val = new float[numComponents];

    for (int i = 0; i < numComponents; i++) {
        float min = cs.getMinValue(i);
        float max = cs.getMaxValue(i);

        val[i] = 0.5f * (max - min);
    }

    rgb = new float[]{0.5f, 0.5f, 0.5f};
    cie = new float[]{0.5f, 0.5f, 0.5f};
}
 
Example 6
Source File: Color.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a color in the specified <code>ColorSpace</code>
 * with the color components specified in the <code>float</code>
 * array and the specified alpha.  The number of components is
 * determined by the type of the <code>ColorSpace</code>.  For
 * example, RGB requires 3 components, but CMYK requires 4
 * components.
 * @param cspace the <code>ColorSpace</code> to be used to
 *                  interpret the components
 * @param components an arbitrary number of color components
 *                      that is compatible with the <code>ColorSpace</code>
 * @param alpha alpha value
 * @throws IllegalArgumentException if any of the values in the
 *         <code>components</code> array or <code>alpha</code> is
 *         outside of the range 0.0 to 1.0
 * @see #getComponents
 * @see #getColorComponents
 */
public Color(ColorSpace cspace, float components[], float alpha) {
    boolean rangeError = false;
    String badComponentString = "";
    int n = cspace.getNumComponents();
    fvalue = new float[n];
    for (int i = 0; i < n; i++) {
        if (components[i] < 0.0 || components[i] > 1.0) {
            rangeError = true;
            badComponentString = badComponentString + "Component " + i
                                 + " ";
        } else {
            fvalue[i] = components[i];
        }
    }
    if (alpha < 0.0 || alpha > 1.0) {
        rangeError = true;
        badComponentString = badComponentString + "Alpha";
    } else {
        falpha = alpha;
    }
    if (rangeError) {
        throw new IllegalArgumentException(
            "Color parameter outside of expected range: " +
            badComponentString);
    }
    frgbvalue = cspace.toRGB(fvalue);
    cs = cspace;
    value = ((((int)(falpha*255)) & 0xFF) << 24) |
            ((((int)(frgbvalue[0]*255)) & 0xFF) << 16) |
            ((((int)(frgbvalue[1]*255)) & 0xFF) << 8)  |
            ((((int)(frgbvalue[2]*255)) & 0xFF) << 0);
}
 
Example 7
Source File: ComponentColorModel.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static int bitsHelper(int transferType,
                              ColorSpace colorSpace,
                              boolean hasAlpha) {
    int numBits = DataBuffer.getDataTypeSize(transferType);
    int numComponents = colorSpace.getNumComponents();
    if (hasAlpha) {
        ++numComponents;
    }
    return numBits * numComponents;
}
 
Example 8
Source File: Color.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a color in the specified <code>ColorSpace</code>
 * with the color components specified in the <code>float</code>
 * array and the specified alpha.  The number of components is
 * determined by the type of the <code>ColorSpace</code>.  For
 * example, RGB requires 3 components, but CMYK requires 4
 * components.
 * @param cspace the <code>ColorSpace</code> to be used to
 *                  interpret the components
 * @param components an arbitrary number of color components
 *                      that is compatible with the <code>ColorSpace</code>
 * @param alpha alpha value
 * @throws IllegalArgumentException if any of the values in the
 *         <code>components</code> array or <code>alpha</code> is
 *         outside of the range 0.0 to 1.0
 * @see #getComponents
 * @see #getColorComponents
 */
public Color(ColorSpace cspace, float components[], float alpha) {
    boolean rangeError = false;
    String badComponentString = "";
    int n = cspace.getNumComponents();
    fvalue = new float[n];
    for (int i = 0; i < n; i++) {
        if (components[i] < 0.0 || components[i] > 1.0) {
            rangeError = true;
            badComponentString = badComponentString + "Component " + i
                                 + " ";
        } else {
            fvalue[i] = components[i];
        }
    }
    if (alpha < 0.0 || alpha > 1.0) {
        rangeError = true;
        badComponentString = badComponentString + "Alpha";
    } else {
        falpha = alpha;
    }
    if (rangeError) {
        throw new IllegalArgumentException(
            "Color parameter outside of expected range: " +
            badComponentString);
    }
    frgbvalue = cspace.toRGB(fvalue);
    cs = cspace;
    value = ((((int)(falpha*255)) & 0xFF) << 24) |
            ((((int)(frgbvalue[0]*255)) & 0xFF) << 16) |
            ((((int)(frgbvalue[1]*255)) & 0xFF) << 8)  |
            ((((int)(frgbvalue[2]*255)) & 0xFF) << 0);
}
 
Example 9
Source File: ComponentColorModel.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private static int bitsHelper(int transferType,
                              ColorSpace colorSpace,
                              boolean hasAlpha) {
    int numBits = DataBuffer.getDataTypeSize(transferType);
    int numComponents = colorSpace.getNumComponents();
    if (hasAlpha) {
        ++numComponents;
    }
    return numBits * numComponents;
}
 
Example 10
Source File: ComponentColorModel.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static int bitsHelper(int transferType,
                              ColorSpace colorSpace,
                              boolean hasAlpha) {
    int numBits = DataBuffer.getDataTypeSize(transferType);
    int numComponents = colorSpace.getNumComponents();
    if (hasAlpha) {
        ++numComponents;
    }
    return numBits * numComponents;
}
 
Example 11
Source File: ComponentColorModel.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static int bitsHelper(int transferType,
                              ColorSpace colorSpace,
                              boolean hasAlpha) {
    int numBits = DataBuffer.getDataTypeSize(transferType);
    int numComponents = colorSpace.getNumComponents();
    if (hasAlpha) {
        ++numComponents;
    }
    return numBits * numComponents;
}
 
Example 12
Source File: Color.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a color in the specified {@code ColorSpace}
 * with the color components specified in the {@code float}
 * array and the specified alpha.  The number of components is
 * determined by the type of the {@code ColorSpace}.  For
 * example, RGB requires 3 components, but CMYK requires 4
 * components.
 * @param cspace the {@code ColorSpace} to be used to
 *                  interpret the components
 * @param components an arbitrary number of color components
 *                      that is compatible with the {@code ColorSpace}
 * @param alpha alpha value
 * @throws IllegalArgumentException if any of the values in the
 *         {@code components} array or {@code alpha} is
 *         outside of the range 0.0 to 1.0
 * @see #getComponents
 * @see #getColorComponents
 */
public Color(ColorSpace cspace, float components[], float alpha) {
    boolean rangeError = false;
    String badComponentString = "";
    int n = cspace.getNumComponents();
    fvalue = new float[n];
    for (int i = 0; i < n; i++) {
        if (components[i] < 0.0 || components[i] > 1.0) {
            rangeError = true;
            badComponentString = badComponentString + "Component " + i
                                 + " ";
        } else {
            fvalue[i] = components[i];
        }
    }
    if (alpha < 0.0 || alpha > 1.0) {
        rangeError = true;
        badComponentString = badComponentString + "Alpha";
    } else {
        falpha = alpha;
    }
    if (rangeError) {
        throw new IllegalArgumentException(
            "Color parameter outside of expected range: " +
            badComponentString);
    }
    frgbvalue = cspace.toRGB(fvalue);
    cs = cspace;
    value = ((((int)(falpha*255)) & 0xFF) << 24) |
            ((((int)(frgbvalue[0]*255)) & 0xFF) << 16) |
            ((((int)(frgbvalue[1]*255)) & 0xFF) << 8)  |
            ((((int)(frgbvalue[2]*255)) & 0xFF) << 0);
}
 
Example 13
Source File: ComponentColorModel.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static int bitsHelper(int transferType,
                              ColorSpace colorSpace,
                              boolean hasAlpha) {
    int numBits = DataBuffer.getDataTypeSize(transferType);
    int numComponents = colorSpace.getNumComponents();
    if (hasAlpha) {
        ++numComponents;
    }
    return numBits * numComponents;
}
 
Example 14
Source File: ImageTypeSpecifier.java    From jdk8u60 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 15
Source File: ImageTypeSpecifier.java    From hottub 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 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 = 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 17
Source File: ImageTypeSpecifier.java    From JDKSourceCode1.8 with MIT License 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 jdk8u-jdk 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 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 20
Source File: ImageTypeSpecifier.java    From jdk1.8-source-analysis with Apache License 2.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);
}