java.awt.image.IndexColorModel#getMapSize()源码实例Demo

下面列出了java.awt.image.IndexColorModel#getMapSize() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openjdk-jdk8u   文件: GIFImageReader.java
private static synchronized byte[] getDefaultPalette() {
    if (defaultPalette == null) {
        BufferedImage img = new BufferedImage(1, 1,
                BufferedImage.TYPE_BYTE_INDEXED);
        IndexColorModel icm = (IndexColorModel) img.getColorModel();

        final int size = icm.getMapSize();
        byte[] r = new byte[size];
        byte[] g = new byte[size];
        byte[] b = new byte[size];
        icm.getReds(r);
        icm.getGreens(g);
        icm.getBlues(b);

        defaultPalette = new byte[size * 3];

        for (int i = 0; i < size; i++) {
            defaultPalette[3 * i + 0] = r[i];
            defaultPalette[3 * i + 1] = g[i];
            defaultPalette[3 * i + 2] = b[i];
        }
    }
    return defaultPalette;
}
 
源代码2 项目: jdk8u-dev-jdk   文件: GIFImageReader.java
private static synchronized byte[] getDefaultPalette() {
    if (defaultPalette == null) {
        BufferedImage img = new BufferedImage(1, 1,
                BufferedImage.TYPE_BYTE_INDEXED);
        IndexColorModel icm = (IndexColorModel) img.getColorModel();

        final int size = icm.getMapSize();
        byte[] r = new byte[size];
        byte[] g = new byte[size];
        byte[] b = new byte[size];
        icm.getReds(r);
        icm.getGreens(g);
        icm.getBlues(b);

        defaultPalette = new byte[size * 3];

        for (int i = 0; i < size; i++) {
            defaultPalette[3 * i + 0] = r[i];
            defaultPalette[3 * i + 1] = g[i];
            defaultPalette[3 * i + 2] = b[i];
        }
    }
    return defaultPalette;
}
 
源代码3 项目: jdk8u60   文件: GIFImageReader.java
private static synchronized byte[] getDefaultPalette() {
    if (defaultPalette == null) {
        BufferedImage img = new BufferedImage(1, 1,
                BufferedImage.TYPE_BYTE_INDEXED);
        IndexColorModel icm = (IndexColorModel) img.getColorModel();

        final int size = icm.getMapSize();
        byte[] r = new byte[size];
        byte[] g = new byte[size];
        byte[] b = new byte[size];
        icm.getReds(r);
        icm.getGreens(g);
        icm.getBlues(b);

        defaultPalette = new byte[size * 3];

        for (int i = 0; i < size; i++) {
            defaultPalette[3 * i + 0] = r[i];
            defaultPalette[3 * i + 1] = g[i];
            defaultPalette[3 * i + 2] = b[i];
        }
    }
    return defaultPalette;
}
 
源代码4 项目: dragonwell8_jdk   文件: ShortHistogramTest.java
private IIOMetadataNode gethISTNode(BufferedImage bi) {
    IndexColorModel icm = (IndexColorModel)bi.getColorModel();
    int mapSize = icm.getMapSize();

    int[] hist = new int[mapSize];
    Arrays.fill(hist, 0);

    Raster r = bi.getData();
    for (int y = 0; y < bi.getHeight(); y++) {
        for (int x = 0; x < bi.getWidth(); x++) {
            int s = r.getSample(x, y, 0);
            hist[s] ++;
        }
    }

    IIOMetadataNode hIST = new IIOMetadataNode("hIST");
    for (int i = 0; i < hist.length; i++) {
        IIOMetadataNode n = new IIOMetadataNode("hISTEntry");
        n.setAttribute("index", "" + i);
        n.setAttribute("value", "" + hist[i]);
        hIST.appendChild(n);
    }

    return hIST;
}
 
源代码5 项目: jdk8u-jdk   文件: GIFImageReader.java
private static synchronized byte[] getDefaultPalette() {
    if (defaultPalette == null) {
        BufferedImage img = new BufferedImage(1, 1,
                BufferedImage.TYPE_BYTE_INDEXED);
        IndexColorModel icm = (IndexColorModel) img.getColorModel();

        final int size = icm.getMapSize();
        byte[] r = new byte[size];
        byte[] g = new byte[size];
        byte[] b = new byte[size];
        icm.getReds(r);
        icm.getGreens(g);
        icm.getBlues(b);

        defaultPalette = new byte[size * 3];

        for (int i = 0; i < size; i++) {
            defaultPalette[3 * i + 0] = r[i];
            defaultPalette[3 * i + 1] = g[i];
            defaultPalette[3 * i + 2] = b[i];
        }
    }
    return defaultPalette;
}
 
源代码6 项目: TencentKona-8   文件: ShortHistogramTest.java
private IIOMetadataNode gethISTNode(BufferedImage bi) {
    IndexColorModel icm = (IndexColorModel)bi.getColorModel();
    int mapSize = icm.getMapSize();

    int[] hist = new int[mapSize];
    Arrays.fill(hist, 0);

    Raster r = bi.getData();
    for (int y = 0; y < bi.getHeight(); y++) {
        for (int x = 0; x < bi.getWidth(); x++) {
            int s = r.getSample(x, y, 0);
            hist[s] ++;
        }
    }

    IIOMetadataNode hIST = new IIOMetadataNode("hIST");
    for (int i = 0; i < hist.length; i++) {
        IIOMetadataNode n = new IIOMetadataNode("hISTEntry");
        n.setAttribute("index", "" + i);
        n.setAttribute("value", "" + hist[i]);
        hIST.appendChild(n);
    }

    return hIST;
}
 
JFIFThumbPalette(BufferedImage thumb) throws IllegalThumbException {
    super(thumb);
    IndexColorModel icm = (IndexColorModel) thumbnail.getColorModel();
    if (icm.getMapSize() > 256) {
        throw new IllegalThumbException();
    }
}
 
源代码8 项目: Bytecoder   文件: TexturePaintContext.java
public static boolean isFilterableICM(ColorModel cm) {
    if (cm instanceof IndexColorModel) {
        IndexColorModel icm = (IndexColorModel) cm;
        if (icm.getMapSize() <= 256) {
            return true;
        }
    }
    return false;
}
 
源代码9 项目: openjdk-jdk8u   文件: WPrinterJob.java
protected void drawDIBImage(byte[] image,
                            float destX, float destY,
                            float destWidth, float destHeight,
                            float srcX, float srcY,
                            float srcWidth, float srcHeight,
                            int sampleBitsPerPixel,
                            IndexColorModel icm) {
    int bitCount = 24;
    byte[] bmiColors = null;

    if (icm != null) {
        bitCount = sampleBitsPerPixel;
        bmiColors = new byte[(1<<icm.getPixelSize())*4];
        for (int i=0;i<icm.getMapSize(); i++) {
            bmiColors[i*4+0]=(byte)(icm.getBlue(i)&0xff);
            bmiColors[i*4+1]=(byte)(icm.getGreen(i)&0xff);
            bmiColors[i*4+2]=(byte)(icm.getRed(i)&0xff);
        }
    }

    drawDIBImage(getPrintDC(), image,
                 destX, destY,
                 destWidth, destHeight,
                 srcX, srcY,
                 srcWidth, srcHeight,
                 bitCount, bmiColors);
}
 
源代码10 项目: jdk-1.7-annotated   文件: TexturePaintContext.java
public static boolean isFilterableICM(ColorModel cm) {
    if (cm instanceof IndexColorModel) {
        IndexColorModel icm = (IndexColorModel) cm;
        if (icm.getMapSize() <= 256) {
            return true;
        }
    }
    return false;
}
 
源代码11 项目: hottub   文件: TexturePaintContext.java
public static boolean isFilterableICM(ColorModel cm) {
    if (cm instanceof IndexColorModel) {
        IndexColorModel icm = (IndexColorModel) cm;
        if (icm.getMapSize() <= 256) {
            return true;
        }
    }
    return false;
}
 
源代码12 项目: scifio   文件: AWTImageTools.java
/** Converts an IndexColorModel to a 2D byte array. */
public static byte[][] get8BitLookupTable(final ColorModel model) {
	if (!(model instanceof IndexColorModel)) return null;
	final IndexColorModel m = (IndexColorModel) model;
	final byte[][] lut = new byte[3][m.getMapSize()];
	m.getReds(lut[0]);
	m.getGreens(lut[1]);
	m.getBlues(lut[2]);
	return lut;
}
 
源代码13 项目: jdk8u-dev-jdk   文件: TexturePaintContext.java
public static boolean isFilterableICM(ColorModel cm) {
    if (cm instanceof IndexColorModel) {
        IndexColorModel icm = (IndexColorModel) cm;
        if (icm.getMapSize() <= 256) {
            return true;
        }
    }
    return false;
}
 
源代码14 项目: TencentKona-8   文件: WPrinterJob.java
protected void drawDIBImage(byte[] image,
                            float destX, float destY,
                            float destWidth, float destHeight,
                            float srcX, float srcY,
                            float srcWidth, float srcHeight,
                            int sampleBitsPerPixel,
                            IndexColorModel icm) {
    int bitCount = 24;
    byte[] bmiColors = null;

    if (icm != null) {
        bitCount = sampleBitsPerPixel;
        bmiColors = new byte[(1<<icm.getPixelSize())*4];
        for (int i=0;i<icm.getMapSize(); i++) {
            bmiColors[i*4+0]=(byte)(icm.getBlue(i)&0xff);
            bmiColors[i*4+1]=(byte)(icm.getGreen(i)&0xff);
            bmiColors[i*4+2]=(byte)(icm.getRed(i)&0xff);
        }
    }

    drawDIBImage(getPrintDC(), image,
                 destX, destY,
                 destWidth, destHeight,
                 srcX, srcY,
                 srcWidth, srcHeight,
                 bitCount, bmiColors);
}
 
源代码15 项目: jdk1.8-source-analysis   文件: GIFImageWriter.java
/**
 * Create a color table from the image ColorModel and SampleModel.
 */
private static byte[] createColorTable(ColorModel colorModel,
                                       SampleModel sampleModel)
{
    byte[] colorTable;
    if (colorModel instanceof IndexColorModel) {
        IndexColorModel icm = (IndexColorModel)colorModel;
        int mapSize = icm.getMapSize();

        /**
         * The GIF image format assumes that size of image palette
         * is power of two. We will use closest larger power of two
         * as size of color table.
         */
        int ctSize = getGifPaletteSize(mapSize);

        byte[] reds = new byte[ctSize];
        byte[] greens = new byte[ctSize];
        byte[] blues = new byte[ctSize];
        icm.getReds(reds);
        icm.getGreens(greens);
        icm.getBlues(blues);

        /**
         * fill tail of color component arrays by replica of first color
         * in order to avoid appearance of extra colors in the color table
         */
        for (int i = mapSize; i < ctSize; i++) {
            reds[i] = reds[0];
            greens[i] = greens[0];
            blues[i] = blues[0];
        }

        colorTable = new byte[3*ctSize];
        int idx = 0;
        for (int i = 0; i < ctSize; i++) {
            colorTable[idx++] = reds[i];
            colorTable[idx++] = greens[i];
            colorTable[idx++] = blues[i];
        }
    } else if (sampleModel.getNumBands() == 1) {
        // create gray-scaled color table for single-banded images
        int numBits = sampleModel.getSampleSize()[0];
        if (numBits > 8) {
            numBits = 8;
        }
        int colorTableLength = 3*(1 << numBits);
        colorTable = new byte[colorTableLength];
        for (int i = 0; i < colorTableLength; i++) {
            colorTable[i] = (byte)(i/3);
        }
    } else {
        // We do not have enough information here
        // to create well-fit color table for RGB image.
        colorTable = null;
    }

    return colorTable;
}
 
源代码16 项目: jdk8u60   文件: GIFImageWriter.java
/**
 * Create a color table from the image ColorModel and SampleModel.
 */
private static byte[] createColorTable(ColorModel colorModel,
                                       SampleModel sampleModel)
{
    byte[] colorTable;
    if (colorModel instanceof IndexColorModel) {
        IndexColorModel icm = (IndexColorModel)colorModel;
        int mapSize = icm.getMapSize();

        /**
         * The GIF image format assumes that size of image palette
         * is power of two. We will use closest larger power of two
         * as size of color table.
         */
        int ctSize = getGifPaletteSize(mapSize);

        byte[] reds = new byte[ctSize];
        byte[] greens = new byte[ctSize];
        byte[] blues = new byte[ctSize];
        icm.getReds(reds);
        icm.getGreens(greens);
        icm.getBlues(blues);

        /**
         * fill tail of color component arrays by replica of first color
         * in order to avoid appearance of extra colors in the color table
         */
        for (int i = mapSize; i < ctSize; i++) {
            reds[i] = reds[0];
            greens[i] = greens[0];
            blues[i] = blues[0];
        }

        colorTable = new byte[3*ctSize];
        int idx = 0;
        for (int i = 0; i < ctSize; i++) {
            colorTable[idx++] = reds[i];
            colorTable[idx++] = greens[i];
            colorTable[idx++] = blues[i];
        }
    } else if (sampleModel.getNumBands() == 1) {
        // create gray-scaled color table for single-banded images
        int numBits = sampleModel.getSampleSize()[0];
        if (numBits > 8) {
            numBits = 8;
        }
        int colorTableLength = 3*(1 << numBits);
        colorTable = new byte[colorTableLength];
        for (int i = 0; i < colorTableLength; i++) {
            colorTable[i] = (byte)(i/3);
        }
    } else {
        // We do not have enough information here
        // to create well-fit color table for RGB image.
        colorTable = null;
    }

    return colorTable;
}
 
源代码17 项目: Bytecoder   文件: GIFImageWriter.java
/**
 * Create a color table from the image ColorModel and SampleModel.
 */
private static byte[] createColorTable(ColorModel colorModel,
                                       SampleModel sampleModel)
{
    byte[] colorTable;
    if (colorModel instanceof IndexColorModel) {
        IndexColorModel icm = (IndexColorModel)colorModel;
        int mapSize = icm.getMapSize();

        /**
         * The GIF image format assumes that size of image palette
         * is power of two. We will use closest larger power of two
         * as size of color table.
         */
        int ctSize = getGifPaletteSize(mapSize);

        byte[] reds = new byte[ctSize];
        byte[] greens = new byte[ctSize];
        byte[] blues = new byte[ctSize];
        icm.getReds(reds);
        icm.getGreens(greens);
        icm.getBlues(blues);

        /**
         * fill tail of color component arrays by replica of first color
         * in order to avoid appearance of extra colors in the color table
         */
        for (int i = mapSize; i < ctSize; i++) {
            reds[i] = reds[0];
            greens[i] = greens[0];
            blues[i] = blues[0];
        }

        colorTable = new byte[3*ctSize];
        int idx = 0;
        for (int i = 0; i < ctSize; i++) {
            colorTable[idx++] = reds[i];
            colorTable[idx++] = greens[i];
            colorTable[idx++] = blues[i];
        }
    } else if (sampleModel.getNumBands() == 1) {
        // create gray-scaled color table for single-banded images
        int numBits = sampleModel.getSampleSize()[0];
        if (numBits > 8) {
            numBits = 8;
        }
        int colorTableLength = 3*(1 << numBits);
        colorTable = new byte[colorTableLength];
        for (int i = 0; i < colorTableLength; i++) {
            colorTable[i] = (byte)(i/3);
        }
    } else {
        // We do not have enough information here
        // to create well-fit color table for RGB image.
        colorTable = null;
    }

    return colorTable;
}
 
源代码18 项目: jdk8u-dev-jdk   文件: ImageRepresentation.java
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);
}
 
源代码19 项目: openjdk-jdk8u-backup   文件: ImageRepresentation.java
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);
}
 
源代码20 项目: pumpernickel   文件: MinimalGifEncoder.java
@Override
public void writeImage(OutputStream out, BufferedImage image,
		int frameDurationInCentiseconds, IndexColorModel globalColorModel,
		boolean writeLocalColorTable) throws IOException {

	if (frameDurationInCentiseconds >= 0
			|| globalColorModel.getTransparentPixel() != -1) {
		if (frameDurationInCentiseconds < 0)
			frameDurationInCentiseconds = 0;
		GifGraphicControlExtension gce = new GifGraphicControlExtension(
				frameDurationInCentiseconds,
				DisposalMethod.RESTORE_BACKGROUND,
				globalColorModel.getTransparentPixel());
		gce.write(out);
	}
	int localColorSize = 0;
	if (writeLocalColorTable) {
		localColorSize = globalColorModel.getMapSize();
		int k = 2;
		while (localColorSize > k) {
			k *= 2;
		}
		if (k > 256)
			throw new IllegalArgumentException("Illegal number of colors ("
					+ localColorSize + ").  There can only be 256 at most.");
		localColorSize = k;
	}

	Dimension d = new Dimension(image.getWidth(), image.getHeight());

	GifImageDescriptor id = new GifImageDescriptor(0, 0, d.width, d.height,
			false, localColorSize);
	id.write(out);
	if (localColorSize > 0) {
		GifLocalColorTable ct = new GifLocalColorTable(globalColorModel);
		ct.write(out);
	}
	GifImageDataBlock dataBlock = new GifImageDataBlock(image,
			globalColorModel);
	dataBlock.write(out);
}