How can i get the original id of an id to color algorithm?

0

I have the following function to convert a given id of an object into an RGB color:

int r = ((int) id & 0x000000FF) >> 0;
int g = ((int) id & 0x0000FF00) >> 8;
int b = ((int) id & 0x00FF0000) >> 16;

How would I receive the original id if I can get the RGB color from the mouse pixel? I can't wrap my mind around these bit operations.

Any suggestions?

EDIT my approach:

int r = pixels[index] & 0xFF;
int g = pixels[index + 1] & 0xFF;
int b = pixels[index + 2] & 0xFF;

return r + g * 256 + b * 256 * 256;

EDIT 2 example: Input: 50 -> RGB : 255,0,0 returned value: -1,0,0 -> ID: 255

java
rgb
bitwise-operators
asked on Stack Overflow May 18, 2021 by lumow • edited May 18, 2021 by lumow

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0