Click here to Skip to main content
15,867,756 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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
C++
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) ;

   }


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
Posted
Updated 19-Aug-13 16:30pm
v2
Comments
Sergey Alexandrovich Kryukov 19-Aug-13 21:57pm    
To start with, you need to say what you wanted.
—SA
chinahyin 19-Aug-13 22:06pm    
sorry i want to merge yuv picture ,for example i have two yuv files all of them is one picture ,i want merge them into one picture
Sergey Alexandrovich Kryukov 19-Aug-13 22:28pm    
Do you at least understand that this is already ambiguous?
—SA
SoMad 19-Aug-13 22:36pm    
I am afraid I don't quite understand either. What are the sizes of the two pictures and what size do you want to have in the merged picture?

Soren Madsen
chinahyin 19-Aug-13 22:41pm    
the two picture is all 320*240 the merged picture is 640*480 so sorry for my poor english

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?
 
Share this answer
 
Comments
H.Brydon 21-Aug-13 22:45pm    
Your answer is so good that I figured out what the question was by reading the answer. Is this Jeopardy?

+5
nv3 22-Aug-13 2:15am    
Thanks, Harvey. I also had to read the question twice until I got it. And actually, SoMad's comments were what made it clear.
chinahyin 22-Sep-13 2:43am    
thank you very much you are so kind
For merge pictures it is better to load both pictures into objects and than draw them on a DC and than save the bits.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900