亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
亚洲日本在线看| 亚洲综合小说图片| 色综合天天性综合| 美女性感视频久久| 亚洲视频一区二区免费在线观看 | 91丨porny丨国产入口| 亚洲va欧美va国产va天堂影院| 精品国产不卡一区二区三区| 色狠狠av一区二区三区| 国产精品中文字幕日韩精品| 婷婷综合五月天| 伊人一区二区三区| 国产精品视频线看| 欧美tk丨vk视频| 欧美肥胖老妇做爰| 色偷偷久久人人79超碰人人澡 | 天天av天天翘天天综合网色鬼国产 | 亚洲成人久久影院| 亚洲女同ⅹxx女同tv| 久久色视频免费观看| 欧美剧情片在线观看| www.成人在线| 成人激情动漫在线观看| 国产一区二区成人久久免费影院 | 亚洲精品高清视频在线观看| 日本一区二区视频在线| 欧美精品一区二区三区四区 | 久久精品国产亚洲高清剧情介绍 | 亚洲欧美另类久久久精品2019 | 日韩在线一区二区| 一区二区高清在线| 日韩一区在线看| 自拍偷拍欧美精品| 中文字幕亚洲区| 亚洲日本一区二区| 亚洲欧美日韩在线播放| 亚洲人成网站在线| 亚洲免费成人av| 亚洲日本在线观看| 亚洲人精品午夜| 一级做a爱片久久| 亚洲国产欧美一区二区三区丁香婷| 亚洲欧美国产三级| 一区二区三区在线观看欧美| 一区二区三区四区视频精品免费| 亚洲精品国产第一综合99久久| 伊人一区二区三区| 亚洲成人www| 日本大胆欧美人术艺术动态| 免费观看在线综合色| 国产中文字幕一区| 丁香婷婷深情五月亚洲| 91麻豆免费看| 欧美日韩国产高清一区二区| 7777精品伊人久久久大香线蕉经典版下载 | 免费人成精品欧美精品| 蜜臀久久久久久久| 国产真实乱偷精品视频免| 国产高清在线观看免费不卡| av福利精品导航| 欧美性猛交一区二区三区精品| 欧美日韩在线电影| 精品久久久久久最新网址| 久久久久久一二三区| 亚洲欧美综合另类在线卡通| 亚洲国产cao| 狠狠色丁香九九婷婷综合五月| 国产乱国产乱300精品| 91美女精品福利| 欧美精品一二三四| 久久理论电影网| 亚洲色图欧洲色图| 久久精品国产999大香线蕉| 成人在线视频首页| 欧美片在线播放| 久久久精品黄色| 亚洲一区二区在线免费观看视频| 奇米综合一区二区三区精品视频| 国产大陆a不卡| 欧美三片在线视频观看| 久久奇米777| 一区二区三区中文在线观看| 精品亚洲免费视频| 色综合久久综合网| 久久久一区二区三区| 亚洲一区二区三区美女| 国产盗摄一区二区| 在线不卡一区二区| 国产精品国产三级国产普通话蜜臀 | 欧美日韩一区成人| 久久精品一区二区| 天天操天天干天天综合网| 国产成人在线看| 91精选在线观看| 亚洲欧美另类在线| 国产不卡在线视频| 日韩欧美国产高清| 亚洲成人激情av| 91美女福利视频| 欧美国产精品v| 精品亚洲免费视频| 欧美一区二区精品在线| 亚洲人123区| 国产成人在线视频网址| 欧美大片一区二区| 亚洲成av人片一区二区三区| 91网站最新地址| 国产精品色噜噜| 国产精品一区二区无线| 91精品在线免费| 亚洲福利视频一区二区| 91视频精品在这里| 国产精品美女久久久久aⅴ| 久久黄色级2电影| 日韩色视频在线观看| 天天色天天操综合| 欧美三级乱人伦电影| 一区二区三区 在线观看视频| 风间由美性色一区二区三区| 亚洲精品一线二线三线| 免费观看一级欧美片| 91精品国产一区二区三区香蕉| 亚洲综合一区二区三区| 91在线精品一区二区| 国产精品高潮呻吟久久| av色综合久久天堂av综合| 欧美国产精品中文字幕| 成人免费视频一区二区| 国产精品久久久久久一区二区三区| 国产精品一区免费在线观看| 久久久久久久av麻豆果冻| 国产一区二区中文字幕| 久久久久88色偷偷免费| 高清不卡在线观看| 中文字幕精品一区| 成av人片一区二区| 亚洲图片欧美激情| 91亚洲大成网污www| 亚洲日本一区二区三区| 欧美伊人精品成人久久综合97 | www成人在线观看| 国产一区二区不卡在线| 国产精品色婷婷久久58| 99久久精品费精品国产一区二区| 中文字幕亚洲电影| 一本一本久久a久久精品综合麻豆| 亚洲日本一区二区| 精品视频在线免费看| 日韩成人精品在线观看| 欧美不卡123| 丁香婷婷综合激情五月色| 亚洲天堂2014| 在线观看日韩精品| 日本伊人精品一区二区三区观看方式| 67194成人在线观看| 蜜桃视频第一区免费观看| 欧美精品一区二区蜜臀亚洲| 国产成人精品1024| 一区二区视频在线看| 欧美日本韩国一区| 国精品**一区二区三区在线蜜桃| 国产亚洲人成网站| 色菇凉天天综合网| 免费精品视频在线| 欧美国产欧美综合| 欧洲激情一区二区| 男女性色大片免费观看一区二区| 久久品道一品道久久精品| 91网址在线看| 美脚の诱脚舐め脚责91| 国产精品高潮呻吟久久| 欧美福利电影网| 岛国一区二区在线观看| 亚洲成人免费视频| 国产三级欧美三级| 欧美性受xxxx黑人xyx性爽| 韩国一区二区三区| 亚洲一区视频在线观看视频| 26uuu国产在线精品一区二区| 91麻豆免费观看| 捆绑紧缚一区二区三区视频| 中文字幕一区二区在线观看| 91麻豆精品91久久久久久清纯| 成人听书哪个软件好| 日韩影院免费视频| 一区精品在线播放| 日韩欧美中文字幕一区| 一本久久精品一区二区| 国产一二三精品| 青青草国产成人av片免费| 椎名由奈av一区二区三区| 精品国产乱子伦一区| 在线观看不卡视频| 国产成人免费在线观看不卡| 日韩精品色哟哟| 伊人一区二区三区| 国产精品区一区二区三区| 日韩欧美一区二区视频| 欧美三级视频在线观看| 91在线视频18|