Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

ZXUPCEANReader.h 4.7KB

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