Unit DibUtil

Classes

Functions

BitmapToDIB - *********************************************************************** * * BitmapToDIB() * * Parameters: * * HBITMAP hBitmap - specifies the bitmap to convert * * HPALETTE hPal - specifies the palette to use with the bitmap * * Return Value: * * HDIB - identifies the device-dependent bitmap * * Description: * * This function creates a DIB from a bitmap using the specified palette.
CreateDIB - *********************************************************************** * * CreateDIB() * * Parameters: * * DWORD dwWidth - Width for new bitmap, in pixels * DWORD dwHeight - Height for new bitmap * WORD wBitCount - Bit Count for new DIB (1, 4, 8, or 24) * * Return Value: * * HDIB - Handle to new DIB * * Description: * * This function allocates memory for and initializes a new DIB by * filling in the BITMAPINFOHEADER, allocating memory for the color * table, and allocating memory for the bitmap bits.
CreateDIBPalette - *********************************************************************** * * 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.
DIBHeight -
DIBNumColors - *********************************************************************** * * DIBNumColors() * * Parameter: * * LPSTR lpDIB - 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.
DIBToBitmap - *********************************************************************** * * DIBToBitmap() * * Parameters: * * HDIB hDIB - specifies the DIB to convert * * HPALETTE hPal - specifies the palette to use with the bitmap * * Return Value: * * HBITMAP - identifies the device-dependent bitmap * * Description: * * This function creates a bitmap from a DIB using the specified palette.
DIBWidth -
FindDIBits - *********************************************************************** * * FindDIBBits() * * Parameter: * * LPSTR lpDIB - 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.
GetPixel24 -
GetPixel8 -
LoadDIB - *********************************************************************** * * LoadDIB() * * Loads the specified DIB from a file, allocates memory for it, * and reads the disk file into the memory.
PaintDIB - *********************************************************************** * * 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 * * Return Value: * * BOOL - TRUE if DIB was drawn, FALSE otherwise * * Description: * Painting routine for a DIB.
PaletteSize - *********************************************************************** * * PaletteSize() * * Parameter: * * LPSTR lpDIB - 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.
ReadDIBFile - *********************************************************************** * * Function: ReadDIBFile (int) * * Purpose: Reads in the specified DIB file into a global chunk of * memory.
WIDTHBYTES - WIDTHBYTES performs DWORD-aligning of DIB scanlines.

Types

HDIB
PColor24
PColor8
TColor24

Constants

NULL

Variables


Functions


function BitmapToDIB(hBitmap: HBITMAP; hPal: HPALETTE): HDIB;

*********************************************************************** * * BitmapToDIB() * * Parameters: * * HBITMAP hBitmap - specifies the bitmap to convert * * HPALETTE hPal - specifies the palette to use with the bitmap * * Return Value: * * HDIB - identifies the device-dependent bitmap * * Description: * * This function creates a DIB from a bitmap using the specified palette. *

function CreateDIB(dwWidth, dwHeight: DWORD; wBitCount: WORD): HDIB;

*********************************************************************** * * CreateDIB() * * Parameters: * * DWORD dwWidth - Width for new bitmap, in pixels * DWORD dwHeight - Height for new bitmap * WORD wBitCount - Bit Count for new DIB (1, 4, 8, or 24) * * Return Value: * * HDIB - Handle to new DIB * * Description: * * This function allocates memory for and initializes a new DIB by * filling in the BITMAPINFOHEADER, allocating memory for the color * table, and allocating memory for the bitmap bits. As with all * HDIBs, the header, colortable and bits are all in one contiguous * memory block. This function is similar to the CreateBitmap() * Windows API. * * The colortable and bitmap bits are left uninitialized (zeroed) in the * returned HDIB. * *

function CreateDIBPalette(hDIB: HDIB): HPALETTE;

*********************************************************************** * * 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). *

function DIBHeight(p: pointer): integer;


function DIBNumColors(lpDIB: LPSTR): WORD;

*********************************************************************** * * DIBNumColors() * * Parameter: * * LPSTR lpDIB - 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 OS/2-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. *

function DIBToBitmap(hDIB: HDIB; hPal: HPALETTE): HBITMAP;

*********************************************************************** * * DIBToBitmap() * * Parameters: * * HDIB hDIB - specifies the DIB to convert * * HPALETTE hPal - specifies the palette to use with the bitmap * * Return Value: * * HBITMAP - identifies the device-dependent bitmap * * Description: * * This function creates a bitmap from a DIB using the specified palette. * If no palette is specified, default is used. * * NOTE: * * The bitmap returned from this funciton is always a bitmap compatible * with the screen (e.g. same bits/pixel and color planes) rather than * a bitmap with the same attributes as the DIB. This behavior is by * design, and occurs because this function calls CreateDIBitmap to * do its work, and CreateDIBitmap always creates a bitmap compatible * with the hDC parameter passed in (because it in turn calls * CreateCompatibleBitmap). * * So for instance, if your DIB is a monochrome DIB and you call this * function, you will not get back a monochrome HBITMAP -- you will * get an HBITMAP compatible with the screen DC, but with only 2 * colors used in the bitmap. * * If your application requires a monochrome HBITMAP returned for a * monochrome DIB, use the function SetDIBits(). * * Also, the DIBpassed in to the function is not destroyed on exit. This * must be done later, once it is no longer needed. *

function DIBWidth(p: pointer): integer;


function FindDIBits(lpDIB: LPSTR): LPSTR;

*********************************************************************** * * FindDIBBits() * * Parameter: * * LPSTR lpDIB - 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. *

function GetPixel24(lpDIBits: LPSTR; x, y, Wid: integer): PColor24;


function GetPixel8(lpDIBits: LPSTR; x, y, Wid: integer): PColor8;


function LoadDIB(fn: string): HDIB;

*********************************************************************** * * LoadDIB() * * Loads the specified DIB from a file, allocates memory for it, * and reads the disk file into the memory. * * * Parameters: * * LPSTR lpFileName - specifies the file to load a DIB from * * Returns: A handle to a DIB, or NULL if unsuccessful. * * NOTE: The DIB API were not written to handle OS/2 DIBs; This * function will reject any file that is not a Windows DIB. *

function PaintDIB(hdc: HDC; lpDCRect: PRect; hDIB: HDIB; lpDIBRect: PRect; hPal: HPALETTE): integer;

*********************************************************************** * * 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 * * 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. * * NOTE: This function always selects the palette as background. Before * calling this function, be sure your palette is selected to desired * priority (foreground or background). * *

function PaletteSize(lpDIB: LPSTR): WORD;

*********************************************************************** * * PaletteSize() * * Parameter: * * LPSTR lpDIB - 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 OS/2- * style DIB). *

function ReadDIBFile(hFile: THandle): HDIB;

*********************************************************************** * * Function: ReadDIBFile (int) * * Purpose: Reads in the specified DIB file into a global chunk of * memory. * * Returns: A handle to a dib (hDIB) if successful. * NULL if an error occurs. * * Comments: BITMAPFILEHEADER is stripped off of the DIB. Everything * from the end of the BITMAPFILEHEADER structure on is * returned in the global memory handle. * * * NOTE: The DIB API were not written to handle OS/2 DIBs, so this * function will reject any file that is not a Windows DIB. *

function WIDTHBYTES(bits: integer): integer;

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.

Types


HDIB = THandle

PColor24 = ^TColor24

PColor8  = ^byte

TColor24 = record
Blu : byte;
Grn : byte;
Red : byte;
end;

Constants

NULL = THandle(0)

To use Palette arrays, turn off range checking {$R-

Variables