L_FastMagicWand

#include "l_bitmap.h"

L_LTIMGCOR_API L_INT EXT_FUNCTION L_FastMagicWand(MagicWnd, nTolerance, Xposition, Yposition, pObjectInfo, uFlags)

MAGICWANDHANDLE MagicWnd;

/* fast magic wand handle */

L_INT nTolerance;

/* tolerance values */

L_INT Xposition;

/* x coordinate */

L_INT Yposition;

/* y coordinate */

pOBJECTINFO pObjectInfo;

/* pointer to OBJECTINFO */

L_UINT32 uFlags;

/* flags */

Performs the fast magic wand operation and obtains the region through OBJECTINFO structure depending on color value at Xposition and Yposition.

Parameter

Description

MagicWnd

A fast magic wand handle, initialized by calling the L_StartFastMagicWandEngine function.

nTolerance

The tolerance value sets the stopping upper and lower color boundaries.

Xposition

X-coordinate of the point. The point�s color is used to find the region.

Yposition

Y-coordinate of the point. The point�s color is used to find the region.

pObjectInfo

Pointer to OBJECTINFO structure to be updated with the obtained region.

uFlags

Reserved for future use. Must be 0.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

This function can only be called after the L_StartFastMagicWandEngine has been called. The MAGICWANDHANDLE structure passed must be the same as the one passed to L_StartFastMagicWandEngine function.

The MAGICWANDHANDLE and OBJECTINFO structures must be deleted by calling L_EndFastMagicWandEngine and L_DeleteObjectInfo functions.

This function is used when it is needed to select many regions over one image, especially large images as it performs faster.

This function supports 1, 8, and 24-bit images.

This function does not support 32-bit grayscale images. It returns the error code ERROR_GRAY32_UNSUPPORTED if a 32-bit grayscale image is passed to this function.

Required DLLs and Libraries

LTIMGCOR

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 2000 / XP, Windows VISTA.

See Also

Functions:

L_DeleteObjectInfo ,L_EndFastMagicWandEngine, L_ObjectCounter, L_StartFastMagicWandEngine, L_SetBitmapRgnMagicWand

Topics:

Raster Image Functions: Image Analysis

 

Processing an Image

Example

This example loads a bitmap and applies the FastMagicWand at a specified point and tolerance of color and colors the region white

L_INT FastMagicWandExample(L_VOID)
{  
   L_INT i , j ;           /*counters*/
   L_INT nRet;             /*to hold return values*/
   BITMAPHANDLE LeadBitmap; /*Bitmap handle to hold the loaded image*/
   L_INT X = 100;          /*X position*/
   L_INT Y = 100;          /*Y position*/
   L_INT Tolerance = 50;   /*color Tolerance*/
   MAGICWANDHANDLE MagicWnd;
   OBJECTINFO ObjectInfo;
   /* Load the bitmap, keeping the bits per pixel of the file */
   nRet = L_LoadBitmap (TEXT("C:\\Program Files\\LEAD Technologies\\LEADTOOLS16\\Images\\IMAGE3.CMP"), 
      &LeadBitmap, sizeof(BITMAPHANDLE), 0,
      ORDER_BGR, NULL, NULL);
   if(nRet != SUCCESS)
      return nRet;

   //performing the magicwand
   nRet = L_StartFastMagicWandEngine(&MagicWnd, &LeadBitmap, 0);
   if(nRet != SUCCESS)
      return nRet;

   nRet = L_FastMagicWand(MagicWnd, Tolerance, X, Y, &ObjectInfo, 0);
   if(nRet != SUCCESS)
      return nRet;

   nRet = L_EndFastMagicWandEngine(MagicWnd, 0);
   if(nRet != SUCCESS)
      return nRet;

   //coloring the region with white
   for( i = ObjectInfo.rcRect.left; i < ObjectInfo.rcRect.right; i++)
   {
      for( j = ObjectInfo.rcRect.top ; j < ObjectInfo.rcRect.bottom; j++)
      {
         if(ObjectInfo.pObject[i - ObjectInfo.rcRect.left][ j - ObjectInfo.rcRect.top] == 1)
         {
            L_PutPixelColor(&LeadBitmap , j, i, RGB(0,0,0));
         }
      }
   }

   //deleting the region data
   nRet = L_DeleteObjectInfo(&ObjectInfo , 0);
   if(nRet != SUCCESS)
      return nRet;


   //free bitmap 
   if(LeadBitmap.Flags.Allocated)  
      L_FreeBitmap(&LeadBitmap);
   return SUCCESS;

}