IM: Windows DIB

IM - An Imaging Tool

Windows DIB
[Utilities]


Detailed Description

Windows DIBs in memory are handled just like a BMP file without the file header.
These functions will work only in Windows. They are usefull for interchanging data with the clipboard, with capture drivers, with the AVI and WMF file formats and others.
Supported DIB aspects:
  • bpp must be 1, 4, 8, 16, 24, or 32.
  • BITMAPV4HEADER or BITMAPV5HEADER are handled but ignored.
  • BITMAPCOREHEADER is not handled .
  • BI_JPEG and BI_PNG compressions are not handled.
  • biHeight can be negative, compression can be RLE only if created from imDibCreateReference, imDibPasteClipboard, imDibLoadFile.
  • can not encode/decode Images to/from RLE compressed Dibs.
  • if working with RLE Dibs bits_size is greatter than used.
  • the resolution of a new Dib is taken from the screen.
  • SetDIBitsToDevice(start_scan is 0, scan_lines is dib->bmih->biHeight).
  • StretchDIBits(use always DIB_RGB_COLORS).
  • CreateDIBPatternBrushPt(packed_dib is dib->dib).
Must include <windows.h> before using these functions.
Check <wingdi.h> for structures and definitions.
See im_dib.h


Data Structures

struct  _imDib
 Windows DIB Structure. More...

Typedefs

typedef _imDib imDib
typedef unsigned int(* imDibLineGetPixel )(unsigned char *line, int col)
typedef void(* imDibLineSetPixel )(unsigned char *line, int col, unsigned int pixel)

Functions

imDibimDibCreate (int width, int height, int bpp)
imDibimDibCreateCopy (const imDib *dib)
imDibimDibCreateReference (BYTE *bmi, BYTE *bits)
imDibimDibCreateSection (HDC hDC, HBITMAP *image, int width, int height, int bpp)
void imDibDestroy (imDib *dib)
imDibLineGetPixel imDibLineGetPixelFunc (int bpp)
imDibLineSetPixel imDibLineSetPixelFunc (int bpp)
imDibimDibFromHBitmap (const HBITMAP image, const HPALETTE hPalette)
HBITMAP imDibToHBitmap (const imDib *dib)
HPALETTE imDibLogicalPalette (const imDib *dib)
imDibimDibCaptureScreen (int x, int y, int width, int height)
void imDibCopyClipboard (imDib *dib)
imDibimDibPasteClipboard (void)
int imDibIsClipboardAvailable (void)
int imDibSaveFile (const imDib *dib, const char *filename)
imDibimDibLoadFile (const char *filename)
void imDibDecodeToRGBA (const imDib *dib, unsigned char *red, unsigned char *green, unsigned char *blue, unsigned char *alpha)
void imDibDecodeToMap (const imDib *dib, unsigned char *map, long *palette)
void imDibEncodeFromRGBA (imDib *dib, const unsigned char *red, const unsigned char *green, const unsigned char *blue, const unsigned char *alpha)
void imDibEncodeFromMap (imDib *dib, const unsigned char *map, const long *palette, int palette_count)
void imDibEncodeFromBitmap (imDib *dib, const unsigned char *data)
void imDibDecodeToBitmap (const imDib *dib, unsigned char *data)

Typedef Documentation

typedef struct _imDib imDib
 

Windows DIB Structure.

Handles a DIB in memory.
The DIB is stored in only one buffer. The secondary members are pointers to the main buffer.

typedef unsigned int(* imDibLineGetPixel)(unsigned char *line, int col)
 

DIB GetPixel function definition.
the DWORD is a raw copy of the bits, use (unsigned char*)&pixel

typedef void(* imDibLineSetPixel)(unsigned char *line, int col, unsigned int pixel)
 

DIB SetPixel function definition


Function Documentation

imDib* imDibCreate int  width,
int  height,
int  bpp
 

Creates a new DIB.
use bpp=-16/-32 to allocate space for BITFLIEDS.

imDib* imDibCreateCopy const imDib dib  ) 
 

Duplicates the DIB contents in a new DIB.

imDib* imDibCreateReference BYTE *  bmi,
BYTE *  bits
 

Creates a DIB using an already allocated memory.
"bmi" must be a pointer to BITMAPINFOHEADER.
"bits" can be NULL if it is inside "bmi" after the palette.

imDib* imDibCreateSection HDC  hDC,
HBITMAP *  image,
int  width,
int  height,
int  bpp
 

Creates a DIB section for drawing porposes.
Returns the image handle also created.

void imDibDestroy imDib dib  ) 
 

Destroy the DIB

imDibLineGetPixel imDibLineGetPixelFunc int  bpp  ) 
 

Returns a function to read pixels from a DIB line.

imDibLineSetPixel imDibLineSetPixelFunc int  bpp  ) 
 

Returns a function to write pixels into a DIB line.

imDib* imDibFromHBitmap const HBITMAP  image,
const HPALETTE  hPalette
 

Creates a DIB from a image handle and a palette handle.

HBITMAP imDibToHBitmap const imDib dib  ) 
 

Creates a image handle from a DIB.

HPALETTE imDibLogicalPalette const imDib dib  ) 
 

Returns a Logical palette from the DIB palette.
DIB bpp must be <=8.

imDib* imDibCaptureScreen int  x,
int  y,
int  width,
int  height
 

Captures the screen into a DIB.

void imDibCopyClipboard imDib dib  ) 
 

Transfer the DIB to the clipboard.
"dib" pointer can not be used after, or use imDibCopyClipboard(imDibCreateCopy(dib)). Warning: Clipboard functions in C++ can fail with Visual C++ /EHsc (Enable C++ Exceptions)

imDib* imDibPasteClipboard void   ) 
 

Creates a reference for the DIB in the clipboard if any. Returns NULL otherwise. Warning: Clipboard functions in C++ can fail with Visual C++ /EHsc (Enable C++ Exceptions)

int imDibIsClipboardAvailable void   ) 
 

Checks if there is a dib at the clipboard.

int imDibSaveFile const imDib dib,
const char *  filename
 

Saves the DIB into a file ".bmp".

imDib* imDibLoadFile const char *  filename  ) 
 

Creates a DIB from a file ".bmp".

void imDibDecodeToRGBA const imDib dib,
unsigned char *  red,
unsigned char *  green,
unsigned char *  blue,
unsigned char *  alpha
 

Converts a DIB into an RGBA image. alpha is optional. bpp must be >8.
alpha is used only when bpp=32.

void imDibDecodeToMap const imDib dib,
unsigned char *  map,
long *  palette
 

Converts a DIB into an indexed image. bpp must be <=8. colors must have room for at least 256 colors. colors is rgb packed (RGBRGBRGB...)

void imDibEncodeFromRGBA imDib dib,
const unsigned char *  red,
const unsigned char *  green,
const unsigned char *  blue,
const unsigned char *  alpha
 

Converts an RGBA image into a DIB. alpha is optional. bpp must be >8.
alpha is used only when bpp=32.

void imDibEncodeFromMap imDib dib,
const unsigned char *  map,
const long *  palette,
int  palette_count
 

Converts an indexed image into a DIB. bpp must be <=8.
colors is rgb packed (RGBRGBRGB...)

void imDibEncodeFromBitmap imDib dib,
const unsigned char *  data
 

Converts a IM_RGB packed image, with or without alpha, into a DIB.

void imDibDecodeToBitmap const imDib dib,
unsigned char *  data
 

Converts a DIB into IM_RGB packed image, with or without alpha.