HacroCam - recalculate to greyscale before sending (processing example)

Hi robtillaart,

got the 4bit part now working too.

encoding:

int grayLeft=pbuf[A] & 0xF0;
int grayRight=(pbuf[A+1] & 0xF0) >> 4;
pbuf[pos]=(grayLeft | grayRight);

decoding:

int LeftPixel = packedbuf[loc/2] & 0xF0;
int RightPixel = (0x0F & packedbuf[loc/2]) << 4;
img.pixels[loc] = color(LeftPixel, LeftPixel, LeftPixel);
img.pixels[loc+1] = color(RightPixel, RightPixel, RightPixel);

Regarding to 5/6 bit to 8 bit transcoding:
until now I used:

r = r << 2;
g = g << 1;
b = b << 2;

you suggested (gived the black areas):

r = r << 3;
g = g << 2;
b = b << 3;

The processing code uses:

r = (r << 3)|(r >>> 2);
g = (g << 2)|(g >>> 4);
b = (b << 3)|(b >>> 2);

I now use:

r = (r << 2)|(r >> 1);
g = (g << 1)|(g >> 3);
b = (b << 2)|(b >> 1);

This gives quite good results. I still don't understand why I have to shift one bit less than even the Processing code does.

At least it works.

Robert