Java Code Examples for java.awt.image.ColorModel#getRGBdefault()

The following examples show how to use java.awt.image.ColorModel#getRGBdefault() . 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: BufferedImageGraphicsConfig.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the color model associated with this configuration that
 * supports the specified transparency.
 */
public ColorModel getColorModel(int transparency) {

    if (model.getTransparency() == transparency) {
        return model;
    }
    switch (transparency) {
    case Transparency.OPAQUE:
        return new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
    case Transparency.BITMASK:
        return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
    case Transparency.TRANSLUCENT:
        return ColorModel.getRGBdefault();
    default:
        return null;
    }
}
 
Example 2
Source File: PixelGrabber.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void convertToRGB() {
    int size = dstW * dstH;
    int newpixels[] = new int[size];
    if (bytePixels != null) {
        for (int i = 0; i < size; i++) {
            newpixels[i] = imageModel.getRGB(bytePixels[i] & 0xff);
        }
    } else if (intPixels != null) {
        for (int i = 0; i < size; i++) {
            newpixels[i] = imageModel.getRGB(intPixels[i]);
        }
    }
    bytePixels = null;
    intPixels = newpixels;
    dstScan = dstW;
    dstOff = 0;
    imageModel = ColorModel.getRGBdefault();
}
 
Example 3
Source File: PrinterGraphicsConfig.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the color model associated with this configuration that
 * supports the specified transparency.
 */
@Override
public ColorModel getColorModel(int transparency) {
    switch (transparency) {
    case Transparency.OPAQUE:
        return getColorModel();
    case Transparency.BITMASK:
        return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
    case Transparency.TRANSLUCENT:
        return ColorModel.getRGBdefault();
    default:
        return null;
    }
}
 
Example 4
Source File: Win32GraphicsConfig.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the color model associated with this configuration that
 * supports the specified transparency.
 */
public ColorModel getColorModel(int transparency) {
    switch (transparency) {
    case Transparency.OPAQUE:
        return getColorModel();
    case Transparency.BITMASK:
        return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
    case Transparency.TRANSLUCENT:
        return ColorModel.getRGBdefault();
    default:
        return null;
    }
}
 
Example 5
Source File: PrinterGraphicsConfig.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the color model associated with this configuration that
 * supports the specified transparency.
 */
public ColorModel getColorModel(int transparency) {
    switch (transparency) {
    case Transparency.OPAQUE:
        return getColorModel();
    case Transparency.BITMASK:
        return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
    case Transparency.TRANSLUCENT:
        return ColorModel.getRGBdefault();
    default:
        return null;
    }
}
 
Example 6
Source File: PrinterGraphicsConfig.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the color model associated with this configuration that
 * supports the specified transparency.
 */
public ColorModel getColorModel(int transparency) {
    switch (transparency) {
    case Transparency.OPAQUE:
        return getColorModel();
    case Transparency.BITMASK:
        return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
    case Transparency.TRANSLUCENT:
        return ColorModel.getRGBdefault();
    default:
        return null;
    }
}
 
Example 7
Source File: ImageRepresentation.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public void setColorModel(ColorModel model) {
    if (src != null) {
        src.checkSecurity(null, false);
    }
    srcModel = model;

    // Check to see if model is INT_RGB
    if (model instanceof IndexColorModel) {
        if (model.getTransparency() == model.TRANSLUCENT) {
            // REMIND:
            // Probably need to composite anyway so force ARGB
            cmodel = ColorModel.getRGBdefault();
            srcLUT = null;
        }
        else {
            IndexColorModel icm = (IndexColorModel) model;
            numSrcLUT = icm.getMapSize();
            srcLUT = new int[Math.max(numSrcLUT, 256)];
            icm.getRGBs(srcLUT);
            srcLUTtransIndex = icm.getTransparentPixel();
            cmodel = model;
        }
    }
    else {
        if (cmodel == null) {
            cmodel = model;
            srcLUT   = null;
        }
        else if (model instanceof DirectColorModel) {
            // If it is INT_RGB or INT_ARGB, use the model
            DirectColorModel dcm = (DirectColorModel) model;
            if ((dcm.getRedMask() == 0xff0000) &&
                (dcm.getGreenMask() == 0xff00) &&
                (dcm.getBlueMask()  == 0x00ff)) {
                cmodel   = model;
                srcLUT   = null;
            }
        }
    }

    isSameCM = (cmodel == model);
}
 
Example 8
Source File: ImageRepresentation.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public void setColorModel(ColorModel model) {
    if (src != null) {
        src.checkSecurity(null, false);
    }
    srcModel = model;

    // Check to see if model is INT_RGB
    if (model instanceof IndexColorModel) {
        if (model.getTransparency() == model.TRANSLUCENT) {
            // REMIND:
            // Probably need to composite anyway so force ARGB
            cmodel = ColorModel.getRGBdefault();
            srcLUT = null;
        }
        else {
            IndexColorModel icm = (IndexColorModel) model;
            numSrcLUT = icm.getMapSize();
            srcLUT = new int[Math.max(numSrcLUT, 256)];
            icm.getRGBs(srcLUT);
            srcLUTtransIndex = icm.getTransparentPixel();
            cmodel = model;
        }
    }
    else {
        if (cmodel == null) {
            cmodel = model;
            srcLUT   = null;
        }
        else if (model instanceof DirectColorModel) {
            // If it is INT_RGB or INT_ARGB, use the model
            DirectColorModel dcm = (DirectColorModel) model;
            if ((dcm.getRedMask() == 0xff0000) &&
                (dcm.getGreenMask() == 0xff00) &&
                (dcm.getBlueMask()  == 0x00ff)) {
                cmodel   = model;
                srcLUT   = null;
            }
        }
    }

    isSameCM = (cmodel == model);
}
 
Example 9
Source File: MultipleGradientPaintContext.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This function is the meat of this class.  It calculates an array of
 * gradient colors based on an array of fractions and color values at
 * those fractions.
 */
private void calculateLookupData(Color[] colors) {
    Color[] normalizedColors;
    if (colorSpace == ColorSpaceType.LINEAR_RGB) {
        // create a new colors array
        normalizedColors = new Color[colors.length];
        // convert the colors using the lookup table
        for (int i = 0; i < colors.length; i++) {
            int argb = colors[i].getRGB();
            int a = argb >>> 24;
            int r = SRGBtoLinearRGB[(argb >> 16) & 0xff];
            int g = SRGBtoLinearRGB[(argb >>  8) & 0xff];
            int b = SRGBtoLinearRGB[(argb      ) & 0xff];
            normalizedColors[i] = new Color(r, g, b, a);
        }
    } else {
        // we can just use this array by reference since we do not
        // modify its values in the case of SRGB
        normalizedColors = colors;
    }

    // this will store the intervals (distances) between gradient stops
    normalizedIntervals = new float[fractions.length-1];

    // convert from fractions into intervals
    for (int i = 0; i < normalizedIntervals.length; i++) {
        // interval distance is equal to the difference in positions
        normalizedIntervals[i] = this.fractions[i+1] - this.fractions[i];
    }

    // initialize to be fully opaque for ANDing with colors
    transparencyTest = 0xff000000;

    // array of interpolation arrays
    gradients = new int[normalizedIntervals.length][];

    // find smallest interval
    float Imin = 1;
    for (int i = 0; i < normalizedIntervals.length; i++) {
        Imin = (Imin > normalizedIntervals[i]) ?
            normalizedIntervals[i] : Imin;
    }

    // Estimate the size of the entire gradients array.
    // This is to prevent a tiny interval from causing the size of array
    // to explode.  If the estimated size is too large, break to using
    // separate arrays for each interval, and using an indexing scheme at
    // look-up time.
    int estimatedSize = 0;
    for (int i = 0; i < normalizedIntervals.length; i++) {
        estimatedSize += (normalizedIntervals[i]/Imin) * GRADIENT_SIZE;
    }

    if (estimatedSize > MAX_GRADIENT_ARRAY_SIZE) {
        // slow method
        calculateMultipleArrayGradient(normalizedColors);
    } else {
        // fast method
        calculateSingleArrayGradient(normalizedColors, Imin);
    }

    // use the most "economical" model
    if ((transparencyTest >>> 24) == 0xff) {
        model = xrgbmodel;
    } else {
        model = ColorModel.getRGBdefault();
    }
}
 
Example 10
Source File: OffScreenImageSource.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
private void sendPixels() {
    ColorModel cm = image.getColorModel();
    WritableRaster raster = image.getRaster();
    int numDataElements = raster.getNumDataElements();
    int dataType = raster.getDataBuffer().getDataType();
    int[] scanline = new int[width*numDataElements];
    boolean needToCvt = true;

    if (cm instanceof IndexColorModel) {
        byte[] pixels = new byte[width];
        theConsumer.setColorModel(cm);

        if (raster instanceof ByteComponentRaster) {
            needToCvt = false;
            for (int y=0; y < height; y++) {
                raster.getDataElements(0, y, width, 1, pixels);
                theConsumer.setPixels(0, y, width, 1, cm, pixels, 0,
                                      width);
            }
        }
        else if (raster instanceof BytePackedRaster) {
            needToCvt = false;
            // Binary image.  Need to unpack it
            for (int y=0; y < height; y++) {
                raster.getPixels(0, y, width, 1, scanline);
                for (int x=0; x < width; x++) {
                    pixels[x] = (byte) scanline[x];
                }
                theConsumer.setPixels(0, y, width, 1, cm, pixels, 0,
                                      width);
            }
        }
        else if (dataType == DataBuffer.TYPE_SHORT ||
                 dataType == DataBuffer.TYPE_INT)
        {
            // Probably a short or int "GRAY" image
            needToCvt = false;
            for (int y=0; y < height; y++) {
                raster.getPixels(0, y, width, 1, scanline);
                theConsumer.setPixels(0, y, width, 1, cm, scanline, 0,
                                      width);
            }
        }
    }
    else if (cm instanceof DirectColorModel) {
        theConsumer.setColorModel(cm);
        needToCvt = false;
        switch (dataType) {
        case DataBuffer.TYPE_INT:
            for (int y=0; y < height; y++) {
                raster.getDataElements(0, y, width, 1, scanline);
                theConsumer.setPixels(0, y, width, 1, cm, scanline, 0,
                                      width);
            }
            break;
        case DataBuffer.TYPE_BYTE:
            byte[] bscanline = new byte[width];
            for (int y=0; y < height; y++) {
                raster.getDataElements(0, y, width, 1, bscanline);
                for (int x=0; x < width; x++) {
                    scanline[x] = bscanline[x]&0xff;
                }
                theConsumer.setPixels(0, y, width, 1, cm, scanline, 0,
                                      width);
            }
            break;
        case DataBuffer.TYPE_USHORT:
            short[] sscanline = new short[width];
            for (int y=0; y < height; y++) {
                raster.getDataElements(0, y, width, 1, sscanline);
                for (int x=0; x < width; x++) {
                    scanline[x] = sscanline[x]&0xffff;
                }
                theConsumer.setPixels(0, y, width, 1, cm, scanline, 0,
                                      width);
            }
            break;
        default:
            needToCvt = true;
        }
    }

    if (needToCvt) {
        // REMIND: Need to add other types of CMs here
        ColorModel newcm = ColorModel.getRGBdefault();
        theConsumer.setColorModel(newcm);

        for (int y=0; y < height; y++) {
            for (int x=0; x < width; x++) {
                scanline[x] = image.getRGB(x, y);
            }
            theConsumer.setPixels(0, y, width, 1, newcm, scanline, 0,
                                  width);
        }
    }
}
 
Example 11
Source File: ToolkitImage.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
protected ImageRepresentation makeImageRep() {
    return new ImageRepresentation(this, ColorModel.getRGBdefault(),
                                   false);
}
 
Example 12
Source File: BytecoderGraphicsConfiguration.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
@Override
public ColorModel getColorModel() {
    return ColorModel.getRGBdefault();
}
 
Example 13
Source File: ToolkitImage.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
protected ImageRepresentation makeImageRep() {
    return new ImageRepresentation(this, ColorModel.getRGBdefault(),
                                   false);
}
 
Example 14
Source File: ToolkitImage.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
protected ImageRepresentation makeImageRep() {
    return new ImageRepresentation(this, ColorModel.getRGBdefault(),
                                   false);
}
 
Example 15
Source File: ToolkitImage.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
protected ImageRepresentation makeImageRep() {
    return new ImageRepresentation(this, ColorModel.getRGBdefault(),
                                   false);
}
 
Example 16
Source File: ColorTools.java    From commons-imaging with Apache License 2.0 4 votes vote down vote up
public BufferedImage convertTosRGB(final BufferedImage bi) {
    final ColorModel srgbCM = ColorModel.getRGBdefault();
    return convertToColorSpace(bi, srgbCM.getColorSpace());
}
 
Example 17
Source File: ImageRepresentation.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public void setColorModel(ColorModel model) {
    if (src != null) {
        src.checkSecurity(null, false);
    }
    srcModel = model;

    // Check to see if model is INT_RGB
    if (model instanceof IndexColorModel) {
        if (model.getTransparency() == model.TRANSLUCENT) {
            // REMIND:
            // Probably need to composite anyway so force ARGB
            cmodel = ColorModel.getRGBdefault();
            srcLUT = null;
        }
        else {
            IndexColorModel icm = (IndexColorModel) model;
            numSrcLUT = icm.getMapSize();
            srcLUT = new int[Math.max(numSrcLUT, 256)];
            icm.getRGBs(srcLUT);
            srcLUTtransIndex = icm.getTransparentPixel();
            cmodel = model;
        }
    }
    else {
        if (cmodel == null) {
            cmodel = model;
            srcLUT   = null;
        }
        else if (model instanceof DirectColorModel) {
            // If it is INT_RGB or INT_ARGB, use the model
            DirectColorModel dcm = (DirectColorModel) model;
            if ((dcm.getRedMask() == 0xff0000) &&
                (dcm.getGreenMask() == 0xff00) &&
                (dcm.getBlueMask()  == 0x00ff)) {
                cmodel   = model;
                srcLUT   = null;
            }
        }
    }

    isSameCM = (cmodel == model);
}
 
Example 18
Source File: MultipleGradientPaintContext.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This function is the meat of this class.  It calculates an array of
 * gradient colors based on an array of fractions and color values at
 * those fractions.
 */
private void calculateLookupData(Color[] colors) {
    Color[] normalizedColors;
    if (colorSpace == ColorSpaceType.LINEAR_RGB) {
        // create a new colors array
        normalizedColors = new Color[colors.length];
        // convert the colors using the lookup table
        for (int i = 0; i < colors.length; i++) {
            int argb = colors[i].getRGB();
            int a = argb >>> 24;
            int r = SRGBtoLinearRGB[(argb >> 16) & 0xff];
            int g = SRGBtoLinearRGB[(argb >>  8) & 0xff];
            int b = SRGBtoLinearRGB[(argb      ) & 0xff];
            normalizedColors[i] = new Color(r, g, b, a);
        }
    } else {
        // we can just use this array by reference since we do not
        // modify its values in the case of SRGB
        normalizedColors = colors;
    }

    // this will store the intervals (distances) between gradient stops
    normalizedIntervals = new float[fractions.length-1];

    // convert from fractions into intervals
    for (int i = 0; i < normalizedIntervals.length; i++) {
        // interval distance is equal to the difference in positions
        normalizedIntervals[i] = this.fractions[i+1] - this.fractions[i];
    }

    // initialize to be fully opaque for ANDing with colors
    transparencyTest = 0xff000000;

    // array of interpolation arrays
    gradients = new int[normalizedIntervals.length][];

    // find smallest interval
    float Imin = 1;
    for (int i = 0; i < normalizedIntervals.length; i++) {
        Imin = (Imin > normalizedIntervals[i]) ?
            normalizedIntervals[i] : Imin;
    }

    // Estimate the size of the entire gradients array.
    // This is to prevent a tiny interval from causing the size of array
    // to explode.  If the estimated size is too large, break to using
    // separate arrays for each interval, and using an indexing scheme at
    // look-up time.
    int estimatedSize = 0;
    for (int i = 0; i < normalizedIntervals.length; i++) {
        estimatedSize += (normalizedIntervals[i]/Imin) * GRADIENT_SIZE;
    }

    if (estimatedSize > MAX_GRADIENT_ARRAY_SIZE) {
        // slow method
        calculateMultipleArrayGradient(normalizedColors);
    } else {
        // fast method
        calculateSingleArrayGradient(normalizedColors, Imin);
    }

    // use the most "economical" model
    if ((transparencyTest >>> 24) == 0xff) {
        model = xrgbmodel;
    } else {
        model = ColorModel.getRGBdefault();
    }
}
 
Example 19
Source File: PixelGrabber.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Create a PixelGrabber object to grab the (x, y, w, h) rectangular
 * section of pixels from the image produced by the specified
 * ImageProducer into the given array.
 * The pixels are stored into the array in the default RGB ColorModel.
 * The RGB data for pixel (i, j) where (i, j) is inside the rectangle
 * (x, y, w, h) is stored in the array at
 * <tt>pix[(j - y) * scansize + (i - x) + off]</tt>.
 * @param ip the <code>ImageProducer</code> that produces the
 * image from which to retrieve pixels
 * @param x the x coordinate of the upper left corner of the rectangle
 * of pixels to retrieve from the image, relative to the default
 * (unscaled) size of the image
 * @param y the y coordinate of the upper left corner of the rectangle
 * of pixels to retrieve from the image
 * @param w the width of the rectangle of pixels to retrieve
 * @param h the height of the rectangle of pixels to retrieve
 * @param pix the array of integers which are to be used to hold the
 * RGB pixels retrieved from the image
 * @param off the offset into the array of where to store the first pixel
 * @param scansize the distance from one row of pixels to the next in
 * the array
 * @see ColorModel#getRGBdefault
 */
public PixelGrabber(ImageProducer ip, int x, int y, int w, int h,
                    int[] pix, int off, int scansize) {
    producer = ip;
    dstX = x;
    dstY = y;
    dstW = w;
    dstH = h;
    dstOff = off;
    dstScan = scansize;
    intPixels = pix;
    imageModel = ColorModel.getRGBdefault();
}
 
Example 20
Source File: PixelGrabber.java    From jdk1.8-source-analysis with Apache License 2.0 3 votes vote down vote up
/**
 * Create a PixelGrabber object to grab the (x, y, w, h) rectangular
 * section of pixels from the image produced by the specified
 * ImageProducer into the given array.
 * The pixels are stored into the array in the default RGB ColorModel.
 * The RGB data for pixel (i, j) where (i, j) is inside the rectangle
 * (x, y, w, h) is stored in the array at
 * <tt>pix[(j - y) * scansize + (i - x) + off]</tt>.
 * @param ip the <code>ImageProducer</code> that produces the
 * image from which to retrieve pixels
 * @param x the x coordinate of the upper left corner of the rectangle
 * of pixels to retrieve from the image, relative to the default
 * (unscaled) size of the image
 * @param y the y coordinate of the upper left corner of the rectangle
 * of pixels to retrieve from the image
 * @param w the width of the rectangle of pixels to retrieve
 * @param h the height of the rectangle of pixels to retrieve
 * @param pix the array of integers which are to be used to hold the
 * RGB pixels retrieved from the image
 * @param off the offset into the array of where to store the first pixel
 * @param scansize the distance from one row of pixels to the next in
 * the array
 * @see ColorModel#getRGBdefault
 */
public PixelGrabber(ImageProducer ip, int x, int y, int w, int h,
                    int[] pix, int off, int scansize) {
    producer = ip;
    dstX = x;
    dstY = y;
    dstW = w;
    dstH = h;
    dstOff = off;
    dstScan = scansize;
    intPixels = pix;
    imageModel = ColorModel.getRGBdefault();
}