📄 oxdib.h
字号:
// ==========================================================================
// Class Specification : COXDIB
// ==========================================================================
// Header file : oxdib.h
// Source : Periphere NV (OOP adaptation by R.Mortelmans)
// Original C code from MFC sample diblook
// Dither code from SDK Halftone sample
// Creation Date : 16th November 1995
// Last Modification : 10th September 1996
// //////////////////////////////////////////////////////////////////////////
// Properties:
// NO Abstract class (does not have any objects)
// YES Derived from CObject
// NO Is a Cwnd.
// NO Two stage creation (constructor & Create())
// NO Has a message map
// NO Needs a resource (template)
// YES Persistent objects (saveable on disk)
// YES Uses exceptions
// //////////////////////////////////////////////////////////////////////////
// Desciption :
// This class represents a persistent Device Independent Bitmap (DIB)
// The bitmap can be read from file and saved back to file
// By using the Paint function you can display (a part of) it
// on a DC
// Remark:
// Copy and assignment operators are implemented as well.
// Notice that in this case a GlobalAlloc is called to
// actually vopy the bitmaps contents
// Prerequisites (necessary conditions):
//
/////////////////////////////////////////////////////////////////////////////
#ifndef __DIB_H__
#define __DIB_H__
// Handle to a DIB
DECLARE_HANDLE(HDIB);
typedef LPBITMAPINFOHEADER PDIB;
#if defined(WIN32) || defined(_WIN32)
#define _huge
#endif
// DIB constants
#define PALVERSION 0x300
// DIB Macros
#define IS_WIN30_DIB(lpbi) ((*(LPDWORD)(lpbi)) == sizeof(BITMAPINFOHEADER))
#ifdef WIN32
#define HandleFromDib(lpbi) GlobalHandle(lpbi)
#else
#define HandleFromDib(lpbi) (HANDLE)GlobalHandle(SELECTOROF(lpbi))
#endif
#define DibFromHandle(h) (PDIB)GlobalLock(h)
#define DibFree(pdib) GlobalFreePtr(pdib)
// WIDTHBYTES performs DWORD-aligning of DIB scanlines. The "bits"
// parameter is the bit count for the scanline (biWidth * biBitCount),
// and this macro returns the number of DWORD-aligned bytes needed
// to hold those bits.
#ifndef WIDTHBYTES
#define WIDTHBYTES(bits) ((unsigned)((bits+31)&(~31))/8) /* ULONG aligned ! */
#endif
#define DibWidth(lpbi) (UINT)(((LPBITMAPINFOHEADER)(lpbi))->biWidth)
#define DibHeight(lpbi) (UINT)(((LPBITMAPINFOHEADER)(lpbi))->biHeight)
#define DibBitCount(lpbi) (UINT)(((LPBITMAPINFOHEADER)(lpbi))->biBitCount)
#define DibCompression(lpbi) (DWORD)(((LPBITMAPINFOHEADER)(lpbi))->biCompression)
#define DibWidthBytesN(lpbi, n) (UINT)WIDTHBYTES((UINT)(lpbi)->biWidth * (UINT)(n))
#define DibWidthBytes(lpbi) DibWidthBytesN(lpbi, (lpbi)->biBitCount)
#define DibSizeImage(lpbi) ((lpbi)->biSizeImage == 0 \
? ((DWORD)(UINT)DibWidthBytes(lpbi) * (DWORD)(UINT)(lpbi)->biHeight) \
: (lpbi)->biSizeImage)
#define DibSize(lpbi) ((lpbi)->biSize + (lpbi)->biSizeImage + (int)(lpbi)->biClrUsed * sizeof(RGBQUAD))
#define DibPaletteSize(lpbi) (DibNumColors(lpbi) * sizeof(RGBQUAD))
#define DibFlipY(lpbi, y) ((int)(lpbi)->biHeight-1-(y))
//HACK for NT BI_BITFIELDS DIBs
#ifdef WIN32
#define DibPtr(lpbi) ((lpbi)->biCompression == BI_BITFIELDS \
? (LPVOID)(DibColors(lpbi) + 3) \
: (LPVOID)(DibColors(lpbi) + (UINT)(lpbi)->biClrUsed))
#else
#define DibPtr(lpbi) (LPVOID)(DibColors(lpbi) + (UINT)(lpbi)->biClrUsed)
#endif
#define DibColors(lpbi) ((RGBQUAD FAR *)((LPBYTE)(lpbi) + (int)(lpbi)->biSize))
#define DibNumColors(lpbi) ((lpbi)->biClrUsed == 0 && (lpbi)->biBitCount <= 8 \
? (int)(1 << (int)(lpbi)->biBitCount) \
: (int)(lpbi)->biClrUsed)
#define DibXYN(lpbi,pb,x,y,n) (LPVOID)( \
(BYTE _huge *)(pb) + \
(UINT)((UINT)(x) * (UINT)(n) / 8u) + \
((DWORD)DibWidthBytesN(lpbi,n) * (DWORD)(UINT)(y)))
#define DibXY(lpbi,x,y) DibXYN(lpbi,DibPtr(lpbi),x,y,(lpbi)->biBitCount)
#define FixBitmapInfo(lpbi) if ((lpbi)->biSizeImage == 0) \
(lpbi)->biSizeImage = DibSizeImage(lpbi); \
if ((lpbi)->biClrUsed == 0) \
(lpbi)->biClrUsed = DibNumColors(lpbi); \
if ((lpbi)->biCompression == BI_BITFIELDS && (lpbi)->biClrUsed == 0) \
; // (lpbi)->biClrUsed = 3;
#define DibInfo(pDIB) ((BITMAPINFO FAR *)(pDIB))
/***************************************************************************/
#ifndef BI_BITFIELDS
#define BI_BITFIELDS 3
#endif
class AFX_EXT_CLASS COXDIB : public CObject
{
DECLARE_SERIAL(COXDIB)
// Data members -------------------------------------------------------------
public:
protected:
HDIB m_hDIB;
CPalette* m_pPalette;
#ifndef NO_DITHER
static PALETTEENTRY const aHalfTonePalette[256];
static BYTE const aDividedBy51Rounded[256];
static BYTE const aDividedBy51[256];
static BYTE const aModulo51[256];
static BYTE const aTimes6[6];
static BYTE const aTimes36[6];
static BYTE const aHalftone16x16[256];
static BYTE const aHalftone8x8[64];
static BYTE const aHalftone4x4_1[16];
static BYTE const aHalftone4x4_2[16];
static BYTE const aWinGHalftoneTranslation[216];
static const COLORREF NT_REF;
#endif // NO_DITHER
private:
// Member functions ---------------------------------------------------------
public:
COXDIB();
// --- In :
// --- Out :
// --- Returns :
// --- Effect : Contructor of object
// It will initialize the internal state as empty
// This is a handy routine for clipboard support
COXDIB(HDIB hDIB);
// --- In :
// --- Out :
// --- Returns :
// --- Effect : Contructor of object out of a handle
// It will initialize the internal state as empty
static BOOL ClearSystemPalette();
// --- In :
// --- Out :
// --- Returns : succeeded or not
// --- Effect : Clear the System Palette so that we can ensure an identity palette
// mapping for fast performance.
static BOOL GetSystemPalette(CPalette* pPalette);
// --- In :
// --- Out : pPalette : the current system palette
// --- Returns : succeeded or not
// --- Effect : Creates the System Palette
HDIB WINAPI MakeCopy();
// --- In :
// --- Out :
// --- Returns : Handle to new global memory block.
// --- Effect : Makes a copy of this DIB to a new global memory block.
// This is a handy routine for clipboard support
CBitmap* MakeBitmap(CDC* pDC, CSize& bmSize);
// --- In : pDC : the device context from where the bitmap will be copied to
// bmSize : A CSize
// --- Out : bmSize : The size of the newly selected bitmap
// --- Returns : Pointer to the old bitmap off the dc. This is a temporary
// pointer and should not be stored for later use.
// --- Effect : Replaces the dc's existing bitmap with a new one from the DIB
// and return the new size
BOOL IsEmpty() const;
// --- In :
// --- Out :
// --- Returns : Whether the objects contains a DIB or is still empty
// --- Effect :
void Empty();
// --- In :
// --- Out :
// --- Returns :
// --- Effect : Clear the contents of the DIB
BOOL Paint(CDC* pDC, const CRect& rDCRect, const CRect& rDIBRect);
// --- In : pDC : DC to do output to
// rDCRect : rectangle on DC to do output to
// rDIBRect : rectangle of DIB to output into rDCRect
// --- Out :
// --- Returns :TRUE if DIB was drawn, FALSE otherwise
// --- Effect : 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 rDCRect. The area of the DIB to be output is
// given by rDIBRect.
LPSTR FindDIBBits (LPSTR lpDIBHeader = NULL);
// --- In : lpDIBHeader : pointer to the dib header whose bits we want to locate
// --- Out :
// --- Returns : pointer to the DIB bits
// --- Effect : This function calculates the address of the DIB's bits and returns a
// pointer to the DIB bits.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -