L_BarCodeReadExt

Summary

Searches for barcodes within the specified area with callback functionality.

Syntax

#include "ltbar.h"

L_LTBAR_API L_INT L_BarCodeReadExt(pBitmap, prcSearch, ulSearchType, nUnits, ulFlags, nMultipleMaxCount, pBarCode1D, pBarCodePDF, pBarCodeColor, ppBarCodeData, pfnCallback, pUserData, uStructSize)

Parameters

pBITMAPHANDLE pBitmap

Pointer to the bitmap handle referencing the bitmap that holds the image data.

RECT * prcSearch

Pointer to the rectangle that contains the search area for the barcodes. Pass NULL to search the whole image. If this parameter is NULL and the image does not have a region, the entire image will be searched. If this parameter is NULL and the image does have a region, only the region will be searched.

L_UINT32 ulSearchType

Type of barcode for which to search. You can combine values when appropriate among the same group values, by using a bitwise OR ( | ). Possible values are:

Linear Barcode:

Value Meaning
BARCODE_1D_EAN_13 [0x80000001] To read EAN 13 type.
BARCODE_1D_EAN_8 [0x80000002] To read EAN 8 type.
BARCODE_1D_UPC_A [0x80000004] To read UPC version A type.
BARCODE_1D_UPC_E [0x80000008] To read UPC version E type.
BARCODE_1D_CODE_3_OF_9 [0x80000010] To read Code 3 of 9 (Code 39) type.
BARCODE_1D_CODE_3_OF_9_EXTENDED [0x80040000] To read Code 3 of 9 (Code 39) type with extended characters encoded.
BARCODE_1D_CODE_128 [0x80000020] To read Code 128 type.
BARCODE_1D_CODE_I2_OF_5 [0x80000040] To read Interleaved 2 of 5 type.
BARCODE_1D_CODA_BAR [0x80000080] To read CODABAR type.
BARCODE_1D_UCCEAN_128 [0x80000100] To read UCCEAND 128 type
BARCODE_1D_CODE_93 [0x80000200] To read Code 93 type.
BARCODE_1D_CODE_93_EXTENDED [0x80000201] Code 93 Extended type. Compressed form of Code 39.
BARCODE_1D_EANEXT_5 [0x80000400] To read 5-digit supplemental type.
BARCODE_1D_EANEXT_2 [0x80000800] To read 2-digit supplemental type.
BARCODE_1D_MSI [0x80001000] To read MSI (Modified Plessey) type.
BARCODE_1D_CODE11 [0x80002000] To read Code 11(USD-8) type.
BARCODE_1D_CODE_S25 [0x80004000] To read Standard 2 of 5 (Industrial 2 of 5) type.
BARCODE_1D_RSS14 [0x80008000] GS1 Databar (formerly RSS14) standard and GS1 Databar (formerly RSS14) truncated.
BARCODE_1D_RSS14_LIMITED [0x80010000] GS1 Databar (formerly RSS14) Limited type.
BARCODE_1D_RSS14_EXPANDED [0x80020000] GS1 Databar (formerly RSS14) Expanded type.
BARCODE_1D_READ_ANYTYPE [0x8003FFFF] Enables searching of all linear barcode types.
BARCODE_1D_READ_ANYTYPE_NO_RSS14 [0x80007FFF] Enables searching of all linear barcode types except  GS1 Databar (formerly RSS14) types. Speeds up the read process compared to the  BARCODE_1D_READ_ANYTYPE option.

Patch Code Barcodes:

Value Meaning
BARCODE_1D_PATCH_CODE [0x04000001] To read Patch Code.

Postal barcodes:

Value Meaning
BARCODE_1D_POST_NET [0x04000002] To read Postnet.
BARCODE_1D_PLANET [0x04000004] Planet type.

4 State barcode symbols:

Value Meaning
BARCODE_1D_AUST_POST [0x04000008] Australian Post 4 State type.
BARCODE_1D_RM4SCC [0x04000010] Royal Mail (RM4SCC) 4 State type.
BARCODE_1D_USPS4BC [0x04000080] USPS OneCode 4-State barcode (4BC) type.

GS1 Databar (formerly RSS14) Stacked barcode symbols:

Value Meaning
BARCODE_1D_RSS14_STACKED [0x04000020] GS1 Databar (formerly RSS14) Stacked / Stacked Omni-Directional types.
BARCODE_1D_RSS14_EXP_STACKED [0x04000040] GS1 Databar (formerly RSS14) Expanded Stacked barcode type.

PDF Barcodes:

Value Meaning
BARCODE_PDF417 [0x20002000] To read PDF417 type.

MicroPDF417 Barcodes:

Value Meaning
BARCODE_MICRO_PDF417 [0x20000001] To read MicroPDF417 type.

QR Barcodes:

Value Meaning
BARCODE_QR_CODE [0x08000001] To read QR barcodes.

Data Matrix Barcode:

Value Meaning
BARCODE_DM_READ_SQUARE [0x10000001] To read square Data Matrix symbols.
BARCODE_DM_READ_RECTANGLE [0x10000002] To read rectangular Data Matrix symbols.
BARCODE_DM_READ_SMALL [0x10000004] To read small Data Matrix symbols.

Aztec Barcode:

Value Meaning
BARCODE_AZTEC_CODE [0x21000000] To read Aztec barcodes.

Maxi Barcode:

Value Meaning
BARCODE_MAXI_CODE [0x22000000] To read Maxi barcodes.

MicroQR Barcode:

Value Meaning
BARCODE_MICRO_QR_CODE [0x24000000] To read MicroQR barcodes.

Other barcode symbol:

Value Meaning
BARCODE_1D_PHARMA_CODE [0x04000100] PharmaCode type. Used in the pharmaceutical industry as a packing control system.

L_INT nUnits

Unit of measure. Possible values are:

Value Meaning
BARCODE_SCANLINES_PER_PIXELS [0] The rectangle search area is measured in pixels.
BARCODE_INCHES [1] The rectangle search area is measured in inches. You must multiply the search area by 100. (i.e., to specify 1 inch set this to 100)
BARCODE_MILLIMETERS [2] The rectangle search area is measured in mm.

L_UINT32 ulFlags

Processing options. You can combine values when appropriate, by using a bitwise OR ( | ). The following values are used only when you want to search for linear barcodes. Pass 0 to get the default. Possible values are:

Value Meaning
BARCODE_MARKERS [0x0001] Enables the reading of barcodes that have start and end markers.
BARCODE_BLOCK_SEARCH [0x0002] Search for barcodes by moving up or down through the rectangle until the first character is read or there is no barcode found.
BARCODE_RRESIZESMALL1D [0x0004] Enhance the bars for the small module width symbols. Should be used when reading 1D symbols that have small width per module especially if the image has a low dpi value.
BARCODE_USECOLORS [0x0200] Enables searching for color barcodes. The colors are used as the exact bar and space colors for searching for the barcode.
BARCODE_APPLY_PREPROCESSING [0x04200000] Setting this bit enables image segmentation and advanced image preprocessing during barcode recognition.
BARCODE_DOUBLE_PASS [0x04000000] Setting this bit enables the use of double pass when reading 2D symbols.
BARCODE_DOUBLE_PASS_IF_SUCCESS [0x04100000] Setting this bit forces the use of double pass when reading 2D symbols.
BARCODE_TRY_DISTORTED [0x04400000] Setting this bit enables advanced image preprocessing to attempt to read distorted barcodes. This may slow down the recognition process.
BARCODE_IMAGETYPE_PICTURE [0x08000000] Setting this bit indicates that pBitmap is a picture taken from a camera or a video device; otherwise, pBitmap is a scanned document image.
BARCODE_RETURNCHECK [0x1000] When setting this bit, then the check character will  return in all cases, whether BARCODE1D.bErrorCheck is enabled or not. The default behavior returns the check digit for only BARCODE_1D_EAN_13, BARCODE_1D_EAN_8, BARCODE_1D_UPC_A, and BARCODE_1D_UPC_E.
BARCODE_DONOTRETURNCHECK [0x4000] When setting this bit, then the check character will not return in all cases, whether BARCODE1D.bErrorCheck is enabled or not. The default behavior returns the check digit for only BARCODE_1D_EAN_13, BARCODE_1D_EAN_8, BARCODE_1D_UPC_A, and BARCODE_1D_UPC_E.
BARCODE_CALCULATEBWR [0x8000] When setting this bit, the bar width reduction will be calculated and stored in BarCodeData.nBWR.
BARCODE_RETURNCORRUPT [0x080] Enables the engine to return the area at which an un-readable PDF417 symbol was located.
BARCODE_RETURN_FOUR_POINTS [0x00002000] Enables return of four corners and not bounding rectangle.
BARCODE_HRItoGS1 [0x00004000] Formats an HRI string as GS1 when writing a DM symbol.
BARCODE_GS1toHRI [0x00004001] Formats a GS1 string as HRI when reading a DM symbol.
BARCODE_DM_FORCE_INVERT [0x00000800] Forces the Data Matrix read to search for reversed color symbols even if non-inverted color symbols were found.
BARCODE_DM_FASTFIND_DISABLE [0x00001000] Disables fast find feature when reading Data Matrix symbols. Fast find is automatically disabled when reading small symbols.
BARCODE_PDF_READ_RETURN_PARTIAL [0x01000000] Returns PDF417 data even if ECC does not succeed.
BARCODE_PDF_READ_MODE_0 [0x0000] Basic Channel Mode :No transmission of symbology ID, No escape doubling, Macro PDF is illegal. ECI is illegal, Reserved code words are illegal. Used with PDF417 and MicroPDF417.
BARCODE_PDF_READ_MODE_1 [0x1000] Extended Channel Mode. Transmit] L1 symbology ID. Escape doubling. Macro PDF is transmitted. ECI is transmitted. Reserved code words are transmitted. Used with PDF417 and MicroPDF417.
BARCODE_PDF_READ_MODE_2 [0x4000] Basic Channel Mode. Transmit ] L2 symbology ID. No escape doubling. Macro PDF is illegal. ECI is illegal. Reserved code words are illegal. Used with PDF417 and MicroPDF417.
BARCODE_PDF_READ_MODE_3_BASIC [0x5000] Basic Channel Mode. Transmit ] L0 symbology ID. No escape doubling. Macro PDF is illegal. ECI is illegal. Reserved code words are illegal. Used with PDF417 and MicroPDF417.
BARCODE_PDF_READ_MODE_3_EXTENDED [0x8000] Extended Channel Mode. Transmit ] L0 symbology ID. Escape doubling. Macro PDF is transmitted. ECI is transmitted in GLI format. Reserved code words transmitted. Used with PDF417 and MicroPDF417.
BARCODE_MICRO_PDF_READ_BASIC [0x9000] Code 128 Emulation Basic Channel Mode. Transmit ] L0, ] L3, ] L4, or ] L5 symbology ID. No escape doubling. Macro PDF is illegal. ECI is illegal. Reserved code words are illegal. Only used with MicroPDF417.
BARCODE_MICRO_PDF_READ_EXTENDED [0xC000] Code 128 Emulation Extended Channel Mode. Transmit ] L0, ] L3, ] L4, or ] L5 symbology ID. Escape doubling. Macro PDF is transmitted. ECI is transmitted in GLI format. Reserved code words transmitted. Only used with MicroPDF417.
BARCODE_PDF_READ_MACRO_OPTION_0 [0x00010000] Enables the return of the optional macro File Name field.
BARCODE_PDF_READ_MACRO_OPTION_1 [0x00020000] Enables the return of the optional macro Segment Count field.
BARCODE_PDF_READ_MACRO_OPTION_2 [0x00040000] Enables the return of the optional macro Time Stamp field.
BARCODE_PDF_READ_MACRO_OPTION_3 [0x00080000] Enables the return of the optional macro Sender field.
BARCODE_PDF_READ_MACRO_OPTION_4 [0x00100000] Enables the return of the optional macro Addressee field.
BARCODE_PDF_READ_MACRO_OPTION_5 [0x00200000] Enables the return of the optional macro File Size field.
BARCODE_PDF_READ_MACRO_OPTION_6 [0x00400000] Enables the return of the optional macro Checksum field.
BARCODE_PDF_READ_MACRO_OPTION_79AZ [0x00800000] Enables the return of all optional macro fields 7 to 9 and A to Z.
BARCODE_PDF_FASTREAD [0x02000000] Enables fast find feature when reading PDF417 symbols.
BARCODE_PDF_NO_INDICATORS_TRIAL [0x10000000] Enables reading PDF417 symbols without indicators.
BARCODE_MICRO_PDF_READ_CCA3COLS [0x20000000] Enables reading MicroPDF417 CCA 3 Columns symbols.

L_INT nMultipleMaxCount

Specifies the maximum number of barcodes to search. Pass 0 to read all barcodes in a specified search area.

pBARCODE1D pBarCode1D

Pointer to the BARCODE1D structure. Pass NULL to use the default structure or if you don't want to search for linear barcodes.

pBARCODEREADPDF pBarCodePDF

Pointer to the BARCODEREADPDF structure. Pass NULL to use the default structure or if you don't want to search for PDF barcodes.

pBARCODECOLOR pBarCodeColor

Pointer to the BARCODECOLOR structure. Pass NULL to search for barcode using the default colors.

pBARCODEDATA * ppBarCodeData

Address of the pointer to the BARCODEDATA structure, the function will automatically allocate an array of BARCODEDATA structures using the total number of barcodes found.

BARCODEREADCALLBACK pfnCallback

Optional callback function to be called when a barcode symbolgoy is decoded correctly. If you do not provide callback function, use NULL as the value of this parameter. If you do provide callback function, use the function pointer as the value of this parameter. The callback function must adhere to the function prototype described in BARCODEREADCALLBACK Function.

L_VOID * pUserData

Void pointer that you can use to pass one or more additional parameters that the help 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 *. 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.

L_UINT uStructSize

Size of BARCODEDATA structure in bytes. Use the sizeof operator to calculate this value.

Returns

Value Meaning
SUCCESS The function was successful.
< 1 An error occurred. Refer to Return Codes.

Comments

This function supports all bitmaps currently supported by LEADTOOLS.

Use this function to recognize barcode data.

NOTE: RSS14 has been renamed as GS1 Databar. All references to RSS 14 now refer to GS1 Databar.

To determine if a barcode element is duplicated or not, use L_BarCodeIsDuplicated function. If the barcode is duplicated, you can get it using L_BarCodeGetDuplicated and to get the next duplicated barcode use L_BarCodeGetNextDuplicated.

If you know the index of a duplicated barcode, you can get the first duplicate of that barcode using L_BarCodeGetFirstDuplicated.

Since the function allocates storage to hold a Barcode array, you must free this storage by calling L_BarCodeFree.

When the BARCODE_USECOLORS flag is set this function will use the pBarCodeColor parameter. Otherwise, the function will ignore it and use the default colors of black for bars and white for spaces.

Using colors does not apply for 1-bit per pixel images.

The BARCODE_USECOLORS is used with all barcode kinds.

The BARCODE_RETURNCHECK flag is used only when reading linear barcodes.

The smallest Data Matrix symbol size is 40 pixels by 40 pixels. It can be read using BARCODE_DM_READ_SMALL since this enables the reading of Data Matrix symbols that are between 20 to 40 pixels in size.

The Linear barcodes are not supported in UNICODE.

When reading barcodes from poor quality images, use BARCODE_APPLY_PREPROCESSING to enable image segmentation and advanced image preprocessing during barcode recognition.

When reading 2D barcodes, LEADTOOLS can perform internal auto preprocessing using BARCODE_DOUBLE_PASS on the image and try again if the engine cannot detect the barcode required. But this may take extra processing which will increase the barcode detection time.  Hence, it is not recommended to always have it enabled except in certain situations:

The LEADTOOLS Barcode Demo leaves the option disabled by default.

When calling the L_BarCodeRead function with the BARCODE_RETURN_FOUR_POINTS flag set, the BARCODEDATA.rcBarLocation member will be updated with the coordinates of the four corners of the barcode rather than the coordinates of the bounding rectangle. These coordinates are encoded values and must be decoded before they can be used. The following example shows how to decode the four-point corner values:

POINT p1, p2, p3, p4; 
int nStartX = BarCodeData.rcBarLocation.left; 
int nStartY = BarCodeData.rcBarLocation.top; 
int nWidth = BarCodeData.rcBarLocation.right - nStartX; 
int nHeight = BarCodeData.rcBarLocation.bottom - nStartY; 
p1.x = (nStartX & 0xffff); 
p1.y = (nStartX >> 16); 
p2.x = (nStartY & 0xffff); 
p2.y = (nStartY >> 16); 
p3.x = (nWidth & 0xffff); 
p3.y = (nWidth >> 16); 
p4.x = (nHeight & 0xffff); 
p4.y = (nHeight >> 16); 

Reading Linear Barcodes (1D)

A barcode is composed of start mark, data, and end mark. Reading barcodes from left to right (passing BARCODE_DIR_LEFT_TO_RIGHT value to the nDirection member) or from right to left (passing BARCODE_DIR_RIGHT_TO_LEFT value to the nDirection member) will produce the same result in most cases, because the barcode reader engine recognizes the start and end marks, and handles the data accordingly.

For example, if BARCODE_DIR_LEFT_TO_RIGHT is passed and the user reads barcodes from left to right (the barcode is not rotated), the engine will recognize the start mark first, then the data, and finally the end mark.

But if the user reads barcodes from right to left (the barcode is rotated 180 degrees), the engine will first recognize the end mark, then read the (reverse-order) data, and then recognize the start mark. In this case, the engine will flip the data to normal (start/data/end) order.

Sample for BARCODE_RETURN_FOUR_POINTS

pBARCODEDATA barData; 
int nStartX, nStartY, nWidth, nHeight; 
POINT p1, p2, p3, p4; 
// Call L_BarCodeRead(&); 
nStartX = barData[0].rcBarLocation.left; 
nStartY = barData[0].rcBarLocation.top; 
nWidth = barData[0].rcBarLocation.right - nStartX; 
nHeight = barData[0].rcBarLocation.bottom - nStartY; 
p1.x = (nStartX & 0xffff); 
p1.y = (nStartX >> 16); 
p2.x = (nStartY & 0xffff); 
p2.y = (nStartY >> 16); 
p3.x = (nWidth & 0xffff); 
p3.y = (nWidth >> 16); 
p4.x = (nHeight & 0xffff); 
p4.y = (nHeight >> 16); 

For a table containing information useful when writing 1D barcode data, refer to Writing Linear 1D Barcodes.

QR stores up to 2335 ASCII characters in one barcode symbol.

DataMatrix stores up to 2218 ASCII characters in one barcode symbol.

PDF417 stores up to 1,850 ASCII characters in one barcode symbol.

MicroPDF stores up to 366 ASCII characters in one barcode symbol.

Required DLLs and Libraries

Platforms

Win32, x64, Linux.

See Also

Functions

Topics

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

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