Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 "ZXBitArray.h"
  17. #import "ZXEAN8Reader.h"
  18. #import "ZXIntArray.h"
  19. @interface ZXEAN8Reader ()
  20. @property (nonatomic, strong, readonly) ZXIntArray *decodeMiddleCounters;
  21. @end
  22. @implementation ZXEAN8Reader
  23. - (id)init {
  24. if (self = [super init]) {
  25. _decodeMiddleCounters = [[ZXIntArray alloc] initWithLength:4];
  26. }
  27. return self;
  28. }
  29. - (int)decodeMiddle:(ZXBitArray *)row startRange:(NSRange)startRange result:(NSMutableString *)result error:(NSError **)error {
  30. ZXIntArray *counters = self.decodeMiddleCounters;
  31. [counters clear];
  32. int end = row.size;
  33. int rowOffset = (int)NSMaxRange(startRange);
  34. for (int x = 0; x < 4 && rowOffset < end; x++) {
  35. int bestMatch = [ZXUPCEANReader decodeDigit:row counters:counters rowOffset:rowOffset patternType:ZX_UPC_EAN_PATTERNS_L_PATTERNS error:error];
  36. if (bestMatch == -1) {
  37. return -1;
  38. }
  39. [result appendFormat:@"%C", (unichar)('0' + bestMatch)];
  40. rowOffset += [counters sum];
  41. }
  42. NSRange middleRange = [[self class] findGuardPattern:row rowOffset:rowOffset whiteFirst:YES pattern:ZX_UPC_EAN_MIDDLE_PATTERN patternLen:ZX_UPC_EAN_MIDDLE_PATTERN_LEN error:error];
  43. if (middleRange.location == NSNotFound) {
  44. return -1;
  45. }
  46. rowOffset = (int)NSMaxRange(middleRange);
  47. for (int x = 0; x < 4 && rowOffset < end; x++) {
  48. int bestMatch = [ZXUPCEANReader decodeDigit:row counters:counters rowOffset:rowOffset patternType:ZX_UPC_EAN_PATTERNS_L_PATTERNS error:error];
  49. if (bestMatch == -1) {
  50. return -1;
  51. }
  52. [result appendFormat:@"%C", (unichar)('0' + bestMatch)];
  53. rowOffset += [counters sum];
  54. }
  55. return rowOffset;
  56. }
  57. - (ZXBarcodeFormat)barcodeFormat {
  58. return kBarcodeFormatEan8;
  59. }
  60. @end