You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ZXUPCEANExtensionSupport.m 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 "ZXUPCEANExtensionSupport.h"
  17. #import "ZXUPCEANExtension2Support.h"
  18. #import "ZXUPCEANExtension5Support.h"
  19. #import "ZXUPCEANReader.h"
  20. const int ZX_UPCEAN_EXTENSION_START_PATTERN[] = {1,1,2};
  21. @interface ZXUPCEANExtensionSupport ()
  22. @property (nonatomic, strong, readonly) ZXUPCEANExtension2Support *twoSupport;
  23. @property (nonatomic, strong, readonly) ZXUPCEANExtension5Support *fiveSupport;
  24. @end
  25. @implementation ZXUPCEANExtensionSupport
  26. - (id)init {
  27. if (self = [super init]) {
  28. _twoSupport = [[ZXUPCEANExtension2Support alloc] init];
  29. _fiveSupport = [[ZXUPCEANExtension5Support alloc] init];
  30. }
  31. return self;
  32. }
  33. - (ZXResult *)decodeRow:(int)rowNumber row:(ZXBitArray *)row rowOffset:(int)rowOffset error:(NSError **)error {
  34. NSRange extensionStartRange = [ZXUPCEANReader findGuardPattern:row
  35. rowOffset:rowOffset
  36. whiteFirst:NO
  37. pattern:ZX_UPCEAN_EXTENSION_START_PATTERN
  38. patternLen:sizeof(ZX_UPCEAN_EXTENSION_START_PATTERN)/sizeof(int)
  39. error:error];
  40. if (extensionStartRange.location == NSNotFound) {
  41. return nil;
  42. }
  43. ZXResult *result = [self.fiveSupport decodeRow:rowNumber row:row extensionStartRange:extensionStartRange error:error];
  44. if (!result) {
  45. result = [self.twoSupport decodeRow:rowNumber row:row extensionStartRange:extensionStartRange error:error];
  46. }
  47. return result;
  48. }
  49. @end