Need a 3D graph? Try the 3DSurface Viewer! Draw 3D graphs with free calculus software from Bright Ideas Software.
GLE32 Ver. 4 Manual
  Skip Navigation Links
Math ToolsExpand Math Tools
DevelopersExpand Developers
About BISExpand About BIS
  Skip Navigation LinksHome --> Developers --> GLE32 Version 4 --> GLE32 Manual --> Search:
Skip Navigation Links

OpenGL® and OpenGL|ES are trademarks of Silicon Graphics, Inc.





DIBSection Library

This extremely useful image manipulation library wraps DIBSections and greatly simplifies use of this powerful graphics tool, providing functions to: convert to DIBSections of different color depths; convert to DIBS of various color depths; perform high-speed pixel value manipulation; to generate various types of palettes and apply these to images; to ease transferring images to the clipboard or printer, and to perform image file I/O.

The key data element is the DIBSTRUCT structure, the definition of which is shown below.


typedef void * HDIB ;

#define HDIB_SIGNATURE (* (int *) "Dib ")

typedef struct  DIBSTRUCT<
{
     PBYTE   *ppRow; // array of pointers to the rows of pixels
     int        iSignature; // defined above
     HBITMAP    hBitmap;// handle to the bitmap
     BYTE   *pBits; // pointer to the bytes (same as pointer 0 from above)
     DIBSECTION ds; // the GDI DIBSECTION structure
     int        iRShift[3]; // right shift values
     int        iLShift[3]; // left shift values
}
DIBSTRUCT, * PDIBSTRUCT ;

The various functions in the library have been divided into the categories listed below; click on a link to view function prototypes and descriptions. In addition to the functions, a set of macros are defined which can be used for high - speed pixel access. They're faster than the functions in the library, but have no error checking.


DIBSection Creation Functions

Function

  

Description

HDIB DibCreate (int cx, int cy, int cBitsPerPixel, int cColorTableSize)  Creates an HDIB from explicit arguments. Set cColorTableSize to 0 for default size table.
HDIB DibCreateFromInfo (BITMAPINFO* pbmi)  All DIBSTRUCT creation functions ultimately call this one. This function is responsible for calling CreateDIBSection, allocating memory for DIBSTRUCT, and setting up the row pointer.
BOOL DibDelete(HDIB dib)  Frees all memory associated with the DIBSTRUCT.
HDIB DibCopy (HDIB hdibSrc, BOOL fRotate)  Creates a new DIBSTRUCT from an existing DIBSTRUCT, possibly swapping the DIB width and height.
HDIB DibConvert (HDIB hdibSrc, int iBitCountDst, int MedianCutRes)  Converts DIBSTRUCT from one pixel format to another.Default value of MedianCutRes is 6; allowed range is 3 through 8.

I/O Functions

HDIB DibFileLoad (const TCHAR* szFileName)  Creates a DIBSTRUCT from a DIB file.
void DibFileSave (HDIB hdib, const TCHAR* szFileName)  Saves a DIB section to a .bmp file.
HBITMAP DibCopyToDdb (HDIB hdib, HWND hwnd, HPALETTE hPalette)  For more efficient screen displays.
HBITMAPDibCopyToDdb (HDIB hdib, HDC hDC, HPALETTE hPalette)  Overloaded version of the preceding function.
BITMAPINFO* DibCopyToPackedDib (HDIB hdib, BOOL fUseGlobal)  DibCopyToPackedDib is generally used for saving DIBs and for transferring DIBs to the clipboard. In the second case, the second argument should be set to TRUE so that the memory is allocated with the GMEM_SHARE flag.
HDIB DibCopyFromPackedDib (BITMAPINFO* pPackedDib)  DibCopyFromPackedDib is generally used for pasting DIBs from the clipboard.
HDIB LoadImageFile (LPCSTR Filename, colorREF Transparent_Clr = 0x00ffffff, BOOL DoAlphaBlend = FALSE)  Load any of the supported image types. Optionally pre-blend 32-bit images with specified background color.
HDIB LoadImageResource(HINSTANCE AppInstance, UINT ImageID, colorREF Transparent_Clr = 0x00ffffff, BOOL DoAlphaBlend = FALSE) Load an image from an embedded binary resource. See the 2D Texture Class description for more information on loading images from resources.
HDIB LoadTGAFromRAM (BYTE* pByte)  Create an HDIB from a TGA image in RAM.
HDIB LoadPPMFromRAM (BYTE* pByte, long bytes)  Creates an HDIB from a PPB image in RAM.
HDIB LoadPGMFromRAM (BYTE* ptr, long bytes)  
HDIB DIBFromIPicture (IPicture* pic)   
HDIB DibDecompress(BITMAPINFO* pbmi, void* pBytes, int Count)  Decompresses RLE-compressed bitmaps.

Misc. Manipulation Functions

HDIB DibFlipHorizontal (HDIB hdibSrc)   
HDIB DibFlipVertical (HDIB hdibSrc)   
HDIB DibRotateRight (HDIB hdibSrc)   
HDIB DibRotateLeft (HDIB hdibSrc)   
void DibGrayScale (HDIB hdib)  Converts an HDIB to a gray-scale image of the same color depth.
HDIB DibAlphaBlend (HDIB DibSrc, colorREF Transparent_Clr)  Returns a pre-blended 24-bit DIBSection when supplied with a valid 32-bit DIBSection and background color.
HDIB DibEmboss (HDIB DibSrc)  Returns an embossed version of an image. Embossing is performed with a standard 3x3 convolution kernel.
HDIB ConvertDibToNormalMap (HDIB dibSrc, float Scale)  Returns a normal map suitable for use with bump-mapped objects.

Bitmap Info Functions

BITMAPINFO* DibGetInfo (HDIB hdib)   
BOOL DibIsValid (HDIB hdib)  Returns TRUE if hdib points to a valid DIBSTRUCT.
HBITMAP DibBitmapHandle (HDIB hdib)  Returns the handle to the DIBSection bitmap object.
int DibWidth (HDIB hdib)  Returns the bitmap width, in pixels.
int DibHeight (HDIB hdib)  Returns the bitmap height, in pixels.
int DibBitCount (HDIB hdib)  Returns the number of bits per pixel.
int DibRowLength (HDIB hdib)  Returns the number of bytes per row of pixels.
int DibNumColors (HDIB hdib)  Returns the number of colors in the color table.
DWORD DibMask (HDIB hdib, int i)  Returns one of the color masks.
int DibRShift (HDIB hdib, int i)  Returns one of the right shift values.
int DibLShift (HDIB hdib, int i)  Returns one of the left shift values.
int DibCompression (HDIB hdib)  Returns the value of the biCompression field.
BOOL DibIsAddressable (HDIB hdib)  Returns TRUE is the DIB is not compresssed.

DIBSection Info Functions

BITMAPINFOHEADER* DibInfoHeaderPtr (HDIB hdib)   
DWORD* DibMaskPtr (HDIB hdib)   
void* DibBitsPtr (HDIB hdib)   
BOOL DibGetColor (HDIB hdib, int index, RGBQUAD * prgb)   
BOOL DibSetColor (HDIB hdib, int index, RGBQUAD * prgb)   
void DibCopyColorTable (HDIB dibSrc, HDIB dibDst)   

Pixel Functions

BYTE* DibPixelPtr (HDIB hdib, int x, int y)  Returns a pointer to the pixel at position (x, y).
DWORD DibGetPixel (HDIB hdib, int x, int y)  Obtains a pixel value at (x, y).
BOOL DibSetPixel (HDIB hdib, int x, int y, DWORD dwPixel)  Sets a pixel value at (x, y).
BOOL DibGetPixelColor (HDIB hdib, int x, int y, RGBQUAD * prgb)  Obtains the pixel color at (x, y).
BOOL DibSetPixelColor (HDIB hdib, int x, int y, RGBQUAD * prgb)  Sets the pixel color at (x, y).

Pixel Macros

Quick no-bounds-checked pixel accessors.
 
BYTE* DibPixelPtr1 (HBID hdib, int x, int y)   
BYTE* DibPixelPtr4 (HBID hdib, int x, int y)   
BYTE* DibPixelPtr8 (HBID hdib, int x, int y)   
WORD* DibPixelPtr16 (HBID hdib, int x, int y)   
RGBTRIPLE* DibPixelPtr24 (HBID hdib, int x, int y)   
DWORD* DibPixelPtr32 (HBID hdib, int x, int y)   
BYTE DibGetPixel1 (HBID hdib, int x, int y)   
BYTE DibGetPixel4 (HBID hdib, int x, int y)   
BYTE DibGetPixel8 (HBID hdib, int x, int y)   
WORD DibGetPixel16 (HBID hdib, int x, int y)   
RGBTRIPLE DibGetPixel24 (HBID hdib, int x, int y)   
DWORD DibGetPixel32 (HBID hdib, int x, int y)   
DibSetPixel1 (HBID hdib, int x, int y, BYTE p)   
DibSetPixel4 (HBID hdib, int x, int y, BYTE p)   
DibSetPixel8 (HBID hdib, int x, int y, BYTE p)   
DibSetPixel16 (HBID hdib, int x, int y, WORD p)   
DibSetPixel24 (HBID hdib, int x, int y, RGBTRIPLE p)   
DibSetPixel32 (HBID hdib, int x, int y, DWORD p)   

Palette Functions

void DibAdjustColorsToRamp (HDIB hdib, colorREF clrDark, colorREF clrLight)  Shift a DIBs colors to a specific range.
HPALETTE DibPalDibTable (HDIB hdib)  Create a palette from a DIBs color table.
HPALETTE DibPalAllPurpose (void)  Creates a palette suitable for a wide variety of images; the palette has 247 entries, but 15 of them are duplicates or match the standard 20 colors.
HPALETTE DibPalUniformGrays (int iNum)  Creates a palette of iNum grays, uniformly spaced.
HPALETTE DibPalUniformColors (int iNumR, int iNumG, int iNumB)  Creates a palette of iNumR x iNumG x iNumB colors.
HPALETTE DibPalRedRamp (int iNum)  Creates a palette of iNum reds, uniformly spaced.
HPALETTE DibPalGreenRamp (int iNum)  Creates a palette of iNum greens, uniformly spaced.
HPALETTE DibPalBlueRamp (int iNum)  Creates a palette of iNum blues, uniformly spaced.
HPALETTE DibPalVga (void)  Creates a palette based on standard 16 VGA colors.
HPALETTE DibPalPopularity (HDIB hdib, int iRes)  Uses popularity algorithm to produce palette optimized to hdib. Allowed range for iRes is 3~8.
HPALETTE DibPalMedianCut (HDIB hdib, int iRes)  Uses median cut algorithm to produce palette optimized to hdib. Allowed range for iRes is 3~8.
HPALETTE gleGetSystemPalette (void)  Returns a copy of the current system palette.
HPALETTE gleCreateGLPalette (HDC dc)  Returns a palette optimized for OpenGL applications on 256 color displays.

Packed DIB Info Functions

These functions return the sizes of various components of a DIBsection AS THEY WOULD APPEAR in a packed DIB. These functions aid in converting the DIB section to a packed DIB and in saving DIB files.
 
DWORD DibInfoHeaderSize (HDIB hdib)   
DWORD DibMaskSize (HDIB hdib)   
DWORD DibColorSize (HDIB hdib)   
DWORD DibInfoSize (HDIB hdib)   
DWORD DibBitsSize (HDIB hdib)   
DWORD DibTotalSize (HDIB hdib)   

Packed DIB Library

This library, while not as extensive as the DIBSection collection, is just as indispensable. The two actually complement one another - some things are easier (and faster) using the DIBSection library, while other operations are easier if the image is treated as a DIB. Of particular note in this group is the function used to extract the native palette from a DIB's color table.
 
BITMAPINFO* PackedDibLoad (LPTSTR szFileName)  Load DIB File as Packed-Dib Memory Block.
int PackedDibGetWidth (BITMAPINFO* pPackedDib)  Returns the bitmap width, in pixels.
int PackedDibGetHeight (BITMAPINFO* pPackedDib)  Returns the bitmap height, in pixels.
int PackedDibGetBitCount (BITMAPINFO* pPackedDib)  Returns the number of bits per pixel.
int PackedDibGetRowLength (BITMAPINFO* pPackedDib)  Returns the number of bytes per row of pixels.
int PackedDibGetInfoHeaderSize (BITMAPINFO* pPackedDib)  PackedDibGetInfoHeaderSize includes possible color masks.
int PackedDibGetColorsUsed (BITMAPINFO* pPackedDib)  PackedDibGetColorsUsed returns value in information header; could be 0 to indicate non-truncated color table.
int PackedDibGetNumColors (BITMAPINFO* pPackedDib)  PackedDibGetNumColors is actual number of entries in color table.
int PackedDibGetColorTableSize (BITMAPINFO* pPackedDib)  Byte count of the color table.
RGBQUAD* PackedDibGetColorTablePtr (BITMAPINFO* pPackedDib)   
RGBQUAD* PackedDibGetColorTableEntry (BITMAPINFO* pPackedDib, int i)   
BYTE* PackedDibGetBitsPtr (BITMAPINFO* pPackedDib)   
int PackedDibGetBitsSize (BITMAPINFO* pPackedDib)  PackedDibGetBitsSize can be calculated from the height and row length if it's not explicitly in the biSizeImage field.
HPALETTE PackedDibCreatePalette (BITMAPINFO* pPackedDib)  Creates a palette from a PackedDib's color table.

Back To Top



Copyright© 2001-2008 by Bright Ideas Software®. All rights reserved.