Hi Thomas, > Correct GIMP creates palette that adapts to the contents > of the image. There are many ways of doing this, I don't > know what method GIMP uses but it is probably a pretty > good one, the one I referenced earlier is also pretty good > and very standard.
While I don't understand what GIMP is doing, the resulting PNG will be the good starting point for me. Because I'm not familiar with the image manipulation at all, my first step is to know "What is the desirable Color Palette?" :-) I played with the indexed PNG from GIMP. The next code fragment prints the RGB values in the indexed Color Palette: BufferedImage bi=..... ColorModel model=bi.getColorModel(); if(!(model instanceof IndexColorModel)){ System.out.println("Not a IndexColorModel!"); System.exit(0); } IndexColorModel index=(IndexColorModel)model; int mapSize=index.getMapSize(); System.out.println("Map size is :"+mapSize); byte[] red=new byte[mapSize]; byte[] green=new byte[mapSize]; byte[] blue=new byte[mapSize]; index.getReds(red); index.getGreens(green); index.getBlues(blue); int mask=Integer.parseInt("0000ff",16); System.out.println("Available reds..."); for(int i=0; i<mapSize; i++){ System.out.print(Integer.toHexString(((int)red[i])&mask)+" "); } System.out.println(""); System.out.println("Available greens..."); for(int i=0; i<mapSize; i++){ System.out.print(Integer.toHexString(((int)green[i])&mask)+" "); } System.out.println(""); System.out.println("Available blues..."); for(int i=0; i<mapSize; i++){ System.out.print(Integer.toHexString(((int)blue[i])&mask)+" "); } System.out.println(""); From RGB-PNG, I should calculate the values for: byte[] red=new byte[x]; byte[] green=new byte[x]; byte[] blue=new byte[x]; Then, I can use: IndexColorModel model=new IndexColorModel(8,x,red,green,blue); new BufferedImage(w, h, BufferedImage.TYPE_BYTE_INDEXED, model); Is this the way to go? Anyway, I tried to pick up all the available colors in RGB-PNG. Only way I found is.... BufferedImage bi=... int w=bi.getWidth(); int h=bi.getHeight(); int red_mask=Integer.parseInt("ff0000",16); int green_mask=Integer.parseInt("00ff00",16); int blue_mask=Integer.parseInt("0000ff",16); Set redSet=new HashSet(); Set greenSet=new HashSet(); Set blueSet=new HashSet(); int rgb=0; for(int i_w=0; i_w<w; i_w++){ for(int i_h=0; i_h<h; i_h++){ rgb=bi.getRGB(i_w,i_h); redSet.add(Integer.toHexString(((rgb&red_mask)>>16))); greenSet.add(Integer.toHexString(((rgb&green_mask)>>8))); blueSet.add(Integer.toHexString(rgb&blue_mask)); } } if(redSet.size()>0){ System.out.println("Available red color is..."); Iterator redIt=redSet.iterator(); while(redIt.hasNext()){ System.out.println((String)(redIt.next())); } } else{ System.out.println("No red color!"); } if(greenSet.size()>0){ System.out.println("Available green color is..."); Iterator greenIt=greenSet.iterator(); while(greenIt.hasNext()){ System.out.println((String)(greenIt.next())); } } else{ System.out.println("No green color!"); } if(blueSet.size()>0){ System.out.println("Available blue color is..."); Iterator blueIt=blueSet.iterator(); while(blueIt.hasNext()){ System.out.println((String)(blueIt.next())); } } else{ System.out.println("No blue color!"); } I think I made a little progress, but I'm not sure if this is the right way or not. Happy Java programming! ------------------------ Jun Inamori OOP-Reserch E-mail: [EMAIL PROTECTED] URL: http://www.oop-reserch.com/ --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]