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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? dibapi.cpp

?? Visual C++、Matlab圖像處理與識別實用案例精選
?? 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))
	{

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
激情欧美一区二区| 欧美sm极限捆绑bd| 亚洲综合清纯丝袜自拍| 91免费观看视频在线| 亚洲综合视频在线观看| 欧美日韩视频在线一区二区| 午夜成人在线视频| 久久蜜臀中文字幕| 国产不卡视频在线观看| 亚洲人成网站影音先锋播放| 91精品福利视频| 日本成人在线不卡视频| 欧美精品一区二区三区高清aⅴ| 精品亚洲国产成人av制服丝袜| 精品日韩一区二区三区| 成人黄色小视频在线观看| 亚洲女人****多毛耸耸8| 欧美日韩日日摸| 久久99精品视频| 亚洲视频1区2区| 91精品国产高清一区二区三区蜜臀| 精品一区二区三区蜜桃| 一区二区中文视频| 日韩精品一区二区三区四区视频| 不卡一区二区在线| 麻豆精品视频在线观看| 亚洲图片欧美激情| 久久香蕉国产线看观看99| 国产91精品露脸国语对白| 日韩精品乱码av一区二区| 亚洲美女淫视频| 中文字幕日本乱码精品影院| 日韩一区二区电影网| 欧美唯美清纯偷拍| 欧美在线免费播放| 不卡的看片网站| 成人自拍视频在线| 丁香激情综合国产| 国产成人免费视| 久久精工是国产品牌吗| 午夜精品久久久久久久99水蜜桃| 最新日韩在线视频| 亚洲欧美韩国综合色| 亚洲欧美一区二区三区孕妇| 国产精品欧美一区喷水| 欧美韩日一区二区三区四区| 欧美国产一区在线| 国产午夜亚洲精品理论片色戒| 久久精品欧美一区二区三区不卡| 日韩精品自拍偷拍| 久久综合狠狠综合| 国产精品久久久久一区二区三区共| 中文字幕在线观看不卡视频| 亚洲欧美国产三级| 日本aⅴ精品一区二区三区| 另类成人小视频在线| 国产精品自在欧美一区| 99精品国产99久久久久久白柏| 色久优优欧美色久优优| 欧美军同video69gay| 欧美va亚洲va香蕉在线| 国产精品久久久久一区二区三区共 | 中文字幕视频一区二区三区久| 亚洲免费在线播放| 日韩精品每日更新| 91网址在线看| 日韩精品在线一区二区| 国产精品理论片在线观看| 午夜精品福利在线| 99精品黄色片免费大全| 日韩精品一区二区三区在线播放 | 欧美综合色免费| 久久久99精品免费观看| 日韩精品午夜视频| 色视频欧美一区二区三区| 久久青草欧美一区二区三区| 一区二区三区资源| 国产精品伊人色| 日韩欧美亚洲另类制服综合在线| 亚洲精选视频免费看| 成人午夜在线免费| 欧美一激情一区二区三区| 亚洲精品一二三区| 91在线视频18| 国产色一区二区| 久久激情五月婷婷| 欧美一区二区在线免费观看| 亚洲国产精品久久久男人的天堂| 不卡av免费在线观看| 精品88久久久久88久久久| 老色鬼精品视频在线观看播放| 这里只有精品免费| 日本午夜一区二区| 日韩精品一区二区三区在线播放 | 韩国欧美国产一区| 久久久久久亚洲综合影院红桃| 狠狠色丁香婷综合久久| 精品久久久久久综合日本欧美 | 国产高清精品在线| 国产精品色哟哟网站| 国产91高潮流白浆在线麻豆| 国产三级精品视频| av成人老司机| 午夜精品久久久久久| 久久午夜色播影院免费高清| 国产91精品精华液一区二区三区| 成人欧美一区二区三区1314| 欧美日韩国产首页| 国产91精品免费| 日韩高清一区在线| 国产精品女主播av| 91精品国产综合久久久久久久久久| 久久99精品国产.久久久久久| 久久综合九色综合97婷婷| 一本色道久久综合狠狠躁的推荐 | 欧美日韩和欧美的一区二区| 久久精品国产第一区二区三区| 国产精品久久久久国产精品日日| 欧美在线观看18| 国产成人av在线影院| 亚洲大片免费看| 国产精品美女久久久久久2018| 欧美日韩精品三区| 成人免费看黄yyy456| 玖玖九九国产精品| 亚洲18色成人| 亚洲精品免费在线| 国产精品第五页| 国产欧美精品日韩区二区麻豆天美| 欧美精品九九99久久| 99re亚洲国产精品| 国产999精品久久久久久绿帽| 蜜桃av一区二区在线观看 | 国产又黄又大久久| 美女精品一区二区| 亚洲成人久久影院| 一区二区三区精品| 亚洲最新在线观看| 一区二区三区蜜桃| 午夜精品福利视频网站| 亚洲尤物视频在线| 亚洲成人自拍偷拍| 美洲天堂一区二卡三卡四卡视频| 成人高清av在线| 99久久精品一区| 在线观看亚洲精品| 欧美精品欧美精品系列| 欧美一区二区三区免费观看视频| 91精品国产综合久久小美女| 5566中文字幕一区二区电影 | 欧美一级xxx| 久久精品水蜜桃av综合天堂| 久久久三级国产网站| 日韩理论片中文av| 亚洲.国产.中文慕字在线| 久久99国产精品免费网站| 成人免费视频网站在线观看| 一本一道综合狠狠老| 欧美一区二区三区四区久久| 欧美韩国一区二区| 午夜精品在线看| 国产精品1区2区| 制服丝袜日韩国产| 国产精品第五页| 老司机午夜精品99久久| 成人av免费在线播放| 欧美精品1区2区3区| 日本一区二区高清| 日韩国产精品大片| www.色精品| 亚洲精品一区二区在线观看| 亚洲免费av高清| 国产乱码字幕精品高清av| 欧美日韩一区二区三区在线看| 久久久99久久| 九色综合狠狠综合久久| 欧美疯狂性受xxxxx喷水图片| 国产精品国产馆在线真实露脸 | 色哟哟国产精品免费观看| 精品美女在线观看| 日韩**一区毛片| 欧美日韩美女一区二区| 一区二区三区四区中文字幕| 国产suv精品一区二区三区| 精品国产制服丝袜高跟| 日本午夜精品一区二区三区电影| 色av综合在线| 亚洲一区二区三区三| 99久久精品国产观看| 中文字幕一区二区三区不卡在线 | 99视频有精品| 亚洲欧美视频在线观看视频| 成人app下载| 亚洲少妇中出一区| 欧美性猛片xxxx免费看久爱| 亚洲丰满少妇videoshd| 91精品国产手机| 国产麻豆成人精品| 国产精品女主播av| 欧美午夜一区二区三区免费大片|