The conversion of NV12 and YUV420 is the conversion in the same sampling space, just the adjustment of the individual component position, as long as the arrangement of Y, U, V components is understood, it is easy to write.
The code is as follows:
/** yyyy yyyy UV UV-YYYY yyyy UU VV */void yuv420sp_to_yuv420p (unsigned char* yuv420sp, unsigned char* yuv420p,
int width, int height) {int I, J;
int y_size = width * height;
unsigned char* y = yuv420sp;
unsigned char* UV = yuv420sp + y_size;
unsigned char* y_tmp = yuv420p;
unsigned char* u_tmp = yuv420p + y_size;
unsigned char* v_tmp = yuv420p + y_size * 5/4;
Y memcpy (y_tmp, y, y_size);
U for (j = 0, i = 0; j < y_size/2; j+=2, i++) {u_tmp[i] = uv[j];
V_tmp[i] = uv[j+1]; }}/** yyyy yyyy uu VV, yyyy yyyy UV UV */void yuv420p_to_yuv420sp (unsigned char* yuv420p, unsigned char* yuv42
0SP, int width, int height) {int I, J;
int y_size = width * height;
unsigned char* y = yuv420p;
unsigned char* u = yuv420p + y_size;
unsigned char* v = yuv420p + y_size * 5/4;
unsigned char* y_tmp = yuv420sp;
unsigned char* uv_tmp = yuv420sp + y_size; Y memcpy (y_tmp, y, y_size);
U for (j = 0, i = 0; j < y_size/2; j+=2, i++) {//Here you can adjust the position of U, V, into NV12 or NV21 #if uv_tmp[j] = u[i];
UV_TMP[J+1] = V[i];
#else uv_tmp[j] = v[i];
UV_TMP[J+1] = U[i]; #endif}}
Postscript:
I wrote the things I had been studying for a long time, as if I had not written the idea. Before also tried to write a highly technical article, everywhere looking for information, find out, but later found that they are not that piece of material, and then directly affixed to the code, the theory of things instead of saying-because it is unclear, but also afraid to say wrong.
About YUV, initially heard in 6, 7 years ago the University, began to contact is 4, 5 years ago, and really understand its principles, but in recent years. The progress of learning is not slow. Write it, there is a confession. Also prepare yourself for the YUV player you are ready to implement.
Late 2015.8.5 Night