Leptonica 1.54
Файл src/bardecode.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "allheaders.h"
#include "readbarcode.h"

Макросы

#define DEBUG_CODES   0

Функции

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)

Макросы

#define DEBUG_CODES   0

Функции

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.

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.

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.

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).

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

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.

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.

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

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

l_int32 barcodeFormatIsSupported ( l_int32  format)

barcodeFormatIsSupported()

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

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.