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

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

?? 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))
	{

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美三级韩国三级日本一级| 国产亚洲一区二区三区| 欧美大片在线观看一区二区| 欧美极品aⅴ影院| 免费久久99精品国产| 色婷婷综合久久久中文一区二区 | www.欧美色图| 欧美成人一区二区三区在线观看 | 国产精品入口麻豆原神| 青青草国产成人99久久| 日本精品视频一区二区| 国产欧美日韩在线看| 美女爽到高潮91| 欧美精品在线观看播放| 亚洲激情综合网| 99久久国产综合精品麻豆| 国产欧美精品一区二区色综合| 视频一区中文字幕国产| 欧美综合亚洲图片综合区| 国产精品―色哟哟| 国产成人亚洲综合色影视| 国产成人精品一区二区三区网站观看 | av动漫一区二区| 久久午夜羞羞影院免费观看| 老司机一区二区| 欧美一区二区三区在| 一区二区三区精密机械公司| 91玉足脚交白嫩脚丫在线播放| 国产视频一区二区在线| 韩国v欧美v日本v亚洲v| 日韩精品一区二区三区老鸭窝| 性做久久久久久免费观看| 一本高清dvd不卡在线观看| 国产精品乱码一区二区三区软件| 国产成人av电影在线| 久久精品一二三| 国产成人免费9x9x人网站视频| 久久精品视频网| 粉嫩13p一区二区三区| 欧美激情一区二区三区在线| 国产 欧美在线| 中文字幕在线观看一区二区| 91年精品国产| 亚洲成人激情av| 制服丝袜中文字幕亚洲| 韩国欧美国产一区| 国产精品乱人伦一区二区| 一本到高清视频免费精品| 亚洲成a人片在线不卡一二三区| 欧美日韩成人综合天天影院| 麻豆国产91在线播放| 久久久久久一二三区| 不卡视频在线看| 亚洲国产毛片aaaaa无费看| 日韩一级片网址| 成人一区二区三区| 亚洲五码中文字幕| 精品免费99久久| 91碰在线视频| 极品瑜伽女神91| 国产日韩高清在线| 97精品超碰一区二区三区| 中文字幕一区二区三区av| 国产一区二区电影| 国产精品美女久久久久av爽李琼 | 一区二区三区欧美激情| 欧美天堂亚洲电影院在线播放| 一区二区激情视频| 欧美日韩亚洲综合在线| 日韩精品福利网| 精品国产电影一区二区| 91在线一区二区| 亚洲国产成人av好男人在线观看| 欧美日韩国产中文| 国产一区二区福利视频| 中文字幕制服丝袜成人av| 欧洲一区二区三区在线| 男人操女人的视频在线观看欧美| 国产欧美综合在线| 在线免费观看日本一区| 成人欧美一区二区三区视频网页| 91精品国产综合久久精品图片 | 日韩和欧美一区二区三区| 精品国产乱码久久久久久夜甘婷婷| 国产一区在线看| 亚洲精品成人a在线观看| 欧美一三区三区四区免费在线看 | 成人av综合一区| 亚洲国产婷婷综合在线精品| 精品sm捆绑视频| www.成人在线| 精品在线播放午夜| 亚洲女性喷水在线观看一区| 欧美电影免费观看高清完整版| 狠狠色狠狠色合久久伊人| 一区二区国产盗摄色噜噜| 久久久久成人黄色影片| av高清久久久| 国产又黄又大久久| 亚洲韩国精品一区| 欧美精品一区二区三区在线| 91久久人澡人人添人人爽欧美| 国产一区二区免费在线| 亚洲小说春色综合另类电影| 欧美精品一区二区三区蜜桃视频| 99视频热这里只有精品免费| 激情小说亚洲一区| 午夜精品福利一区二区三区av | 中文字幕一区二区三区不卡在线| 91精品国产91久久久久久一区二区| aaa亚洲精品一二三区| 激情欧美一区二区| 午夜成人在线视频| 亚洲欧美一区二区在线观看| 欧美伊人久久大香线蕉综合69| 亚洲影视在线播放| 亚洲日本在线天堂| 欧美高清在线精品一区| 日韩精品在线一区二区| 99精品欧美一区| 国产中文一区二区三区| 日本午夜一区二区| 污片在线观看一区二区| 中文字幕日本乱码精品影院| 亚洲欧美一区二区三区孕妇| 国产日韩欧美制服另类| 国产日韩欧美精品一区| 26uuu色噜噜精品一区二区| 91精品国产欧美一区二区18| 欧美老女人在线| 欧美视频在线播放| 欧美日韩在线观看一区二区| 欧美一区二区三区系列电影| 欧美日韩在线综合| 制服丝袜国产精品| 88在线观看91蜜桃国自产| 7777精品伊人久久久大香线蕉超级流畅| 色婷婷精品大视频在线蜜桃视频 | 亚洲国产精品国自产拍av| 国产午夜精品久久久久久久| 国产日韩高清在线| 国产精品久久久久影院亚瑟| 亚洲欧洲99久久| 亚洲午夜国产一区99re久久| 午夜精品爽啪视频| 久久99精品久久久久婷婷| 久草这里只有精品视频| 国产精品一区二区三区四区| 粉嫩高潮美女一区二区三区| 97se亚洲国产综合自在线观| 欧美少妇bbb| 欧美性大战久久久| 精品国产自在久精品国产| 久久―日本道色综合久久| 国产婷婷精品av在线| 久久亚洲一级片| 国产精品久线在线观看| 亚洲一区在线视频| 老司机精品视频导航| 国产99久久久精品| 91国模大尺度私拍在线视频| 欧美性猛片xxxx免费看久爱| 精品噜噜噜噜久久久久久久久试看 | 欧美日韩日本视频| 欧美电影免费观看高清完整版在线观看| 久久先锋影音av鲁色资源网| 国产精品家庭影院| 丝袜诱惑制服诱惑色一区在线观看| 黄色资源网久久资源365| 99精品黄色片免费大全| 欧美日韩国产另类一区| 久久久久久久久久久久久女国产乱 | 亚洲欧洲色图综合| 成人欧美一区二区三区视频网页 | 欧美国产禁国产网站cc| 亚洲成人动漫在线免费观看| 日韩高清在线观看| 91蝌蚪porny九色| 欧美电影免费观看高清完整版在线 | 日本亚洲电影天堂| 岛国精品在线观看| 欧美日韩高清一区二区不卡| 国产丝袜欧美中文另类| 日本欧美一区二区| 94色蜜桃网一区二区三区| 精品久久人人做人人爰| 尤物视频一区二区| 国产福利91精品一区| 成人激情免费视频| 国产视频一区在线播放| 毛片av一区二区三区| 欧美午夜不卡视频| 国产精品二三区| 国产乱淫av一区二区三区 | 欧美色欧美亚洲另类二区| 精品久久久久久久久久久久久久久久久| 国产区在线观看成人精品| 亚洲图片有声小说| 欧美日韩国产小视频在线观看| 中文字幕欧美激情|