I need an image file that verifies this test "if (input.getColorModel() instanceof IndexColorModel)"

StackOverflow https://stackoverflow.com/questions/23232274

  •  07-07-2023
  •  | 
  •  

Question

In order to see the impact of the code below i need an image file which verify the if test; and can you give me the different IndexColorModel of images.

System.out.println(input.getColorModel());
System.out.println("vvvvvv");

if (input.getColorModel() instanceof IndexColorModel) {
    System.out.println("eeeeeeeee");

    // Retrieve the IndexColorModel
    IndexColorModel icm = (IndexColorModel)input.getColorModel();

    // Cache the number of elements in each band of the colormap.
    int mapSize = icm.getMapSize();

    // Allocate an array for the lookup table data.
    System.out.println("eeeeeeeee");
    System.out.println(mapSize);
    byte[][] lutData = new byte[3][mapSize];

    // Load the lookup table data from the IndexColorModel.
    icm.getReds(lutData[0]);
    icm.getGreens(lutData[1]);
    icm.getBlues(lutData[2]);

    // Create the lookup table object.
    LookupTableJAI lut = new LookupTableJAI(lutData);

    // Replace the original image with the 3-band RGB image.
    input = JAI.create("lookup", input, lut);
}
Was it helpful?

Solution

An IndexColorModel is typically created from a GIF or a PNG with a PLTE (palette) chunk. BMP files with palette might also work.

Try reading a GIF file, using ImageIO.read(yourGIF), it should come out with an IndexColorModel.

Another option would be to create a blank image like this, if you can live with the fixed color map:

input = new BufferedImage(1, 1, BufferedImage.TYPE_BYTE_INDEXED);

But I think for your use case, it's simpler to just create a new IndexColorModel using predefined look-up tables. You don't need to get it from an input image.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top