亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
国产成人av一区二区三区在线| 日韩欧美亚洲国产另类| 欧美一区二区三区男人的天堂| 久久久久免费观看| 视频在线观看国产精品| 99久久精品国产麻豆演员表| 精品国产乱码久久久久久1区2区 | 亚洲乱码国产乱码精品精可以看| 免费一区二区视频| 欧美三级三级三级爽爽爽| 中文字幕一区二区三区在线播放| 裸体健美xxxx欧美裸体表演| 在线观看日韩av先锋影音电影院| 国产精品国产三级国产aⅴ无密码| 捆绑紧缚一区二区三区视频| 欧美精品一级二级| 夜夜夜精品看看| 91麻豆精品国产91久久久久久久久| 国产欧美一区二区三区在线看蜜臀 | 精品国产污网站| 日韩激情一区二区| 欧美一区二区性放荡片| 日韩国产高清影视| 91精品国产日韩91久久久久久| 一区二区三区在线免费观看| 色婷婷综合久色| 一区二区在线观看免费视频播放| 97久久超碰国产精品| 国产精品乱人伦| 9色porny自拍视频一区二区| 国产精品免费久久| 成人av先锋影音| 亚洲少妇最新在线视频| 91精品福利视频| 亚洲精选视频在线| 欧美日韩在线三区| 天堂影院一区二区| 日韩一级片在线播放| 麻豆成人久久精品二区三区红| 精品久久久久av影院 | 91黄视频在线| 亚洲国产一区二区三区| 欧美一区二区三区免费视频| 裸体歌舞表演一区二区| 中文字幕一区二区三区在线播放 | 欧美日韩国产首页| 一区二区三区在线视频观看58| 成人激情免费网站| 亚洲欧美在线视频| 欧美三片在线视频观看| 喷白浆一区二区| 国产欧美一区二区三区在线看蜜臀| av亚洲产国偷v产偷v自拍| 一区二区免费看| 欧美一区二区三区男人的天堂| 国产一区二区三区久久悠悠色av| 一色屋精品亚洲香蕉网站| 欧美性猛片xxxx免费看久爱| 久久精品国产精品亚洲精品 | 亚洲男人天堂av网| 欧美一区二区三区四区高清| 国产成人免费视频一区| 亚洲国产日韩一级| 久久九九影视网| 色婷婷av一区| 黄色资源网久久资源365| 日韩毛片高清在线播放| 91麻豆精品久久久久蜜臀| 国产精品99久久久久久久女警| 一区二区三区国产| 2023国产精华国产精品| 91久久线看在观草草青青| 精品一区二区三区在线播放| 亚洲精品大片www| 久久久综合视频| 欧美精品欧美精品系列| 成人蜜臀av电影| 久久成人久久爱| 午夜精品久久久久久久久久久| 久久久91精品国产一区二区精品| 欧美日韩黄视频| 成人丝袜18视频在线观看| 蜜桃av一区二区在线观看| 一区二区三区.www| 国产精品亲子乱子伦xxxx裸| 欧美不卡在线视频| 欧美日韩专区在线| 色综合久久99| av动漫一区二区| 国产成人在线视频播放| 男男成人高潮片免费网站| 亚洲一级不卡视频| 中文字幕一区二区5566日韩| 国产欧美一区二区精品仙草咪| 欧美一区二区三区视频在线| 欧美三级日韩三级国产三级| 99久久免费视频.com| 国产成人av一区二区| 国产揄拍国内精品对白| 另类欧美日韩国产在线| 日日摸夜夜添夜夜添国产精品| 亚洲一区二区三区三| 亚洲欧美乱综合| 国产精品网站在线| 国产清纯在线一区二区www| 日韩视频一区二区三区| 日韩一区和二区| 日韩美女在线视频| 精品乱人伦小说| 久久久久国产精品麻豆ai换脸| 26uuu亚洲| 国产日韩欧美综合在线| 国产精品美女一区二区三区| 国产精品网曝门| 国产精品美日韩| 尤物视频一区二区| 亚洲国产va精品久久久不卡综合 | 国产成人精品亚洲777人妖 | 亚洲男人的天堂av| 一区二区三区在线影院| 亚洲宅男天堂在线观看无病毒| 亚洲国产欧美在线人成| 午夜精品一区二区三区电影天堂| 日本色综合中文字幕| 久久成人免费日本黄色| 国产电影一区二区三区| eeuss鲁片一区二区三区在线看| 91同城在线观看| 欧美精品电影在线播放| 91精品国产福利在线观看| 精品盗摄一区二区三区| 国产女主播一区| 亚洲一区二区三区四区在线观看| 午夜精品久久久久久| 九九**精品视频免费播放| 国产成人福利片| 91久久精品午夜一区二区| 欧美一区二区视频在线观看2022| 久久你懂得1024| 亚洲精品国产第一综合99久久| 五月婷婷欧美视频| 国产激情精品久久久第一区二区| www.亚洲国产| 91精品国产91久久久久久最新毛片| 久久久蜜桃精品| 亚洲一区二区在线观看视频| 久久99日本精品| 91蜜桃视频在线| 精品av久久707| 亚洲与欧洲av电影| 国产精品一二三四五| 欧美系列在线观看| 国产网站一区二区| 亚洲国产日韩a在线播放 | 蜜臂av日日欢夜夜爽一区| 国产v日产∨综合v精品视频| 正在播放一区二区| 欧美巨大另类极品videosbest | 精品久久国产字幕高潮| 国产精品毛片久久久久久| 日韩和欧美一区二区| 成人动漫一区二区在线| 日韩午夜中文字幕| 亚洲免费电影在线| 国产激情91久久精品导航 | 欧美视频一区二区| 国产女主播在线一区二区| 视频一区视频二区在线观看| 成人动漫av在线| 久久综合九色综合97婷婷| 亚洲bt欧美bt精品777| 91一区在线观看| 国产日韩精品一区二区浪潮av| 视频在线观看一区二区三区| 一本大道久久a久久综合婷婷| 国产日产欧美一区| 加勒比av一区二区| 欧美一区二区三区视频| 亚洲成人免费看| 在线观看一区二区视频| 中文字幕日本不卡| 成人丝袜高跟foot| 中文一区一区三区高中清不卡| 国内精品伊人久久久久av影院| 欧美一区二区三区四区五区| 亚洲超碰97人人做人人爱| 日本精品免费观看高清观看| 国产精品久久99| 99国产精品国产精品久久| 国产精品女同一区二区三区| 粉嫩久久99精品久久久久久夜| 久久亚洲二区三区| 国内久久精品视频| 国产肉丝袜一区二区| 国产精品羞羞答答xxdd| 久久九九99视频| 福利一区在线观看| 中文字幕在线一区免费| 色欧美乱欧美15图片| 一区二区三区中文字幕电影|