blob: d1e832bc110b142ba87232d056d8d8b5d2370e95 [file] [log] [blame]
static void yuv_to_rgb16(unsigned char y, unsigned char u, unsigned char v, unsigned char *rgb)
{
int r,g,b;
int z;
int rgb16;
z = 0;
r = 1.164 * (y - 16) + 1.596 * (v - 128);
g = 1.164 * (y - 16) - 0.813 * (v - 128) - 0.391 * (u -128);
b = 1.164 * (y - 16) + 2.018 * (u - 128);
if (r > 255) r = 255;
if (g > 255) g = 255;
if (b > 255) b = 255;
if (r < 0) r = 0;
if (g < 0) g = 0;
if (b < 0) b = 0;
rgb16 = (int)(((r >> 3)<<11) | ((g >> 2) << 5)| ((b >> 3) << 0));
*rgb = (unsigned char)(rgb16 & 0xFF);
rgb++;
*rgb = (unsigned char)((rgb16 & 0xFF00) >> 8);
}
void convertYUYVtoRGB565(unsigned char *buf, unsigned char *rgb, int width, int height)
{
int x,y,z=0;
int blocks;
blocks = (width * height) * 2;
for (y = 0; y < blocks; y+=4) {
unsigned char Y1, Y2, U, V;
Y1 = buf[y + 0];
U = buf[y + 1];
Y2 = buf[y + 2];
V = buf[y + 3];
yuv_to_rgb16(Y1, U, V, &rgb[y]);
yuv_to_rgb16(Y2, U, V, &rgb[y + 2]);
}
}