This function allows you to create a custom effects filter for raster images.

[C++Builder]   HANDLE IKCustomFilter(PTR_IKSELECT_IMAGE SrcHandle, BYTE SelectMode, LPPOINT lpPoint, int Points, LPRECT Rect, BOOL InOut, LPINT Matrix, BYTE Div, BYTE Level, BOOL Red, BOOL Green, BOOL Blue, IKPROCESSPROC UserProc, LPCTSTR Caption, LPCTSTR Message, LPCTSTR Button);
[Delphi]   function IKCustomFilter(var SrcHandle: IKSELECT_IMAGE; SelectMode: Byte; var lpPoint: TPoint; Points: Integer; var Rect : TRect; InOut: LongBool; var Matrix: Integer; Div, Level: Byte; Red, Green, Blue: LongBool; UserProc: LONG_PTR; Caption, Message, Button: PChar): THandle;

Parameters

Name Explanation
SrcHandle A structure containing the image handle and the mask image handle member variables
hImgBmh must be 8bit grayscale, 16, 24, or 32 bit images
SelectMode Sets the method for selecting the area on the image that will be processed (0: Mask handle, 1: Total image, 2: Polygon, 3: Ellipse)
lpPoint A structure defining coordinates for the points of the polygonal area on the image. (This parameter is enabled when SelectMode is 2)

In C++Builder, pass the pointer to the first element in the structure array.

In Delphi, if Pt is an array of TPoint, then the arguments are returned in the first elements of the array Pt[0]

Points The number of points defining the polygonal area on the image, i.e. the number of points in the lpPoint array (This parameter is enabled when SelectMode is 2).
Rect A structure specifying the coordinates for the rectangle bounding the elliptical area on the image (This parameter is enabled when SelectMode is 3)
InOut Determines whether the area inside the selected area will be processed or the area outside the selected area will be processed. Enabled for polygon and ellipse (SelectMode is 2 or 3). If False (0), the area outside the selected area is processed. If True (nonzero) the area inside the selected area is processed.
Matrix 9x9 matrix (an array of 81 items ranging from 0 to 80).

(1) In C++Builder, pass the pointer to the first element in the matrix array.

(2) In Delphi, Mt: array [0..80] of Integer, the arguments are returned in the first element of the array Mt[0]

Div The division factor
Level The bias factor (from 0 to 255, as this factor increases, the color becomes brighter)
Red To process the red plane, set toTrue, otherwise set to False (0)
Green To process the green plane, set toTrue, otherwise set to False (0)
Blue To process the blue plane, set toTrue, otherwise set to False (0)
UserProc The address of the user function (If not using the user function then set to 0)
Caption Sets the text displayed in the title bar of the progress dialog box
Message Sets the message displayed in the progress dialog box
Button Sets the name of the button displayed in the progress dialog box

Return Value

Returns the raster image handle if successful (1 bit image). Returns 0 if unsuccessful.

Explanation

The IKCustomFilter function allows you to create a custom effects filter for raster images. An effects filter alters each pixel's color based on its current color and the colors of any neighboring pixels (See the explanation of the filter matrix below).


Before executing this function, you must set the area on the image that will be affected. There are 4 ways to do this.

  1. To use a mask image, set SelectMode to 0. Then set the mask image handle in SrcHandle.
  2. To process the total image, set SelectMode to 1.
  3. To process the polygonal area on the image, set SelectMode to 2. Select the polygon by setting the appropriate coordinate values for the points of the polygon in the lpPoint structure. Then set the number of points defining the polygon in Points (must be 3 or more).
  4. To process an elliptical area on the image, set SelectMode to 3. Select the ellipse by setting the appropriate values for the bounding rectangle in the Rect structure.

For the lpPoint and Rect structure members, coordinate points are in pixel units. When SelectMode is set to a value other than 2, set a dummy array in lpPoint and set Points to 0. When SelectMode is set to a value other than 3, then set a dummy array in Rect. When processing a grayscale image the Red, Green and Blue parameter values are ineffective (dummy values).


Note: the image handles passed to IKSELECT_IMAGE are NOT automatically freed after executing this function.


If the user function is set or if the Caption, Message, and Button parameters are blank then the Progress dialog box is not displayed. If the Progress dialog box is displayed, it indicates the percentage of the current process completed. For more information about the user function please refer to the Definition of User Function in the Ik10Effect.dll, Ik10EffectA.dll, Ik10Effect64.dll, Ik10Effect64A.dlll section.

The filter consists of an array of coefficients called a filter matrix. A filter processes an image on a pixel-by-pixel basis. Each pixel's color value is multiplied by the coefficient in the matrix center, and any pixels within the matrix are multiplied by the corresponding coefficients. The sum of the products becomes the target pixel's new value. To make the filter matrix, it is necessary to create an array containing 80 elements and set the appropriate coefficient values in the array elements. The formula used to calculate the target pixel's value is given below:

Where F is the output value of the target pixel, Pi is a pixel in the grid, and Ci is a coefficient in the matrix. Div is the division factor which allows you to achieve effects that would otherwise require decimal coefficients. Level is a bias factor. You use the bias to shift the value of each pixel by a fixed amount. As the bias factor increases, the resultant color is brighter. Bias adjustments are particularly useful for creating embossing effects.


Some sample matrix are given below:

 

The ImageKit10 VCL is a product created by Newtone Corporation