Leptonica  1.83.1
Image processing and image analysis suite
bardecode.c File Reference
#include <string.h>
#include "allheaders.h"
#include "readbarcode.h"

Go to the source code of this file.

Macros

#define DEBUG_CODES   0
 

Functions

static l_int32 barcodeFindFormat (char *barstr)
 
static l_int32 barcodeVerifyFormat (char *barstr, l_int32 format, l_int32 *pvalid, l_int32 *preverse)
 
static char * barcodeDecode2of5 (char *barstr, l_int32 debugflag)
 
static char * barcodeDecodeI2of5 (char *barstr, l_int32 debugflag)
 
static char * barcodeDecode93 (char *barstr, l_int32 debugflag)
 
static char * barcodeDecode39 (char *barstr, l_int32 debugflag)
 
static char * barcodeDecodeCodabar (char *barstr, l_int32 debugflag)
 
static char * barcodeDecodeUpca (char *barstr, l_int32 debugflag)
 
static char * barcodeDecodeEan13 (char *barstr, l_int32 first, l_int32 debugflag)
 
char * barcodeDispatchDecoder (char *barstr, l_int32 format, l_int32 debugflag)
 
l_int32 barcodeFormatIsSupported (l_int32 format)
 

Detailed Description


     Dispatcher
         char            *barcodeDispatchDecoder()

     Format Determination
         static l_int32   barcodeFindFormat()
         l_int32          barcodeFormatIsSupported()
         static l_int32   barcodeVerifyFormat()

     Decode 2 of 5
         static char     *barcodeDecode2of5()

     Decode Interleaved 2 of 5
         static char     *barcodeDecodeI2of5()

     Decode Code 93
         static char     *barcodeDecode93()

     Decode Code 39
         static char     *barcodeDecode39()

     Decode Codabar
         static char     *barcodeDecodeCodabar()

     Decode UPC-A
         static char     *barcodeDecodeUpca()

     Decode EAN 13
         static char     *barcodeDecodeEan13()

Definition in file bardecode.c.

Function Documentation

◆ barcodeDecode2of5()

static char * barcodeDecode2of5 ( char *  barstr,
l_int32  debugflag 
)
static

barcodeDecode2of5()

Parameters
[in]barstrof widths, in set {1, 2}
[in]debugflag
Returns
data string of digits, or NULL if none found or on error
Notes:
     (1) Ref: http://en.wikipedia.org/wiki/Two-out-of-five_code (Note:
                the codes given here are wrong!)
              http://morovia.com/education/symbology/code25.asp
     (2) This is a very low density encoding for the 10 digits.
         Each digit is encoded with 5 black bars, of which 2 are wide
         and 3 are narrow.  No information is carried in the spaces
         between the bars, which are all equal in width, represented by
         a "1" in our encoding.
     (3) The mapping from the sequence of five bar widths to the
         digit is identical to the mapping used by the interleaved
         2 of 5 code.  The start code is 21211, representing two
         wide bars and a narrow bar, and the interleaved "1" spaces
         are explicit.  The stop code is 21112.  For all codes
         (including start and stop), the trailing space "1" is
         implicit -- there is no reason to represent it in the
         Code2of5[] array.

Definition at line 372 of file bardecode.c.

References barcodeVerifyFormat(), lept_stderr(), stringNew(), and stringReverse().

Referenced by barcodeDispatchDecoder().

◆ barcodeDecode39()

static char * barcodeDecode39 ( char *  barstr,
l_int32  debugflag 
)
static

barcodeDecode39()

Parameters
[in]barstrof widths, in set {1, 2}
[in]debugflag
Returns
data string of digits, or NULL if none found or on error
Notes:
     (1) Ref:  http://en.wikipedia.org/wiki/Code39
               http://morovia.com/education/symbology/code39.asp
     (2) Each symbol has 5 black and 4 white bars.
         The start and stop codes are 121121211 (the asterisk)
     (3) This decoder was contributed by Roger Hyde.

Definition at line 660 of file bardecode.c.

References barcodeVerifyFormat(), lept_stderr(), stringNew(), and stringReverse().

Referenced by barcodeDispatchDecoder().

◆ barcodeDecode93()

static char * barcodeDecode93 ( char *  barstr,
l_int32  debugflag 
)
static

barcodeDecode93()

Parameters
[in]barstrof widths, in set {1, 2, 3, 4}
[in]debugflag
Returns
data string of digits, or NULL if none found or on error
Notes:
     (1) Ref:  http://en.wikipedia.org/wiki/Code93
               http://morovia.com/education/symbology/code93.asp
     (2) Each symbol has 3 black and 3 white bars.
         The start and stop codes are 111141; the stop code then is
         terminated with a final (1) bar.
     (3) The last two codes are check codes.  We are checking them
         for correctness, and issuing a warning on failure.  Should
         probably not return any data on failure.

Definition at line 545 of file bardecode.c.

References barcodeVerifyFormat(), lept_stderr(), stringNew(), and stringReverse().

Referenced by barcodeDispatchDecoder().

◆ barcodeDecodeCodabar()

static char * barcodeDecodeCodabar ( char *  barstr,
l_int32  debugflag 
)
static

barcodeDecodeCodabar()

Parameters
[in]barstrof widths, in set {1, 2}
[in]debugflag
Returns
data string of digits, or NULL if none found or on error
Notes:
     (1) Ref:  http://en.wikipedia.org/wiki/Codabar
               http://morovia.com/education/symbology/codabar.asp
     (2) Each symbol has 4 black and 3 white bars.  They represent the
         10 digits, and optionally 6 other characters.  The start and
         stop codes can be any of four (typically denoted A,B,C,D).

Definition at line 741 of file bardecode.c.

References barcodeVerifyFormat(), lept_stderr(), stringNew(), and stringReverse().

Referenced by barcodeDispatchDecoder().

◆ barcodeDecodeEan13()

static char * barcodeDecodeEan13 ( char *  barstr,
l_int32  first,
l_int32  debugflag 
)
static

barcodeDecodeEan13()

Parameters
[in]barstrof widths, in set {1, 2, 3, 4}
[in]firstfirst digit: 0 - 9
[in]debugflag
Returns
data string of digits, or NULL if none found or on error
Notes:
     (1) Ref:  http://en.wikipedia.org/wiki/UniversalProductCode
               http://morovia.com/education/symbology/ean-13.asp
     (2) The encoding is essentially the same as UPC-A, except
         there are 13 digits in total, of which 12 are encoded
         by bars (as with UPC-A) and the 13th is a leading digit
         that determines the encoding of the next 6 digits,
         selecting each digit from one of two tables.
         encoded in the bars (as with UPC-A).  If the first digit
         is 0, the encoding is identical to UPC-A.
     (3) As with UPC-A, the last digit is a check digit.
     (4) For now, we assume the first digit is input to this function.
         Eventually, we will read it by pattern matching.

   TODO: fix this for multiple tables, depending on the value of first

Definition at line 942 of file bardecode.c.

References barcodeVerifyFormat(), lept_stderr(), stringNew(), and stringReverse().

Referenced by barcodeDispatchDecoder().

◆ barcodeDecodeI2of5()

static char * barcodeDecodeI2of5 ( char *  barstr,
l_int32  debugflag 
)
static

barcodeDecodeI2of5()

Parameters
[in]barstrof widths, in set {1, 2}
[in]debugflag
Returns
data string of digits, or NULL if none found or on error
Notes:
     (1) Ref: http://en.wikipedia.org/wiki/Interleaved_2_of_5
     (2) This always encodes an even number of digits.
         The start code is 1111; the stop code is 211.

Definition at line 450 of file bardecode.c.

References barcodeVerifyFormat(), lept_stderr(), stringNew(), and stringReverse().

Referenced by barcodeDispatchDecoder().

◆ barcodeDecodeUpca()

static char * barcodeDecodeUpca ( char *  barstr,
l_int32  debugflag 
)
static

barcodeDecodeUpca()

Parameters
[in]barstrof widths, in set {1, 2, 3, 4}
[in]debugflag
Returns
data string of digits, or NULL if none found or on error
Notes:
     (1) Ref:  http://en.wikipedia.org/wiki/UniversalProductCode
               http://morovia.com/education/symbology/upc-a.asp
     (2) Each symbol has 2 black and 2 white bars, and encodes a digit.
         The start and stop codes are 111 and 111.  There are a total of
         30 black bars, encoding 12 digits in two sets of 6, with
         2 black bars separating the sets.
     (3) The last digit is a check digit.  We check for correctness, and
         issue a warning on failure.  Should probably not return any
         data on failure.

Definition at line 827 of file bardecode.c.

References barcodeVerifyFormat(), lept_stderr(), stringNew(), and stringReverse().

Referenced by barcodeDispatchDecoder().

◆ barcodeDispatchDecoder()

char* barcodeDispatchDecoder ( char *  barstr,
l_int32  format,
l_int32  debugflag 
)

barcodeDispatchDecoder()

Parameters
[in]barstrstring of integers in set {1,2,3,4} of bar widths
[in]formatL_BF_ANY, L_BF_CODEI2OF5, L_BF_CODE93, ...
[in]debugflaguse 1 to generate debug output
Returns
data string of decoded barcode data, or NULL on error

Definition at line 97 of file bardecode.c.

References barcodeDecode2of5(), barcodeDecode39(), barcodeDecode93(), barcodeDecodeCodabar(), barcodeDecodeEan13(), barcodeDecodeI2of5(), barcodeDecodeUpca(), and barcodeFindFormat().

◆ barcodeFindFormat()

static l_int32 barcodeFindFormat ( char *  barstr)
static

barcodeFindFormat()

Parameters
[in]barstrof barcode widths, in set {1,2,3,4}
Returns
format for barcode, or L_BF_UNKNOWN if not recognized

Definition at line 142 of file bardecode.c.

References barcodeVerifyFormat().

Referenced by barcodeDispatchDecoder().

◆ barcodeFormatIsSupported()

l_int32 barcodeFormatIsSupported ( l_int32  format)

barcodeFormatIsSupported()

Parameters
[in]format
Returns
1 if format is one of those supported; 0 otherwise

Definition at line 170 of file bardecode.c.

Referenced by pixProcessBarcodes(), and pixReadBarcodes().

◆ barcodeVerifyFormat()

static l_int32 barcodeVerifyFormat ( char *  barstr,
l_int32  format,
l_int32 *  pvalid,
l_int32 *  preverse 
)
static

barcodeVerifyFormat()

Parameters
[in]barstrof barcode widths, in set {1,2,3,4}
[in]formatL_BF_CODEI2OF5, L_BF_CODE93, ...
[out]pvalid0 if not valid, 1 and 2 if valid
[out]preverse[optional] 1 if reversed; 0 otherwise
Returns
0 if OK, 1 on error
Notes:
     (1) If valid == 1, the barcode is of the given format in the
         forward order; if valid == 2, it is backwards.
     (2) If the barcode needs to be reversed to read it, and &reverse
         is provided, a 1 is put into reverse.
     (3) Require at least 12 data bits, in addition to format identifiers.
         (TODO) If the barcode has a fixed length, this should be used
         explicitly, as is done for L_BF_UPCA and L_BF_EAN13.
     (4) (TODO) Add to this as more formats are supported.

Definition at line 204 of file bardecode.c.

References stringReverse().

Referenced by barcodeDecode2of5(), barcodeDecode39(), barcodeDecode93(), barcodeDecodeCodabar(), barcodeDecodeEan13(), barcodeDecodeI2of5(), barcodeDecodeUpca(), and barcodeFindFormat().