| Herd Software Development
|=
DaVinci Graphics Library
|==
DaVinci Documentation Home Search Order


Leonardo: The CreateFIRFilteredDIB function

Creates a filtered copy of a 24 bit DIB.

HDIB FAR PASCAL CreateSharpenedDIB(
HDIB hDIB,
LPINT matrices,
int width,
int height,
int addtoaverage
);

hDIB HDIB Handle of the source DIB.

The source DIB must be a 24 bit (TrueColor) DIB.

matrices LPINT Pointer to an array of (width * height) integer equivalents with multiplication factors for the pixels of the bitmap.

A value of 256 corresponds to a multiplication factor of 1.0

width int Width of the multiplication matrix

This value must be odd (not evenly divisible by 2).

height int Height of the multiplication matrix

This value must be odd (not evenly divisible by 2).

addtoaverage int Constant value which should be added to every pixel in the matrix.

Returns

If successful, the return value is the handle of the newly created DIB, otherwise it is NULL. The handle must be released by the application using GlobalFree.

Examples

This function applies a linear two-dimensional FIR filtration on the input DIB's color values to produce the output DIB.

Example: Matrix for pointed drawing

A multiplication matrix has nine filter coefficients. This matrix has a height of 3 pixels (height=3) and a width of 3 pixels (width=3).

static int SharpenMatrix[9] =
	{    0, -64,   0,
	   -64, 512, -64,
	     0, -64,   0 };

DIB data is stored in memory using mathematical x/y axial coordinates, and the first line of the matrix is the lowest line of bitmap data (row of pixels).

P[x-1,y-1]

P[x-1,y]

P[x-1,y+1]

P[x,y-1]

P[x,y]

P[x,y+1]

P[x+1,y-1]

P[x+1,y]

P[x+1,y+1]


The above example generates a filter matrix for sharpening. The value of each pixel is doubled (512 corresponds to a multiplication factor of 2.0), and a quarter of all the neighbor points is subtracted, so the average value is (2.0-4*0.25)=1.0.

Example: Matrix for blurring of photos
static int BlurrMatrix  [9] = 
	{  0, 32,  0,
	  32,128, 32,
	  0, 32,  0 };

Example: Source code for sharpening of photos
/* CreateSharpenedDIB
 *
 * Computes a new TrueColor DIB from a given TrueColor 24-Bit DIB
 * with sharpened Image
 */
static int SharpenMatrix[9] =
	{    0, -64,   0,
	   -64, 512, -64,
	     0, -64,   0 };
HDIB API CreateSharpenedDIB(HDIB hDib)
{ return CreateFIRFilteredDIB(hDib, SharpenMatrix, 3, 3, 0);
}