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

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

?? dibapi.cpp

?? 該源碼實現了對一256色灰度圖像的霍夫曼編碼輸出
?? 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" 

 
/************************************************************************* 
 * 
 * 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); 
} 
 
/************************************************************************* 
 * 
 * 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 != 24) 
            nNumColors = 1 << lpbi->biBitCount; // standard size table 
    } 
 
    // fill in some default values if they are zero 
 
    if (lpbi->biClrUsed == 0) 
        lpbi->biClrUsed = nNumColors; 
 
    if (lpbi->biSizeImage == 0) 
    { 
        lpbi->biSizeImage = ((((lpbi->biWidth * (DWORD)lpbi->biBitCount) + 
                31) & ~31) >> 3) * lpbi->biHeight; 
    } 
 
    // get a proper-sized buffer for header, color table and bits 
 
    GlobalUnlock(hDIB); 
    hDIBtmp = GlobalReAlloc(hDIB, lpbi->biSize + nNumColors * 
            sizeof(RGBQUAD) + lpbi->biSizeImage, 0); 
 
    if (!hDIBtmp) // can't resize buffer for loading 
        goto ErrExitNoUnlock; //MPB 
    else 
        hDIB = hDIBtmp; 
 
    lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDIB); 
 
    // read the color table 
 
    ReadFile (hFile, (LPBYTE)(lpbi) + lpbi->biSize, 
            nNumColors * sizeof(RGBQUAD), &dwRead, NULL); 
 
    // offset to the bits from start of DIB header 
 
    offBits = lpbi->biSize + nNumColors * sizeof(RGBQUAD); 
 
    // If the bfOffBits field is non-zero, then the bits might *not* be 
    // directly following the color table in the file.  Use the value in 
    // bfOffBits to seek the bits. 
 
    if (bmfHeader.bfOffBits != 0L) 
        SetFilePointer(hFile, bmfHeader.bfOffBits, NULL, FILE_BEGIN); 
 
    if (ReadFile(hFile, (LPBYTE)lpbi + offBits, lpbi->biSizeImage, &dwRead, 
            NULL)) 
        goto OKExit; 
 
ErrExit: 
    GlobalUnlock(hDIB);     
 
ErrExitNoUnlock:     
    GlobalFree(hDIB); 
    return NULL; 
 
OKExit: 
    GlobalUnlock(hDIB); 
    return 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; 

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
5月丁香婷婷综合| 91麻豆精品久久久久蜜臀| 国产亚洲美州欧州综合国| 国产精品69久久久久水密桃| 国产午夜亚洲精品午夜鲁丝片| 国产麻豆精品在线观看| 国产精品污www在线观看| 97精品国产97久久久久久久久久久久| 中文字幕亚洲精品在线观看| 91九色最新地址| 男女性色大片免费观看一区二区| 欧美精品一区二区三区在线播放| 国产成人免费9x9x人网站视频| 久久久蜜桃精品| 欧洲一区二区三区在线| 久久97超碰色| 亚洲情趣在线观看| 日韩欧美一二区| 99国产精品99久久久久久| 午夜精品久久久久久久久久久| 欧美不卡视频一区| 92精品国产成人观看免费| 亚瑟在线精品视频| 国产女人18毛片水真多成人如厕 | 欧美性xxxxxx少妇| 久久se精品一区精品二区| 中文字幕一区二区在线观看| 欧美三级午夜理伦三级中视频| 秋霞国产午夜精品免费视频 | 日本一区二区成人| 91极品美女在线| 久久福利资源站| 自拍偷在线精品自拍偷无码专区| 7777精品伊人久久久大香线蕉经典版下载| 国产在线精品一区在线观看麻豆| 亚洲色图在线播放| 日韩美女主播在线视频一区二区三区 | 秋霞电影网一区二区| 久久蜜桃av一区精品变态类天堂| 欧美亚洲一区三区| 成人在线综合网| 久久99精品久久久久久动态图| 亚洲欧美一区二区三区久本道91| 精品国产百合女同互慰| 欧美午夜理伦三级在线观看| 国产91高潮流白浆在线麻豆 | 成人国产一区二区三区精品| 日本欧美肥老太交大片| 亚洲黄色片在线观看| 国产亚洲成年网址在线观看| 欧美一区二区三区在线观看视频| 色婷婷av一区二区三区软件| 成人综合在线观看| 国产成人精品一区二| 秋霞午夜鲁丝一区二区老狼| 亚洲一区二区在线免费看| 欧美国产综合色视频| 337p日本欧洲亚洲大胆色噜噜| 欧美日韩国产美| 欧美日韩中文字幕精品| 在线免费不卡视频| 一本到三区不卡视频| 成人动漫精品一区二区| 国产高清不卡一区| 激情综合色综合久久| 午夜精品在线视频一区| 亚洲综合免费观看高清完整版在线 | 中文字幕一区av| 欧美激情在线一区二区三区| 亚洲精品一区二区三区99| 欧美成人性战久久| 精品久久久久久久久久久久包黑料 | 日产国产欧美视频一区精品| 午夜av一区二区| 亚洲sss视频在线视频| 亚洲一区二区三区四区五区中文| 亚洲欧洲在线观看av| 中文字幕制服丝袜一区二区三区| 国产精品毛片无遮挡高清| 国产精品久久久久久一区二区三区 | 久久精品国产亚洲一区二区三区| 免费视频最近日韩| 蜜臀av国产精品久久久久| 麻豆免费精品视频| 国产在线看一区| 成人av在线一区二区| 成人av免费在线播放| 成人免费视频app| 91网站在线播放| 欧美影视一区在线| 欧美日韩三级在线| 欧美不卡一区二区三区四区| 久久综合国产精品| 日韩一区有码在线| 午夜精品在线视频一区| 九九热在线视频观看这里只有精品 | 国产欧美一区在线| 成人免费在线视频| 亚洲电影第三页| 一区二区在线免费观看| 美女久久久精品| 亚洲激情五月婷婷| 亚洲日本青草视频在线怡红院| 大胆亚洲人体视频| 一级日本不卡的影视| 国产一区 二区| 日韩国产精品91| 国产麻豆精品视频| 欧美日韩精品三区| 国产精品理论在线观看| 亚洲h在线观看| 色综合久久天天| 久久久久久99精品| 秋霞国产午夜精品免费视频| 99re这里都是精品| 2014亚洲片线观看视频免费| 日韩电影免费一区| 日本国产一区二区| 一区二区三区久久久| 欧美日韩在线电影| 欧美老肥妇做.爰bbww视频| 久久久噜噜噜久久中文字幕色伊伊 | 久久久噜噜噜久久人人看| 日韩黄色在线观看| 欧美日本精品一区二区三区| 亚洲乱码一区二区三区在线观看| 国产麻豆一精品一av一免费| 精品国产凹凸成av人网站| 国产中文字幕精品| 欧美亚男人的天堂| 亚洲一区免费在线观看| 欧美日韩国产一级片| 男女性色大片免费观看一区二区 | 国产精品一品二品| 亚洲欧洲综合另类在线| 91麻豆免费在线观看| 午夜影视日本亚洲欧洲精品| 国内精品嫩模私拍在线| 欧美一区二区三区性视频| 国产在线视频精品一区| 夜夜爽夜夜爽精品视频| 8v天堂国产在线一区二区| 青青草原综合久久大伊人精品 | 一区二区三区丝袜| 欧美日韩电影在线| 国产麻豆91精品| 亚洲小说春色综合另类电影| 99久久精品免费看国产| 欧美精品久久天天躁| 亚洲小说春色综合另类电影| 97aⅴ精品视频一二三区| 亚洲成人一二三| 日韩女优视频免费观看| 看片网站欧美日韩| 国产区在线观看成人精品| 欧美一卡二卡在线观看| 91精品免费在线观看| 日韩一区二区三区高清免费看看| 国产欧美中文在线| 在线观看一区不卡| www.亚洲精品| 欧美一二三四区在线| 亚洲h在线观看| 欧美日韩精品二区第二页| 国产精品久久久久永久免费观看 | 午夜电影一区二区| 成人app网站| 久久久777精品电影网影网| 美女脱光内衣内裤视频久久网站 | 欧美日韩在线播放| 亚洲va欧美va人人爽| 欧美精品自拍偷拍| 日韩av一区二区三区四区| 在线不卡一区二区| 日韩精品亚洲专区| 91精品福利在线一区二区三区 | 99精品在线免费| 亚洲另类在线制服丝袜| 精品免费国产一区二区三区四区| 日韩中文欧美在线| 精品国产区一区| 国产成人免费视频| 亚洲欧美经典视频| 欧美欧美欧美欧美首页| 日本伊人精品一区二区三区观看方式| 欧美一级高清片| 国产成人啪午夜精品网站男同| 日本一区二区免费在线| 91香蕉国产在线观看软件| 亚洲午夜电影在线观看| 欧美一区二区在线视频| 国模套图日韩精品一区二区| 中文字幕乱码亚洲精品一区 | 欧美日韩国产免费一区二区| 久久激情五月婷婷| 中文字幕日本不卡| 欧美色区777第一页| 精品一区二区三区不卡| 亚洲日本一区二区三区| 日韩一区二区麻豆国产|