本系列文章将使用GPU实现图像处理中常用的算法,此处只给出代码,关于算法原理描述有很多资料,大家可以自行查找。不足之处请大家不吝赐教,共同提高。
/********************************
* Author: rabbit729
* E-mail: wlq_729@163.com
* Date: 2012-09-20
* Description: 图像的二值化
********************************/
#include <d3dx9.h>
//-----------------------------------------------------------------------------
// Desc: 全局变量
//-----------------------------------------------------------------------------
LPDIRECT3D9 g_pD3D = NULL; //Direct3D对象
LPDIRECT3DDEVICE9 g_pd3dDevice = NULL; //Direct3D设备对象
LPDIRECT3DTEXTURE9 g_pTextureScreen = NULL; //待处理图片
ID3DXEffect* g_pEffect = NULL; //效果指针
//常量句柄
D3DXHANDLE hTechScreen = NULL; //Effect句柄
D3DXHANDLE hTexScreen = NULL; //纹理句柄
D3DXHANDLE hViewPortWidthInv = NULL; //视口宽倒数句柄
D3DXHANDLE hViewPortHeightInv = NULL; //视口高倒数句柄
LPDIRECT3DVERTEXBUFFER9 g_pScreenSpaceQuad = NULL; //背板VB
const int WIDTH = 465;
const int HEIGHT = 669;
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ | D3DFVF_TEX1)
struct Vertex
{
Vertex(){}
Vertex(float x, float y, float z, float w)
{
_x = x; _y = y; _z = z; _w = w;
}
float _x, _y, _z, _w;
static const DWORD FVF;
};
const DWORD Vertex::FVF = D3DFVF_XYZW;
//-----------------------------------------------------------------------------
// Desc: 设置世界矩阵
//-----------------------------------------------------------------------------
VOID SetWorldMatrix()
{
//创建并设置世界矩阵
D3DXMATRIXA16 matWorld, matRotateX, matRotateY;
D3DXMATRIXA16 matScale;
D3DXMatrixIdentity(&matScale);
matScale._11 = matScale._22 = matScale._33 = 0.5f;
D3DXMatrixIdentity(&matWorld);
D3DXMatrixIdentity(&matRotateX);
D3DXMatrixIdentity(&matRotateY);
D3DXMatrixRotationX( &matRotateX, D3DX_PI / 3.0 );
D3DXMatrixRotationY( &matRotateY, -D3DX_PI / 8.0 );
D3DXMatrixMultiply(&matWorld, &matRotateX, &matRotateY)