如何将两个yuv文件合并为一个

问题描述:

我想合并两个yuv文件

但在我制作之前

i尝试了一些简单的

i使用了一个yuv文件

试图为这张图片创建一个文件

以下是我的代码

i want to merge two yuv files
but before i make it
i tried some simple
i used one yuv file
tried to make a file contains for this picture
below is my code

BYTE *pY = m_pSrcBuffer ;

BYTE *pV = m_pSrcBuffer +SRC_HEIGHT*SRC_WIDTH ;

BYTE *pU = m_pSrcBuffer + SRC_WIDTH*SRC_HEIGHT*5/4 ;

BYTE *pTemp = m_pDstBuffer ;



BYTE *pYd = m_pDstBuffer ;
BYTE *pVd = m_pDstBuffer+m_nDstHeight*m_nDstWidth ;
BYTE *pUd = m_pDstBuffer + m_nDstHeight*m_nDstWidth*5/4 ;

   for (int i = 0 ;i< 4;i++)
   {
      memcpy(pYd+i*SRC_WIDTH*SRC_HEIGHT,pY,SRC_HEIGHT*SRC_WIDTH) ;
   }

   for (int i = 0 ;i<4 ;i++)
   {
      memcpy(pVd+i*SRC_HEIGHT*SRC_WIDTH/4,pV,SRC_HEIGHT*SRC_WIDTH/4) ;
   }
   for (int i = 0 ;i<4 ;i++)
   {
      memcpy(pUd+i*SRC_HEIGHT*SRC_WIDTH/4,pU,SRC_HEIGHT*SRC_WIDTH/4) ;

   }





结果不是我想要的

图片是8不是4

和身高成为我想要的一半



i不知道为什么

是有些人可以给我一些建议吗?

谢谢你提前



the result is not what i want
the picture is eight not four
and the height become the half of what i want

i do not know why
is some body who can give me some advice?
thank you advance

你正在假设你的图像格式,它是YUV:8:2:2由彩色平面存储。那可能是正确的。我们假设您已经检查过这是您现在的图像格式。



您犯的最大错误是您尝试复制一种颜色的全部内容在单个复制操作中通道到目标图像。让我试着向你展示一下这里发生了什么。您第一张图片的Y频道可能如下所示:



111111

111111

111111 >


当您从四个部分图像中创建一个大图像时,您想得到这个:



111111222222 >
111111222222

111111222222

333333444444

333333444444

333333444444



这意味着您必须将源图像分割为扫描线并将每条扫描线复制到目标图像中的位置。根据您显示的代码,您将获得



111111111111

111111222222

222222222222

333333333333

333333444444

444444444444



你看出出了什么问题?当然,你必须为所有三个颜色平面做到这一点。你明白我的意思了吗?
You are making an assumption about your image format, that it is YUV:8:2:2 stored by color planes. That might be correct or not. Let's assume you have checked that this is the format of your images for now.

The big mistake you are making is that you try to copy the entire contents of one color channel to your destination image in a single copy operation. Let me try to show you with a little demonstration what's going on here. The Y channel of your first image might look like this:

111111
111111
111111

When you compose one big image from the four partial images you want to get this:

111111222222
111111222222
111111222222
333333444444
333333444444
333333444444

That means you have to split up your source image into scan lines and copy each scan line to its place in the destination image. With the code you are showing you would get

111111111111
111111222222
222222222222
333333333333
333333444444
444444444444

You see what's going wrong? Of course you have to do that for all three color planes. You see what I mean?


对于合并图片,最好将两张图片加载到对象中,然后在DC上绘制它们,而不是保存位。
For merge pictures it is better to load both pictures into objects and than draw them on a DC and than save the bits.