2016-07-15 150 views
0

我有两个YV12格式的图像缓冲区,需要将它们合并为一个并排图像。将两个YV12图像缓冲区合并为一个并排图像

(1920×1080)+(1920×1080)=(3840 * 1080)

YV12被分成3米单独的平面上。

YYYYYYYY VV UU 

像素格式是每像素12位。

我创建了一个方法,memcpy s一个缓冲区(1920x1080)到一个更大的缓冲区(3840x1080),但它不起作用。

这是我的C++。

BYTE* source = buffer; 
BYTE* destination = convertBuffer3D; 

// copy over the Y 
for (int x = 0; x < height; x++) 
{ 
    memcpy(destination, source, width); 
    destination += width * 2; 
    source += width; 
} 

// copy over the V 
for (int x = 0; x < (height/2); x++) 
{ 
    memcpy(destination, source, width/2); 
    destination += width; 
    source += width/2; 
} 

// copy over the U 
for (int x = 0; x < (height/2); x++) 
{ 
    memcpy(destination, source, width/2); 
    destination += width; 
    source += width/2; 
} 

我预计:

Correct image

相反,我得到这样的结果:

Incorrect image

我缺少什么?

+0

代码看起来约权。你可能错过了其他的东西(跨越任何一个图像被扩展?底部填充?)。 –

+0

没有扩展我们的填充。我的1920x1080图像的总缓冲区大小是3110400(1920x1080x1.5),所以没有额外的数据。 –

+0

另外我想如果它是NV12而不是YV12,也会有类似的效果。然后你需要在循环之后简单地检查源和目标。如果它们是正确的,那么问题不在于循环,而在于图像结构与您期望的不同。 –

回答

1

你想这是什么:

Y1 Y1 Y1 Y1 Y2 Y2 Y2 Y2 
Y1 Y1 Y1 Y1 Y2 Y2 Y2 Y2 
Y1 Y1 Y1 Y1 Y2 Y2 Y2 Y2 
Y1 Y1 Y1 Y1 Y2 Y2 Y2 Y2 
U1 U1 U2 U2 V1 V1 V2 V2 
U1 U1 U2 U2 V1 V1 V2 V2 

但你的代码实际上是这样做的:

Y1 Y1 Y1 Y1 Y2 Y2 Y2 Y2 
Y1 Y1 Y1 Y1 Y2 Y2 Y2 Y2 
Y1 Y1 Y1 Y1 Y2 Y2 Y2 Y2 
Y1 Y1 Y1 Y1 Y2 Y2 Y2 Y2 
U1 U1 V1 V1 U2 U2 V2 V2 
U1 U1 V1 V1 U2 U2 V2 V2 

下面是更正后的代码(未经测试)

BYTE* source = buffer; 
BYTE* destination = convertBuffer3D; 

// copy over the Y 
for (int x = 0; x < height; x++) 
{ 
    memcpy(destination, source, width); 
    destination += width * 2; 
    source += width; 
} 

for (int x = 0; x < (height/2); x++) 
{ 
    // copy over the V 
    memcpy(destination, source, width/2); 
    destination += width; 
    source += width/2; 

    // copy over the U 
    memcpy(destination, source, width/2); 
    destination += width; 
    source += width/2; 
}