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

The following examples show how to use java.awt.color.ColorSpace#getInstance() . 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: D3DGraphicsConfig.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Override
public ColorModel getColorModel(int transparency) {
    switch (transparency) {
    case Transparency.OPAQUE:
        // REMIND: once the ColorModel spec is changed, this should be
        //         an opaque premultiplied DCM...
        return new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
    case Transparency.BITMASK:
        return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
    case Transparency.TRANSLUCENT:
        ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
        return new DirectColorModel(cs, 32,
                                    0xff0000, 0xff00, 0xff, 0xff000000,
                                    true, DataBuffer.TYPE_INT);
    default:
        return null;
    }
}
 
Example 2
Source File: Color.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a <code>float</code> array containing only the color
 * components of the <code>Color</code> in the
 * <code>ColorSpace</code> specified by the <code>cspace</code>
 * parameter. If <code>compArray</code> is <code>null</code>, an array
 * with length equal to the number of components in
 * <code>cspace</code> is created for the return value.  Otherwise,
 * <code>compArray</code> must have at least this length, and it is
 * filled in with the components and returned.
 * @param cspace a specified <code>ColorSpace</code>
 * @param compArray an array that this method fills with the color
 *          components of this <code>Color</code> in the specified
 *          <code>ColorSpace</code>
 * @return the color components in a <code>float</code> array.
 */
public float[] getColorComponents(ColorSpace cspace, float[] compArray) {
    if (cs == null) {
        cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    }
    float f[];
    if (fvalue == null) {
        f = new float[3];
        f[0] = ((float)getRed())/255f;
        f[1] = ((float)getGreen())/255f;
        f[2] = ((float)getBlue())/255f;
    } else {
        f = fvalue;
    }
    float tmp[] = cs.toCIEXYZ(f);
    float tmpout[] = cspace.fromCIEXYZ(tmp);
    if (compArray == null) {
        return tmpout;
    }
    for (int i = 0 ; i < tmpout.length ; i++) {
        compArray[i] = tmpout[i];
    }
    return compArray;
}
 
Example 3
Source File: UNIXToolkit.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * This method is used by JNI as a callback from load_stock_icon.
 * Image data is passed back to us via this method and loaded into the
 * local BufferedImage and then returned via getStockIcon.
 *
 * Do NOT call this method directly.
 */
public void loadIconCallback(byte[] data, int width, int height,
        int rowStride, int bps, int channels, boolean alpha) {
    // Reset the stock image to null.
    tmpImage = null;

    // Create a new BufferedImage based on the data returned from the
    // JNI call.
    DataBuffer dataBuf = new DataBufferByte(data, (rowStride * height));
    // Maybe test # channels to determine band offsets?
    WritableRaster raster = Raster.createInterleavedRaster(dataBuf,
            width, height, rowStride, channels,
            (alpha ? BAND_OFFSETS_ALPHA : BAND_OFFSETS), null);
    ColorModel colorModel = new ComponentColorModel(
            ColorSpace.getInstance(ColorSpace.CS_sRGB), alpha, false,
            ColorModel.TRANSLUCENT, DataBuffer.TYPE_BYTE);

    // Set the local image so we can return it later from
    // getStockIcon().
    tmpImage = new BufferedImage(colorModel, raster, false, null);
}
 
Example 4
Source File: D3DGraphicsConfig.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public ColorModel getColorModel(int transparency) {
    switch (transparency) {
    case Transparency.OPAQUE:
        // REMIND: once the ColorModel spec is changed, this should be
        //         an opaque premultiplied DCM...
        return new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
    case Transparency.BITMASK:
        return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
    case Transparency.TRANSLUCENT:
        ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
        return new DirectColorModel(cs, 32,
                                    0xff0000, 0xff00, 0xff, 0xff000000,
                                    true, DataBuffer.TYPE_INT);
    default:
        return null;
    }
}
 
Example 5
Source File: BMPSubsamplingTest.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private BufferedImage create3ByteImage(int[] nBits, int[] bOffs) {
    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    ColorModel colorModel =
        new ComponentColorModel(cs, nBits,
                                false, false,
                                Transparency.OPAQUE,
                                DataBuffer.TYPE_BYTE);
    WritableRaster raster =
        Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
                                       w, h,
                                       w*3, 3,
                                       bOffs, null);
    return new BufferedImage(colorModel, raster, false, null);
}
 
Example 6
Source File: CMMTests.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
protected static ColorSpace getColorSpace(TestEnvironment env) {
    ColorSpace cs;
    Boolean usePlatfrom = true; //(Boolean)env.getModifier(usePlatfromProfiles);

    int cs_code = env.getIntValue(csList);
    if (usePlatfrom) {
        cs = ColorSpace.getInstance(cs_code);
    } else {
        String resource = "profiles/";
        switch (cs_code) {
            case ColorSpace.CS_CIEXYZ:
                resource += "CIEXYZ.pf";
                break;
            case ColorSpace.CS_GRAY:
                resource += "GRAY.pf";
                break;
            case ColorSpace.CS_LINEAR_RGB:
                resource += "LINEAR_RGB.pf";
                break;
            case ColorSpace.CS_PYCC:
                resource += "PYCC.pf";
                break;
            case ColorSpace.CS_sRGB:
                resource += "sRGB.pf";
                break;
            default:
                throw new RuntimeException("Unknown color space: " + cs_code);
        }

        try {
            InputStream is = CMMTests.class.getResourceAsStream(resource);
            ICC_Profile p = ICC_Profile.getInstance(is);

            cs = new ICC_ColorSpace(p);
        } catch (IOException e) {
            throw new RuntimeException("Unable load profile from resource " + resource, e);
        }
    }
    return cs;
}
 
Example 7
Source File: RenderToCustomBufferTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static BufferedImage createCustomBuffer() {
    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    ColorModel cm = new ComponentColorModel(cs, false, false,
            Transparency.OPAQUE, DataBuffer.TYPE_FLOAT);
    WritableRaster wr = cm.createCompatibleWritableRaster(width, height);

    return new BufferedImage(cm, wr, false, null);
}
 
Example 8
Source File: AlphaTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);

    ColorConvertOp op = new ColorConvertOp(cs, null);
    // create source image filled with an opaque color
    BufferedImage src = createSrc();
    int srcAlpha = getAlpha(src);

    System.out.printf("Src alpha: 0x%02x\n", srcAlpha);

    // create clear (transparent black) destination image
    BufferedImage dst = createDst();
    int dstAlpha = getAlpha(dst);
    System.out.printf("Dst alpha: 0x%02x\n", dstAlpha);


    dst = op.filter(src, dst);
    dstAlpha = getAlpha(dst);
    // we expect that destination image is opaque
    // i.e. alpha is transferred from source to
    // the destination
    System.out.printf("Result alpha: 0x%02x\n", dstAlpha);

    if (srcAlpha != dstAlpha) {
        throw new RuntimeException("Test failed!");
    }
    System.out.println("Test passed");
}
 
Example 9
Source File: CMYKJPEGImageReader.java    From jpexs-decompiler with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a buffered image from a raster in the YCCK color space,
 * converting the colors to RGB using the provided CMYK ICC_Profile.
 *
 * @param ycckRaster A raster with (at least) 4 bands of samples.
 * @param cmykProfile An ICC_Profile for conversion from the CMYK color
 * space to the RGB color space. If this parameter is null, a default
 * profile is used.
 * @return a BufferedImage in the RGB color space.
 * @throws NullPointerException.
 */
public static BufferedImage createRGBImageFromYCCK(Raster ycckRaster, ICC_Profile cmykProfile) {
    BufferedImage image;
    if (cmykProfile != null) {
        ycckRaster = convertYCCKtoCMYK(ycckRaster);
        image = createRGBImageFromCMYK(ycckRaster, cmykProfile);
    } else {
        int w = ycckRaster.getWidth(), h = ycckRaster.getHeight();
        int[] rgb = new int[w * h];
        int[] Y = ycckRaster.getSamples(0, 0, w, h, 0, (int[]) null);
        int[] Cb = ycckRaster.getSamples(0, 0, w, h, 1, (int[]) null);
        int[] Cr = ycckRaster.getSamples(0, 0, w, h, 2, (int[]) null);
        int[] K = ycckRaster.getSamples(0, 0, w, h, 3, (int[]) null);

        float vr, vg, vb;
        for (int i = 0, imax = Y.length; i < imax; i++) {
            // FIXME - Use integer arithmetic to improve performance
            float k = K[i], y = Y[i], cb = Cb[i], cr = Cr[i];
            vr = y + 1.402f * (cr - 128) - k;
            vg = y - 0.34414f * (cb - 128) - 0.71414f * (cr - 128) - k;
            vb = y + 1.772f * (cb - 128) - k;
            rgb[i] = (0xff & (vr < 0.0f ? 0 : vr > 255.0f ? 0xff : (int) (vr + 0.5f))) << 16
                    | (0xff & (vg < 0.0f ? 0 : vg > 255.0f ? 0xff : (int) (vg + 0.5f))) << 8
                    | (0xff & (vb < 0.0f ? 0 : vb > 255.0f ? 0xff : (int) (vb + 0.5f)));
        }

        Raster rgbRaster = Raster.createPackedRaster(
                new DataBufferInt(rgb, rgb.length),
                w, h, w, new int[]{0xff0000, 0xff00, 0xff}, null);
        ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
        ColorModel cm = RGB;//new DirectColorModel(cs, 24, 0xff0000, 0xff00, 0xff, 0x0, false, DataBuffer.TYPE_INT);

        image = new BufferedImage(cm, (WritableRaster) rgbRaster, true, null);
    }
    return image;
}
 
Example 10
Source File: WDataTransferer.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected byte[] imageToPlatformBytes(Image image, long format)
        throws IOException {
    String mimeType = null;
    if (format == CF_PNG) {
        mimeType = "image/png";
    } else if (format == CF_JFIF) {
        mimeType = "image/jpeg";
    }
    if (mimeType != null) {
        return imageToStandardBytes(image, mimeType);
    }

    int width = 0;
    int height = 0;

    if (image instanceof ToolkitImage) {
        ImageRepresentation ir = ((ToolkitImage)image).getImageRep();
        ir.reconstruct(ImageObserver.ALLBITS);
        width = ir.getWidth();
        height = ir.getHeight();
    } else {
        width = image.getWidth(null);
        height = image.getHeight(null);
    }

    // Fix for 4919639.
    // Some Windows native applications (e.g. clipbrd.exe) do not handle
    // 32-bpp DIBs correctly.
    // As a workaround we switched to 24-bpp DIBs.
    // MSDN prescribes that the bitmap array for a 24-bpp should consist of
    // 3-byte triplets representing blue, green and red components of a
    // pixel respectively. Additionally each scan line must be padded with
    // zeroes to end on a LONG data-type boundary. LONG is always 32-bit.
    // We render the given Image to a BufferedImage of type TYPE_3BYTE_BGR
    // with non-default scanline stride and pass the resulting data buffer
    // to the native code to fill the BITMAPINFO structure.
    int mod = (width * 3) % 4;
    int pad = mod > 0 ? 4 - mod : 0;

    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    int[] nBits = {8, 8, 8};
    int[] bOffs = {2, 1, 0};
    ColorModel colorModel =
            new ComponentColorModel(cs, nBits, false, false,
                    Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
    WritableRaster raster =
            Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, width, height,
                    width * 3 + pad, 3, bOffs, null);

    BufferedImage bimage = new BufferedImage(colorModel, raster, false, null);

    // Some Windows native applications (e.g. clipbrd.exe) do not understand
    // top-down DIBs.
    // So we flip the image vertically and create a bottom-up DIB.
    AffineTransform imageFlipTransform =
            new AffineTransform(1, 0, 0, -1, 0, height);

    Graphics2D g2d = bimage.createGraphics();

    try {
        g2d.drawImage(image, imageFlipTransform, null);
    } finally {
        g2d.dispose();
    }

    DataBufferByte buffer = (DataBufferByte)raster.getDataBuffer();

    byte[] imageData = buffer.getData();
    return imageDataToPlatformImageBytes(imageData, width, height, format);
}
 
Example 11
Source File: X11GraphicsConfig.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static DirectColorModel createDCM32(int rMask, int gMask, int bMask,
                                           int aMask, boolean aPre) {
    return new DirectColorModel(
        ColorSpace.getInstance(ColorSpace.CS_sRGB),
        32, rMask, gMask, bMask, aMask, aPre, DataBuffer.TYPE_INT);
}
 
Example 12
Source File: bug8038000.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private void checkOps() throws Exception {

        RasterOp[] ops = new RasterOp[] {
                new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_sRGB),
                        ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), null),
                new AffineTransformOp(AffineTransform.getScaleInstance(1, 1.1), null)
        };


        for (RasterOp op: ops) {
            // Banded rasters
            checkOp(Raster.createBandedRaster(DataBuffer.TYPE_BYTE, 10, 1, 10,
                            new int[] {0, 1, 2}, new int[]{2,1,0}, null),
                    Raster.createBandedRaster(DataBuffer.TYPE_BYTE, 10, 1, 1001,
                            new int[] {0, 1, 2}, new int[]{2,1,0}, null), op);
            checkOp(Raster.createBandedRaster(DataBuffer.TYPE_USHORT, 10, 1, 10,
                    new int[] {0, 1, 2}, new int[]{2,1,0}, null),
                    Raster.createBandedRaster(DataBuffer.TYPE_USHORT, 10, 1, 1001,
                            new int[] {0, 1, 2}, new int[]{2,1,0}, null), op);
            checkOp(Raster.createBandedRaster(DataBuffer.TYPE_INT, 10, 1, 10,
                    new int[] {0, 1, 2}, new int[]{2,1,0}, null),
                    Raster.createBandedRaster(DataBuffer.TYPE_INT, 10, 1, 1001,
                            new int[] {0, 1, 2}, new int[]{2,1,0}, null), op);

            // Interleaved rasters
            checkOp(Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
                            10, 1, 30, 3, new int[]{0, 1, 2}, null),
                    Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
                            10, 1, 1001, 3, new int[]{0, 1, 2}, null),
                    op);

            checkOp(Raster.createInterleavedRaster(DataBuffer.TYPE_USHORT,
                            10, 1, 30, 3, new int[]{0, 1, 2}, null),
                    Raster.createInterleavedRaster(DataBuffer.TYPE_USHORT,
                            10, 1, 1001, 3, new int[]{0, 1, 2}, null),
                    op);

            // Packed rasters
            checkOp(Raster.createPackedRaster(new DataBufferByte(10), 10, 1, 10,
                            new int[] {0x01, 0x02, 0x04}, null),
                    Raster.createPackedRaster(new DataBufferByte(10), 10, 1, 2000,
                            new int[] {0x01, 0x02, 0x04}, null),
                    op);
            checkOp(Raster.createPackedRaster(new DataBufferInt(10), 10, 1, 10,
                        new int[] {0xff0000, 0x00ff00, 0x0000ff}, null),
                    Raster.createPackedRaster(new DataBufferInt(10), 10, 1, 20,
                            new int[] {0xff0000, 0x00ff00, 0x0000ff}, null),
                    op);

        }
    }
 
Example 13
Source File: GrayTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public GrayTest() {
    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
    op = new ColorConvertOp(cs, null);
}
 
Example 14
Source File: StreamLayer.java    From Panako with GNU Affero General Public License v3.0 4 votes vote down vote up
private Color getBackgroundColor(){
	float[] components = new float[3];
	color.getColorComponents(components);
	Color backgroundColor = new Color(ColorSpace.getInstance(ColorSpace.CS_sRGB),components , 0.13f);
	return backgroundColor;
}
 
Example 15
Source File: ChromaticityDiagramController.java    From MyBox with Apache License 2.0 4 votes vote down vote up
private void initCIEData() {
    synchronized (this) {
        if (task != null) {
            return;
        }
        task = new SingletonTask<Void>() {
            private String degree2nm1String, degree10nm1String,
                    degree2nm5String, degree10nm5String;

            @Override
            protected boolean handle() {
                CIEData cieData = new CIEData();
                ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);

                degree2nm1Data = FXCollections.observableArrayList();
                degree2nm1Data.addAll(cieData.cie1931Observer2Degree1nmData(cs));
                degree2nm1String = cieData.cie1931Observer2Degree1nmString(cs);

                degree10nm1Data = FXCollections.observableArrayList();
                degree10nm1Data.addAll(cieData.cie1964Observer10Degree1nmData(cs));
                degree10nm1String = cieData.cie1964Observer10Degree1nmString(cs);

                degree2nm5Data = FXCollections.observableArrayList();
                degree2nm5Data.addAll(cieData.cie1931Observer2Degree5nmData(cs));
                degree2nm5String = cieData.cie1931Observer2Degree5nmString(cs);

                degree10nm5Data = FXCollections.observableArrayList();
                degree10nm5Data.addAll(cieData.cie1964Observer10Degree5nmData(cs));
                degree10nm5String = cieData.cie1964Observer10Degree5nmString(cs);

                return true;
            }

            @Override
            protected void whenSucceeded() {
                d2n1TableView.setItems(degree2nm1Data);
                d2n1Area.setText(degree2nm1String);

                d10n1TableView.setItems(degree10nm1Data);
                d10n1Area.setText(degree10nm1String);

                d2n5TableView.setItems(degree2nm5Data);
                d2n5Area.setText(degree2nm5String);

                d10n5TableView.setItems(degree10nm5Data);
                d10n5Area.setText(degree10nm5String);

                setColor(paletteButton, Color.THISTLE);

                loadTableData();
            }

        };
        openHandlingStage(task, Modality.WINDOW_MODAL);
        Thread thread = new Thread(task);
        thread.setDaemon(true);
        thread.start();
    }

}
 
Example 16
Source File: X11GraphicsConfig.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public static DirectColorModel createDCM32(int rMask, int gMask, int bMask,
                                           int aMask, boolean aPre) {
    return new DirectColorModel(
        ColorSpace.getInstance(ColorSpace.CS_sRGB),
        32, rMask, gMask, bMask, aMask, aPre, DataBuffer.TYPE_INT);
}
 
Example 17
Source File: IndexColorModel.java    From jdk8u_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Constructs an <code>IndexColorModel</code> from the given arrays
 * of red, green, and blue components.  Pixels described by this color
 * model all have alpha components of 255 unnormalized
 * (1.0&nbsp;normalized), which means they are fully opaque, except
 * for the indicated pixel to be made transparent.  All of the arrays
 * specifying the color components must have at least the specified
 * number of entries.
 * The <code>ColorSpace</code> is the default sRGB space.
 * The transparency value may be <code>Transparency.OPAQUE</code> or
 * <code>Transparency.BITMASK</code> depending on the arguments, as
 * specified in the <a href="#transparency">class description</a> above.
 * The transfer type is the smallest of <code>DataBuffer.TYPE_BYTE</code>
 * or <code>DataBuffer.TYPE_USHORT</code> that can hold a
 * single pixel.
 * @param bits      the number of bits each pixel occupies
 * @param size      the size of the color component arrays
 * @param r         the array of red color components
 * @param g         the array of green color components
 * @param b         the array of blue color components
 * @param trans     the index of the transparent pixel
 * @throws IllegalArgumentException if <code>bits</code> is less than
 *          1 or greater than 16
 * @throws IllegalArgumentException if <code>size</code> is less than
 *          1
 */
public IndexColorModel(int bits, int size,
                       byte r[], byte g[], byte b[], int trans) {
    super(bits, opaqueBits,
          ColorSpace.getInstance(ColorSpace.CS_sRGB),
          false, false, OPAQUE,
          ColorModel.getDefaultTransferType(bits));
    if (bits < 1 || bits > 16) {
        throw new IllegalArgumentException("Number of bits must be between"
                                           +" 1 and 16.");
    }
    setRGBs(size, r, g, b, null);
    setTransparentPixel(trans);
    calculatePixelMask();
}
 
Example 18
Source File: DirectColorModel.java    From Bytecoder with Apache License 2.0 3 votes vote down vote up
/**
 * Constructs a {@code DirectColorModel} from the specified masks
 * that indicate which bits in an {@code int} pixel representation
 * contain the red, green and blue color samples and the alpha sample,
 * if present.  If {@code amask} is 0, pixel values do not contain
 * alpha information and all pixels are treated as opaque, which means
 * that alpha&nbsp;=&nbsp;1.0.  All of the bits in each mask must
 * be contiguous and fit in the specified number of least significant bits
 * of an {@code int} pixel representation.  Alpha, if present, is not
 * premultiplied.  The {@code ColorSpace} is the default sRGB space.
 * The transparency value is Transparency.OPAQUE if no alpha is
 * present, or Transparency.TRANSLUCENT otherwise.  The transfer type
 * is the smallest of DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT,
 * or DataBuffer.TYPE_INT that can hold a single pixel.
 * @param bits the number of bits in the pixel values; for example,
 *         the sum of the number of bits in the masks.
 * @param rmask specifies a mask indicating which bits in an
 *         integer pixel contain the red component
 * @param gmask specifies a mask indicating which bits in an
 *         integer pixel contain the green component
 * @param bmask specifies a mask indicating which bits in an
 *         integer pixel contain the blue component
 * @param amask specifies a mask indicating which bits in an
 *         integer pixel contain the alpha component
 */
public DirectColorModel(int bits, int rmask, int gmask,
                        int bmask, int amask) {
    super (ColorSpace.getInstance(ColorSpace.CS_sRGB),
           bits, rmask, gmask, bmask, amask, false,
           amask == 0 ? Transparency.OPAQUE : Transparency.TRANSLUCENT,
           ColorModel.getDefaultTransferType(bits));
    setFields();
}
 
Example 19
Source File: IndexColorModel.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Constructs an <code>IndexColorModel</code> from an
 * <code>int</code> array where each <code>int</code> is
 * comprised of red, green, blue, and alpha
 * components in the default RGB color model format.
 * The array must have enough values in it to fill all
 * of the needed component arrays of the specified size.
 * The <code>ColorSpace</code> is the default sRGB space.
 * The transparency value may be any of <code>Transparency.OPAQUE</code>,
 * <code>Transparency.BITMASK</code>,
 * or <code>Transparency.TRANSLUCENT</code>
 * depending on the arguments, as specified
 * in the <a href="#transparency">class description</a> above.
 * The transfer type must be one of <code>DataBuffer.TYPE_BYTE</code>
 * <code>DataBuffer.TYPE_USHORT</code>.
 * The <code>BigInteger</code> object specifies the valid/invalid pixels
 * in the <code>cmap</code> array.  A pixel is valid if the
 * <code>BigInteger</code> value at that index is set, and is invalid
 * if the <code>BigInteger</code> bit  at that index is not set.
 * @param bits the number of bits each pixel occupies
 * @param size the size of the color component array
 * @param cmap the array of color components
 * @param start the starting offset of the first color component
 * @param transferType the specified data type
 * @param validBits a <code>BigInteger</code> object.  If a bit is
 *    set in the BigInteger, the pixel at that index is valid.
 *    If a bit is not set, the pixel at that index
 *    is considered invalid.  If null, all pixels are valid.
 *    Only bits from 0 to the map size are considered.
 * @throws IllegalArgumentException if <code>bits</code> is less
 *           than 1 or greater than 16
 * @throws IllegalArgumentException if <code>size</code> is less
 *           than 1
 * @throws IllegalArgumentException if <code>transferType</code> is not
 *           one of <code>DataBuffer.TYPE_BYTE</code> or
 *           <code>DataBuffer.TYPE_USHORT</code>
 *
 * @since 1.3
 */
public IndexColorModel(int bits, int size, int cmap[], int start,
                       int transferType, BigInteger validBits) {
    super (bits, alphaBits,
           ColorSpace.getInstance(ColorSpace.CS_sRGB),
           true, false, TRANSLUCENT,
           transferType);

    if (bits < 1 || bits > 16) {
        throw new IllegalArgumentException("Number of bits must be between"
                                           +" 1 and 16.");
    }
    if (size < 1) {
        throw new IllegalArgumentException("Map size ("+size+
                                           ") must be >= 1");
    }
    if ((transferType != DataBuffer.TYPE_BYTE) &&
        (transferType != DataBuffer.TYPE_USHORT)) {
        throw new IllegalArgumentException("transferType must be either" +
            "DataBuffer.TYPE_BYTE or DataBuffer.TYPE_USHORT");
    }

    if (validBits != null) {
        // Check to see if it is all valid
        for (int i=0; i < size; i++) {
            if (!validBits.testBit(i)) {
                this.validBits = validBits;
                break;
            }
        }
    }

    setRGBs(size, cmap, start, true);
    calculatePixelMask();
}
 
Example 20
Source File: IndexColorModel.java    From hottub with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Constructs an <code>IndexColorModel</code> from an
 * <code>int</code> array where each <code>int</code> is
 * comprised of red, green, blue, and alpha
 * components in the default RGB color model format.
 * The array must have enough values in it to fill all
 * of the needed component arrays of the specified size.
 * The <code>ColorSpace</code> is the default sRGB space.
 * The transparency value may be any of <code>Transparency.OPAQUE</code>,
 * <code>Transparency.BITMASK</code>,
 * or <code>Transparency.TRANSLUCENT</code>
 * depending on the arguments, as specified
 * in the <a href="#transparency">class description</a> above.
 * The transfer type must be one of <code>DataBuffer.TYPE_BYTE</code>
 * <code>DataBuffer.TYPE_USHORT</code>.
 * The <code>BigInteger</code> object specifies the valid/invalid pixels
 * in the <code>cmap</code> array.  A pixel is valid if the
 * <code>BigInteger</code> value at that index is set, and is invalid
 * if the <code>BigInteger</code> bit  at that index is not set.
 * @param bits the number of bits each pixel occupies
 * @param size the size of the color component array
 * @param cmap the array of color components
 * @param start the starting offset of the first color component
 * @param transferType the specified data type
 * @param validBits a <code>BigInteger</code> object.  If a bit is
 *    set in the BigInteger, the pixel at that index is valid.
 *    If a bit is not set, the pixel at that index
 *    is considered invalid.  If null, all pixels are valid.
 *    Only bits from 0 to the map size are considered.
 * @throws IllegalArgumentException if <code>bits</code> is less
 *           than 1 or greater than 16
 * @throws IllegalArgumentException if <code>size</code> is less
 *           than 1
 * @throws IllegalArgumentException if <code>transferType</code> is not
 *           one of <code>DataBuffer.TYPE_BYTE</code> or
 *           <code>DataBuffer.TYPE_USHORT</code>
 *
 * @since 1.3
 */
public IndexColorModel(int bits, int size, int cmap[], int start,
                       int transferType, BigInteger validBits) {
    super (bits, alphaBits,
           ColorSpace.getInstance(ColorSpace.CS_sRGB),
           true, false, TRANSLUCENT,
           transferType);

    if (bits < 1 || bits > 16) {
        throw new IllegalArgumentException("Number of bits must be between"
                                           +" 1 and 16.");
    }
    if (size < 1) {
        throw new IllegalArgumentException("Map size ("+size+
                                           ") must be >= 1");
    }
    if ((transferType != DataBuffer.TYPE_BYTE) &&
        (transferType != DataBuffer.TYPE_USHORT)) {
        throw new IllegalArgumentException("transferType must be either" +
            "DataBuffer.TYPE_BYTE or DataBuffer.TYPE_USHORT");
    }

    if (validBits != null) {
        // Check to see if it is all valid
        for (int i=0; i < size; i++) {
            if (!validBits.testBit(i)) {
                this.validBits = validBits;
                break;
            }
        }
    }

    setRGBs(size, cmap, start, true);
    calculatePixelMask();
}