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

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

源代码1 项目: jdk8u_jdk   文件: JFIFMarkerSegment.java
void write(ImageOutputStream ios,
           JPEGImageWriter writer) throws IOException {
    super.write(ios, writer); // width and height
    // Write the palette (must be 768 bytes)
    byte [] palette = new byte[768];
    IndexColorModel icm = (IndexColorModel) thumbnail.getColorModel();
    byte [] reds = new byte [256];
    byte [] greens = new byte [256];
    byte [] blues = new byte [256];
    icm.getReds(reds);
    icm.getGreens(greens);
    icm.getBlues(blues);
    for (int i = 0; i < 256; i++) {
        palette[i*3] = reds[i];
        palette[i*3+1] = greens[i];
        palette[i*3+2] = blues[i];
    }
    ios.write(palette);
    writePixels(ios, writer);
}
 
源代码2 项目: jdk1.8-source-analysis   文件: 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 项目: dragonwell8_jdk   文件: JFIFMarkerSegment.java
void write(ImageOutputStream ios,
           JPEGImageWriter writer) throws IOException {
    super.write(ios, writer); // width and height
    // Write the palette (must be 768 bytes)
    byte [] palette = new byte[768];
    IndexColorModel icm = (IndexColorModel) thumbnail.getColorModel();
    byte [] reds = new byte [256];
    byte [] greens = new byte [256];
    byte [] blues = new byte [256];
    icm.getReds(reds);
    icm.getGreens(greens);
    icm.getBlues(blues);
    for (int i = 0; i < 256; i++) {
        palette[i*3] = reds[i];
        palette[i*3+1] = greens[i];
        palette[i*3+2] = blues[i];
    }
    ios.write(palette);
    writePixels(ios, writer);
}
 
源代码4 项目: hottub   文件: JFIFMarkerSegment.java
void write(ImageOutputStream ios,
           JPEGImageWriter writer) throws IOException {
    super.write(ios, writer); // width and height
    // Write the palette (must be 768 bytes)
    byte [] palette = new byte[768];
    IndexColorModel icm = (IndexColorModel) thumbnail.getColorModel();
    byte [] reds = new byte [256];
    byte [] greens = new byte [256];
    byte [] blues = new byte [256];
    icm.getReds(reds);
    icm.getGreens(greens);
    icm.getBlues(blues);
    for (int i = 0; i < 256; i++) {
        palette[i*3] = reds[i];
        palette[i*3+1] = greens[i];
        palette[i*3+2] = blues[i];
    }
    ios.write(palette);
    writePixels(ios, writer);
}
 
源代码5 项目: TencentKona-8   文件: 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 项目: ios-image-util   文件: MainFrame.java
protected IndexColorModel getIndexColorModel(BufferedImage src) {
	// index color with transparent
	ColorModel cm = src.getColorModel();
	if (cm instanceof IndexColorModel) {
		IndexColorModel icm = (IndexColorModel)cm;
		int mapSize = icm.getMapSize();
		byte[] reds = new byte[mapSize];
		byte[] greens = new byte[mapSize];
		byte[] blues = new byte[mapSize];
		icm.getReds(reds);
		icm.getGreens(greens);
		icm.getBlues(blues);
		return new IndexColorModel(8, mapSize, reds, greens, blues, 0);
	}
	return null;
}
 
源代码7 项目: jdk8u60   文件: JFIFMarkerSegment.java
void write(ImageOutputStream ios,
           JPEGImageWriter writer) throws IOException {
    super.write(ios, writer); // width and height
    // Write the palette (must be 768 bytes)
    byte [] palette = new byte[768];
    IndexColorModel icm = (IndexColorModel) thumbnail.getColorModel();
    byte [] reds = new byte [256];
    byte [] greens = new byte [256];
    byte [] blues = new byte [256];
    icm.getReds(reds);
    icm.getGreens(greens);
    icm.getBlues(blues);
    for (int i = 0; i < 256; i++) {
        palette[i*3] = reds[i];
        palette[i*3+1] = greens[i];
        palette[i*3+2] = blues[i];
    }
    ios.write(palette);
    writePixels(ios, writer);
}
 
源代码8 项目: 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;
}
 
源代码9 项目: JDKSourceCode1.8   文件: JFIFMarkerSegment.java
void write(ImageOutputStream ios,
           JPEGImageWriter writer) throws IOException {
    super.write(ios, writer); // width and height
    // Write the palette (must be 768 bytes)
    byte [] palette = new byte[768];
    IndexColorModel icm = (IndexColorModel) thumbnail.getColorModel();
    byte [] reds = new byte [256];
    byte [] greens = new byte [256];
    byte [] blues = new byte [256];
    icm.getReds(reds);
    icm.getGreens(greens);
    icm.getBlues(blues);
    for (int i = 0; i < 256; i++) {
        palette[i*3] = reds[i];
        palette[i*3+1] = greens[i];
        palette[i*3+2] = blues[i];
    }
    ios.write(palette);
    writePixels(ios, writer);
}
 
源代码10 项目: JDKSourceCode1.8   文件: 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;
}
 
源代码11 项目: openjdk-jdk8u-backup   文件: JFIFMarkerSegment.java
void write(ImageOutputStream ios,
           JPEGImageWriter writer) throws IOException {
    super.write(ios, writer); // width and height
    // Write the palette (must be 768 bytes)
    byte [] palette = new byte[768];
    IndexColorModel icm = (IndexColorModel) thumbnail.getColorModel();
    byte [] reds = new byte [256];
    byte [] greens = new byte [256];
    byte [] blues = new byte [256];
    icm.getReds(reds);
    icm.getGreens(greens);
    icm.getBlues(blues);
    for (int i = 0; i < 256; i++) {
        palette[i*3] = reds[i];
        palette[i*3+1] = greens[i];
        palette[i*3+2] = blues[i];
    }
    ios.write(palette);
    writePixels(ios, writer);
}
 
源代码12 项目: openjdk-jdk9   文件: JFIFMarkerSegment.java
void write(ImageOutputStream ios,
           JPEGImageWriter writer) throws IOException {
    super.write(ios, writer); // width and height
    // Write the palette (must be 768 bytes)
    byte [] palette = new byte[768];
    IndexColorModel icm = (IndexColorModel) thumbnail.getColorModel();
    byte [] reds = new byte [256];
    byte [] greens = new byte [256];
    byte [] blues = new byte [256];
    icm.getReds(reds);
    icm.getGreens(greens);
    icm.getBlues(blues);
    for (int i = 0; i < 256; i++) {
        palette[i*3] = reds[i];
        palette[i*3+1] = greens[i];
        palette[i*3+2] = blues[i];
    }
    ios.write(palette);
    writePixels(ios, writer);
}
 
源代码13 项目: 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;
}
 
/** Gets the LUT from the <code>IndexColorModel</code> as an two-dimensional
 *  byte array.
 */
private static byte[][] getLUT(IndexColorModel icm) {
    int[] comp = icm.getComponentSize();
    int size = icm.getMapSize();
    byte[][] lut = new byte[comp.length][size];
    icm.getReds(lut[0]);
    icm.getGreens(lut[1]);
    icm.getBlues(lut[2]);
    if (comp.length == 4)
        icm.getAlphas(lut[3]);
    return lut;
}
 
源代码15 项目: 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;
}
 
源代码16 项目: openjdk-jdk9   文件: 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 项目: openjdk-8   文件: 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 项目: dragonwell8_jdk   文件: 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;
}
 
源代码19 项目: jdk8u-jdk   文件: 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;
}
 
源代码20 项目: jdk8u-jdk   文件: 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;
}