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

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

?? dibapi.cpp

?? 這是一個在VC++環境下實現對圖像二值化的程序。
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
//  dibapi.cpp
//
//  Source file for Device-Independent Bitmap (DIB) API.  Provides
//  the following functions:
//
//  PaintDIB()          - Painting routine for a DIB
//  CreateDIBPalette()  - Creates a palette from a DIB
//  FindDIBBits()       - Returns a pointer to the DIB bits
//  DIBWidth()          - Gets the width of the DIB
//  DIBHeight()         - Gets the height of the DIB
//  PaletteSize()       - Gets the size required to store the DIB's palette
//  DIBNumColors()      - Calculates the number of colors
//                        in the DIB's color table
//  CopyHandle()        - Makes a copy of the given global memory block
//
// This is a part of the Microsoft Foundation Classes C++ library.
// Copyright (C) 1992-1997 Microsoft Corporation
// All rights reserved.
//
// This source code is only intended as a supplement to the
// Microsoft Foundation Classes Reference and related
// electronic documentation provided with the library.
// See these sources for detailed information regarding the
// Microsoft Foundation Classes product.

#include "stdafx.h"
#include "dibapi.h"
#include <io.h>
#include <errno.h>
#include <math.h>

#define DIB_HEADER_MARKER   ((WORD) ('M' << 8) | 'B')

#ifdef _MAC
#define SWAPWORD(x) MAKEWORD(HIBYTE(x), LOBYTE(x))
#define SWAPLONG(x) MAKELONG(SWAPWORD(HIWORD(x)), SWAPWORD(LOWORD(x)))
void ByteSwapHeader(BITMAPFILEHEADER* bmiHeader);
void ByteSwapInfo(LPSTR lpHeader, BOOL fWin30Header);
#endif

/*************************************************************************
 *
 * PaintDIB()
 *
 * Parameters:
 *
 * HDC hDC          - DC to do output to
 *
 * LPRECT lpDCRect  - rectangle on DC to do output to
 *
 * HDIB hDIB        - handle to global memory with a DIB spec
 *                    in it followed by the DIB bits
 *
 * LPRECT lpDIBRect - rectangle of DIB to output into lpDCRect
 *
 * CPalette* pPal   - pointer to CPalette containing DIB's palette
 *
 * Return Value:
 *
 * BOOL             - TRUE if DIB was drawn, FALSE otherwise
 *
 * Description:
 *   Painting routine for a DIB.  Calls StretchDIBits() or
 *   SetDIBitsToDevice() to paint the DIB.  The DIB is
 *   output to the specified DC, at the coordinates given
 *   in lpDCRect.  The area of the DIB to be output is
 *   given by lpDIBRect.
 *
 ************************************************************************/

BOOL WINAPI PaintDIB(HDC     hDC,
					LPRECT  lpDCRect,
					HDIB    hDIB,
					LPRECT  lpDIBRect,
					CPalette* pPal)
{
	LPSTR    lpDIBHdr;            // Pointer to BITMAPINFOHEADER
	LPSTR    lpDIBBits;           // Pointer to DIB bits
	BOOL     bSuccess=FALSE;      // Success/fail flag
	HPALETTE hPal=NULL;           // Our DIB's palette
	HPALETTE hOldPal=NULL;        // Previous palette

	/* Check for valid DIB handle */
	if (hDIB == NULL)
		return FALSE;

	/* Lock down the DIB, and get a pointer to the beginning of the bit
	 *  buffer
	 */
	lpDIBHdr  = (LPSTR) ::GlobalLock((HGLOBAL) hDIB);
	lpDIBBits = ::FindDIBBits(lpDIBHdr);

	// Get the DIB's palette, then select it into DC
	if (pPal != NULL)
	{
		hPal = (HPALETTE) pPal->m_hObject;

		// Select as background since we have
		// already realized in forground if needed
		hOldPal = ::SelectPalette(hDC, hPal, TRUE);
	}

	/* Make sure to use the stretching mode best for color pictures */
	::SetStretchBltMode(hDC, COLORONCOLOR);

	/* Determine whether to call StretchDIBits() or SetDIBitsToDevice() */
	if ((RECTWIDTH(lpDCRect)  == RECTWIDTH(lpDIBRect)) &&
	   (RECTHEIGHT(lpDCRect) == RECTHEIGHT(lpDIBRect)))
		bSuccess = ::SetDIBitsToDevice(hDC,                    // hDC
								   lpDCRect->left,             // DestX
								   lpDCRect->top,              // DestY
								   RECTWIDTH(lpDCRect),        // nDestWidth
								   RECTHEIGHT(lpDCRect),       // nDestHeight
								   lpDIBRect->left,            // SrcX
								   (int)DIBHeight(lpDIBHdr) -
									  lpDIBRect->top -
									  RECTHEIGHT(lpDIBRect),   // SrcY
								   0,                          // nStartScan
								   (WORD)DIBHeight(lpDIBHdr),  // nNumScans
								   lpDIBBits,                  // lpBits
								   (LPBITMAPINFO)lpDIBHdr,     // lpBitsInfo
								   DIB_RGB_COLORS);            // wUsage
   else
	  bSuccess = ::StretchDIBits(hDC,                          // hDC
							   lpDCRect->left,                 // DestX
							   lpDCRect->top,                  // DestY
							   RECTWIDTH(lpDCRect),            // nDestWidth
							   RECTHEIGHT(lpDCRect),           // nDestHeight
							   lpDIBRect->left,                // SrcX
							   lpDIBRect->top,                 // SrcY
							   RECTWIDTH(lpDIBRect),           // wSrcWidth
							   RECTHEIGHT(lpDIBRect),          // wSrcHeight
							   lpDIBBits,                      // lpBits
							   (LPBITMAPINFO)lpDIBHdr,         // lpBitsInfo
							   DIB_RGB_COLORS,                 // wUsage
							   SRCCOPY);                       // dwROP

   ::GlobalUnlock((HGLOBAL) hDIB);

	/* Reselect old palette */
	if (hOldPal != NULL)
	{
		::SelectPalette(hDC, hOldPal, TRUE);
	}

   return bSuccess;
}

/*************************************************************************
 *
 * CreateDIBPalette()
 *
 * Parameter:
 *
 * HDIB hDIB        - specifies the DIB
 *
 * Return Value:
 *
 * HPALETTE         - specifies the palette
 *
 * Description:
 *
 * This function creates a palette from a DIB by allocating memory for the
 * logical palette, reading and storing the colors from the DIB's color table
 * into the logical palette, creating a palette from this logical palette,
 * and then returning the palette's handle. This allows the DIB to be
 * displayed using the best possible colors (important for DIBs with 256 or
 * more colors).
 *
 ************************************************************************/


BOOL WINAPI CreateDIBPalette(HDIB hDIB, CPalette* pPal)
{
	LPLOGPALETTE lpPal;      // pointer to a logical palette
	HANDLE hLogPal;          // handle to a logical palette
	HPALETTE hPal = NULL;    // handle to a palette
	int i;                   // loop index
	WORD wNumColors;         // number of colors in color table
	LPSTR lpbi;              // pointer to packed-DIB
	LPBITMAPINFO lpbmi;      // pointer to BITMAPINFO structure (Win3.0)
	LPBITMAPCOREINFO lpbmc;  // pointer to BITMAPCOREINFO structure (old)
	BOOL bWinStyleDIB;       // flag which signifies whether this is a Win3.0 DIB
	BOOL bResult = FALSE;

	/* if handle to DIB is invalid, return FALSE */

	if (hDIB == NULL)
	  return FALSE;

   lpbi = (LPSTR) ::GlobalLock((HGLOBAL) hDIB);

   /* get pointer to BITMAPINFO (Win 3.0) */
   lpbmi = (LPBITMAPINFO)lpbi;

   /* get pointer to BITMAPCOREINFO (old 1.x) */
   lpbmc = (LPBITMAPCOREINFO)lpbi;

   /* get the number of colors in the DIB */
   wNumColors = ::DIBNumColors(lpbi);

   if (wNumColors != 0)
   {
		/* allocate memory block for logical palette */
		hLogPal = ::GlobalAlloc(GHND, sizeof(LOGPALETTE)
									+ sizeof(PALETTEENTRY)
									* wNumColors);

		/* if not enough memory, clean up and return NULL */
		if (hLogPal == 0)
		{
			::GlobalUnlock((HGLOBAL) hDIB);
			return FALSE;
		}

		lpPal = (LPLOGPALETTE) ::GlobalLock((HGLOBAL) hLogPal);

		/* set version and number of palette entries */
		lpPal->palVersion = PALVERSION;
		lpPal->palNumEntries = (WORD)wNumColors;

		/* is this a Win 3.0 DIB? */
		bWinStyleDIB = IS_WIN30_DIB(lpbi);
		for (i = 0; i < (int)wNumColors; i++)
		{
			if (bWinStyleDIB)
			{
				lpPal->palPalEntry[i].peRed = lpbmi->bmiColors[i].rgbRed;
				lpPal->palPalEntry[i].peGreen = lpbmi->bmiColors[i].rgbGreen;
				lpPal->palPalEntry[i].peBlue = lpbmi->bmiColors[i].rgbBlue;
				lpPal->palPalEntry[i].peFlags = 0;
			}
			else
			{
				lpPal->palPalEntry[i].peRed = lpbmc->bmciColors[i].rgbtRed;
				lpPal->palPalEntry[i].peGreen = lpbmc->bmciColors[i].rgbtGreen;
				lpPal->palPalEntry[i].peBlue = lpbmc->bmciColors[i].rgbtBlue;
				lpPal->palPalEntry[i].peFlags = 0;
			}
		}

		/* create the palette and get handle to it */
		bResult = pPal->CreatePalette(lpPal);
		::GlobalUnlock((HGLOBAL) hLogPal);
		::GlobalFree((HGLOBAL) hLogPal);
	}

	::GlobalUnlock((HGLOBAL) hDIB);

	return bResult;
}

/*************************************************************************
 *
 * FindDIBBits()
 *
 * Parameter:
 *
 * LPSTR lpbi       - pointer to packed-DIB memory block
 *
 * Return Value:
 *
 * LPSTR            - pointer to the DIB bits
 *
 * Description:
 *
 * This function calculates the address of the DIB's bits and returns a
 * pointer to the DIB bits.
 *
 ************************************************************************/


LPSTR WINAPI FindDIBBits(LPSTR lpbi)
{
	return (lpbi + *(LPDWORD)lpbi + ::PaletteSize(lpbi));
}


/*************************************************************************
 *
 * DIBWidth()
 *
 * Parameter:
 *
 * LPSTR lpbi       - pointer to packed-DIB memory block
 *
 * Return Value:
 *
 * DWORD            - width of the DIB
 *
 * Description:
 *
 * This function gets the width of the DIB from the BITMAPINFOHEADER
 * width field if it is a Windows 3.0-style DIB or from the BITMAPCOREHEADER
 * width field if it is an other-style DIB.
 *
 ************************************************************************/


DWORD WINAPI DIBWidth(LPSTR lpDIB)
{
	LPBITMAPINFOHEADER lpbmi;  // pointer to a Win 3.0-style DIB
	LPBITMAPCOREHEADER lpbmc;  // pointer to an other-style DIB

	/* point to the header (whether Win 3.0 and old) */

	lpbmi = (LPBITMAPINFOHEADER)lpDIB;
	lpbmc = (LPBITMAPCOREHEADER)lpDIB;

	/* return the DIB width if it is a Win 3.0 DIB */
	if (IS_WIN30_DIB(lpDIB))
		return lpbmi->biWidth;
	else  /* it is an other-style DIB, so return its width */
		return (DWORD)lpbmc->bcWidth;
}


/*************************************************************************
 *
 * DIBHeight()
 *
 * Parameter:
 *
 * LPSTR lpbi       - pointer to packed-DIB memory block
 *
 * Return Value:
 *
 * DWORD            - height of the DIB
 *
 * Description:
 *
 * This function gets the height of the DIB from the BITMAPINFOHEADER
 * height field if it is a Windows 3.0-style DIB or from the BITMAPCOREHEADER
 * height field if it is an other-style DIB.
 *
 ************************************************************************/


DWORD WINAPI DIBHeight(LPSTR lpDIB)
{
	LPBITMAPINFOHEADER lpbmi;  // pointer to a Win 3.0-style DIB
	LPBITMAPCOREHEADER lpbmc;  // pointer to an other-style DIB

	/* point to the header (whether old or Win 3.0 */

	lpbmi = (LPBITMAPINFOHEADER)lpDIB;
	lpbmc = (LPBITMAPCOREHEADER)lpDIB;

	/* return the DIB height if it is a Win 3.0 DIB */
	if (IS_WIN30_DIB(lpDIB))
		return lpbmi->biHeight;
	else  /* it is an other-style DIB, so return its height */
		return (DWORD)lpbmc->bcHeight;
}


/*************************************************************************
 *
 * PaletteSize()
 *
 * Parameter:
 *
 * LPSTR lpbi       - pointer to packed-DIB memory block
 *
 * Return Value:
 *
 * WORD             - size of the color palette of the DIB
 *
 * Description:
 *
 * This function gets the size required to store the DIB's palette by
 * multiplying the number of colors by the size of an RGBQUAD (for a
 * Windows 3.0-style DIB) or by the size of an RGBTRIPLE (for an other-
 * style DIB).
 *
 ************************************************************************/


WORD WINAPI PaletteSize(LPSTR lpbi)
{
   /* calculate the size required by the palette */
   if (IS_WIN30_DIB (lpbi))
	  return (WORD)(::DIBNumColors(lpbi) * sizeof(RGBQUAD));
   else
	  return (WORD)(::DIBNumColors(lpbi) * sizeof(RGBTRIPLE));
}


/*************************************************************************
 *
 * DIBNumColors()
 *
 * Parameter:
 *
 * LPSTR lpbi       - pointer to packed-DIB memory block
 *
 * Return Value:
 *
 * WORD             - number of colors in the color table
 *
 * Description:
 *
 * This function calculates the number of colors in the DIB's color table
 * by finding the bits per pixel for the DIB (whether Win3.0 or other-style
 * DIB). If bits per pixel is 1: colors=2, if 4: colors=16, if 8: colors=256,
 * if 24, no colors in color table.
 *
 ************************************************************************/


WORD WINAPI DIBNumColors(LPSTR lpbi)
{
	WORD wBitCount;  // DIB bit count

	/*  If this is a Windows-style DIB, the number of colors in the
	 *  color table can be less than the number of bits per pixel
	 *  allows for (i.e. lpbi->biClrUsed can be set to some value).
	 *  If this is the case, return the appropriate value.
	 */

	if (IS_WIN30_DIB(lpbi))
	{

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产精品一区二区不卡| 日本一区二区在线不卡| 亚洲一线二线三线视频| 色婷婷久久综合| 亚洲女人的天堂| 欧美午夜影院一区| 日韩精品每日更新| 欧美www视频| 国产精品99久| 日韩一区有码在线| 欧美亚洲一区二区在线观看| 亚洲成精国产精品女| 91麻豆精品国产无毒不卡在线观看| 日本不卡一区二区| 久久久99久久精品欧美| 成人91在线观看| 亚洲一卡二卡三卡四卡五卡| 91麻豆精品国产综合久久久久久| 三级一区在线视频先锋| 91精品国产91热久久久做人人| 天天综合网 天天综合色| 欧美日韩成人一区| 蜜桃av噜噜一区| 精品国产91久久久久久久妲己| 老司机午夜精品99久久| 久久伊人中文字幕| 成人激情小说网站| 一二三四社区欧美黄| 欧美久久久久久久久中文字幕| 日本在线观看不卡视频| 精品成人免费观看| av网站一区二区三区| 亚洲一区二区综合| 日韩视频免费直播| 国产精品91一区二区| 亚洲人成网站精品片在线观看| 色婷婷精品久久二区二区蜜臂av| 亚洲欧美在线aaa| 丰满少妇在线播放bd日韩电影| 亚洲欧美自拍偷拍| 3d成人h动漫网站入口| 国产乱子轮精品视频| 337p日本欧洲亚洲大胆精品| 国产一区二区三区久久悠悠色av| 26uuu欧美| a级高清视频欧美日韩| 日韩电影免费一区| 国产精品久久久久桃色tv| 欧美蜜桃一区二区三区| 国产精品18久久久久久久久久久久| 日韩理论在线观看| 欧美变态凌虐bdsm| 色婷婷综合久久久久中文| 久久精品99国产精品| 亚洲色图丝袜美腿| 久久奇米777| 欧美日韩国产在线播放网站| 国产91在线看| 日本一不卡视频| 亚洲精品免费视频| 久久久久久久久久久久久久久99 | 欧美亚洲动漫精品| 紧缚捆绑精品一区二区| 国产精品不卡一区| 精品国产乱码久久久久久闺蜜| 欧美午夜一区二区三区| 成人激情午夜影院| 国产主播一区二区三区| 亚洲国产aⅴ成人精品无吗| 国产精品日日摸夜夜摸av| 欧美一级视频精品观看| 欧洲国内综合视频| 成人激情视频网站| 国产在线精品一区二区夜色| 亚洲va欧美va天堂v国产综合| 国产精品久久久久影视| 久久免费精品国产久精品久久久久| 欧美日产在线观看| 在线观看一区二区视频| 91丨国产丨九色丨pron| 大尺度一区二区| 国产一区二区三区av电影| 日韩电影在线免费看| 亚洲成人激情综合网| 亚洲精品国产品国语在线app| 日本一区二区成人在线| 欧美经典三级视频一区二区三区| 精品少妇一区二区三区 | 亚洲电影你懂得| 久久精品视频网| 国产欧美一区视频| 久久精品一区二区三区不卡| 日韩欧美色电影| 日韩美女在线视频 | 日本在线不卡视频| 五月激情综合网| 亚洲综合网站在线观看| 日韩一区在线看| 日韩一区在线免费观看| 中文字幕在线免费不卡| 亚洲色图视频免费播放| 亚洲日本在线天堂| 一区二区三区欧美日韩| 亚洲精品久久久蜜桃| 欧美伊人精品成人久久综合97 | 午夜成人免费电影| 国内外成人在线| 亚洲成人激情av| 婷婷六月综合网| 五月婷婷久久丁香| 奇米亚洲午夜久久精品| 理论电影国产精品| 国产一区二区三区蝌蚪| 成人av在线电影| 欧美这里有精品| 欧美日韩国产大片| 日韩精品专区在线| 国产日韩欧美不卡在线| ...xxx性欧美| 视频在线观看91| 国产又黄又大久久| 成人av电影免费观看| 在线视频综合导航| 在线影视一区二区三区| 欧美日韩免费观看一区三区| 337p亚洲精品色噜噜狠狠| 色悠久久久久综合欧美99| 日韩精品最新网址| 日韩一区二区在线看| 日韩欧美电影一区| 久久久电影一区二区三区| 夜夜揉揉日日人人青青一国产精品| 手机精品视频在线观看| 国产传媒一区在线| 在线观看91视频| 337p日本欧洲亚洲大胆色噜噜| 中文av一区特黄| 视频一区二区国产| 成人国产精品免费观看| 欧美疯狂做受xxxx富婆| 日本一区二区三区国色天香| 午夜精品久久久久久久| 国产成人夜色高潮福利影视| 91麻豆福利精品推荐| 精品国产一区二区三区久久影院 | 中文字幕不卡三区| 亚洲高清一区二区三区| 国产福利一区在线| 欧美色图在线观看| 国产精品久久一卡二卡| 亚洲精品国产品国语在线app| 免费在线一区观看| 99re视频这里只有精品| 欧美一级二级三级蜜桃| 国产亚洲精品资源在线26u| 亚洲成人自拍偷拍| heyzo一本久久综合| 日韩视频在线你懂得| 亚洲精品国产第一综合99久久 | 日本电影欧美片| 国产亚洲精品精华液| 麻豆成人久久精品二区三区红| 91免费国产视频网站| 国产亚洲欧美一区在线观看| 免费成人美女在线观看.| 在线观看av不卡| 亚洲三级在线免费观看| 久久精品国产第一区二区三区 | 日本精品一区二区三区高清| 精品免费日韩av| 国产精品久久久99| 国产伦精一区二区三区| 51精品秘密在线观看| 三级在线观看一区二区| 精品视频一区二区不卡| 亚洲黄色小视频| 色综合天天做天天爱| 国产精品国产三级国产aⅴ无密码 国产精品国产三级国产aⅴ原创 | 91在线码无精品| 欧美激情艳妇裸体舞| 国产一区日韩二区欧美三区| 欧美一区二区三区在线| 日韩精品久久久久久| 欧美午夜影院一区| 欧美一区二区三区影视| 亚洲一区二区三区影院| 日韩视频免费观看高清完整版| 日韩国产精品91| 国产午夜久久久久| 欧美亚一区二区| 国产乱码精品1区2区3区| 国产精品久久久久7777按摩| 色噜噜狠狠一区二区三区果冻| 亚洲第一在线综合网站| 欧美精品在线一区二区三区| 韩国精品久久久| 亚洲一区电影777| 久久香蕉国产线看观看99| 91在线观看污| 成人h动漫精品一区二|