Log in

View Full Version : How do i draw YUV data in a window in C++?


redeemer-dk
5th June 2003, 19:52
I would like to draw my 4:2:0 YCbCr data in my window in my application. I can see from DVD2AVI that it's possible, but i can't figure out the code from DVD2AVI, i've tried using some of it but it doesen't work for me.

Does anyone have a sample on how to do it or know it?

BTW, using Win32, not MFC :)

Thanks in advance.

-Rune Svendsen

Nic
6th June 2003, 09:42
Depends...You can either use DirectDraw...which will support YUV (if the graphics card does). The DirectDraw code from DVD2AVI isn't bad (if a little messy) but you could look up some more basic directdraw on the net. Or you could use some XviD code to convert the YUV to RGB and then use the GDI functions. (Its slow, its lazy...and its what I did in dvd2avi_nic ;) )

-Nic

Valiant
6th June 2003, 18:33
How much slower is GDI than DirectDraw? Did anyone ever a benchmark / comparison?
However, I use DrawDib ...

(DrawDib Operations (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/drawdib_7yb7.asp)):
1. DrawDibOpen() (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/mmfunc_8tda.asp)
2. DrawDibBegin() (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/mmfunc_7usu.asp)
3. DrawDibDraw() (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/mmfunc_76if.asp)

example code:

//! Handle to the window all images will be drawn into
HWND m_hWndVideo;
//! Handle of the DrawDIB instance
HDRAWDIB m_hDrawDIB;

// constructor
CImageMonitor::CImageMonitor()
{
m_hWndVideo = NULL;
m_hDrawDIB = NULL;

m_hDrawDIB = DrawDibOpen();
}

// the target window of our bitmap
bool CImageMonitor::Initialize(HWND hWndDest)
{
m_hWndVideo = hWndDest;

return true;
}

// Image is our custom RAW image format...
bool CImageMonitor::drawImage(Image *pImage)
{
BITMAPINFO *pBitmap = NULL;

long iSize = NULL;
bool bRet = true;

if( ! ( iSize = pImage->exportDIB( &pBitmap ) ))
return false;

bRet = drawDIB(pBitmap, pImage->width, pImage->height);

delete pBitmap;

return bRet;
}

bool CImageMonitor::drawDIB(BITMAPINFO *pBitmap, int iWidth, int iHeight)
{
HDC hDC = GetDC( m_hWndVideo );

if ( ! DrawDibBegin(m_hDrawDIB, hDC, -1, -1, &(pBitmap->bmiHeader), iWidth, iHeight, NULL) )
return false;
if ( ! DrawDibDraw(m_hDrawDIB, hDC, 0, 0, -1, -1, &(pBitmap->bmiHeader), (LPSTR)pBitmap + (WORD)(pBitmap->bmiHeader.biSize), 0, 0, iWidth, iHeight, NULL) )
return false;

return true;
}

Harlequin
6th June 2003, 20:47
There's a reffrence page for decoding fourCC codes here http://www.fourcc.org/indexyuv.htm

redeemer-dk
6th June 2003, 21:44
I think the FOURCC NV12 is what I'm looking for. How do i decode to RGB24 when i know the FOURCC of my source?

Harlequin
7th June 2003, 19:53
If you're using the DVD2AVI source the FourCC is YUY2; I think that this is the minimal code to decode YUY2 to RGB24.

void Store_RGB24(unsigned char *src[]){
static unsigned char *y444;

conv422to444(src[1], u444);
conv422to444(src[2], v444);

y444 = src[0];
conv444toRGB24even(y444, u444, v444, rgb24);
conv444toRGB24odd(y444, u444, v444, rgb24);
}

redeemer-dk
8th June 2003, 17:56
1) How do i convert my 4:2:0 data to 4:2:2?
2) How do i organize the data in the buffer?
3) What is src[1] and what is src[2]?