C + + based on DirectX MMX implementation of image grayscale conversion code _c language

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.