The previous article talked about the YUYV, Yvyu, UYVY, and Vyuy formats in the topic, all of which are YUV422 packaging formats-that is, in memory, Y, U, and V are sorted next to each other. Their names represent the order of Y, U, v. Like Yuyv, y, u, y, V, y, u, y, v. When you do the conversion, it becomes easy and simple.
Because they are extremely similar, they are all closed to a function in the various formats. The code is as follows:
void Yuv422packed_to_rgb24 (Yuv_type TYPE, unsigned char* yuv422p, unsigned char* rgb, int width, int height) {int y,
CB, CR;
int R, G, B;
int i = 0;
unsigned char* p;
unsigned char* P_rgb;
p = yuv422p;
P_rgb = RGB;
Init_yuv422p_table (); for (i = 0; i < width * HEIGHT/2; i++) {switch (type) {case fmt_yuyv:y = P
[0];
cb = P[1];
CR = P[3];
Break
Case fmt_yvyu:y = p[0];
CR = P[1];
cb = P[3];
Break
Case FMT_UYVY:CB = p[0];
y = p[1];
CR = P[2];
Break
Case FMT_VYUY:CR = p[0];
y = p[1];
cb = p[2];
Break
Default:break; } r = MAX (0, MIN (255, (V[CR] + y1[y])/10000); R Value B = MAX (0, MIN (255, (U[CB] + y1[y])/10000); B Value g = MAX(0, MIN (255, (Y2[y]-5094* (R)-1942* (b))/10000));
G value//Here can adjust the RGB sorting, BMP picture sorting to BGR//default sort: rgb p_rgb[0] = r;
P_rgb[1] = g;
P_RGB[2] = b;
Switch (type) {case Fmt_yuyv:case fmt_yvyu:y = p[2];
Break
Case Fmt_uyvy:case fmt_vyuy:y = p[3];
Break
Default:break; } r = MAX (0, MIN (255, (V[CR] + y1[y])/10000); R Value B = MAX (0, MIN (255, (U[CB] + y1[y])/10000); B Value g = MAX (0, MIN (255, (Y2[y]-5094* (R)-1942* (b))/10000);
G value p_rgb[3] = r;
P_RGB[4] = g;
P_RGB[5] = b;
p + = 4;
P_rgb + = 6; }
}
When doing the conversion, pay attention to the YUV422 sampling format, 2 y common 1 U and a V, so each cycle is to read 1 y, a U and V converted to R, G, B, and then read the next y, U, v. Because the UV is common, so the 2nd time conversion without giving U, v assignment.
In summary, the code is still very simple.
2015.8.5 Night Li Yu