i have a simple byte array that i want to take colours from. My plan was to have three bits from red, three bits for green, and two bits for blue. 8-bit.
I think the colours are right:
Please correct me if i'm wrong,
byte[] colours = new byte[256]; //256 different colours, 8 * 8 * 4
//(3 bits(red) + 3 bits(green) + 2 bits(blue)
int index = 0;
for(byte r = 0; r < 8; r++){
for(byte g = 0; g < 8; g++){
for(byte b = 0; b < 4; b++){
byte rr = (r & 255);
byte gg = (g & 255);
byte bb = (b & 255);
colours[index++] = (rr << 5 | gg << 2 | bb);
}
}
}
My goal is to make a getColor(byte r, byte g, byte b) like
public static byte getColor(byte r, byte g, byte b){
return colours[return the right color using r g b];
}
But i don't know how. Here's where i need help.
I would like to rather not use the Color class if it's possible.
Other information: I'm using a BufferedImage.TYPE.BYTE.INDEXED to paint on.
Sorry if my english is bad :)
EDIT Fixed where it was wrong