1998-05-20 10:12:05 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: dibutils.h
|
|
|
|
// Purpose: Utilities for DIBs
|
|
|
|
// Author: Julian Smart
|
|
|
|
// Modified by:
|
|
|
|
// Created: 04/01/98
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) Microsoft, Julian Smart
|
1998-08-07 19:52:45 -04:00
|
|
|
// Licence: wxWindows licence
|
1998-05-20 10:12:05 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
|
|
|
|
(C) Copyright 1994 Microsoft Corp. All rights reserved.
|
|
|
|
|
|
|
|
You have a royalty-free right to use, modify, reproduce and
|
|
|
|
distribute the Sample Files (and/or any modified version) in
|
|
|
|
any way you find useful, provided that you agree that
|
|
|
|
Microsoft has no warranty obligations or liability for any
|
|
|
|
Sample Application Files which are modified.
|
|
|
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
Functions for handling Device Independent Bitmaps and clearing the
|
|
|
|
System Palette.
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
#ifndef SAMPLES_UTILS_H
|
|
|
|
#define SAMPLES_UTILS_H
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma interface "dibutils.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef LPBITMAPINFOHEADER PDIB;
|
|
|
|
typedef HANDLE HDIB;
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
External function declarations
|
|
|
|
**************************************************************************/
|
|
|
|
|
1999-10-04 07:39:13 -04:00
|
|
|
void wxClearSystemPalette(void);
|
|
|
|
PDIB wxDibOpenFile(LPTSTR szFile);
|
|
|
|
int wxDibWriteFile(LPTSTR szFile, LPBITMAPINFOHEADER lpbi);
|
|
|
|
BOOL wxDibSetUsage(PDIB pdib, HPALETTE hpal,UINT wUsage);
|
|
|
|
PDIB wxDibCreate(int bits, int dx, int dy);
|
|
|
|
BOOL wxDibMapToPalette(PDIB pdib, HPALETTE hpal);
|
|
|
|
HPALETTE wxMakePalette(const BITMAPINFO FAR* Info, UINT flags);
|
1998-05-20 10:12:05 -04:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
Internal function declarations
|
|
|
|
***************************************************************************/
|
|
|
|
|
1999-10-04 07:39:13 -04:00
|
|
|
PDIB wxDibReadBitmapInfo(HFILE fh);
|
1998-05-20 10:12:05 -04:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
DIB macros.
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#ifdef WIN32
|
1999-10-04 07:39:13 -04:00
|
|
|
#define wxHandleFromDib(lpbi) GlobalHandle(lpbi)
|
1998-05-20 10:12:05 -04:00
|
|
|
#else
|
1999-10-04 07:39:13 -04:00
|
|
|
#define wxHandleFromDib(lpbi) (HANDLE)GlobalHandle(SELECTOROF(lpbi))
|
1998-05-20 10:12:05 -04:00
|
|
|
#endif
|
|
|
|
|
1999-10-04 07:39:13 -04:00
|
|
|
#define wxDibFromHandle(h) (PDIB)GlobalLock(h)
|
1998-05-20 10:12:05 -04:00
|
|
|
|
1999-10-04 07:39:13 -04:00
|
|
|
#define wxDibFree(pdib) GlobalFreePtr(pdib)
|
1998-05-20 10:12:05 -04:00
|
|
|
|
1999-10-04 07:39:13 -04:00
|
|
|
#define wxWIDTHBYTES(i) ((unsigned)((i+31)&(~31))/8) /* ULONG aligned ! */
|
1998-05-20 10:12:05 -04:00
|
|
|
|
1999-10-04 07:39:13 -04:00
|
|
|
#define wxDibWidth(lpbi) (UINT)(((LPBITMAPINFOHEADER)(lpbi))->biWidth)
|
|
|
|
#define wxDibHeight(lpbi) (UINT)(((LPBITMAPINFOHEADER)(lpbi))->biHeight)
|
|
|
|
#define wxDibBitCount(lpbi) (UINT)(((LPBITMAPINFOHEADER)(lpbi))->biBitCount)
|
|
|
|
#define wxDibCompression(lpbi) (DWORD)(((LPBITMAPINFOHEADER)(lpbi))->biCompression)
|
1998-05-20 10:12:05 -04:00
|
|
|
|
1999-10-04 07:39:13 -04:00
|
|
|
#define wxDibWidthBytesN(lpbi, n) (UINT)wxWIDTHBYTES((UINT)(lpbi)->biWidth * (UINT)(n))
|
|
|
|
#define wxDibWidthBytes(lpbi) wxDibWidthBytesN(lpbi, (lpbi)->biBitCount)
|
1998-05-20 10:12:05 -04:00
|
|
|
|
1999-10-04 07:39:13 -04:00
|
|
|
#define wxDibSizeImage(lpbi) ((lpbi)->biSizeImage == 0 \
|
|
|
|
? ((DWORD)(UINT)wxDibWidthBytes(lpbi) * (DWORD)(UINT)(lpbi)->biHeight) \
|
1998-05-20 10:12:05 -04:00
|
|
|
: (lpbi)->biSizeImage)
|
|
|
|
|
1999-10-04 07:39:13 -04:00
|
|
|
#define wxDibSize(lpbi) ((lpbi)->biSize + (lpbi)->biSizeImage + (int)(lpbi)->biClrUsed * sizeof(RGBQUAD))
|
|
|
|
#define wxDibPaletteSize(lpbi) (wxDibNumColors(lpbi) * sizeof(RGBQUAD))
|
1998-05-20 10:12:05 -04:00
|
|
|
|
1999-10-04 07:39:13 -04:00
|
|
|
#define wxDibFlipY(lpbi, y) ((int)(lpbi)->biHeight-1-(y))
|
1998-05-20 10:12:05 -04:00
|
|
|
|
|
|
|
//HACK for NT BI_BITFIELDS DIBs
|
|
|
|
#ifdef WIN32
|
1999-10-04 07:39:13 -04:00
|
|
|
#define wxDibPtr(lpbi) ((lpbi)->biCompression == BI_BITFIELDS \
|
|
|
|
? (LPVOID)(wxDibColors(lpbi) + 3) \
|
|
|
|
: (LPVOID)(wxDibColors(lpbi) + (UINT)(lpbi)->biClrUsed))
|
1998-05-20 10:12:05 -04:00
|
|
|
#else
|
1999-10-04 07:39:13 -04:00
|
|
|
#define wxDibPtr(lpbi) (LPVOID)(wxDibColors(lpbi) + (UINT)(lpbi)->biClrUsed)
|
1998-05-20 10:12:05 -04:00
|
|
|
#endif
|
|
|
|
|
1999-10-04 07:39:13 -04:00
|
|
|
#define wxDibColors(lpbi) ((RGBQUAD FAR *)((LPBYTE)(lpbi) + (int)(lpbi)->biSize))
|
1998-05-20 10:12:05 -04:00
|
|
|
|
1999-10-04 07:39:13 -04:00
|
|
|
#define wxDibNumColors(lpbi) ((lpbi)->biClrUsed == 0 && (lpbi)->biBitCount <= 8 \
|
1998-05-20 10:12:05 -04:00
|
|
|
? (int)(1 << (int)(lpbi)->biBitCount) \
|
|
|
|
: (int)(lpbi)->biClrUsed)
|
|
|
|
|
1999-10-04 07:39:13 -04:00
|
|
|
#define wxDibXYN(lpbi,pb,x,y,n) (LPVOID)( \
|
1998-05-20 10:12:05 -04:00
|
|
|
(BYTE _huge *)(pb) + \
|
|
|
|
(UINT)((UINT)(x) * (UINT)(n) / 8u) + \
|
1999-10-04 07:39:13 -04:00
|
|
|
((DWORD)wxDibWidthBytesN(lpbi,n) * (DWORD)(UINT)(y)))
|
1998-05-20 10:12:05 -04:00
|
|
|
|
1999-10-04 07:39:13 -04:00
|
|
|
#define wxDibXY(lpbi,x,y) wxDibXYN(lpbi,wxDibPtr(lpbi),x,y,(lpbi)->biBitCount)
|
1998-05-20 10:12:05 -04:00
|
|
|
|
1999-10-04 07:39:13 -04:00
|
|
|
#define wxFixBitmapInfo(lpbi) if ((lpbi)->biSizeImage == 0) \
|
|
|
|
(lpbi)->biSizeImage = wxDibSizeImage(lpbi); \
|
1998-05-20 10:12:05 -04:00
|
|
|
if ((lpbi)->biClrUsed == 0) \
|
1999-10-04 07:39:13 -04:00
|
|
|
(lpbi)->biClrUsed = wxDibNumColors(lpbi);
|
1999-05-25 19:51:10 -04:00
|
|
|
|
|
|
|
// if ((lpbi)->biCompression == BI_BITFIELDS && (lpbi)->biClrUsed == 0)
|
|
|
|
// ; // (lpbi)->biClrUsed = 3;
|
1998-05-20 10:12:05 -04:00
|
|
|
|
1999-10-04 07:39:13 -04:00
|
|
|
#define wxDibInfo(pDIB) ((BITMAPINFO FAR *)(pDIB))
|
1998-05-20 10:12:05 -04:00
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
#ifndef BI_BITFIELDS
|
|
|
|
#define BI_BITFIELDS 3
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HALFTONE
|
|
|
|
#define HALFTONE COLORONCOLOR
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|