Leptonica 1.68
C Image Processing Library

bardecode.c File Reference

Decode barcodes after sequence of widths is found. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "allheaders.h"
#include "readbarcode.h"

Go to the source code of this file.

Defines

#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

Decode barcodes after sequence of widths is found.

    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.


Define Documentation

#define DEBUG_CODES   0

Definition at line 69 of file bardecode.c.


Function Documentation

static l_int32 barcodeFindFormat ( char *  barstr) [static]

barcodeFindFormat()

Input: barstr (of barcode widths, in set {1,2,3,4}) Return: format (for barcode), or L_BF_UNKNOWN if not recognized

Definition at line 132 of file bardecode.c.

References barcodeVerifyFormat(), ERROR_INT, L_BF_UNKNOWN, L_INFO_STRING, NULL, NumSupportedBarcodeFormats, PROCNAME, SupportedBarcodeFormat, and SupportedBarcodeFormatName.

Referenced by barcodeDispatchDecoder().

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

barcodeVerifyFormat()

Input: barstr (of barcode widths, in set {1,2,3,4}) format (L_BF_CODEI2OF5, L_BF_CODE93, ...) &valid (<return> 0 if not valid, 1 and 2 if valid) &reverse (<optional return>=""> 1 if reversed; 0 otherwise) Return: 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 . (3) Add to this as more formats are supported.

Definition at line 191 of file bardecode.c.

References C25_START, C25_STOP, C39_START, C39_STOP, C93_START, C93_STOP, CI25_START, CI25_STOP, Codabar, Code2of5, Code39, Code93, CodeI2of5, ERROR_INT, FREE, L_BF_CODABAR, L_BF_CODE2OF5, L_BF_CODE39, L_BF_CODE93, L_BF_CODEI2OF5, L_BF_EAN13, L_BF_UPCA, PROCNAME, stringReverse(), Upca, UPCA_MID, UPCA_START, and UPCA_STOP.

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

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

barcodeDecode2of5()

Input: barstr (of widths, in set {1, 2}) debugflag Return: 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 349 of file bardecode.c.

References barcodeVerifyFormat(), CALLOC, Code2of5, L_Bytea::data, ERROR_PTR, FALSE, FREE, L_BF_CODE2OF5, NULL, PROCNAME, stringNew(), stringReverse(), and TRUE.

Referenced by barcodeDispatchDecoder().

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

barcodeDecodeI2of5()

Input: barstr (of widths, in set {1, 2}) debugflag Return: 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 425 of file bardecode.c.

References barcodeVerifyFormat(), CALLOC, CodeI2of5, L_Bytea::data, ERROR_PTR, FALSE, FREE, L_BF_CODEI2OF5, NULL, PROCNAME, stringNew(), stringReverse(), and TRUE.

Referenced by barcodeDispatchDecoder().

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

barcodeDecode93()

Input: barstr (of widths, in set {1, 2, 3, 4}) debugflag Return: 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 518 of file bardecode.c.

References barcodeVerifyFormat(), C93_START, CALLOC, Code93, Code93Val, L_Bytea::data, ERROR_PTR, FALSE, FREE, L_BF_CODE93, L_WARNING, NULL, PROCNAME, stringNew(), stringReverse(), and TRUE.

Referenced by barcodeDispatchDecoder().

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

barcodeDecode39()

Input: barstr (of widths, in set {1, 2}) debugflag Return: 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 631 of file bardecode.c.

References barcodeVerifyFormat(), C39_START, CALLOC, Code39, Code39Val, L_Bytea::data, ERROR_PTR, FALSE, FREE, L_BF_CODE39, NULL, PROCNAME, stringNew(), stringReverse(), and TRUE.

Referenced by barcodeDispatchDecoder().

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

barcodeDecodeCodabar()

Input: barstr (of widths, in set {1, 2}) debugflag Return: 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 710 of file bardecode.c.

References barcodeVerifyFormat(), CALLOC, Codabar, CodabarVal, L_Bytea::data, ERROR_PTR, FALSE, FREE, L_BF_CODABAR, NULL, PROCNAME, stringNew(), stringReverse(), and TRUE.

Referenced by barcodeDispatchDecoder().

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

barcodeDecodeUpca()

Input: barstr (of widths, in set {1, 2, 3, 4}) debugflag Return: 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 794 of file bardecode.c.

References barcodeVerifyFormat(), CALLOC, L_Bytea::data, ERROR_PTR, FALSE, FREE, L_BF_UPCA, L_WARNING, NULL, PROCNAME, stringNew(), stringReverse(), TRUE, and Upca.

Referenced by barcodeDispatchDecoder().

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

barcodeDecodeEan13()

Input: barstr (of widths, in set {1, 2, 3, 4}) first (first digit: 0 - 9) debugflag Return: 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

Definition at line 909 of file bardecode.c.

References barcodeVerifyFormat(), CALLOC, L_Bytea::data, ERROR_PTR, FALSE, FREE, L_BF_UPCA, L_WARNING, NULL, PROCNAME, stringNew(), stringReverse(), TRUE, and Upca.

Referenced by barcodeDispatchDecoder().

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

barcodeDispatchDecoder()

Input: barstr (string of integers in set {1,2,3,4} of bar widths) format (L_BF_ANY, L_BF_CODEI2OF5, L_BF_CODE93, ...) debugflag (use 1 to generate debug output) Return: data (string of decoded barcode data), or null on error

Definition at line 85 of file bardecode.c.

References barcodeDecode2of5(), barcodeDecode39(), barcodeDecode93(), barcodeDecodeCodabar(), barcodeDecodeEan13(), barcodeDecodeI2of5(), barcodeDecodeUpca(), barcodeFindFormat(), L_Bytea::data, ERROR_PTR, FALSE, L_BF_ANY, L_BF_CODABAR, L_BF_CODE2OF5, L_BF_CODE39, L_BF_CODE93, L_BF_CODEI2OF5, L_BF_EAN13, L_BF_UPCA, NULL, and PROCNAME.

Referenced by pixReadBarcodes().

l_int32 barcodeFormatIsSupported ( l_int32  format)

barcodeFormatIsSupported()

Input: format Return: 1 if format is one of those supported; 0 otherwise

Definition at line 162 of file bardecode.c.

References NumSupportedBarcodeFormats, and SupportedBarcodeFormat.

Referenced by pixProcessBarcodes(), and pixReadBarcodes().

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines