This article describes a method based on DirectX MMX to implement image grayscale processing, to compile this program need DirectX SDK5.0, code required ddutil.h and ddutil.cpp files, please download the project. Compiled in a WINDOWNT4.0+SP3 environment, the code has been collated and contains comments. as follows:
#include <windows.h> #include <windowsx.h> #include <stdio.h> #include <ddraw.h> #include < math.h> #include "ddutil.h" #define 0//mean method #define Maximum_gray 1//Maximum method #define Weight_gray weighted mean value method #defin
E title "Grayscale Conversion"//Window title #define CLASSNAME "Gray"//window class name #define WIDTH 640 #define HEIGHT #define COLORS 8 #define STEP 1 #define Scanline hinstance hinst; Application instance handle HWND Hwndmain; Main Window handle Lpdirectdraw lpdd; DirectDraw Object Lpdirectdrawsurface lpddsprimary; Main Page Lpdirectdrawsurface Lpddsback; Background buffer lpdirectdrawsurface LpDDSPic1; Off-screen page 1 Lpdirectdrawpalette lpddpal; Palette BOOL bactive;
Is the application active?
int key=0;
BOOL Contrast=false;
BOOL Gray=false;
function declares void freeobjects (void);
BOOL initddraw (void);
BOOL initpalette (void);
BOOL initsurfaces (void);
void Updateframe (void);
void Makerect (RECT *rect, long left, long up, long right, long bottom); void Increasecontrast (BYTE *pbyte,const int Low,const intHight, const float Grad) {if (*pbyte<=low) *pbyte=0;
else if ((low<*pbyte) && (*pbyte
Interested friends can debug run the example of this article, I believe that you will be in C + + project development to play a certain role in helping.