L_DotRemoveBitmap

#include "l_bitmap.h"

L_INT EXT_FUNCTION L_DotRemoveBitmap(pBitmap, pDotRemove, pfnCallback, pUserData)

pBITMAPHANDLE pBitmap;

/* pointer to the bitmap */

LPDOTREMOVE pDotRemove;

/* pointer to a structure */

DOTREMOVECALLBACK pfnCallback;

/* optional callback function */

L_VOID L_FAR * pUserData;

/* pointer to more parameters for the callback */

Finds and removes dots and specks of various sizes. This function is available in the Document/Medical Toolkits.

Parameter

Description

pBitmap

Pointer to the bitmap handle referencing the bitmap from which to remove dots.

pDotRemove

Pointer to the DOTREMOVE structure that LEADTOOLS uses to remove dots.

pfnCallback

Optional callback function for additional processing.

 

image\sqrblit.gif If you do not provide a callback function, use NULL as the value of this parameter.

 

image\sqrblit.gif If you do provide a callback function, use the function pointer as the value of this parameter.

 

The callback function must adhere to the function prototype described in DOTREMOVECALLBACK Function.

pUserData

Void pointer that you can use to pass one or more additional parameters that the callback function needs.

 

To use this feature, assign a value to a variable or create a structure that contains as many fields as you need. Then, in this parameter, pass the address of the variable or structure, casting it to L_VOID L_FAR *. The callback function, which receives the address in its own pUserData parameter, can cast it to a pointer of the appropriate data type to access your variable or structure.

 

If the additional parameters are not needed, you can pass NULL in this parameter.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

(Document) This function finds and removes dots, specks, and blobs of various sizes in 1-bit documents. The dots, specks, and blobs may or may not be all black. The behavior of this function can be modified by using its callback.

This function works only on 1-bit black and white images.

If a region is selected, only the selected region will be changed by this function. If no region is selected, the whole image will be processed.

This function does not support signed data images. It returns the error code ERROR_SIGNED_DATA_NOT_SUPPORTED if a signed data image is passed to this function.

Required DLLs and Libraries

LTIMG

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

Platforms

Windows 95 / 98 / Me, Windows 2000 / XP, Windows CE.

See Also

Functions:

DOTREMOVECALLBACK, L_SmoothBitmap, L_LineRemoveBitmap, L_InvertedTextBitmap, L_BorderRemoveBitmap, L_HolePunchRemoveBitmap, L_HolesRemovalBitmapRgn

Topics:

Cleaning Up 1-Bit Images

Example

//This example returns a region of all 1x1 to 3x3 specks that are solid black
//If a speck has any white pixels, it is NOT part of the returned region
//The call is configured to return a single LEAD region corresponding to all changes
//The image itself is unchanged
//A callback is used to display information about each speck that is removed
//The callback does NOT return a region
L_INT L_EXPORT EXT_CALLBACK ExampleDotRemoveCB(
    HRGN          hRgn, 
    PRECT         pBoundingRect, 
    L_INT32       iWhiteCount, 
    L_INT32       iBlackCount, 
    L_VOID L_FAR *pUserData
    )
{
   L_TCHAR  szMsg[200];
   L_INT32 nRet;

   //Note: no hRgn to delete because it was not requested
   wsprintf(
      szMsg, 
      TEXT("Size[%dx%d]\tBounds[%d,%d][%d,%d]\tWhiteCount[%d]\tBlackCount[%d]\n"),
      pBoundingRect->right - pBoundingRect->left,
      pBoundingRect->bottom - pBoundingRect->top,
      pBoundingRect->left,
      pBoundingRect->top,
      pBoundingRect->right,
      pBoundingRect->bottom,
      iWhiteCount,
      iBlackCount);
   OutputDebugString(szMsg);

   //Do not remove the speck if it contains any white pixels
   if (iWhiteCount > 0) 
   {
      nRet = SUCCESS_NOREMOVE;
   }
   else 
   {
      nRet = SUCCESS_REMOVE;
   }
   return nRet; 
}

L_VOID ExampleDotRemove(pBITMAPHANDLE pBitmap)
{
   L_INT32        nRet;
   BITMAPHANDLE   BitmapRegion;
   DOTREMOVE      dr;
   
   memset(&BitmapRegion, 0, sizeof(BITMAPHANDLE));
   
   dr.uStructSize = sizeof(DOTREMOVE);
   dr.iMinDotWidth   = 1;
   dr.iMinDotHeight  = 1;
   dr.iMaxDotWidth   = 3;
   dr.iMaxDotHeight  = 3;
   dr.uFlags         = DOT_USE_SIZE | DOT_SINGLE_REGION | DOT_LEAD_REGION | DOT_IMAGE_UNCHANGED;
   dr.pBitmapRegion  = &BitmapRegion;
      
   nRet = L_DotRemoveBitmap(
      pBitmap, 
      &dr,
      (DOTREMOVECALLBACK)(ExampleDotRemoveCB), 
      NULL                              
      );   
   
   if (nRet == SUCCESS)
   {
      RECT rectRgn;
      
      //Delete the existing region
      L_FreeBitmapRgn(pBitmap);
      
      L_GetBitmapRgnBounds(dr.pBitmapRegion, NULL, &rectRgn);
      if (!IsRectEmpty(&rectRgn))
      {
         L_CopyBitmapHandle(pBitmap, dr.pBitmapRegion, sizeof(BITMAPHANDLE));
      }
   }
   
}