Java Code Examples for java.awt.image.IndexColorModel#getReds()

The following examples show how to use java.awt.image.IndexColorModel#getReds() . 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: ColorMap.java    From jtk with Apache License 2.0 6 votes vote down vote up
/**
 * Returns an index color model with specified opacity (alpha).
 * @param icm an index color model from which to copy RGBs.
 * @param alpha opacity in the range [0.0,1.0].
 * @return the index color model with alpha.
 */
public static IndexColorModel setAlpha(IndexColorModel icm, double alpha) {
  int bits = icm.getPixelSize();
  int size = icm.getMapSize();
  byte[] r = new byte[size];
  byte[] g = new byte[size];
  byte[] b = new byte[size];
  byte[] a = new byte[size];
  icm.getReds(r);
  icm.getGreens(g);
  icm.getBlues(b);
  byte ia = (byte)(255.0*alpha+0.5);
  for (int i=0; i<size; ++i)
    a[i] = ia;
  return new IndexColorModel(bits,size,r,g,b,a);
}
 
Example 2
Source File: MyImageUtils.java    From spring-boot with Apache License 2.0 6 votes vote down vote up
static IndexColorModel createIndexColorModel() {
    BufferedImage ex = new BufferedImage(1, 1,
            BufferedImage.TYPE_BYTE_INDEXED);
    IndexColorModel icm = (IndexColorModel) ex.getColorModel();
    int SIZE = 256;
    byte[] r = new byte[SIZE];
    byte[] g = new byte[SIZE];
    byte[] b = new byte[SIZE];
    byte[] a = new byte[SIZE];
    icm.getReds(r);
    icm.getGreens(g);
    icm.getBlues(b);
    java.util.Arrays.fill(a, (byte) 255);
    r[0] = g[0] = b[0] = a[0] = 0; // transparent
    return new IndexColorModel(8, SIZE, r, g, b, a);
}
 
Example 3
Source File: APNGFormat.java    From scifio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void writePLTE() throws IOException {
	if (!(getColorModel() instanceof IndexColorModel)) return;

	final IndexColorModel model = (IndexColorModel) getColorModel();
	final byte[][] lut = new byte[3][256];
	model.getReds(lut[0]);
	model.getGreens(lut[1]);
	model.getBlues(lut[2]);

	getHandle().writeInt(768);
	final byte[] b = new byte[772];
	b[0] = 'P';
	b[1] = 'L';
	b[2] = 'T';
	b[3] = 'E';

	for (int i = 0; i < lut[0].length; i++) {
		for (int j = 0; j < lut.length; j++) {
			b[i * lut.length + j + 4] = lut[j][i];
		}
	}

	getHandle().write(b);
	getHandle().writeInt(crc(b));
}
 
Example 4
Source File: JFIFMarkerSegment.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example 5
Source File: ColorMap.java    From jtk with Apache License 2.0 6 votes vote down vote up
/**
 * Returns an index color model with specified opacities (alphas).
 * @param icm an index color model from which to copy RGBs.
 * @param alpha array of opacities in the range [0.0,1.0].
 * @return the index color model with alphas.
 */
public static IndexColorModel setAlpha(IndexColorModel icm, float[] alpha) {
  int bits = icm.getPixelSize();
  int size = icm.getMapSize();
  byte[] r = new byte[size];
  byte[] g = new byte[size];
  byte[] b = new byte[size];
  byte[] a = new byte[size];
  icm.getReds(r);
  icm.getGreens(g);
  icm.getBlues(b);
  int n = min(size,alpha.length);
  for (int i=0; i<n; ++i)
    a[i] = (byte)(255.0f*alpha[i]+0.5f);
  return new IndexColorModel(bits,size,r,g,b,a);
}
 
Example 6
Source File: GIFImageReader.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 7
Source File: JFIFMarkerSegment.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 8
Source File: GIFImageReader.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 9
Source File: JFIFMarkerSegment.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example 10
Source File: JFIFMarkerSegment.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example 11
Source File: JFIFMarkerSegment.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example 12
Source File: JFIFMarkerSegment.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
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);
}
 
Example 13
Source File: GIFImageReader.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
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;
}
 
Example 14
Source File: GIFImageWriter.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 15
Source File: GIFImageWriter.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * 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;
}
 
Example 16
Source File: GIFImageWriter.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 17
Source File: GIFImageWriter.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 18
Source File: GIFImageWriter.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 19
Source File: GIFImageWriter.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 20
Source File: GIFImageWriter.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}