DirectDraw 示例

DirectDraw 在显示YUV图像的时候,由于 YUV 格式很多,显示不同格式的YUV图像都要针对不同格式专门写一些代码,这样很麻烦,同时也增加代码量。在网上看了一些 DirectDraw 示例以后,发现都是针对某一种格式的显示。我用最基本的 DirectDraw 显示方法,封装了几种格式的显示方法,我的显示器只支持示例中的 YUV 格式,所以只实现了几种格式,如有朋友还需要显示别的 YUV 格式可增加少量代码就可显示

 

#ifndef DirectDraw_H #define DirectDraw_H ////////////////////////////////////////////////////////////////////////// #include <DDraw.h> ////////////////////////////////////////////////////////////////////////// #pragma comment(lib, "DDraw.lib") #pragma comment(lib, "DxGuid.lib") ////////////////////////////////////////////////////////////////////////// struct ImageSpace { enum { SPACE_COUNT = 4, }; PBYTE pBuffer[SPACE_COUNT]; DWORD dwLineSize[SPACE_COUNT]; }; ////////////////////////////////////////////////////////////////////////// struct FormatYV12 { static VOID Build(DDSURFACEDESC2 &ddsd, DWORD dwWidth, DWORD dwHeight) { ZeroMemory(&ddsd, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN|DDSCAPS_VIDEOMEMORY; ddsd.dwFlags = DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH|DDSD_PIXELFORMAT; ddsd.dwWidth = dwWidth; ddsd.dwHeight = dwHeight; ddsd.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT); ddsd.ddpfPixelFormat.dwFlags = DDPF_FOURCC|DDPF_YUV; ddsd.ddpfPixelFormat.dwYUVBitCount = 8; ddsd.ddpfPixelFormat.dwFourCC = MAKEFOURCC('Y','V','1','2'); } static VOID Copy(LPBYTE lpSurface, const ImageSpace &imageSpace, DWORD dwWidth, DWORD dwHeight, LONG lPitch) { LPBYTE lpSrcY = imageSpace.pBuffer[0]; LPBYTE lpSrcU = imageSpace.pBuffer[1]; LPBYTE lpSrcV = imageSpace.pBuffer[2]; DWORD dwCopyLength = 0; if (lpSrcY != NULL) { dwCopyLength = dwWidth; for (LONG i=0; i<dwHeight; ++i) { CopyMemory(lpSurface, lpSrcY, dwCopyLength); lpSrcY += imageSpace.dwLineSize[0]; lpSurface += lPitch; } } if (lpSrcV != NULL) { dwCopyLength = dwWidth >> 1; for (LONG i=0; i<dwHeight >> 1; ++i) { CopyMemory(lpSurface, lpSrcV, dwCopyLength); lpSrcV += imageSpace.dwLineSize[2]; lpSurface += lPitch >> 1; } } if (lpSrcU != NULL) { dwCopyLength = dwWidth >> 1; for (LONG i=0; i<dwHeight >> 1; ++i) { CopyMemory(lpSurface, lpSrcU, dwCopyLength); lpSrcU += imageSpace.dwLineSize[1]; lpSurface += lPitch >> 1; } } } }; struct FormatYUY2 { static VOID Build(DDSURFACEDESC2 &ddsd, DWORD dwWidth, DWORD dwHeight) { ZeroMemory(&ddsd, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN|DDSCAPS_VIDEOMEMORY; ddsd.dwFlags = DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH|DDSD_PIXELFORMAT; ddsd.dwWidth = dwWidth; ddsd.dwHeight = dwHeight; ddsd.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT); ddsd.ddpfPixelFormat.dwFlags = DDPF_FOURCC|DDPF_YUV; ddsd.ddpfPixelFormat.dwYUVBitCount = 8; ddsd.ddpfPixelFormat.dwFourCC = MAKEFOURCC('Y','U','Y','2'); } static VOID Copy(LPBYTE lpSurface, const ImageSpace &imageSpace, DWORD dwWidth, DWORD dwHeight, LONG lPitch) { LPBYTE lpSrcY = imageSpace.pBuffer[0]; DWORD dwCopyLength = dwWidth << 1; for (LONG i=0; i<dwHeight; ++i) { CopyMemory(lpSurface, lpSrcY, dwCopyLength); lpSrcY += imageSpace.dwLineSize[0]; lpSurface += lPitch; } } }; struct FormatUYVY { static VOID Build(DDSURFACEDESC2 &ddsd, DWORD dwWidth, DWORD dwHeight) { ZeroMemory(&ddsd, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN|DDSCAPS_VIDEOMEMORY; ddsd.dwFlags = DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH|DDSD_PIXELFORMAT; ddsd.dwWidth = dwWidth; ddsd.dwHeight = dwHeight; ddsd.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT); ddsd.ddpfPixelFormat.dwFlags = DDPF_FOURCC|DDPF_YUV; ddsd.ddpfPixelFormat.dwYUVBitCount = 8; ddsd.ddpfPixelFormat.dwFourCC = MAKEFOURCC('U','Y','V','Y'); } static VOID Copy(LPBYTE lpSurface, const ImageSpace &imageSpace, DWORD dwWidth, DWORD dwHeight, LONG lPitch) { FormatYUY2::Copy(lpSurface, imageSpace, dwWidth, dwHeight, lPitch); } }; ////////////////////////////////////////////////////////////////////////// struct FormatPAL8 { static VOID Build(DDSURFACEDESC2 &ddsd, DWORD dwWidth, DWORD dwHeight) { ZeroMemory(&ddsd, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN|DDSCAPS_VIDEOMEMORY; ddsd.dwFlags = DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH|DDSD_PIXELFORMAT; ddsd.dwWidth = dwWidth; ddsd.dwHeight = dwHeight; ddsd.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT); ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB|DDPF_PALETTEINDEXED8; ddsd.ddpfPixelFormat.dwRGBBitCount = 8; } static VOID Copy(LPBYTE lpSurface, const ImageSpace &imageSpace, DWORD dwWidth, DWORD dwHeight, LONG lPitch) { LPBYTE lpSrcY = imageSpace.pBuffer[0]; DWORD dwCopyLength = dwWidth << 2; for (LONG i=0; i<dwHeight; ++i) { CopyMemory(lpSurface, lpSrcY, dwCopyLength); lpSrcY += imageSpace.dwLineSize[0]; lpSurface += lPitch; } } }; struct FormatRGB555 { enum { RBitMask = 0x7C00, GBitMask = 0x03E0, BBitMask = 0x001F, }; static VOID Build(DDSURFACEDESC2 &ddsd, DWORD dwWidth, DWORD dwHeight) { ZeroMemory(&ddsd, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN|DDSCAPS_VIDEOMEMORY; ddsd.dwFlags = DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH|DDSD_PIXELFORMAT; ddsd.dwWidth = dwWidth; ddsd.dwHeight = dwHeight; ddsd.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT); ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB; ddsd.ddpfPixelFormat.dwRGBBitCount = 16; ddsd.ddpfPixelFormat.dwRBitMask = RBitMask; ddsd.ddpfPixelFormat.dwGBitMask = GBitMask; ddsd.ddpfPixelFormat.dwBBitMask = BBitMask; ddsd.ddpfPixelFormat.dwRGBAlphaBitMask = 0; } static VOID Copy(LPBYTE lpSurface, const ImageSpace &imageSpace, DWORD dwWidth, DWORD dwHeight, LONG lPitch) { PSHORT lpSrcY = (PSHORT) imageSpace.pBuffer[0]; PSHORT lpDstY = (PSHORT) lpSurface; for (LONG i=0; i<dwHeight; ++i) { ZeroMemory(lpDstY, dwWidth * sizeof(SHORT)); for (LONG j=0; j<dwWidth; ++j) { lpDstY[j] |= (lpSrcY[j] & RBitMask) >> 10; lpDstY[j] |= (lpSrcY[j] & GBitMask); lpDstY[j] |= (lpSrcY[j] & BBitMask) << 10; } lpSrcY += imageSpace.dwLineSize[0] / sizeof(SHORT); lpDstY += lPitch / sizeof(SHORT); } } }; struct FormatRGB565 { enum { RBitMask = 0xF800, GBitMask = 0x07E0, BBitMask = 0x001F, }; static VOID Build(DDSURFACEDESC2 &ddsd, DWORD dwWidth, DWORD dwHeight) { ZeroMemory(&ddsd, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN|DDSCAPS_VIDEOMEMORY; ddsd.dwFlags = DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH|DDSD_PIXELFORMAT; ddsd.dwWidth = dwWidth; ddsd.dwHeight = dwHeight; ddsd.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT); ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB; ddsd.ddpfPixelFormat.dwRGBBitCount = 16; ddsd.ddpfPixelFormat.dwRBitMask = RBitMask; ddsd.ddpfPixelFormat.dwGBitMask = GBitMask; ddsd.ddpfPixelFormat.dwBBitMask = BBitMask; ddsd.ddpfPixelFormat.dwRGBAlphaBitMask = 0; } static VOID Copy(LPBYTE lpSurface, const ImageSpace &imageSpace, DWORD dwWidth, DWORD dwHeight, LONG lPitch) { PSHORT lpSrcY = (PSHORT) imageSpace.pBuffer[0]; PSHORT lpDstY = (PSHORT) lpSurface; for (LONG i=0; i<dwHeight; ++i) { ZeroMemory(lpDstY, dwWidth * sizeof(SHORT)); for (LONG j=0; j<dwWidth; ++j) { lpDstY[j] |= (lpSrcY[j] & RBitMask) >> 11; lpDstY[j] |= (lpSrcY[j] & GBitMask); lpDstY[j] |= (lpSrcY[j] & BBitMask) << 11; } lpSrcY += imageSpace.dwLineSize[0] / sizeof(SHORT); lpDstY += lPitch / sizeof(SHORT); } } }; struct FormatBGR24 { static VOID Build(DDSURFACEDESC2 &ddsd, DWORD dwWidth, DWORD dwHeight) { ZeroMemory(&ddsd, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN|DDSCAPS_VIDEOMEMORY; ddsd.dwFlags = DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH|DDSD_PIXELFORMAT; ddsd.dwWidth = dwWidth; ddsd.dwHeight = dwHeight; ddsd.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT); ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB; ddsd.ddpfPixelFormat.dwRGBBitCount = 32; ddsd.ddpfPixelFormat.dwRGBAlphaBitMask = 0; } static VOID Copy(LPBYTE lpSurface, const ImageSpace &imageSpace, DWORD dwWidth, DWORD dwHeight, LONG lPitch) { LPBYTE lpSrcY = imageSpace.pBuffer[0]; LPDWORD lpDstY = (LPDWORD) lpSurface; for (LONG i=0; i<dwHeight; ++i) { ZeroMemory(lpDstY, dwWidth * sizeof(DWORD)); for (LONG j=0; j<dwWidth; ++j) { lpDstY[j] |= (lpSrcY[3 * j]); lpDstY[j] |= (lpSrcY[3 * j + 1] << 8); lpDstY[j] |= (lpSrcY[3 * j + 2] << 16); } lpSrcY += imageSpace.dwLineSize[0]; lpDstY += lPitch / sizeof(DWORD); } } }; struct FormatRGB32 { static VOID Build(DDSURFACEDESC2 &ddsd, DWORD dwWidth, DWORD dwHeight) { ZeroMemory(&ddsd, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN|DDSCAPS_VIDEOMEMORY; ddsd.dwFlags = DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH|DDSD_PIXELFORMAT; ddsd.dwWidth = dwWidth; ddsd.dwHeight = dwHeight; ddsd.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT); ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB; ddsd.ddpfPixelFormat.dwRGBBitCount = 32; ddsd.ddpfPixelFormat.dwRGBAlphaBitMask = 0; } static VOID Copy(LPBYTE lpSurface, const ImageSpace &imageSpace, DWORD dwWidth, DWORD dwHeight, LONG lPitch) { LPBYTE lpSrcY = imageSpace.pBuffer[0]; LPDWORD lpDstY = (LPDWORD) lpSurface; for (LONG i=0; i<dwHeight; ++i) { ZeroMemory(lpDstY, dwWidth * sizeof(DWORD)); for (LONG j=0; j<dwWidth; ++j) { lpDstY[j] |= (lpSrcY[4 * j]); lpDstY[j] |= (lpSrcY[4 * j + 1] << 8); lpDstY[j] |= (lpSrcY[4 * j + 2] << 16); lpDstY[j] |= (lpSrcY[4 * j + 3] << 24); } lpSrcY += imageSpace.dwLineSize[0]; lpDstY += lPitch / sizeof(DWORD); } } }; struct FormatBGR32 { static VOID Build(DDSURFACEDESC2 &ddsd, DWORD dwWidth, DWORD dwHeight) { ZeroMemory(&ddsd, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN|DDSCAPS_VIDEOMEMORY; ddsd.dwFlags = DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH|DDSD_PIXELFORMAT; ddsd.dwWidth = dwWidth; ddsd.dwHeight = dwHeight; ddsd.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT); ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB; ddsd.ddpfPixelFormat.dwRGBBitCount = 32; ddsd.ddpfPixelFormat.dwRGBAlphaBitMask = 0; } static VOID Copy(LPBYTE lpSurface, const ImageSpace &imageSpace, DWORD dwWidth, DWORD dwHeight, LONG lPitch) { LPBYTE lpSrcY = imageSpace.pBuffer[0]; LPDWORD lpDstY = (LPDWORD) lpSurface; for (LONG i=0; i<dwHeight; ++i) { ZeroMemory(lpDstY, dwWidth * sizeof(DWORD)); for (LONG j=0; j<dwWidth; ++j) { lpDstY[j] |= (lpSrcY[4 * j] << 16); lpDstY[j] |= (lpSrcY[4 * j + 1] << 8); lpDstY[j] |= (lpSrcY[4 * j + 2]); lpDstY[j] |= (lpSrcY[4 * j + 3] << 24); } lpSrcY += imageSpace.dwLineSize[0]; lpDstY += lPitch / sizeof(DWORD); } } }; ////////////////////////////////////////////////////////////////////////// class CDirectDraw { typedef VOID (*CopyCallback)(LPBYTE lpSurface, const ImageSpace &imageSpace, DWORD dwWidth, DWORD dwHeight, LONG lPitch); public: CDirectDraw() : m_hWnd(NULL), m_dwWidth(0), m_dwHeight(0), m_pClipper(NULL), m_pDirectDraw(NULL), m_pSurfacePrimary(NULL), m_pSurfaceOffScreen(NULL), m_copyCallback(NULL) { } ~CDirectDraw() { Release(); } HRESULT Draw(const ImageSpace &imageSpace) { HRESULT hr = E_INVALIDARG; RECT rectSrc = { 0 }; RECT rectDst = { 0 }; DDSURFACEDESC2 ddOffScreenSurfaceDesc = { 0 }; if (m_copyCallback == NULL || m_pSurfaceOffScreen == NULL || m_dwWidth == 0 || m_dwHeight == 0) { goto Exit; } ddOffScreenSurfaceDesc.dwSize = sizeof(ddOffScreenSurfaceDesc); hr = m_pSurfaceOffScreen->Lock(NULL, &ddOffScreenSurfaceDesc, DDLOCK_WAIT|DDLOCK_WRITEONLY, NULL); if (hr != S_OK) { goto Exit; } m_copyCallback((LPBYTE) ddOffScreenSurfaceDesc.lpSurface, imageSpace, ddOffScreenSurfaceDesc.dwWidth, ddOffScreenSurfaceDesc.dwHeight, ddOffScreenSurfaceDesc.lPitch); m_pSurfaceOffScreen->Unlock(NULL); rectSrc.right = ddOffScreenSurfaceDesc.dwWidth; rectSrc.bottom = ddOffScreenSurfaceDesc.dwHeight; ::GetClientRect(m_hWnd, &rectDst); ::ClientToScreen(m_hWnd, (LPPOINT) &(rectDst.left)); ::ClientToScreen(m_hWnd, (LPPOINT) &(rectDst.right)); while (TRUE) { hr = m_pSurfacePrimary->Blt(&rectDst, m_pSurfaceOffScreen, &rectSrc, DDBLT_WAIT, NULL); if (hr == DDERR_SURFACELOST) { m_pSurfacePrimary->Restore(); m_pSurfaceOffScreen->Restore(); } if (hr != DDERR_WASSTILLDRAWING) { break; } } hr = S_OK; Exit: return hr; } template <typename PixelFormatT> HRESULT Create(HWND hWnd, DDSURFACEDESC2 &ddOffScreenSurfaceDesc) { Release(); HRESULT hr = DirectDrawCreateEx(NULL, (LPVOID *) &m_pDirectDraw, IID_IDirectDraw7, NULL); if (hr != S_OK) { goto Exit; } hr = m_pDirectDraw->SetCooperativeLevel(hWnd, DDSCL_NORMAL); if (hr != S_OK) { goto Exit; } { DDSURFACEDESC2 ddPrimarySurfaceDesc = { 0 }; ZeroMemory(&ddPrimarySurfaceDesc, sizeof(ddPrimarySurfaceDesc)); ddPrimarySurfaceDesc.dwSize = sizeof(ddPrimarySurfaceDesc); ddPrimarySurfaceDesc.dwFlags = DDSD_CAPS; ddPrimarySurfaceDesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; hr = m_pDirectDraw->CreateSurface(&ddPrimarySurfaceDesc, &m_pSurfacePrimary, NULL); if (hr != S_OK) { goto Exit; } hr = m_pDirectDraw->CreateClipper(0, &m_pClipper, NULL); if (hr != S_OK) { goto Exit; } hr = m_pClipper->SetHWnd(0, hWnd); if (hr != S_OK) { goto Exit; } m_pSurfacePrimary->SetClipper(m_pClipper); } hr = m_pDirectDraw->CreateSurface(&ddOffScreenSurfaceDesc, &m_pSurfaceOffScreen, NULL); if (hr != S_OK) { goto Exit; } m_hWnd = hWnd; m_dwWidth = ddOffScreenSurfaceDesc.dwWidth; m_dwHeight = ddOffScreenSurfaceDesc.dwHeight; m_copyCallback = PixelFormatT::Copy; Exit: if (hr != S_OK) { Release(); } return hr; } VOID Release() { m_hWnd = NULL; m_dwWidth = 0; m_dwHeight = 0; m_copyCallback = NULL; if (m_pClipper != NULL) { m_pClipper->Release(); m_pClipper = NULL; } if (m_pSurfacePrimary != NULL) { m_pSurfacePrimary->SetClipper(NULL); m_pSurfacePrimary->Release(); m_pSurfacePrimary = NULL; } if (m_pSurfaceOffScreen != NULL) { m_pSurfaceOffScreen->SetClipper(NULL); m_pSurfaceOffScreen->Release(); m_pSurfaceOffScreen = NULL; } if (m_pDirectDraw != NULL) { m_pDirectDraw->Release(); m_pDirectDraw = NULL; } } private: LPDIRECTDRAW7 m_pDirectDraw; LPDIRECTDRAWCLIPPER m_pClipper; LPDIRECTDRAWSURFACE7 m_pSurfacePrimary; LPDIRECTDRAWSURFACE7 m_pSurfaceOffScreen; HWND m_hWnd; DWORD m_dwWidth; DWORD m_dwHeight; CopyCallback m_copyCallback; }; ////////////////////////////////////////////////////////////////////////// #endif 用法如下, view plaincopy to clipboardprint? //声明变量 CDirectDraw m_directDrawYV12; CDirectDraw m_directDrawUYVY; CDirectDraw m_directDrawYUY2; CDirectDraw m_directDrawRGB555; CDirectDraw m_directDrawRGB565; CDirectDraw m_directDrawBGR24; CDirectDraw m_directDrawRGB32; CDirectDraw m_directDrawBGR32; //构造表面 DDSURFACEDESC2 ddsd = { 0 }; FormatYV12::Build(ddsd, 176, 144); m_directDrawYV12.Create<FormatYV12>(::GetDlgItem(m_hWnd, IDC_STATIC_YV12), ddsd); FormatYUY2::Build(ddsd, 176, 144); m_directDrawYUY2.Create<FormatYUY2>(::GetDlgItem(m_hWnd, IDC_STATIC_YUY2), ddsd); FormatUYVY::Build(ddsd, 176, 144); m_directDrawUYVY.Create<FormatUYVY>(::GetDlgItem(m_hWnd, IDC_STATIC_UYVY), ddsd); FormatRGB555::Build(ddsd, 176, 144); m_directDrawRGB555.Create<FormatRGB555>(::GetDlgItem(m_hWnd, IDC_STATIC_RGB555), ddsd); FormatRGB565::Build(ddsd, 176, 144); m_directDrawRGB565.Create<FormatRGB565>(::GetDlgItem(m_hWnd, IDC_STATIC_RGB565), ddsd); FormatBGR24::Build(ddsd, 176, 144); m_directDrawBGR24.Create<FormatBGR24>(::GetDlgItem(m_hWnd, IDC_STATIC_BGR24), ddsd); FormatRGB32::Build(ddsd, 176, 144); m_directDrawRGB32.Create<FormatRGB32>(::GetDlgItem(m_hWnd, IDC_STATIC_RGB32), ddsd); FormatBGR32::Build(ddsd, 176, 144); m_directDrawBGR32.Create<FormatBGR32>(::GetDlgItem(m_hWnd, IDC_STATIC_BGR32), ddsd); //显示图像 LPBYTE lpBuffer = NULL; UINT iLen = 0; FILE *f = NULL; ImageSpace imageSpace = { 0 }; //* f = fopen("176X144-YUV420P.yuv", "rb"); // f = fopen("176X144-YUVJ420P.yuv", "rb"); // f = fopen("176X144-NV21.yuv", "rb"); // f = fopen("176X144-NV12.yuv", "rb"); lpBuffer = new BYTE[WIDTH * HEIGHT * 3 >> 1]; fread(lpBuffer, 1, WIDTH * HEIGHT * 3 >> 1, f); imageSpace.pBuffer[0] = lpBuffer; imageSpace.pBuffer[1] = imageSpace.pBuffer[0] + WIDTH * HEIGHT; imageSpace.pBuffer[2] = imageSpace.pBuffer[1] + (WIDTH * HEIGHT >> 2); imageSpace.dwLineSize[0]= WIDTH; imageSpace.dwLineSize[1]= WIDTH >> 1; imageSpace.dwLineSize[2]= WIDTH >> 1; m_directDrawYV12.Draw(imageSpace); fclose(f); delete []lpBuffer; /**/ //* f = fopen("176X144-YUYV422.yuv", "rb"); lpBuffer = new BYTE[WIDTH * HEIGHT << 1]; iLen = fread(lpBuffer, 1, WIDTH * HEIGHT << 1, f); imageSpace.pBuffer[0] = lpBuffer; imageSpace.dwLineSize[0]= WIDTH << 1; m_directDrawYUY2.Draw(imageSpace); fclose(f); delete []lpBuffer; /**/ //* f = fopen("176X144-UYVY422.yuv", "rb"); lpBuffer = new BYTE[WIDTH * HEIGHT << 1]; iLen = fread(lpBuffer, 1, WIDTH * HEIGHT << 1, f); imageSpace.pBuffer[0] = lpBuffer; imageSpace.dwLineSize[0]= WIDTH << 1; m_directDrawUYVY.Draw(imageSpace); fclose(f); delete []lpBuffer; /**/ //* f = fopen("176X144-RGB555.yuv", "rb"); lpBuffer = new BYTE[WIDTH * HEIGHT << 1]; iLen = fread(lpBuffer, 1, WIDTH * HEIGHT << 1, f); imageSpace.pBuffer[0] = lpBuffer; imageSpace.dwLineSize[0]= WIDTH << 1; m_directDrawRGB555.Draw(imageSpace); fclose(f); delete []lpBuffer; /**/ //* f = fopen("176X144-RGB565.yuv", "rb"); lpBuffer = new BYTE[WIDTH * HEIGHT << 1]; iLen = fread(lpBuffer, 1, WIDTH * HEIGHT << 1, f); imageSpace.pBuffer[0] = lpBuffer; imageSpace.dwLineSize[0]= WIDTH << 1; m_directDrawRGB565.Draw(imageSpace); fclose(f); delete []lpBuffer; /**/ //* f = fopen("176X144-BGR24.yuv", "rb"); lpBuffer = new BYTE[WIDTH * HEIGHT * 3]; iLen = fread(lpBuffer, 1, WIDTH * HEIGHT * 3, f); imageSpace.pBuffer[0] = lpBuffer; imageSpace.dwLineSize[0]= WIDTH * 3; m_directDrawBGR24.Draw(imageSpace); fclose(f); delete []lpBuffer; /**/ //* f = fopen("176X144-RGB32.yuv", "rb"); lpBuffer = new BYTE[WIDTH * HEIGHT << 2]; iLen = fread(lpBuffer, 1, WIDTH * HEIGHT << 2, f); imageSpace.pBuffer[0] = lpBuffer; imageSpace.dwLineSize[0]= WIDTH << 2; m_directDrawRGB32.Draw(imageSpace); fclose(f); delete []lpBuffer; /**/ //* f = fopen("176X144-BGR32.yuv", "rb"); lpBuffer = new BYTE[WIDTH * HEIGHT << 2]; iLen = fread(lpBuffer, 1, WIDTH * HEIGHT << 2, f); imageSpace.pBuffer[0] = lpBuffer; imageSpace.dwLineSize[0]= WIDTH << 2; m_directDrawBGR32.Draw(imageSpace); fclose(f); delete []lpBuffer; /**/

你可能感兴趣的:(DirectDraw 示例)