c/c++ NV21转为YUV444格式代码
时间: 2023-12-20 09:03:12 浏览: 161
以下是将NV21格式转换为YUV444格式的C++代码示例:
```c++
#include <iostream>
// NV21 to YUV444 conversion
void nv21_to_yuv444(unsigned char* nv21, unsigned char* yuv444, int width, int height) {
int frameSize = width * height;
int i, j, yp, y, u, v;
unsigned char* yptr = yuv444;
unsigned char* uptr = yuv444 + frameSize;
unsigned char* vptr = yuv444 + frameSize * 2;
for (j = 0, yp = 0; j < height; j++) {
u = 0; v = 0;
for (i = 0; i < width; i++, yp++) {
y = (int)(nv21[yp]) & 0xff;
if ((i & 1) == 0) {
v = (int)(nv21[frameSize + (yp >> 1)]) & 0xff;
u = (int)(nv21[frameSize + (yp >> 1) + 1]) & 0xff;
}
yptr[yp] = y;
uptr[yp] = u;
vptr[yp] = v;
}
}
}
int main() {
// Dimensions of input NV21 frame
int width = 640;
int height = 480;
// Allocate memory for input NV21 frame
unsigned char* nv21 = new unsigned char[width * height * 3 / 2];
// Allocate memory for output YUV444 frame
unsigned char* yuv444 = new unsigned char[width * height * 3];
// Perform NV21 to YUV444 conversion
nv21_to_yuv444(nv21, yuv444, width, height);
// Clean up memory
delete[] nv21;
delete[] yuv444;
return 0;
}
```
这段代码中的`nv21_to_yuv444`函数用于执行NV21到YUV444的转换。请注意,此代码仅提供了转换功能,您需要根据自己的需求进行适当的输入和输出处理。
阅读全文