亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
欧美日韩精品一区二区三区蜜桃 | 爽好久久久欧美精品| 在线视频国产一区| 捆绑调教一区二区三区| 欧美一区二区在线免费播放| 国内国产精品久久| 亚洲精品高清视频在线观看| 91精品麻豆日日躁夜夜躁| 国产福利精品导航| 亚洲国产另类精品专区| 精品入口麻豆88视频| 91网址在线看| 男女男精品视频| 中文字幕中文字幕中文字幕亚洲无线 | 日韩欧美aaaaaa| thepron国产精品| 亚洲一卡二卡三卡四卡五卡| 26uuu久久天堂性欧美| 91福利在线观看| 国产91丝袜在线播放0| 亚洲国产精品欧美一二99| 国产清纯在线一区二区www| 欧美日韩国产电影| 99视频在线精品| 日韩**一区毛片| 亚洲国产一区二区三区青草影视| 久久久久99精品一区| 欧美日韩国产色站一区二区三区| 成人福利视频在线| 国产一区久久久| 日产欧产美韩系列久久99| 一区二区三区四区不卡在线 | 欧美性大战久久久久久久| 国产麻豆日韩欧美久久| 免费观看91视频大全| 亚洲天堂免费看| 国产欧美1区2区3区| 午夜成人在线视频| 亚洲色图色小说| 欧美国产日产图区| 欧美老年两性高潮| 一本久久综合亚洲鲁鲁五月天 | 99国产精品99久久久久久| 日韩激情av在线| 亚洲一级二级三级| 成人免费视频在线观看| 久久久久国产精品麻豆ai换脸| 91精品国产aⅴ一区二区| 欧美天天综合网| av电影一区二区| 成人午夜视频福利| 国产91精品欧美| 国产精品影视网| 国产在线视频精品一区| 麻豆国产精品一区二区三区| 日韩国产精品91| 日本不卡一区二区| 婷婷综合五月天| 亚洲高清免费观看| 性做久久久久久久久| 亚洲成a人v欧美综合天堂下载| 一级中文字幕一区二区| 亚洲精品老司机| 国产精品久久影院| 国产精品福利电影一区二区三区四区| 国产欧美精品一区二区三区四区| 国产视频在线观看一区二区三区 | 色哟哟在线观看一区二区三区| 成人理论电影网| 成年人午夜久久久| 99久久国产综合精品麻豆| 色综合中文字幕| 欧美亚洲国产bt| 色综合婷婷久久| 91精品欧美福利在线观看| 日韩欧美另类在线| 欧美精品一区二区蜜臀亚洲| 26uuu精品一区二区| 国产欧美精品区一区二区三区| 国产精品传媒视频| 亚洲精品福利视频网站| 日韩精品电影在线| 美腿丝袜亚洲一区| 国产成人精品影院| 日本电影亚洲天堂一区| 欧美精品欧美精品系列| 4438x亚洲最大成人网| 2017欧美狠狠色| 国产精品日日摸夜夜摸av| 亚洲欧美国产高清| 欧美激情一区二区三区在线| 樱桃国产成人精品视频| 日韩国产成人精品| 波波电影院一区二区三区| 在线看国产日韩| 精品国产乱码久久久久久久 | 亚洲欧美在线高清| 一区二区三区日韩精品视频| 久久精品国产99| 97se狠狠狠综合亚洲狠狠| 欧美第一区第二区| 亚洲一区二区三区视频在线| 国产精选一区二区三区| 欧美日韩激情一区二区| 亚洲欧洲精品天堂一级| 国产一区二区美女| 制服丝袜激情欧洲亚洲| 一区二区成人在线观看| 成人免费观看av| 久久精品日产第一区二区三区高清版| 亚洲福利国产精品| 色婷婷一区二区| 自拍偷拍亚洲欧美日韩| 国内不卡的二区三区中文字幕 | 欧美激情在线免费观看| 老司机精品视频在线| 欧美另类高清zo欧美| 一区二区视频在线看| 97se亚洲国产综合在线| 国产精品毛片久久久久久| 九九精品视频在线看| 51精品秘密在线观看| 亚洲电影一级片| 欧美色区777第一页| 亚洲免费观看高清在线观看| 成人禁用看黄a在线| 久久一二三国产| 久久99热国产| 精品奇米国产一区二区三区| 日韩福利电影在线| 制服丝袜成人动漫| 免费成人av在线播放| 欧美一区二区三区在线看| 日韩成人免费看| 日韩欧美国产精品一区| 麻豆免费看一区二区三区| 日韩视频在线一区二区| 久久精品国产一区二区| 欧美xxxxx裸体时装秀| 激情文学综合插| 国产亚洲美州欧州综合国| 丁香六月综合激情| 国产精品激情偷乱一区二区∴| av电影在线观看完整版一区二区| 亚洲人成影院在线观看| 日本电影亚洲天堂一区| 亚洲18女电影在线观看| 7777精品久久久大香线蕉| 免费观看成人鲁鲁鲁鲁鲁视频| 精品久久久久久久久久久久久久久 | 国产欧美视频一区二区| 国产精品1024久久| 国产精品久久久久久久午夜片| 91最新地址在线播放| 一区二区三区丝袜| 91精品国产综合久久福利软件| 日本成人在线看| 国产亚洲成aⅴ人片在线观看| 国产a精品视频| 亚洲精品ww久久久久久p站| 欧美视频在线一区二区三区| 日本特黄久久久高潮| 久久蜜桃一区二区| 91网站最新网址| 日本va欧美va精品发布| 日韩精品在线一区| 国产精品18久久久久久久久久久久| 欧美国产日本韩| 欧美精品免费视频| 福利一区二区在线| 亚洲成a人片在线观看中文| 亚洲精品一区在线观看| 成人av综合在线| 亚洲va天堂va国产va久| 久久美女高清视频| 欧美系列在线观看| 国产麻豆精品一区二区| 亚洲精品乱码久久久久| 日韩精品影音先锋| 91看片淫黄大片一级在线观看| 日韩综合在线视频| 国产精品视频一二三区| 91.xcao| 99re亚洲国产精品| 久久狠狠亚洲综合| 一区二区三区成人| 久久久久久久久久电影| 欧美一a一片一级一片| 国产精品77777| 日产国产高清一区二区三区| 国产精品成人免费精品自在线观看| 欧美电影在哪看比较好| 成人精品在线视频观看| 日韩电影在线免费观看| 亚洲桃色在线一区| 久久精品一区蜜桃臀影院| 91精品国产福利在线观看| 91免费版在线看| 丁香六月久久综合狠狠色| 麻豆成人久久精品二区三区小说|