用qt 实现 方法yuv420p 转 rgb32
时间: 2024-05-12 14:17:18 浏览: 213
YUV420转换成RGB
好的,我理解了您的要求,以下是使用Qt实现yuv420p转rgb32的方法:
```cpp
void yuv420p_to_rgb32(unsigned char* yuv, unsigned char* rgb, int width, int height)
{
int frame_size = width * height;
unsigned char* y = yuv;
unsigned char* u = yuv + frame_size;
unsigned char* v = yuv + frame_size + (frame_size / 4);
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
int index = i * width + j;
int y_val = y[index];
int u_val = u[(i / 2) * (width / 2) + (j / 2)];
int v_val = v[(i / 2) * (width / 2) + (j / 2)];
int r = y_val + 1.370705 * (v_val - 128);
int g = y_val - 0.698001 * (v_val - 128) - 0.337633 * (u_val - 128);
int b = y_val + 1.732446 * (u_val - 128);
r = qBound(0, r, 255);
g = qBound(0, g, 255);
b = qBound(0, b, 255);
int* ptr = (int*)(rgb + index * 4);
*ptr = (r << 16) | (g << 8) | b;
}
}
}
```
这段代码实现的是将yuv420p格式的数据转换成rgb32格式的数据,其中,输入yuv数组为y,u,v三个分量按照顺序排列,输出rgb数组为每个像素点4个字节的rgba格式数据。详细的解释和注释可以在代码中找到。
阅读全文