Java Code Examples for java.awt.image.DirectColorModel#getGreenMask()

The following examples show how to use java.awt.image.DirectColorModel#getGreenMask() . 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: AbstractVideoCodec.java    From jpexs-decompiler with GNU General Public License v3.0 6 votes vote down vote up
/** Gets 32-bit ARGB pixels from a buffer. Returns null if conversion failed. */
protected int[] getARGB32(Buffer buf) {
    if (buf.data instanceof int[]) {
        return (int[]) buf.data;
    }
    if (buf.data instanceof BufferedImage) {
        BufferedImage image = (BufferedImage) buf.data;
        if (image.getColorModel() instanceof DirectColorModel) {
            DirectColorModel dcm = (DirectColorModel) image.getColorModel();
            if (dcm.getBlueMask() == 0xff && dcm.getGreenMask() == 0xff00 && dcm.getRedMask() == 0xff0000) {
                if (image.getRaster().getDataBuffer() instanceof DataBufferInt) {
                    return ((DataBufferInt) image.getRaster().getDataBuffer()).getData();
                }
            }
        }
        return image.getRGB(0, 0, //
                outputFormat.get(WidthKey), outputFormat.get(HeightKey), //
                null, 0, outputFormat.get(WidthKey));
    }
    return null;
}
 
Example 2
Source File: DeviceSocketClient.java    From AndroidRobot with Apache License 2.0 6 votes vote down vote up
private static ImageData getImageData2(BufferedImage bufferedImage){
    DirectColorModel colorModel = (DirectColorModel) bufferedImage.getColorModel();
    //System.out.println("robot:" +colorModel.getRedMask() + " "+colorModel.getGreenMask() + " "+colorModel.getBlueMask());   
    PaletteData palette = new PaletteData(colorModel.getRedMask(), colorModel.getGreenMask(), colorModel
            .getBlueMask());
    ImageData data = new ImageData(bufferedImage.getWidth(), bufferedImage.getHeight(), colorModel
            .getPixelSize(), palette);
    WritableRaster raster = bufferedImage.getRaster();
    int[] pixelArray = new int[3];
    for (int y = 0; y < data.height; y++) {
        for (int x = 0; x < data.width; x++) {
            raster.getPixel(x, y, pixelArray);
            int pixel = palette.getPixel(new RGB(pixelArray[0], pixelArray[1], pixelArray[2]));
            data.setPixel(x, y, pixel);
        }
    }
    return data;
}
 
Example 3
Source File: ImageLoader.java    From pumpernickel with MIT License 6 votes vote down vote up
/**
 * This checks to see if two DirectColorModels are identical. Apparently the
 * "equals" method in DirectColorModel doesn't really work.
 */
private static boolean equals(DirectColorModel d1, DirectColorModel d2) {
	if (d1.getAlphaMask() != d2.getAlphaMask())
		return false;
	if (d1.getGreenMask() != d2.getGreenMask())
		return false;
	if (d1.getRedMask() != d2.getRedMask())
		return false;
	if (d1.getBlueMask() != d2.getBlueMask())
		return false;
	if (d1.getColorSpace() != d2.getColorSpace())
		return false;
	if (d1.isAlphaPremultiplied() != d2.isAlphaPremultiplied())
		return false;
	if (d1.getTransferType() != d2.getTransferType())
		return false;
	if (d1.getTransparency() != d2.getTransparency())
		return false;
	return true;
}
 
Example 4
Source File: BlendComposite.java    From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static boolean checkComponentsOrder(ColorModel cm) {
    if (cm instanceof DirectColorModel &&
            cm.getTransferType() == DataBuffer.TYPE_INT) {
        DirectColorModel directCM = (DirectColorModel) cm;
        
        return directCM.getRedMask() == 0x00FF0000 &&
               directCM.getGreenMask() == 0x0000FF00 &&
               directCM.getBlueMask() == 0x000000FF &&
               (directCM.getNumComponents() != 4 ||
                directCM.getAlphaMask() == 0xFF000000);
    }
    
    return false;
}
 
Example 5
Source File: ImageRepresentation.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
void createBufferedImage() {
    // REMIND:  Be careful!  Is this called everytime there is a
    // startProduction?  We only want to call it if it is new or
    // there is an error
    isDefaultBI = false;
    try {
        biRaster = cmodel.createCompatibleWritableRaster(width, height);
        bimage = createImage(cmodel, biRaster,
                             cmodel.isAlphaPremultiplied(), null);
    } catch (Exception e) {
        // Create a default image
        cmodel = ColorModel.getRGBdefault();
        biRaster = cmodel.createCompatibleWritableRaster(width, height);
        bimage = createImage(cmodel, biRaster, false, null);
    }
    int type = bimage.getType();

    if ((cmodel == ColorModel.getRGBdefault()) ||
           (type == BufferedImage.TYPE_INT_RGB) ||
           (type == BufferedImage.TYPE_INT_ARGB_PRE)) {
        isDefaultBI = true;
    }
    else if (cmodel instanceof DirectColorModel) {
        DirectColorModel dcm = (DirectColorModel) cmodel;
        if (dcm.getRedMask() == 0xff0000 &&
            dcm.getGreenMask() == 0xff00 &&
            dcm.getBlueMask()  == 0xff) {
            isDefaultBI = true;
        }
    }
}
 
Example 6
Source File: ImageRepresentation.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
void createBufferedImage() {
    // REMIND:  Be careful!  Is this called everytime there is a
    // startProduction?  We only want to call it if it is new or
    // there is an error
    isDefaultBI = false;
    try {
        biRaster = cmodel.createCompatibleWritableRaster(width, height);
        bimage = createImage(cmodel, biRaster,
                             cmodel.isAlphaPremultiplied(), null);
    } catch (Exception e) {
        // Create a default image
        cmodel = ColorModel.getRGBdefault();
        biRaster = cmodel.createCompatibleWritableRaster(width, height);
        bimage = createImage(cmodel, biRaster, false, null);
    }
    int type = bimage.getType();

    if ((cmodel == ColorModel.getRGBdefault()) ||
           (type == BufferedImage.TYPE_INT_RGB) ||
           (type == BufferedImage.TYPE_INT_ARGB_PRE)) {
        isDefaultBI = true;
    }
    else if (cmodel instanceof DirectColorModel) {
        DirectColorModel dcm = (DirectColorModel) cmodel;
        if (dcm.getRedMask() == 0xff0000 &&
            dcm.getGreenMask() == 0xff00 &&
            dcm.getBlueMask()  == 0xff) {
            isDefaultBI = true;
        }
    }
}
 
Example 7
Source File: ImageRepresentation.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
void createBufferedImage() {
    // REMIND:  Be careful!  Is this called everytime there is a
    // startProduction?  We only want to call it if it is new or
    // there is an error
    isDefaultBI = false;
    try {
        biRaster = cmodel.createCompatibleWritableRaster(width, height);
        bimage = createImage(cmodel, biRaster,
                             cmodel.isAlphaPremultiplied(), null);
    } catch (Exception e) {
        // Create a default image
        cmodel = ColorModel.getRGBdefault();
        biRaster = cmodel.createCompatibleWritableRaster(width, height);
        bimage = createImage(cmodel, biRaster, false, null);
    }
    int type = bimage.getType();

    if ((cmodel == ColorModel.getRGBdefault()) ||
           (type == BufferedImage.TYPE_INT_RGB) ||
           (type == BufferedImage.TYPE_INT_ARGB_PRE)) {
        isDefaultBI = true;
    }
    else if (cmodel instanceof DirectColorModel) {
        DirectColorModel dcm = (DirectColorModel) cmodel;
        if (dcm.getRedMask() == 0xff0000 &&
            dcm.getGreenMask() == 0xff00 &&
            dcm.getBlueMask()  == 0xff) {
            isDefaultBI = true;
        }
    }
}
 
Example 8
Source File: GDIWindowSurfaceData.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private GDIWindowSurfaceData(WComponentPeer peer, SurfaceType sType) {
    super(sType, peer.getDeviceColorModel());
    ColorModel cm = peer.getDeviceColorModel();
    this.peer = peer;
    int rMask = 0, gMask = 0, bMask = 0;
    int depth;
    switch (cm.getPixelSize()) {
    case 32:
    case 24:
        if (cm instanceof DirectColorModel) {
            depth = 32;
        } else {
            depth = 24;
        }
        break;
    default:
        depth = cm.getPixelSize();
    }
    if (cm instanceof DirectColorModel) {
        DirectColorModel dcm = (DirectColorModel)cm;
        rMask = dcm.getRedMask();
        gMask = dcm.getGreenMask();
        bMask = dcm.getBlueMask();
    }
    this.graphicsConfig =
        (Win32GraphicsConfig) peer.getGraphicsConfiguration();
    this.solidloops = graphicsConfig.getSolidLoops(sType);

    Win32GraphicsDevice gd =
        (Win32GraphicsDevice)graphicsConfig.getDevice();
    initOps(peer, depth, rMask, gMask, bMask, gd.getScreen());
    setBlitProxyKey(graphicsConfig.getProxyKey());
}
 
Example 9
Source File: GDIWindowSurfaceData.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private GDIWindowSurfaceData(WComponentPeer peer, SurfaceType sType) {
    super(sType, peer.getDeviceColorModel());
    ColorModel cm = peer.getDeviceColorModel();
    this.peer = peer;
    int rMask = 0, gMask = 0, bMask = 0;
    int depth;
    switch (cm.getPixelSize()) {
    case 32:
    case 24:
        if (cm instanceof DirectColorModel) {
            depth = 32;
        } else {
            depth = 24;
        }
        break;
    default:
        depth = cm.getPixelSize();
    }
    if (cm instanceof DirectColorModel) {
        DirectColorModel dcm = (DirectColorModel)cm;
        rMask = dcm.getRedMask();
        gMask = dcm.getGreenMask();
        bMask = dcm.getBlueMask();
    }
    this.graphicsConfig =
        (Win32GraphicsConfig) peer.getGraphicsConfiguration();
    this.solidloops = graphicsConfig.getSolidLoops(sType);

    Win32GraphicsDevice gd =
        (Win32GraphicsDevice)graphicsConfig.getDevice();
    initOps(peer, depth, rMask, gMask, bMask, gd.getScreen());
    setBlitProxyKey(graphicsConfig.getProxyKey());
}
 
Example 10
Source File: GDIWindowSurfaceData.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private GDIWindowSurfaceData(WComponentPeer peer, SurfaceType sType) {
    super(sType, peer.getDeviceColorModel());
    ColorModel cm = peer.getDeviceColorModel();
    this.peer = peer;
    int rMask = 0, gMask = 0, bMask = 0;
    int depth;
    switch (cm.getPixelSize()) {
    case 32:
    case 24:
        if (cm instanceof DirectColorModel) {
            depth = 32;
        } else {
            depth = 24;
        }
        break;
    default:
        depth = cm.getPixelSize();
    }
    if (cm instanceof DirectColorModel) {
        DirectColorModel dcm = (DirectColorModel)cm;
        rMask = dcm.getRedMask();
        gMask = dcm.getGreenMask();
        bMask = dcm.getBlueMask();
    }
    this.graphicsConfig =
        (Win32GraphicsConfig) peer.getGraphicsConfiguration();
    this.solidloops = graphicsConfig.getSolidLoops(sType);

    Win32GraphicsDevice gd =
        (Win32GraphicsDevice)graphicsConfig.getDevice();
    initOps(peer, depth, rMask, gMask, bMask, gd.getScreen());
    setBlitProxyKey(graphicsConfig.getProxyKey());
}
 
Example 11
Source File: X11SurfaceDataProxy.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static SurfaceDataProxy createProxy(SurfaceData srcData,
                                           X11GraphicsConfig dstConfig)
{
    if (srcData instanceof X11SurfaceData) {
        // srcData must be a VolatileImage which either matches
        // our visual or not - either way we do not cache it...
        return UNCACHED;
    }

    ColorModel cm = srcData.getColorModel();
    int transparency = cm.getTransparency();

    if (transparency == Transparency.OPAQUE) {
        return new Opaque(dstConfig);
    } else if (transparency == Transparency.BITMASK) {
        // 4673490: updateBitmask() only handles ICMs with 8-bit indices
        if ((cm instanceof IndexColorModel) && cm.getPixelSize() == 8) {
            return new Bitmask(dstConfig);
        }
        // The only other ColorModel handled by updateBitmask() is
        // a DCM where the alpha bit, and only the alpha bit, is in
        // the top 8 bits
        if (cm instanceof DirectColorModel) {
            DirectColorModel dcm = (DirectColorModel) cm;
            int colormask = (dcm.getRedMask() |
                             dcm.getGreenMask() |
                             dcm.getBlueMask());
            int alphamask = dcm.getAlphaMask();

            if ((colormask & 0xff000000) == 0 &&
                (alphamask & 0xff000000) != 0)
            {
                return new Bitmask(dstConfig);
            }
        }
    }

    // For whatever reason, this image is not a good candidate for
    // caching in a pixmap so we return the non-caching (non-)proxy.
    return UNCACHED;
}
 
Example 12
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 13
Source File: X11SurfaceDataProxy.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static SurfaceDataProxy createProxy(SurfaceData srcData,
                                           X11GraphicsConfig dstConfig)
{
    if (srcData instanceof X11SurfaceData) {
        // srcData must be a VolatileImage which either matches
        // our visual or not - either way we do not cache it...
        return UNCACHED;
    }

    ColorModel cm = srcData.getColorModel();
    int transparency = cm.getTransparency();

    if (transparency == Transparency.OPAQUE) {
        return new Opaque(dstConfig);
    } else if (transparency == Transparency.BITMASK) {
        // 4673490: updateBitmask() only handles ICMs with 8-bit indices
        if ((cm instanceof IndexColorModel) && cm.getPixelSize() == 8) {
            return new Bitmask(dstConfig);
        }
        // The only other ColorModel handled by updateBitmask() is
        // a DCM where the alpha bit, and only the alpha bit, is in
        // the top 8 bits
        if (cm instanceof DirectColorModel) {
            DirectColorModel dcm = (DirectColorModel) cm;
            int colormask = (dcm.getRedMask() |
                             dcm.getGreenMask() |
                             dcm.getBlueMask());
            int alphamask = dcm.getAlphaMask();

            if ((colormask & 0xff000000) == 0 &&
                (alphamask & 0xff000000) != 0)
            {
                return new Bitmask(dstConfig);
            }
        }
    }

    // For whatever reason, this image is not a good candidate for
    // caching in a pixmap so we return the non-caching (non-)proxy.
    return UNCACHED;
}
 
Example 14
Source File: ImageRepresentation.java    From hottub 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 15
Source File: ImageRepresentation.java    From jdk8u-dev-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 16
Source File: ImageRepresentation.java    From jdk8u60 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 17
Source File: X11SurfaceDataProxy.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public static SurfaceDataProxy createProxy(SurfaceData srcData,
                                           X11GraphicsConfig dstConfig)
{
    if (srcData instanceof X11SurfaceData) {
        // srcData must be a VolatileImage which either matches
        // our visual or not - either way we do not cache it...
        return UNCACHED;
    }

    ColorModel cm = srcData.getColorModel();
    int transparency = cm.getTransparency();

    if (transparency == Transparency.OPAQUE) {
        return new Opaque(dstConfig);
    } else if (transparency == Transparency.BITMASK) {
        // 4673490: updateBitmask() only handles ICMs with 8-bit indices
        if ((cm instanceof IndexColorModel) && cm.getPixelSize() == 8) {
            return new Bitmask(dstConfig);
        }
        // The only other ColorModel handled by updateBitmask() is
        // a DCM where the alpha bit, and only the alpha bit, is in
        // the top 8 bits
        if (cm instanceof DirectColorModel) {
            DirectColorModel dcm = (DirectColorModel) cm;
            int colormask = (dcm.getRedMask() |
                             dcm.getGreenMask() |
                             dcm.getBlueMask());
            int alphamask = dcm.getAlphaMask();

            if ((colormask & 0xff000000) == 0 &&
                (alphamask & 0xff000000) != 0)
            {
                return new Bitmask(dstConfig);
            }
        }
    }

    // For whatever reason, this image is not a good candidate for
    // caching in a pixmap so we return the non-caching (non-)proxy.
    return UNCACHED;
}
 
Example 18
Source File: X11SurfaceDataProxy.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static SurfaceDataProxy createProxy(SurfaceData srcData,
                                           X11GraphicsConfig dstConfig)
{
    if (srcData instanceof X11SurfaceData) {
        // srcData must be a VolatileImage which either matches
        // our visual or not - either way we do not cache it...
        return UNCACHED;
    }

    ColorModel cm = srcData.getColorModel();
    int transparency = cm.getTransparency();

    if (transparency == Transparency.OPAQUE) {
        return new Opaque(dstConfig);
    } else if (transparency == Transparency.BITMASK) {
        // 4673490: updateBitmask() only handles ICMs with 8-bit indices
        if ((cm instanceof IndexColorModel) && cm.getPixelSize() == 8) {
            return new Bitmask(dstConfig);
        }
        // The only other ColorModel handled by updateBitmask() is
        // a DCM where the alpha bit, and only the alpha bit, is in
        // the top 8 bits
        if (cm instanceof DirectColorModel) {
            DirectColorModel dcm = (DirectColorModel) cm;
            int colormask = (dcm.getRedMask() |
                             dcm.getGreenMask() |
                             dcm.getBlueMask());
            int alphamask = dcm.getAlphaMask();

            if ((colormask & 0xff000000) == 0 &&
                (alphamask & 0xff000000) != 0)
            {
                return new Bitmask(dstConfig);
            }
        }
    }

    // For whatever reason, this image is not a good candidate for
    // caching in a pixmap so we return the non-caching (non-)proxy.
    return UNCACHED;
}
 
Example 19
Source File: X11SurfaceDataProxy.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public static SurfaceDataProxy createProxy(SurfaceData srcData,
                                           X11GraphicsConfig dstConfig)
{
    if (srcData instanceof X11SurfaceData) {
        // srcData must be a VolatileImage which either matches
        // our visual or not - either way we do not cache it...
        return UNCACHED;
    }

    ColorModel cm = srcData.getColorModel();
    int transparency = cm.getTransparency();

    if (transparency == Transparency.OPAQUE) {
        return new Opaque(dstConfig);
    } else if (transparency == Transparency.BITMASK) {
        // 4673490: updateBitmask() only handles ICMs with 8-bit indices
        if ((cm instanceof IndexColorModel) && cm.getPixelSize() == 8) {
            return new Bitmask(dstConfig);
        }
        // The only other ColorModel handled by updateBitmask() is
        // a DCM where the alpha bit, and only the alpha bit, is in
        // the top 8 bits
        if (cm instanceof DirectColorModel) {
            DirectColorModel dcm = (DirectColorModel) cm;
            int colormask = (dcm.getRedMask() |
                             dcm.getGreenMask() |
                             dcm.getBlueMask());
            int alphamask = dcm.getAlphaMask();

            if ((colormask & 0xff000000) == 0 &&
                (alphamask & 0xff000000) != 0)
            {
                return new Bitmask(dstConfig);
            }
        }
    }

    // For whatever reason, this image is not a good candidate for
    // caching in a pixmap so we return the non-caching (non-)proxy.
    return UNCACHED;
}
 
Example 20
Source File: ColorTools.java    From commons-imaging with Apache License 2.0 4 votes vote down vote up
public ColorModel deriveColorModel(final ColorModel colorModel, final ColorSpace cs,
        final boolean forceNoAlpha) throws ImagingOpException {

    if (colorModel instanceof ComponentColorModel) {
        final ComponentColorModel ccm = (ComponentColorModel) colorModel;
        // ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
        if (forceNoAlpha) {
            return new ComponentColorModel(cs, false, false,
                    Transparency.OPAQUE, ccm.getTransferType());
        }
        return new ComponentColorModel(cs, ccm.hasAlpha(),
                ccm.isAlphaPremultiplied(), ccm.getTransparency(),
                ccm.getTransferType());
    } else if (colorModel instanceof DirectColorModel) {
        final DirectColorModel dcm = (DirectColorModel) colorModel;

        final int oldMask = dcm.getRedMask() | dcm.getGreenMask()
                | dcm.getBlueMask() | dcm.getAlphaMask();

        final int oldBits = countBitsInMask(oldMask);

        return new DirectColorModel(cs, oldBits, dcm.getRedMask(),
                dcm.getGreenMask(), dcm.getBlueMask(), dcm.getAlphaMask(),
                dcm.isAlphaPremultiplied(), dcm.getTransferType());
    }
    // else if (old_cm instanceof PackedColorModel)
    // {
    // PackedColorModel pcm = (PackedColorModel) old_cm;
    //
    // // int old_mask = dcm.getRedMask() | dcm.getGreenMask()
    // // | dcm.getBlueMask() | dcm.getAlphaMask();
    //
    // int old_masks[] = pcm.getMasks();
    // // System.out.println("old_mask: " + old_mask);
    // int old_bits = countBitsInMask(old_masks);
    // // System.out.println("old_bits: " + old_bits);
    //
    // // PackedColorModel(ColorSpace space, int bits, int rmask, int gmask,
    // int bmask, int amask, boolean isAlphaPremultiplied, int trans, int
    // transferType)
    // cm = new PackedColorModel(cs, old_bits, pcm.getMasks(),
    //
    // pcm.isAlphaPremultiplied(), pcm.getTransparency(), pcm
    // .getTransferType());
    // }

    throw new ImagingOpException("Could not clone unknown ColorModel Type.");
}