问题
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 memcpy
s 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