typedef unsigned char uint8_t; #define clip_8bit(val) ((val) < 0 ? 0 : (val) > 255 ? 255 : (val)) static uint8_t *yuy2torgb (const uint8_t *data, const int width, const int height) { /* Packed YUV 422 is: Y1, U, Y2, V for each (horizontal) pixel pair. * Left pixel is Y1,U,V, right pixel is Y2,U,V. */ int i; uint8_t *rgb, *ptr,*src; ptr = rgb = (guchar *)malloc (width * height * 3); if (!rgb) return NULL; int R,G,B; src = ( uint8_t *)data; for (i = 0; i < width * height / 2; ++i) { int y = (src[1] - 16) * 11644; int v = src[0] - 128; int u = src[2] - 128; int yy = y-16; int b = table_y[yy] + table_ub[u]; int g = table_y[yy] - table_ug[u] - table_vg[v]; int r = table_y[yy] + table_vr[v]; R = clip_8bit ((y + 15960 * v) / 10000); G = clip_8bit ((y - 3918 * u - 8130 * v) / 10000); B = clip_8bit ((y + 20172 * u) / 10000 ); *ptr++ = R; /* R */ *ptr++ = G; /* G */ *ptr++ = B; /* B */ y = (src[3] - 16) * 11644; R = clip_8bit ((y + 15960 * v) / 10000); G = clip_8bit ((y - 3918 * u - 8130 * v) / 10000); B = clip_8bit ((y + 20172 * u) / 10000 ); *ptr++ = R; /* R */ *ptr++ = G; /* G */ *ptr++ = B; /* B */ src += 4; } return rgb; }