nv12 格式
nv12 转 rgb 两种格式
代码
void NV12_T_RGB(unsigned int width, unsigned int height, unsigned char* Y, unsigned char* UV, unsigned char* rgb)
{int r, g, b;int y, u, v;for (int i = 0; i < height; i++) {for (int j = 0; j < width; j++) {y = Y[i * width + j];u = UV[(i / 2 * width + j / 2 * 2)];v = UV[(i / 2 * width + j / 2 * 2) + 1];// TRACE("yuv(%d, %d, %d)\n", i * width + j, (i / 2 * width + j / 2 * 2), (i / 2 * width + j / 2 * 2) + 1);r = y + 1.4075 * (v-128); //rg = y - 0.344 * (u-128) - 0.714 * (v-128); //gb = y + 1.770 * (u-128); //bif (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;rgb[(i * width + j) * 3 + 0] = (unsigned char)r;rgb[(i * width + j) * 3 + 1] = (unsigned char)g;rgb[(i * width + j) * 3 + 2] = (unsigned char)b;}}
}