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

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

?? dibapi.cpp

?? 圖像處理與識別實用案例精選 圖像處理與識別實用案例精選
?? 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一区二区三区免费野_久草精品视频
成人午夜私人影院| 久久一区二区视频| 一本大道久久a久久综合婷婷| 国产69精品久久久久毛片| 美女视频一区二区三区| 日韩精品免费专区| 亚洲国产日产av| 艳妇臀荡乳欲伦亚洲一区| 亚洲欧美日本韩国| 亚洲毛片av在线| 一区二区三区不卡视频在线观看| 一区二区三区视频在线看| 国产精品你懂的| 一区在线中文字幕| 亚洲天堂久久久久久久| 亚洲另类中文字| 亚洲最大成人综合| 午夜一区二区三区视频| 天堂成人国产精品一区| 日韩av电影免费观看高清完整版 | 美腿丝袜亚洲色图| 麻豆精品一区二区三区| 国产原创一区二区| 国产成人午夜电影网| 成人av资源下载| 日本久久一区二区三区| 欧美三级在线播放| 3d动漫精品啪啪1区2区免费| 欧美videofree性高清杂交| 精品国内片67194| 欧美经典三级视频一区二区三区| 中文字幕一区二区不卡| 夜夜精品浪潮av一区二区三区 | 欧美性淫爽ww久久久久无| 欧美日韩的一区二区| 久久久五月婷婷| 亚洲女人的天堂| 美女网站一区二区| 波多野结衣中文字幕一区二区三区| 色婷婷综合中文久久一本| 欧美日免费三级在线| 日韩免费性生活视频播放| 国产婷婷色一区二区三区四区| 最新国产の精品合集bt伙计| 日韩精品乱码av一区二区| 国产91在线观看丝袜| 欧洲亚洲国产日韩| 精品国产伦一区二区三区免费| 国产精品私人影院| 亚州成人在线电影| 成人综合在线网站| 51精品久久久久久久蜜臀| 欧美高清在线一区| 日韩中文字幕1| 91丝袜国产在线播放| 日韩午夜中文字幕| 亚洲乱码中文字幕| 激情偷乱视频一区二区三区| 色婷婷久久久综合中文字幕 | 麻豆成人久久精品二区三区小说| 99re视频精品| 精品免费国产一区二区三区四区| 亚洲人妖av一区二区| 美女网站色91| 91久久一区二区| 久久久精品日韩欧美| 日韩影院在线观看| 91天堂素人约啪| 日本一区二区三区在线观看| 秋霞午夜鲁丝一区二区老狼| 欧美综合欧美视频| 国产精品天干天干在观线| 久久精品国产亚洲aⅴ| 日本精品一级二级| 国产亚洲综合在线| 裸体健美xxxx欧美裸体表演| 在线日韩一区二区| 欧美韩国日本不卡| 国内精品视频666| 欧美一区二区啪啪| 亚洲一区二区视频在线观看| k8久久久一区二区三区| 久久精品亚洲精品国产欧美kt∨ | 精品一区二区三区的国产在线播放| 日本精品视频一区二区| 中文字幕成人av| 久久99国产精品尤物| 欧美精品日韩一本| 亚洲一区在线看| 91黄色免费网站| 一区二区视频免费在线观看| av电影在线不卡| 国产精品久久久久久妇女6080| 国产精品一区二区久久精品爱涩| 精品国产乱码久久久久久免费| 青青草91视频| 欧美一级日韩一级| 日日骚欧美日韩| 欧美日韩大陆一区二区| 一区二区三区免费看视频| 91免费精品国自产拍在线不卡 | 国产精品99久久久| 日韩精品中文字幕一区二区三区| 爽好久久久欧美精品| 欧美性色综合网| 五月开心婷婷久久| 欧美一级专区免费大片| 日韩av一区二区三区| 日韩欧美一区在线| 麻豆专区一区二区三区四区五区| 日韩欧美一级二级三级久久久| 久久av老司机精品网站导航| 精品久久久久久久人人人人传媒| 国产一区二区在线免费观看| 国产视频一区二区三区在线观看| 国产精品亚洲一区二区三区妖精| 国产精品网曝门| 在线一区二区视频| 偷拍与自拍一区| 欧美tickling网站挠脚心| 国产综合色产在线精品| 国产亚洲综合色| 91网上在线视频| 午夜精品视频一区| 日韩欧美资源站| 国产99久久久国产精品潘金网站| 国产精品久久久久国产精品日日| 91一区二区在线| 五月婷婷综合在线| 久久综合久久综合久久综合| 波多野结衣91| 国产99久久久久| 一区二区三区在线观看欧美| 欧美一区二区视频在线观看2020| 国产专区欧美精品| 中文字幕一区二区不卡| 欧美日本一区二区三区| 国产在线精品国自产拍免费| **性色生活片久久毛片| 欧美理论片在线| 国产激情视频一区二区三区欧美| 亚洲免费观看在线观看| 制服丝袜亚洲播放| 成人中文字幕合集| 一区二区三国产精华液| 欧美tickling挠脚心丨vk| 波多野洁衣一区| 蜜臀99久久精品久久久久久软件| 国产精品麻豆视频| 欧美区视频在线观看| 国产精品亚洲午夜一区二区三区 | 蜜桃视频在线观看一区二区| 中文字幕精品三区| 欧美日韩国产免费一区二区| 国产精品99久久久久久久vr| 亚洲成人av资源| 欧美国产日韩一二三区| 7777精品伊人久久久大香线蕉超级流畅| 国产做a爰片久久毛片| 亚洲最大的成人av| 国产亚洲人成网站| 欧美肥妇毛茸茸| 99精品视频免费在线观看| 奇米精品一区二区三区四区| 亚洲精品免费在线观看| 欧美精品一区二区三区很污很色的| 91美女在线看| 国产成人av福利| 日本特黄久久久高潮| 亚洲免费观看在线视频| 国产丝袜美腿一区二区三区| 欧美一区二区福利视频| 色综合色综合色综合色综合色综合| 国产乱码精品1区2区3区| 午夜精品一区二区三区电影天堂| 综合欧美亚洲日本| 国产三级精品视频| 日韩丝袜情趣美女图片| 欧美日韩中文字幕一区二区| 成人av电影在线| 国产精品香蕉一区二区三区| 免费精品99久久国产综合精品| 亚洲一区二区三区三| 亚洲视频在线一区观看| 久久久国产精品午夜一区ai换脸| 日韩一区二区三区视频在线观看| 在线观看免费一区| 97精品国产露脸对白| 国产盗摄精品一区二区三区在线| 美女视频一区二区三区| 丝袜美腿亚洲一区二区图片| 亚洲第一会所有码转帖| 亚洲精品视频在线| 亚洲视频一区在线观看| 国产欧美日韩久久| 日韩欧美不卡一区| 激情综合一区二区三区| 在线免费不卡视频| 国产精品一区二区x88av| 国产精品久久久久久久裸模|