L_BarCodeGetFirstDuplicated

#include "ltbar.h"

L_LTBAR_API L_INT L_BarCodeGetFirstDuplicated(pBarCodeData, nIndex)

Returns the index of the first barcode in the array that is a duplicate of the barcode at index nIndex.

Parameters

pBARCODEDATA pBarCodeData

Pointer to an array of BARCODEDATA structures that contain barcode information for a bitmap. This parameter is the same array returned by L_BarCodeRead or L_BarCodeReadExt.

L_INT nIndex

Index of a barcode. This index is zero based.

Returns

Value Meaning
>=0 An index of duplicated barcode.
< 0 An error occurred. Refer to Return Codes.

Comments

LEADTOOLS provides a number of functions to let you work with duplicated barcodes. They let you:

To determine whether a barcode is duplicated, use the L_BarCodeIsDuplicated function. If a barcode is duplicated, L_BarCodeGetDuplicated will return the index of the first barcode in the array after the specified barcode, which is a duplicate of the specified barcode.

If you know the index of a barcode within an array, you can get the index of the first duplicate of the specified barcode using L_BarCodeGetFirstDuplicated. Use the L_BarCodeGetNextDuplicated to get the next instance of a duplicated barcode.

Although no function is included to tell you the number of different sets of barcodes that are duplicated, you can easily program this by using the following code:

L_INT i, j, nCount; 
L_BOOL * pbVisited = (L_BOOL *)malloc(pBarCodeData->nTotalCount*sizeof(L_BOOL)); 
memset(pbVisited, 0, pBarCodeData->nTotalCount*sizeof(L_BOOL)); 
nCount = 0; 
for (i=0; i<pBarCodeData->nTotalCount; i++) 
{ 
   if(pbVisited[i]) 
      continue; 
   pbVisited[i] = TRUE; 
   nCount++; 
   j = i; 
   while(pBarCodeData[j].nIndexDuplicate != -1) 
   { 
      j = pBarCodeData[j].nIndexDuplicate; 
      pbVisited[j] = TRUE; 
   } 
} 
free(pbVisited); 

After this code is executed, nCount will contain the number of different sets of barcodes.

As an example, suppose you have a call to L_BarCodeRead that reads ten barcodes into a BARCODEDATA array. When L_BarCodeIsDuplicated is called for the item at index 3 in the array TRUE is returned. Therefore one or more barcodes in the array are duplicates of the specified item.

Calling L_BarCodeGetFirstDuplicated returns the index of the first barcode in the array that is a duplicate of the barcode at index 3 in the array. Suppose this value is 0. The barcode present at index zero in the array is the first duplicate of the barcode at index 3.

Calling L_BarCodeGetNextDuplicated with nIndex set to 3 will return the index of the next barcode in the array that is a duplicate of the barcodes at index 0 and 3. Suppose this value is 9. Therefore the barcodes at index 0, index 3, and index 9 of the array are all duplicates.

Required DLLs and Libraries

Platforms

Win32, x64, Linux.

See Also

Functions

Topics

Example

For complete sample code refer to MFCBar32 demo.

L_INT BarCodeGetFirstDuplicatedExample(HWND hWnd, pBARCODEDATA * ppBarCodeData) 
{ 
   L_INT nDupIndex=0; 
   L_TCHAR szBuffer[256]; 
 
   if (!ppBarCodeData)  
      return FAILURE; 
 
   ZeroMemory(szBuffer, sizeof(szBuffer)); 
 
   // suppose you have more than 5 in ppBarCodeData of BARCODEDATA 
   if (L_BarCodeIsDuplicated(&(*ppBarCodeData)[1])) 
   { 
      nDupIndex = L_BarCodeGetFirstDuplicated(*ppBarCodeData, 1); 
      if (nDupIndex >= 0) 
      { 
         // Print the first duplicated bar code data 
         wsprintf(szBuffer, TEXT("Data is %hs\nType %d\nUnits %d\nPosX %d\nPosY %d\nWidth %d\nHeight %d\n\n"), 
                  (*ppBarCodeData)[nDupIndex].pszBarCodeData, (*ppBarCodeData)[nDupIndex].ulType, (*ppBarCodeData)[nDupIndex].nUnits,  
                  (*ppBarCodeData)[nDupIndex].rcBarLocation.left, 
                  (*ppBarCodeData)[nDupIndex].rcBarLocation.top, 
                  abs((*ppBarCodeData)[nDupIndex].rcBarLocation.right - (*ppBarCodeData)[nDupIndex].rcBarLocation.left), 
                  abs((*ppBarCodeData)[nDupIndex].rcBarLocation.bottom - (*ppBarCodeData)[nDupIndex].rcBarLocation.top)); 
 
         return SUCCESS; 
      } 
      else 
      { 
         wsprintf(szBuffer, TEXT("An error occurred in L_BarCodeGetFirstDuplicated\nError Code = %d\n"), nDupIndex); 
         return nDupIndex; 
      } 
   } 
   else 
      wsprintf(szBuffer, TEXT("This Bar Code does not duplicated ...")); 
 
   MessageBox(hWnd, szBuffer, ((nDupIndex >= 0) ? TEXT("BarCode Info.") : TEXT("Notice!")), MB_OK); 
 
   return SUCCESS; 
} 

Help Version 21.0.2021.7.2
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Barcode C API Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.