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

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

?? dibapi.cpp

?? MFC圖像處理源代碼總集
?? 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一区二区三区免费野_久草精品视频
99久久er热在这里只有精品15 | 亚洲电影一区二区| 亚洲一区二区三区国产| 精品午夜一区二区三区在线观看| 成人免费高清视频在线观看| 欧美疯狂性受xxxxx喷水图片| 国产色综合久久| 免费在线看成人av| 欧美亚洲综合网| 中文字幕日韩精品一区| 精品一区二区三区日韩| 欧美性猛交xxxx乱大交退制版| 26uuu国产电影一区二区| 天天综合色天天综合| 91色视频在线| 国产精品理论片| 国产成人av电影免费在线观看| 3atv在线一区二区三区| 亚洲久本草在线中文字幕| 国产不卡在线一区| 国产区在线观看成人精品| 精品一区二区综合| 精品人伦一区二区色婷婷| 亚洲.国产.中文慕字在线| 91亚洲精品久久久蜜桃网站 | 一区2区3区在线看| 精品亚洲aⅴ乱码一区二区三区| 欧美日韩一本到| 亚洲一卡二卡三卡四卡| 欧美三级视频在线| 亚洲福利一区二区| 91精品国产综合久久福利 | 欧美一区二区三区在线电影| 亚洲一区二区三区免费视频| 在线视频一区二区三区| 伊人夜夜躁av伊人久久| 色菇凉天天综合网| 亚洲亚洲人成综合网络| 欧美性大战久久久久久久蜜臀| 樱花草国产18久久久久| 在线亚洲+欧美+日本专区| 亚洲国产精品一区二区久久| 欧美图片一区二区三区| 日韩一区精品字幕| 精品久久国产老人久久综合| 狠狠色综合日日| 国产精品全国免费观看高清| 本田岬高潮一区二区三区| 亚洲另类在线视频| 91精品国产一区二区三区蜜臀| 另类小说欧美激情| 中文字幕av在线一区二区三区| 97久久精品人人做人人爽50路| 综合av第一页| 欧美精选一区二区| 国产一区二区三区免费播放| 中文在线资源观看网站视频免费不卡 | 国产夫妻精品视频| 亚洲精品老司机| 日韩欧美国产一区二区三区| 国产精品亚洲а∨天堂免在线| 最新国产精品久久精品| 欧美肥大bbwbbw高潮| 国产成人免费视频一区| 中文字幕亚洲区| 欧美国产日韩亚洲一区| 91小视频免费看| 日本欧美韩国一区三区| 国产欧美一区二区精品性色超碰| 欧美艳星brazzers| 国产精品亚洲一区二区三区在线| 夜夜精品浪潮av一区二区三区| 日韩欧美一区二区视频| 91丨九色porny丨蝌蚪| 久久99精品网久久| 亚洲欧美日韩国产综合在线| 欧美一区二区三区影视| 94-欧美-setu| 国产乱人伦偷精品视频免下载| 一区二区三区蜜桃网| 国产亚洲一区二区三区| 91精品欧美福利在线观看| av一区二区三区| 久久99精品视频| 亚洲第一在线综合网站| 国产精品电影院| 精品奇米国产一区二区三区| 欧美综合天天夜夜久久| 成人午夜精品在线| 久久99国产精品久久| 亚洲夂夂婷婷色拍ww47| 国产精品美女久久久久久久久久久 | 中文字幕在线观看不卡视频| 欧美不卡在线视频| 69堂亚洲精品首页| 91国内精品野花午夜精品| 成人黄色a**站在线观看| 国产又粗又猛又爽又黄91精品| 日韩和的一区二区| 亚洲成av人片在线| 亚洲高清视频的网址| 亚洲色图欧洲色图| 中文字幕在线一区二区三区| 久久天堂av综合合色蜜桃网| 日韩欧美国产一区二区三区 | 日本一区二区不卡视频| 欧美精品一区二区三区一线天视频| 欧美精品乱码久久久久久| 色94色欧美sute亚洲线路一久| 国产福利一区在线| 国产成人av福利| 国产精品一区二区久久不卡| 国产在线播精品第三| 精品一区二区三区的国产在线播放| 天天综合色天天综合| 日韩黄色免费电影| 精品一区二区免费| 国产裸体歌舞团一区二区| 国产成人av在线影院| 国产福利精品一区| 成人一区二区视频| 9i看片成人免费高清| 91蜜桃网址入口| 在线免费一区三区| 欧美日韩国产免费一区二区| 欧美日韩精品二区第二页| 欧美日韩一区在线| 日韩一区二区三区电影| 欧美一卡2卡三卡4卡5免费| 欧美成人一级视频| 亚洲国产精品黑人久久久| 亚洲人成精品久久久久| 亚洲444eee在线观看| 九色综合狠狠综合久久| 风流少妇一区二区| 欧美视频一区二| 久久综合色8888| 一区二区三区日韩欧美精品| 精品国产不卡一区二区三区| 日韩精品一区二区三区四区视频| 精品国产亚洲一区二区三区在线观看 | 欧美一区二区三区免费观看视频| 日韩欧美一级二级三级久久久| 久久久久国产精品麻豆ai换脸| 国产精品久久久久久久久快鸭| 午夜伦理一区二区| 国产成人午夜电影网| 一本久久精品一区二区| 日韩欧美国产系列| 亚洲乱码中文字幕| 精品一区二区三区在线观看| caoporen国产精品视频| 4hu四虎永久在线影院成人| 欧美国产日韩精品免费观看| 亚洲第一成年网| 国产不卡视频一区| 91精品国产综合久久婷婷香蕉 | 国产精品免费看片| 日韩精品乱码av一区二区| 国产成人精品一区二| 欧洲亚洲精品在线| 亚洲国产高清不卡| 日韩精品久久理论片| 不卡一区二区在线| 日韩女优毛片在线| 亚洲成人激情自拍| 99re这里只有精品首页| 精品国产免费视频| 亚洲国产精品嫩草影院| 不卡的av中国片| 亚洲精品一区二区三区福利| 亚洲一区二区三区四区五区黄| 国产乱码精品一区二区三区忘忧草| 欧美日韩夫妻久久| 亚洲视频在线观看一区| 大白屁股一区二区视频| 日韩精品在线一区| 亚洲成人精品影院| 色欧美88888久久久久久影院| 国产日本一区二区| 激情综合色播激情啊| 欧美一级欧美一级在线播放| 亚洲国产日韩精品| 91丨九色丨蝌蚪富婆spa| 国产精品欧美综合在线| 国产伦精品一区二区三区免费迷 | 99久久精品情趣| 精品日韩在线一区| 蜜臀精品一区二区三区在线观看 | 国产精品久久综合| 国产精品99久久久| 久久亚洲一区二区三区明星换脸 | 色综合天天综合给合国产| 国产精品麻豆视频| 99视频精品在线| 一区二区三区美女| 在线免费亚洲电影| 日韩国产高清在线| 日韩视频在线你懂得| 麻豆精品国产91久久久久久|