int table_y[240]; int table_ub[256]; int table_ug[256]; int table_vg[256]; int table_vr[256]; void InitialTable() { for (int i = 0; i < 240; ++i) { table_y[i] = 4767*i; table_y[i] = table_y[i] >>12; } for (int j = 0; j < 256; ++j) { table_ub[j] = 8265*(j-128); table_ub[j] = table_ub[j]>>12; table_ug[j] = 1556*(j-128); table_ug[j] = table_ug[j]>>12; table_vg[j] = 3330 * (j-128); table_vg[j] = table_vg[j]>>12; table_vr[j] = 4747*(j-128); table_vr[j] = table_vr[j] >>12; } } 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]; int v = src[0]; int u = src[2]; 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 (r); G = clip_8bit (g); B = clip_8bit (b); *ptr++ = R; /* R */ *ptr++ = G; /* G */ *ptr++ = B; /* B */ y = src[3] ; yy = y-16; b = table_y[yy] + table_ub[u]; g = table_y[yy] - table_ug[u] - table_vg[v]; r = table_y[yy] + table_vr[v]; R = clip_8bit (r); G = clip_8bit (g); B = clip_8bit (b ); *ptr++ = R; /* R */ *ptr++ = G; /* G */ *ptr++ = B; /* B */ src += 4; } return rgb; }