You can use getType() on an Image, and compare against Image.RGB888 and Image.RGBA8888 (and a bunch of others, but these are most used) to find out what type it is.
public static ColorRGBA pickColor(Image textureImage, Vector2f picker)
{
ColorRGBA color;
switch (textureImage.getType())
{
case Image.RGBA8888:
case Image.RGBA8888_DXT1A:
case Image.RGBA8888_DXT3:
case Image.RGBA8888_DXT5:
color = pickColor(textureImage, picker, true);
break;
case Image.RGB888:
case Image.RGB888_DXT1:
default:
color = pickColor(textureImage, picker, false);
break;
}
return color;
}
public static ColorRGBA pickColor(Image textureImage, Vector2f picker, boolean rgba)
{
ByteBuffer bb = textureImage.getData();
int ci = (rgba) ? 4 : 3;
int pixel = (int)(picker.x * picker.y) * ci;
float[] rgb = new float[ci];
for (int i=0; i<rgb.length; i++) rgb[i] = (256f + bb.get(pixel+i))/256f;
return (rgba)
? new ColorRGBA(rgb[0], rgb[1], rgb[2], rgb[3])
: new ColorRGBA(rgb[0], rgb[1], rgb[2], 1f);
}
I used all RGB888 and RGBA8888 format in Image Class, in my tests my images return always "5" (RGB888_DXT1)
I keep public the method pickColor(image, picker, "alpha") but it now can be private too....