PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

I wonder why?

PocketFrog 0.7
Code:

Pixel src = buffer.pixels[(y) * dy + x];
int R = (src & RED_MASK) >> RED_SHIFT; // Get the red part of the pixel
int G = (src & GREEN_MASK)>> GREEN_SHIFT ; // Green part
int B = src & BLUE_MASK; // Blue part

buffer2.pixels[y * dy2 + x] = Color(R,G,B);


in pixel = 25720
out Color returns 2307
Why is that?
Because the Color() function takes 0..255 parameters and you feed in 0..31/0..63 values.

Try this instead:

Code:
Pixel src = buffer.pixels[(y) * dy + x];
int R = (src & RED_MASK) >> RED_SHIFT; // Get the red part of the pixel
int G = (src & GREEN_MASK)>> GREEN_SHIFT ; // Green part
int B = src & BLUE_MASK; // Blue part

// Convert colors to 0..255 range
R = R << 3;
G = G << 2;
B = B << 3;

buffer2.pixels[y * dy2 + x] = Color(R,G,B);


Remember that there is 5 bits of red, 6 bits of green and 5 bits of blue.