directdraw显示YUV格式

  • s5_944047
    了解作者
  • 24.7KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-06-15 05:57
    上传日期
VC++平台使用directdraw显示YUV格式图像程序
189138reply.rar
  • www.pudn.com.txt
    218B
  • YuvTest
  • YuvTest.plg
    1.3KB
  • YuvTest.rc
    2.7KB
  • YuvTest.dsw
    539B
  • YuvTest.dsp
    4.2KB
  • mosquito.ico
    766B
  • YuvTest.ncb
    49KB
  • resource.h
    682B
  • main.cpp
    32.9KB
  • YuvTest.opt
    51.5KB
内容介绍
//**************************************************************************** //* Program: Mosquito //* //* Description: //* Sample application to demonstrate the creation, display, and //* positioning of overlays. //* //* Contents: //* WinMain() - Main entry point for this application. //* MainDlgProc() - Message proc for this app. //* InitDirectDraw() - Creates core DirectDraw objects. //* FreeDirectDraw() - Frees up core DirectDraw objects. //* CreatePrimarySurface() - Creates Primary surface. //* CreateOverlay() - Creates a multi-buffer flippable overlay surface. //* DestroyOverlay() - Hides overlay surface and releases it. //* CopyBitmapToYUVSurface() - Copies a GDI bitmap to a YUV surface. //* Used by LoadImageOntoSurface(). //* LoadImageOntoSurface() - Loads a resource based bitmap onto a surface. //* EnumAttachedCallback() - Callback for EnumAttachedSurfaces(). //* DisplayOverlay() - Displays our overlay on the primary. //* RestoreAllSurfaces() - Restores the primary and overlay surfaces. //* MoveOverlayTimerCallback() - TimerProc for moving the overlay surface. //* //* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF //* ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO //* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A //* PARTICULAR PURPOSE. //* //* Copyright (C) 1996-1997 Microsoft Corporation. All Rights Reserved. //**************************************************************************** // C RunTime Header Files #include <stdlib.h> #include <malloc.h> #include <memory.h> // Windows Header Files: #include <windows.h> #include <mmsystem.h> //added to compile under NT #define INITGUID #include <objbase.h> #include <initguid.h> #include <ddraw.h> // Local Headers #include "resource.h" //#include <stdilb.h> #include <stdio.h> #pragma comment (lib,"ddraw.lib"); #pragma comment (lib,"dxguid.lib"); // Define some macros #define INIT_DIRECTDRAW_STRUCT(x) (ZeroMemory(&x, sizeof(x)), x.dwSize=sizeof(x)) #define RAND_INT(x) (rand()*x/RAND_MAX) #define RANDOM_VELOCITY() ((RAND_INT(5)+3)*2) // Global Variables: LPDIRECTDRAW2 g_lpdd = NULL; LPDIRECTDRAWSURFACE g_lpddsPrimary = NULL; LPDIRECTDRAWSURFACE g_lpddsOverlay = NULL; int g_nOverlayXPos, g_nOverlayYPos; int g_nOverlayXVel, g_nOverlayYVel; int g_nOverlayWidth, g_nOverlayHeight; int g_nOverlayFlipCounter; DWORD g_dwOverlayXPositionAlignment; // used to keep track of any alignment // restrictions on the X postion of // our overlay surface. Comes from the // the DDCAPS dwBoundaryAlignDest field. // Initialized in DisplayOverlay(). // These are the pixel formats this app supports. Most display adapters // with overlay support will recognize one or more of these formats. // The first on our list is the 16-bit RGB formats. These have the widest // support. DDPIXELFORMAT g_ddpfOverlayFormats[] = {/* {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 16, 0x7C00, 0x03e0, 0x001F, 0}, // 16-bit RGB 5:5:5 {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 16, 0xF800, 0x07e0, 0x001F, 0}, // 16-bit RGB 5:6:5 {sizeof(DDPIXELFORMAT), DDPF_FOURCC,MAKEFOURCC('U','Y','V','Y'),0,0,0,0,0}, // UYVY {sizeof(DDPIXELFORMAT), DDPF_FOURCC,MAKEFOURCC('Y','U','Y','2'),0,0,0,0,0}, // YUY2 */ {sizeof(DDPIXELFORMAT),DDPF_FOURCC,MAKEFOURCC('Y','V','1','2'),0,0,0,0,0} }; #define NUM_OVERLAY_FORMATS (sizeof(g_ddpfOverlayFormats) / sizeof(g_ddpfOverlayFormats[0])) // Define some error messages. If we had many more we'd stick 'em in our RC file. #define NO_OVERLAY_HARDWARE "Sorry, In order to run this sample application you must "\ "have a display adapter and driver which support overlays." #define UNABLE_TO_CREATE_OVERLAY "Sorry, your display adapter appears to "\ "support overlays, but we were unable to "\ "create an overlay in any of the formats "\ "this app supports (16-bit RGB and YUV). "\ "You may want to try shutting down other "\ "DirectX apps to free video memory, or try "\ "rerunning this app in a different display "\ "mode." #define UNABLE_TO_DISPLAY_OVERLAY "Sorry, we created an overlay on your "\ "system, but were unable to display it. "\ "Please try rerunning this app in "\ "a different display mode." //**************************************************************************** //* Function: FreeDirectDraw //* //* Description: //* Releases core DirectDraw objects //**************************************************************************** void FreeDirectDraw(void) { if (g_lpddsPrimary) { g_lpddsPrimary->Release(); g_lpddsPrimary=NULL; } if (g_lpdd) { g_lpdd->Release(); g_lpdd=NULL; } } //**************************************************************************** //* Function: CreatePrimarySurface() //* //* Description: //* Creates a Primary Surface. Implemented as a separate function from //* InitDirectDraw() because we occasionally need to just recreate the primary //* surface such as when a mode change occurs. //**************************************************************************** HRESULT CreatePrimarySurface() { DDSURFACEDESC ddsd; HRESULT ddrval; if (!g_lpdd) return E_FAIL; INIT_DIRECTDRAW_STRUCT(ddsd); ddsd.dwFlags = DDSD_CAPS; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; ddrval = g_lpdd->CreateSurface(&ddsd, &g_lpddsPrimary, NULL ); return ddrval; } //**************************************************************************** //* Function: InitDirectDraw //* //* Description: //* Performs DirectDraw initialization. Creates a primary surface which //* is needed to display our overlay on. The actual overlay surface is //* created later in our CreateOverlay() call. //**************************************************************************** BOOL InitDirectDraw() { HRESULT ddrval; LPDIRECTDRAW lpDD1; ddrval = DirectDrawCreate( NULL, &lpDD1, NULL ); if( FAILED(ddrval)) goto ErrorOut; ddrval = lpDD1->QueryInterface(IID_IDirectDraw2, (void **)&g_lpdd); if( FAILED(ddrval)) goto ErrorOut; lpDD1->Release(); // For NORMAL cooperative level we no longer need to provide an HWND. ddrval = g_lpdd->SetCooperativeLevel(NULL, DDSCL_NORMAL); if( FAILED(ddrval)) goto ErrorOut; ddrval= CreatePrimarySurface(); if( FAILED(ddrval)) goto ErrorOut; return TRUE; ErrorOut: FreeDirectDraw(); return FALSE; } //**************************************************************************** //* Function: DestroyOverlay() //* Description: //* Hides the overlay then releases it's surface. //**************************************************************************** void DestroyOverlay() { if (g_lpddsOverlay) { // Use UpdateOverlay() with the DDOVER_HIDE flag to remove an overlay // from the display. g_lpddsOverlay->UpdateOverlay(NULL, g_lpddsPrimary, NULL, DDOVER_HIDE, NULL); g_lpddsOverlay->Release(); g_lpddsOverlay=NULL; } } //**************************************************************************** //* Fun
评论
    相关推荐
    • c++课件
      c++课件c++课件c++课件c++课件c++课件c++课件c++课件c++课件c++课件c++课件c++课件c++课件c++课件
    • C++ PRrimer
      本书是久负盛名的C++经典教程,其内容是C++大师Stanley B. Lippman丰富的实践经验和C++标准委员会原负责人Josée Lajoie对C++标准深入理解的完美结合,已经帮助全球无数程序员学会了C++。本版对前一版进行了彻底的...
    • C++
      C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++
    • Effective C++
      学习c++的经典书籍!每一个学习c++的人有时间最好看看!你会获得很大收获!
    • c++information
      c++c++c++c++c++c++c++c++c++c++c++c++
    • SourceStyler C++
      用DEV-C++写代码很方便,就是不能格式化有点郁闷 c++格式化的好工具 效率高
    • c++yuyanbiancheng
      这是C和C++集成的编程环境!这是C和C++集成的编程环境!这是C和C++集成的编程环境!这是C和C++集成的编程环境!这是C和C++集成的编程环境!
    • C++ primier
      学习C++的经典之作,希望大家学习愉快,快速掌握C++的各种知识。多下哈
    • effective C++
      有关C++编程方面的检验性介绍,对由C转向C++,和有C++编程基础的程序员有帮助,不过是英文版
    • effective c++
      C++经典书籍Effective C++ By Scott Meyers, 已译成中文,chm格式,方便检阅 Uploaded by save (chaisave@sohu.com)