亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
欧美精品免费视频| 精品一区二区免费在线观看| 99麻豆久久久国产精品免费优播| 久久免费视频色| 国产91精品一区二区麻豆亚洲| 国产午夜精品一区二区| av在线综合网| 亚洲一区在线视频| 欧美一区二区三区人| 国内精品视频666| 国产精品乱人伦中文| 色94色欧美sute亚洲13| 亚洲风情在线资源站| 欧美一区二区三区播放老司机| 精品一区二区免费视频| 国产精品国产三级国产普通话99 | 亚洲午夜电影在线观看| 欧美日韩激情在线| 狠狠网亚洲精品| 亚洲欧洲一区二区三区| 欧美在线一区二区| 国内成人免费视频| 亚洲色欲色欲www| 欧美挠脚心视频网站| 国产精品影视天天线| 一级特黄大欧美久久久| 日韩精品最新网址| aaa欧美日韩| 青青青伊人色综合久久| 欧美国产一区二区在线观看| 欧美日韩在线直播| 国产酒店精品激情| 亚洲一区二区欧美激情| 精品国精品国产| 91首页免费视频| 久久av老司机精品网站导航| 亚洲伦理在线精品| 久久欧美中文字幕| 欧美日本一区二区在线观看| 国产成人精品免费| 免费高清在线一区| 亚洲素人一区二区| 欧美哺乳videos| 欧美少妇一区二区| 成人高清免费在线播放| 久久精品国产亚洲一区二区三区| 亚洲欧洲成人精品av97| 欧美电影精品一区二区| 欧美亚一区二区| 99免费精品在线| 国精产品一区一区三区mba视频| 亚洲精品综合在线| 中文字幕免费观看一区| 26uuu另类欧美| 日韩欧美一级精品久久| 欧洲一区二区三区在线| www.一区二区| 国产精一品亚洲二区在线视频| 亚洲国产一区二区a毛片| 中文字幕一区二区三区在线不卡| 337p日本欧洲亚洲大胆精品| 欧美日韩国产精品成人| 色悠久久久久综合欧美99| 国产成人亚洲精品青草天美| 久热成人在线视频| 日韩国产高清在线| 亚洲chinese男男1069| 一区二区三区精品在线| 亚洲欧美一区二区三区极速播放| 国产视频一区在线观看| 久久先锋资源网| 欧美www视频| 日韩欧美www| 欧美一级生活片| 日韩视频永久免费| 欧美一区二区三区免费大片 | 日韩精品一区二区三区老鸭窝| 在线视频中文字幕一区二区| av网站一区二区三区| 成人激情午夜影院| 波多野结衣中文一区| 国产一区二区免费视频| 国产不卡视频在线播放| 高潮精品一区videoshd| 成人国产精品视频| 91丨porny丨首页| 一本到不卡精品视频在线观看| 91在线观看美女| 91亚洲精品乱码久久久久久蜜桃| 99久久精品免费看国产免费软件| av欧美精品.com| 欧美综合一区二区三区| 欧美日韩高清不卡| 欧美一级xxx| 久久久亚洲国产美女国产盗摄| 久久精品一区二区三区av| 中文字幕国产一区二区| 亚洲精品一二三区| 男人的天堂久久精品| 国产一区在线精品| 91丝袜呻吟高潮美腿白嫩在线观看| 色诱亚洲精品久久久久久| 91.麻豆视频| 久久久久久久久一| 亚洲欧美另类图片小说| 日本大胆欧美人术艺术动态| 国产乱码精品一区二区三| av午夜一区麻豆| 欧美一级高清片| 亚洲婷婷在线视频| 蜜桃视频一区二区三区在线观看| 激情综合网av| 91国偷自产一区二区三区成为亚洲经典 | 亚洲激情图片qvod| 日韩国产在线观看一区| 国产成人午夜99999| 91传媒视频在线播放| 精品国产伦一区二区三区观看体验| 国产欧美一区二区精品仙草咪| 亚洲久草在线视频| 久久99精品一区二区三区| 成人免费毛片嘿嘿连载视频| 欧美色图一区二区三区| 久久奇米777| 亚洲图片一区二区| 国产成人av一区| 制服丝袜成人动漫| 中文字幕欧美一| 国内不卡的二区三区中文字幕| 欧洲亚洲精品在线| 国产女人18毛片水真多成人如厕| 亚洲成精国产精品女| 北条麻妃一区二区三区| 日韩网站在线看片你懂的| 亚洲综合在线五月| 懂色av一区二区在线播放| 91精品婷婷国产综合久久性色| 中文字幕在线观看不卡| 极品美女销魂一区二区三区| 6080日韩午夜伦伦午夜伦| 亚洲天堂精品在线观看| 国产成人午夜高潮毛片| 欧美不卡在线视频| 婷婷久久综合九色国产成人| 91亚洲国产成人精品一区二区三| 精品理论电影在线| 日韩电影在线一区二区三区| 日本福利一区二区| 日本一二三不卡| 国产精一区二区三区| 精品国产乱码久久久久久老虎| 亚洲电影一级片| 欧美色图一区二区三区| 亚洲黄色小视频| 色综合视频一区二区三区高清| 国产欧美1区2区3区| 国产乱子伦视频一区二区三区| 日韩欧美一区中文| 男女男精品视频| 91精品国产欧美一区二区| 视频一区二区三区在线| 欧美日韩视频在线观看一区二区三区| 亚洲欧美综合网| 99国产精品久久久久久久久久久| 欧美激情在线观看视频免费| 国产不卡免费视频| 国产三区在线成人av| 国产成人精品一区二| 国产精品欧美一区喷水| 成人禁用看黄a在线| 国产精品久久久久久久久快鸭| 国产91精品一区二区| 国产精品国产三级国产a| av资源站一区| 亚洲精品videosex极品| 在线观看日韩毛片| 亚洲成年人影院| 欧美成人a∨高清免费观看| 精品一区二区成人精品| 久久久久国产精品免费免费搜索| 国产在线精品视频| 国产精品色哟哟| 色婷婷综合久久久中文一区二区 | 蜜臀av一区二区| 精品国产乱码久久久久久久久 | 一区二区三区 在线观看视频| 91视频在线看| 午夜久久久影院| 久久久综合网站| 色乱码一区二区三区88| 日韩精品亚洲一区| 国产午夜三级一区二区三| 成人app在线观看| 亚洲电影视频在线| 久久天天做天天爱综合色| 成人性生交大片免费看在线播放| 亚洲区小说区图片区qvod| 制服丝袜激情欧洲亚洲| 丁香婷婷综合色啪| 亚洲第一综合色|