For people that can find usefull "ColorPicker"

A very short code to pick pixel RGB value from a texture and use it for fog, light, etc…



public static ColorRGBA pickColor(Image textureImage, Vector2f picker, float alpha)
{
        ByteBuffer bb = textureImage.getData();
        int pixel = (int)(picker.x * picker.y) * 3;
        float[] rgb = new float[3];
        for (int i=0; i<rgb.length; i++) rgb[i] = (256f + bb.get(pixel+i))/256f;
   return new ColorRGBA(rgb[0], rgb[1], rgb[2], alpha);
}



simple usage:

ColorRGBA color = pickColor(texture.getImage(), new Vector2f(x,y), alpha_level);


If anyone have suggestion are all good accepted :D

Well, if you want a suggestion, RGBA texture support :slight_smile:

i have looked in past to find a way to get if its rgb or rgba… it get RGBA value from an rgb image but for a good reason.



Mading a simple change:



public static ColorRGBA pickColor(Image textureImage, Vector2f picker)
{

Yes but now it won't work for RGB right? :smiley:



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.

ummh, then is simple… right?



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....