亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? dibapi.cpp

?? 《精通 vc++ 圖像編程》的源代碼
?? CPP
?? 第 1 頁 / 共 5 頁
字號:
//********************************************************************** 
// 
//  AIBAPI.CPP
// 
//  Source file for Device-Independent Bitmap (DIB) API. 
// 
//********************************************************************** 
 
#define     STRICT      // enable strict type checking 
 
#include "stdafx.h"
#include <string.h> 
#include <stdio.h> 
#include <math.h> 
#include <io.h> 
#include <direct.h> 
#include <stdlib.h> 
#include <assert.h> 
#include <windows.h> 
#include <windowsx.h> 
#include <mmsystem.h> 
#include "dibapi.h" 

////////////////////////////////////////////////////////////////////////////////////
// Local use only function prototypes
////////////////////////////////////////////////////////////////////////////////////
BOOL CopyColorTable(LPBITMAPINFO lpTarget, LPBITMAPINFO lpSource, HPALETTE hPalSrc);
void DecreaseContrast(BYTE *pByte, const int Level, const float Grad);
void IncreaseContrast(BYTE *pByte, const int Low, const int High, const float Grad);
double Value(double n1, double n2, double hue);
HGLOBAL DitherImage(LPBYTE lpImageData, WORD Width, WORD Height);
void DitherLine(WORD Width, LPBYTE pLine1, LPBYTE pLine2);
////////////////////////////////////////////////////////////////////////////////////
 
/************************************************************************* 
 * 
 * CreateDIB() 
 * 
 * Parameters: 
 * 
 * DWORD dwWidth    - Width for new bitmap, in pixels 
 * DWORD dwHeight   - Height for new bitmap  
 * WORD  wBitCount  - Bit Count for new DIB (1, 4, 8, or 24) 
 * 
 * Return Value: 
 * 
 * HDIB             - Handle to new DIB 
 * 
 * Description: 
 * 
 * This function allocates memory for and initializes a new DIB by 
 * filling in the BITMAPINFOHEADER, allocating memory for the color 
 * table, and allocating memory for the bitmap bits.  As with all 
 * HDIBs, the header, colortable and bits are all in one contiguous 
 * memory block.  This function is similar to the CreateBitmap()  
 * Windows API. 
 * 
 * The colortable and bitmap bits are left uninitialized (zeroed) in the 
 * returned HDIB. 
 * 
 * 
 ************************************************************************/ 
HDIB CreateDIB(DWORD dwWidth, DWORD dwHeight, WORD wBitCount) 
{ 
    BITMAPINFOHEADER    bi;             // bitmap header 
    LPBITMAPINFOHEADER  lpbi;           // pointer to BITMAPINFOHEADER 
    DWORD               dwLen;          // size of memory block 
    HDIB                hDIB; 
    DWORD               dwBytesPerLine; // Number of bytes per scanline 
 
 
    // Make sure bits per pixel is valid 
 
    if (wBitCount <= 1) 
        wBitCount = 1; 
    else if (wBitCount <= 4) 
        wBitCount = 4; 
    else if (wBitCount <= 8) 
        wBitCount = 8; 
    else if (wBitCount <= 24) 
        wBitCount = 24; 
    else 
        wBitCount = 4;  // set default value to 4 if parameter is bogus 
 
    // initialize BITMAPINFOHEADER 
 
    bi.biSize = sizeof(BITMAPINFOHEADER); 
    bi.biWidth = dwWidth;         // fill in width from parameter 
    bi.biHeight = dwHeight;       // fill in height from parameter 
    bi.biPlanes = 1;              // must be 1 
    bi.biBitCount = wBitCount;    // from parameter 
    bi.biCompression = BI_RGB;     
    bi.biSizeImage = 0;           // 0's here mean "default" 
    bi.biXPelsPerMeter = 0; 
    bi.biYPelsPerMeter = 0; 
    bi.biClrUsed = 0; 
    bi.biClrImportant = 0; 
 
    // calculate size of memory block required to store the DIB.  This 
    // block should be big enough to hold the BITMAPINFOHEADER, the color 
    // table, and the bits 
 
    dwBytesPerLine = WIDTHBYTES(wBitCount * dwWidth); 
    dwLen = bi.biSize + PaletteSize((LPBYTE)&bi) + (dwBytesPerLine * dwHeight); 
 
    // alloc memory block to store our bitmap 
 
    hDIB = GlobalAlloc(GHND, dwLen); 
 
    // major bummer if we couldn't get memory block 
 
    if (!hDIB) 
        return NULL; 
 
    // lock memory and get pointer to it 
 
    lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDIB); 
 
    // use our bitmap info structure to fill in first part of 
    // our DIB with the BITMAPINFOHEADER 
 
    *lpbi = bi; 
 
    // Since we don't know what the colortable and bits should contain, 
    // just leave these blank.  Unlock the DIB and return the HDIB. 
 
    GlobalUnlock(hDIB); 
 
    //return handle to the DIB 
 
    return hDIB; 
} 
 
/************************************************************************* 
 * 
 * CreateDefaultDIB() 
 * 
 * Parameters: 
 * 
 * DWORD dwWidth    - Width for new bitmap, in pixels 
 * DWORD dwHeight   - Height for new bitmap  
  * 
 * Return Value: 
 * 
 * HDIB             - Handle to new DIB 
 * 
 * Description: 
 * 
 * This function allocates memory for and initializes a new DIB by 
 * filling in the BITMAPINFOHEADER, allocating memory for the color 
 * table, and allocating memory for the bitmap bits.  As with all 
 * HDIBs, the header, colortable and bits are all in one contiguous 
 * memory block.  This function is similar to the CreateBitmap()  
 * Windows API. 
 * 
 * The colortable is initialized with system palette, but bitmap bits
 * are left uninitialized (zeroed) in the returned HDIB. 
 * 
 * 
 ************************************************************************/ 
HDIB CreateDefaultDIB(DWORD dwWidth, DWORD dwHeight) 
{ 
	// Get DC
    HDC hDC = GetDC(NULL); 
    if (!hDC) 
        return NULL; 

	// DC bts/pixel
	int nDeviceBitsPixel = GetDeviceCaps(hDC, BITSPIXEL);

	// create DIB according to DC
	HDIB hDIB = CreateDIB(dwWidth, dwHeight, nDeviceBitsPixel);

	// DIB buffer
	LPBITMAPINFO lpbmi = (LPBITMAPINFO)GlobalLock(hDIB);
    LPBYTE lpDIBBits = FindDIBBits((LPBYTE)lpbmi); 
    DWORD dwBitsSize = lpbmi->bmiHeader.biHeight * BytesPerLine((LPBYTE)&(lpbmi->bmiHeader)); 

	// set DIB color to White
	for (DWORD l=0; l<dwBitsSize; ++l)
		lpDIBBits[l] = 0xff;

	// if no palette, return DIB handle
	if (nDeviceBitsPixel > 8)
	{
		GlobalUnlock(hDIB);
	    ReleaseDC(NULL, hDC); 
		return hDIB;
	}

	// if there is palette, set system palette to DIB

	// colors in system palette
    int nColors = PalEntriesOnDevice(hDC);   // Number of palette entries 
  
    // Copy the current system palette into our logical palette 
	PALETTEENTRY pe[256];
    GetSystemPaletteEntries(hDC, 0, nColors, pe); 

	// set color table
	for (int i=0; i<nColors; ++i)
	{
		lpbmi->bmiColors[i].rgbRed = pe[i].peRed;
		lpbmi->bmiColors[i].rgbGreen = pe[i].peGreen;
		lpbmi->bmiColors[i].rgbBlue = pe[i].peBlue;
		lpbmi->bmiColors[i].rgbReserved = 0;
	}

    // clean up 
	GlobalUnlock(hDIB);
    ReleaseDC(NULL, hDC); 

	return hDIB;
}
/************************************************************************* 
 * 
 * DestroyDIB () 
 * 
 * Purpose:  Frees memory associated with a DIB 
 * 
 * Returns:  none 
 * 
 *************************************************************************/ 
void DestroyDIB(HDIB hDib) 
{ 
    GlobalFree(hDib); 
} 
 
/************************************************************************* 
 * 
 * LoadDIB() 
 * 
 * Loads the specified DIB from a file, allocates memory for it, 
 * and reads the disk file into the memory. 
 * 
 * 
 * Parameters: 
 * 
 * LPCTSTR lpFileName - specifies the file to load a DIB from 
 * 
 * Returns: A handle to a DIB, or NULL if unsuccessful. 
 * 
 * NOTE: The DIB API were not written to handle OS/2 DIBs; This 
 * function will reject any file that is not a Windows DIB. 
 * 
 *************************************************************************/ 
HDIB LoadDIB(LPCTSTR lpFileName) 
{ 
    HDIB        hDIB; 
    HANDLE      hFile; 
 
    // Set the cursor to a hourglass, in case the loading operation 
    // takes more than a sec, the user will know what's going on. 
 
    SetCursor(LoadCursor(NULL, IDC_WAIT)); 
 
    if ((hFile = CreateFile(lpFileName, GENERIC_READ, FILE_SHARE_READ, NULL, 
            OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, 
            NULL)) != INVALID_HANDLE_VALUE) 
    { 
        hDIB = ReadDIBFile(hFile); 
        CloseHandle(hFile); 
        SetCursor(LoadCursor(NULL, IDC_ARROW)); 
        return hDIB; 
    } 
    else 
    { 
        SetCursor(LoadCursor(NULL, IDC_ARROW)); 
        return NULL; 
    } 
} 
 
 
/************************************************************************* 
 * 
 * SaveDIB() 
 * 
 * Saves the specified DIB into the specified file name on disk.  No 
 * error checking is done, so if the file already exists, it will be 
 * written over. 
 * 
 * Parameters: 
 * 
 * HDIB hDib - Handle to the dib to save 
 * 
 * LPCTSTR lpFileName - pointer to full pathname to save DIB under 
 * 
 * Return value: TRUE if successful
 *				 FALSE if failure
 * 
 *************************************************************************/ 
BOOL SaveDIB(HDIB hDib, LPCTSTR lpFileName) 
{ 
    HANDLE              fh;         // file handle for opened file 
 
    if (!hDib) 
        return FALSE; 
 
    fh = CreateFile(lpFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 
            FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL); 
 
    if (fh == INVALID_HANDLE_VALUE) 
        return FALSE; 

	BOOL bSuccess = WriteDIBFile(hDib, fh);

    CloseHandle(fh);
	return bSuccess;
}

/************************************************************************* 
 * 
 * Function:  ReadDIBFile (int) 
 * 
 *  Purpose:  Reads in the specified DIB file into a global chunk of 
 *            memory. 
 * 
 *  Returns:  A handle to a dib (hDIB) if successful. 
 *            NULL if an error occurs. 
 * 
 * Comments:  BITMAPFILEHEADER is stripped off of the DIB.  Everything 
 *            from the end of the BITMAPFILEHEADER structure on is 
 *            returned in the global memory handle. 
 * 
 * 
 * NOTE: The DIB API were not written to handle OS/2 DIBs, so this 
 * function will reject any file that is not a Windows DIB. 
 * 
 *************************************************************************/ 
HANDLE ReadDIBFile(HANDLE hFile) 
{ 
    BITMAPFILEHEADER    bmfHeader; 
    DWORD               dwBitsSize; 
    UINT                nNumColors;   // Number of colors in table 
    HANDLE              hDIB;         
    HANDLE              hDIBtmp;      // Used for GlobalRealloc() //MPB 
    LPBITMAPINFOHEADER  lpbi; 
    DWORD               offBits; 
    DWORD               dwRead; 
 
    // get length of DIB in bytes for use when reading 
 
    dwBitsSize = GetFileSize(hFile, NULL); 
 
    // Allocate memory for header & color table. We'll enlarge this 
    // memory as needed. 
 
    hDIB = GlobalAlloc(GMEM_MOVEABLE, (DWORD)(sizeof(BITMAPINFOHEADER) + 
            256 * sizeof(RGBQUAD))); 
 
    if (!hDIB) 
        return NULL; 
 
    lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDIB); 
 
    if (!lpbi)  
    { 
        GlobalFree(hDIB); 
        return NULL; 
    } 
 
    // read the BITMAPFILEHEADER from our file 
 
    if (!ReadFile(hFile, (LPBYTE)&bmfHeader, sizeof (BITMAPFILEHEADER), 
            &dwRead, NULL)) 
        goto ErrExit; 
 
    if (sizeof (BITMAPFILEHEADER) != dwRead) 
        goto ErrExit; 
 
    if (bmfHeader.bfType != 0x4d42)  // 'BM' 
        goto ErrExit; 
 
    // read the BITMAPINFOHEADER 
 
    if (!ReadFile(hFile, (LPBYTE)lpbi, sizeof(BITMAPINFOHEADER), &dwRead, 
            NULL)) 
        goto ErrExit; 
 
    if (sizeof(BITMAPINFOHEADER) != dwRead) 
        goto ErrExit; 
 
    // Check to see that it's a Windows DIB -- an OS/2 DIB would cause 
    // strange problems with the rest of the DIB API since the fields 
    // in the header are different and the color table entries are 
    // smaller. 
    // 
    // If it's not a Windows DIB (e.g. if biSize is wrong), return NULL. 
 
    if (lpbi->biSize == sizeof(BITMAPCOREHEADER)) 
        goto ErrExit; 
 
    // Now determine the size of the color table and read it.  Since the 
    // bitmap bits are offset in the file by bfOffBits, we need to do some 
    // special processing here to make sure the bits directly follow 
    // the color table (because that's the format we are susposed to pass 
    // back) 
 
    if (!(nNumColors = (UINT)lpbi->biClrUsed)) 
    { 
        // no color table for 24-bit, default size otherwise 
 
        if (lpbi->biBitCount > 8)	//(lpbi->biBitCount != 24) 
            nNumColors = 1 << lpbi->biBitCount; // standard size table 
    } 
 

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
午夜精品福利在线| 欧美一区二区成人6969| 国产人成亚洲第一网站在线播放 | 中文字幕精品一区| 国产米奇在线777精品观看| 国产欧美一区二区三区在线看蜜臀 | 国产精品亚洲第一区在线暖暖韩国| 欧美成人a视频| 国产成人精品综合在线观看| 日本一区二区三区在线观看| 色综合久久久久综合体桃花网| 亚洲国产另类av| 欧美tk—视频vk| 成人av动漫在线| 无吗不卡中文字幕| 久久午夜老司机| 色综合中文字幕| 秋霞成人午夜伦在线观看| 国产视频不卡一区| 欧洲精品在线观看| 久久国内精品自在自线400部| 欧美激情一区二区三区在线| 一本色道亚洲精品aⅴ| 日日夜夜精品视频免费| 久久九九久精品国产免费直播| 99久久国产综合色|国产精品| 亚洲成人777| 久久久久久毛片| 欧美中文字幕一区| 激情文学综合插| 一区二区三区四区精品在线视频| 欧美大片在线观看一区二区| 成人免费高清视频| 日本不卡不码高清免费观看| 国产精品亲子乱子伦xxxx裸| 欧美日韩国产另类一区| 懂色av噜噜一区二区三区av| 午夜视频一区在线观看| 国产精品毛片高清在线完整版| 欧美日韩一区二区三区不卡| 成人国产电影网| 日韩av网站在线观看| ㊣最新国产の精品bt伙计久久| 日韩午夜中文字幕| 色成年激情久久综合| 国产精品亚洲一区二区三区妖精 | 午夜久久久久久| 国产精品麻豆网站| 日韩欧美电影在线| 欧美视频一区在线| www.亚洲激情.com| 国产麻豆成人传媒免费观看| 视频在线观看国产精品| 亚洲欧美日韩电影| 国产欧美视频一区二区三区| 日韩精品一区二区在线观看| 欧美日韩视频一区二区| 97超碰欧美中文字幕| 国产高清在线精品| 免费av成人在线| 日产欧产美韩系列久久99| 一区二区在线观看视频| 国产欧美日韩久久| 精品国产污污免费网站入口| 欧美一区中文字幕| 欧美日韩国产大片| 欧美性猛片xxxx免费看久爱| 99re视频精品| 97久久精品人人爽人人爽蜜臀| 国产69精品一区二区亚洲孕妇| 久久精品二区亚洲w码| 青青国产91久久久久久| 日本视频在线一区| 男人操女人的视频在线观看欧美| 天堂午夜影视日韩欧美一区二区| 亚洲一区视频在线| 亚洲成在人线在线播放| 天天综合日日夜夜精品| 五月婷婷欧美视频| 丝袜诱惑亚洲看片| 伦理电影国产精品| 精品一区二区三区日韩| 国内精品伊人久久久久av影院 | 国产视频一区不卡| 亚洲国产成人私人影院tom| 国产精品久久网站| 亚洲欧美日韩人成在线播放| 亚洲免费av在线| 亚洲影院理伦片| 午夜精品福利视频网站| 日本中文字幕一区| 国产一区二区三区免费| 不卡的av中国片| 91在线小视频| 欧美日韩精品久久久| 日韩一区二区免费高清| 久久亚洲综合色一区二区三区| 久久婷婷久久一区二区三区| 国产欧美精品一区二区色综合| 国产精品久久久久久久久久免费看 | 日本韩国一区二区三区视频| 欧美精品一卡两卡| 337p日本欧洲亚洲大胆色噜噜| 中文字幕+乱码+中文字幕一区| 中文字幕一区二区视频| 91免费国产在线观看| 欧美日韩中文另类| 日韩午夜av电影| 国产日韩欧美一区二区三区乱码| 亚洲手机成人高清视频| 日本美女一区二区三区视频| 国产精品88av| 在线一区二区三区四区| 欧美tickling挠脚心丨vk| 亚洲国产精品精华液2区45| 亚洲自拍偷拍网站| 国产在线精品一区在线观看麻豆| 国产99久久久国产精品潘金网站| 欧美影院午夜播放| 久久久精品中文字幕麻豆发布| 亚洲最色的网站| 国产一区二区三区不卡在线观看| 色综合久久综合| 久久影院午夜片一区| 一区二区三区精品在线| 国产麻豆9l精品三级站| 欧美亚洲丝袜传媒另类| 国产精品网曝门| 秋霞午夜av一区二区三区| 91在线porny国产在线看| 精品国产免费视频| 亚洲一区二区三区四区五区中文| 国产一区啦啦啦在线观看| 欧美三级中文字幕| 中文字幕一区三区| 国产一二精品视频| 欧美一级精品在线| 亚洲国产综合人成综合网站| 成人国产亚洲欧美成人综合网| 日韩午夜在线观看视频| 亚洲国产sm捆绑调教视频 | www.亚洲在线| 亚洲精品一区二区精华| 视频在线在亚洲| 91精彩视频在线观看| 国产精品色在线观看| 国产综合久久久久久久久久久久| 欧美三级视频在线| 亚洲精品国产一区二区三区四区在线| 国产福利精品导航| www久久久久| 久久99国产精品免费网站| 欧美女孩性生活视频| 亚洲国产综合91精品麻豆| 91原创在线视频| 一区二区中文视频| www.av精品| 中文字幕日韩一区| www.欧美日韩国产在线| 欧美国产日本视频| 国产福利精品一区| 国产女人18毛片水真多成人如厕| 国内精品国产成人| 久久理论电影网| 国产精品系列在线播放| 久久影院电视剧免费观看| 久久99精品久久久久久动态图 | 亚洲国产美女搞黄色| 欧美在线免费观看亚洲| 一级日本不卡的影视| 色又黄又爽网站www久久| 亚洲精品免费视频| 欧洲视频一区二区| 亚洲成人高清在线| 欧美日韩精品欧美日韩精品一 | 麻豆91精品91久久久的内涵| 7777精品伊人久久久大香线蕉的 | 国产一区二区导航在线播放| 久久色中文字幕| 国产高清亚洲一区| 国产精品理论在线观看| 91亚洲永久精品| 一区二区不卡在线播放| 欧美日韩高清一区二区不卡| 日韩一区精品视频| 亚洲精品一区二区三区香蕉| 国产精品一级片| 自拍视频在线观看一区二区| 欧美性xxxxxxxx| 免费不卡在线观看| 国产农村妇女毛片精品久久麻豆| 波多野结衣的一区二区三区| 亚洲综合免费观看高清完整版在线| 欧美日本一区二区三区四区| 裸体一区二区三区| 国产精品丝袜一区| 欧美日韩免费高清一区色橹橹| 美女久久久精品| 中文字幕在线不卡一区二区三区| 在线观看精品一区|