Combining two YV12 image buffers into a single side-by-side image

我只是一个虾纸丫 提交于 2020-06-28 09:04:39

问题


I have two image buffers in YV12 format that I need to combine into a single side-by-side image.

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

YV12 is split into 3 seperate planes.

YYYYYYYY VV UU

The pixel format is 12 bits-per-pixel.

I have created a method that memcpys one buffer (1920x1080) into a larger buffer (3840x1080), but it isn't working.

Here is my 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;
}

I expected this:

Instead, I get this result:

What am I missing?


回答1:


What you wanted is this:

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

but your code is actually doing this:

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

Here's the corrected code (untested)

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;
}


来源:https://stackoverflow.com/questions/38404312/combining-two-yv12-image-buffers-into-a-single-side-by-side-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!