Java 8 IndexColorModel - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 IndexColorModel class.

This code example shows how to use the following methods:hasAlpha, getBlues, getGreens, getMapSize, getReds
 
	public InverseColorMapRasterOp(final IndexColorModel destCM,
			final int quantizationColors, final int alphaThreshold) {
		this.icm = destCM;
		this.alphaThreshold = alphaThreshold;
		hasAlpha = icm.hasAlpha();
		transparencyIndex = icm.getTransparentPixel();
		final int mapSize = icm.getMapSize();
		final byte[][] colorMap = new byte[3][hasAlpha ? (mapSize - 1)
				: mapSize];
 
		if (hasAlpha) {
			final byte[] r = new byte[mapSize];
			final byte[] g = new byte[mapSize];
			final byte[] b = new byte[mapSize];
			icm.getReds(r);
			icm.getGreens(g);
			icm.getBlues(b);
			final int reducedMapSize = mapSize - 1;
			if (transparencyIndex == 0) {

7
CodeRank
This code example shows how to use the following methods:getAlphas, getBlues, getGreens, getMapSize, getReds
    public SimpleColorIndexer(byte[][] colors) {
        this.colors = colors;
    } 
     
    public SimpleColorIndexer(IndexColorModel icm) {
        this.colors = new byte[4][icm.getMapSize()];
        icm.getReds(colors[0]);
        icm.getGreens(colors[1]);
        icm.getBlues(colors[2]);
        icm.getAlphas(colors[3]);
    } 
 
    @Override 
    public IndexColorModel toIndexColorModel() {
        int bits = (int) Math.ceil(Math.log(colors[0].length) / Math.log(2));
        if (bits == 0) {
            bits = 1;
        } 
        return new IndexColorModel(bits, colors[0].length, colors[0], colors[1], colors[2],
                colors[3]);
7
CodeRank
This code example shows how to use the following methods:hasAlpha, getBlues, getGreens, getMapSize, getReds
 
	protected final int transparencyIndex;
 
	public InverseColorMapOp(final IndexColorModel destCM,
			final int quantizationColors, final int alphaThreshold) {
		this.rasterOp = new InverseColorMapRasterOp(destCM, quantizationColors,
				alphaThreshold);
		this.icm = destCM;
		this.alphaThreshold = alphaThreshold;
		hasAlpha = icm.hasAlpha();
		transparencyIndex = icm.getTransparentPixel();
 
	} 
 
	public InverseColorMapOp(final IndexColorModel destCM) {
		this(destCM, InverseColorMapRasterOp.DEFAULT_QUANTIZATION_COLORS,
				InverseColorMapRasterOp.DEFAULT_ALPHA_TH); 
	} 
 
	public BufferedImage createCompatibleDestImage(BufferedImage src,

7
CodeRank
This code example shows how to use the following methods:hasAlpha, createCompatibleSampleModel, getBlues, getGreens, getMapSize

7
CodeRank
This code example shows how to use the following methods:hasAlpha, createCompatibleSampleModel, getBlues, getGreens, getMapSize
		this.setSource(image, 0);
		this.op=new InverseColorMapRasterOp(icm,quantizationColors,alpaThreshold);
		 
		// setlayout; 
		setImageLayout( 
				new ImageLayout(image).setColorModel(icm).setSampleModel(icm.createCompatibleSampleModel(image.getWidth(), image.getHeight())));
 
	} 
 
	@Override 
	public Raster computeTile(int tx, int ty) {
		final RenderedImage sourceImage = getSourceImage(0);
		final Raster sourceRaster = sourceImage.getTile(tx, ty);
		return op.filter(sourceRaster, null);
	} 
 
} 

7
CodeRank
This code example shows how to use the following methods:getNumComponents, getAlphas, getBlues, getGreens, getMapSize
        // 索引调色板, 我们可以删除alpha通道。因此, 重要从索引色中获得RGB即可,这个主要针对GIF图像 
        if (cm instanceof IndexColorModel) {
            // Retrieve the IndexColorModel 
            IndexColorModel icm = (IndexColorModel) src.getColorModel();
 
            int newNumBands = icm.getNumComponents();
            if (newNumBands < 3) {
                throw new IllegalArgumentException("The number of Components of this image is less than 3");
            } 
            // Cache the number of elements in each band of the colormap. 
            int mapSize = icm.getMapSize();
 
            // Allocate an array for the lookup table data. 
            byte[][] lutData = new byte[newNumBands][mapSize];
 
            // Load the lookup table data from the IndexColorModel. 
            icm.getReds(lutData[0]);
            icm.getGreens(lutData[1]);
            icm.getBlues(lutData[2]);
            if (newNumBands == 4) {

6
CodeRank
This code example shows how to use the following methods:getTransparency, getTransparentPixel
        assertEquals("image/png; mode=8bit", response.getContentType());
         
        InputStream is = getBinaryInputStream(response);
        BufferedImage bi = ImageIO.read(is);
        IndexColorModel cm = (IndexColorModel) bi.getColorModel();
        assertEquals(Transparency.OPAQUE , cm.getTransparency());
        assertEquals(-1, cm.getTransparentPixel());
    } 
     
    @Test
    public void testPng8ForceBitmask() throws Exception {
        MockHttpServletResponse response = getAsServletResponse("wms?bbox=" + bbox
                + "&styles=&layers=" + layers + "&Format=image/png8" + "&request=GetMap"
                + "&width=550" + "&height=250" + "&srs=EPSG:4326&transparent=true&format_options=quantizer:octree"); 
        assertEquals("image/png; mode=8bit", response.getContentType());
         
        InputStream is = getBinaryInputStream(response);
        BufferedImage bi = ImageIO.read(is);
        IndexColorModel cm = (IndexColorModel) bi.getColorModel();
        assertEquals(Transparency.BITMASK , cm.getTransparency());
6
CodeRank
This code example shows how to use the following methods:createCompatibleSampleModel
        ImageLayout il = new ImageLayout();
        il.setMinX(image.getMinX());
        il.setMinY(image.getMinY());
        il.setWidth(image.getWidth());
        il.setHeight(image.getHeight());
        il.setColorModel(icm);
 
        SampleModel sm = icm.createCompatibleSampleModel(image.getWidth(), image.getHeight());
        il.setSampleModel(sm);
         
        if(!(image instanceof BufferedImage)){
 
            il.setTileWidth(image.getTileWidth());
            il.setTileHeight(image.getTileHeight());
            il.setTileGridXOffset(image.getTileGridXOffset());
            il.setTileGridYOffset(image.getTileGridYOffset());        	
        } else { 
        	// untiled in case the input image is untiled 
        	// this could be optimized further by _not_ 
        	// simply forwarding getTile calls but converting coords. 
5
CodeRank
This code example shows how to use the following methods:getAlphas, getBlues, getGreens, getMapSize, getReds
     
    private static BufferedImage PaletteToARGB(BufferedImage src) {
    	IndexColorModel icm = (IndexColorModel) src.getColorModel();
    	int bands = icm.hasAlpha()?4:3;
    	 
    	byte[][] data = new byte[bands][icm.getMapSize()];
    	if (icm.hasAlpha()) icm.getAlphas(data[3]);
    	icm.getReds(data[0]);
    	icm.getGreens(data[1]);
    	icm.getBlues(data[2]);
    	LookupTableJAI rtable = new LookupTableJAI(data);
    	return JAI.create("lookup", src, rtable).getAsBufferedImage();
    } 
 
     
    private static BufferedImage getAlpha(BufferedImage src) {
	return JAI.create("bandselect", src, new int[] { 3 }).getAsBufferedImage();
    } 
     
    private static BufferedImage removeAlpha(BufferedImage src) {
5
CodeRank
This code example shows how to use the following methods:getTransparency, getTransparentPixel
         
        // transparency support 
        final IndexColorModel icm= (IndexColorModel) ri.getColorModel();
        int transparentColorIndex=-1;
         
        if(icm.getTransparency()==Transparency.BITMASK&&(transparentColorIndex=icm.getTransparentPixel())>=0){
            graphicsControlExtensionNode.setAttribute("transparentColorIndex", String.valueOf(transparentColorIndex));
            graphicsControlExtensionNode.setAttribute("transparentColorFlag", "TRUE");              
        } else { 
            graphicsControlExtensionNode.setAttribute("transparentColorIndex", "0");
            graphicsControlExtensionNode.setAttribute("transparentColorFlag", "FALSE");              
        } 
 
        IIOMetadataNode commentsNode = getNode(root, "CommentExtensions");
        commentsNode.setAttribute("CommentExtension", "Created by MAH");
 
        IIOMetadataNode appEntensionsNode = getNode(root, "ApplicationExtensions");
        IIOMetadataNode child = new IIOMetadataNode("ApplicationExtension");
 
        child.setAttribute("applicationID", "NETSCAPE");
5
CodeRank
See Code Examples for Java 8 IndexColorModel Methods: