ZXUPCEANReader.h
4.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
* Copyright 2012 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#import "ZXBarcodeFormat.h"
#import "ZXOneDReader.h"
typedef enum {
ZX_UPC_EAN_PATTERNS_L_PATTERNS = 0,
ZX_UPC_EAN_PATTERNS_L_AND_G_PATTERNS
} ZX_UPC_EAN_PATTERNS;
extern const int ZX_UPC_EAN_START_END_PATTERN_LEN;
extern const int ZX_UPC_EAN_START_END_PATTERN[];
extern const int ZX_UPC_EAN_MIDDLE_PATTERN_LEN;
extern const int ZX_UPC_EAN_MIDDLE_PATTERN[];
extern const int ZX_UPC_EAN_L_PATTERNS_LEN;
extern const int ZX_UPC_EAN_L_PATTERNS_SUB_LEN;
extern const int ZX_UPC_EAN_L_PATTERNS[][4];
extern const int ZX_UPC_EAN_L_AND_G_PATTERNS_LEN;
extern const int ZX_UPC_EAN_L_AND_G_PATTERNS_SUB_LEN;
extern const int ZX_UPC_EAN_L_AND_G_PATTERNS[][4];
@class ZXDecodeHints, ZXEANManufacturerOrgSupport, ZXIntArray, ZXResult, ZXUPCEANExtensionSupport;
/**
* Encapsulates functionality and implementation that is common to UPC and EAN families
* of one-dimensional barcodes.
*/
@interface ZXUPCEANReader : ZXOneDReader
+ (NSRange)findStartGuardPattern:(ZXBitArray *)row error:(NSError **)error;
/**
* Like decodeRow:row:hints:, but allows caller to inform method about where the UPC/EAN start pattern is
* found. This allows this to be computed once and reused across many implementations.
*/
- (ZXResult *)decodeRow:(int)rowNumber row:(ZXBitArray *)row startGuardRange:(NSRange)startGuardRange hints:(ZXDecodeHints *)hints error:(NSError **)error;
/**
* @return checkStandardUPCEANChecksum:
*/
- (BOOL)checkChecksum:(NSString *)s error:(NSError **)error;
/**
* Computes the UPC/EAN checksum on a string of digits, and reports
* whether the checksum is correct or not.
*
* @param s string of digits to check
* @return YES iff string of digits passes the UPC/EAN checksum algorithm
* @return NO if the string does not contain only digits
*/
+ (BOOL)checkStandardUPCEANChecksum:(NSString *)s;
- (NSRange)decodeEnd:(ZXBitArray *)row endStart:(int)endStart error:(NSError **)error;
+ (NSRange)findGuardPattern:(ZXBitArray *)row rowOffset:(int)rowOffset whiteFirst:(BOOL)whiteFirst pattern:(const int[])pattern patternLen:(int)patternLen error:(NSError **)error;
/**
* @param row row of black/white values to search
* @param rowOffset position to start search
* @param whiteFirst if true, indicates that the pattern specifies white/black/white/...
* pixel counts, otherwise, it is interpreted as black/white/black/...
* @param pattern pattern of counts of number of black and white pixels that are being
* searched for as a pattern
* @param counters array of counters, as long as pattern, to re-use
* @return start/end horizontal offset of guard pattern, as an array of two ints
*/
+ (NSRange)findGuardPattern:(ZXBitArray *)row rowOffset:(int)rowOffset whiteFirst:(BOOL)whiteFirst pattern:(const int[])pattern patternLen:(int)patternLen counters:(ZXIntArray *)counters error:(NSError **)error;
/**
* Attempts to decode a single UPC/EAN-encoded digit.
*
* @param row row of black/white values to decode
* @param counters the counts of runs of observed black/white/black/... values
* @param rowOffset horizontal offset to start decoding from
* @param patternType the set of patterns to use to decode -- sometimes different encodings
* for the digits 0-9 are used, and this indicates the encodings for 0 to 9 that should
* be used
* @return horizontal offset of first pixel beyond the decoded digit
* @return -1 if digit cannot be decoded
*/
+ (int)decodeDigit:(ZXBitArray *)row counters:(ZXIntArray *)counters rowOffset:(int)rowOffset patternType:(ZX_UPC_EAN_PATTERNS)patternType error:(NSError **)error;
/**
* Get the format of this decoder.
*
* @return The 1D format.
*/
- (ZXBarcodeFormat)barcodeFormat;
/**
* Subclasses override this to decode the portion of a barcode between the start
* and end guard patterns.
*
* @param row row of black/white values to search
* @param startRange start/end offset of start guard pattern
* @param result NSMutableString to append decoded chars to
* @return horizontal offset of first pixel after the "middle" that was decoded
* @return -1 if decoding could not complete successfully
*/
- (int)decodeMiddle:(ZXBitArray *)row startRange:(NSRange)startRange result:(NSMutableString *)result error:(NSError **)error;
@end