您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ZXAztecReader.m 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 "ZXAztecDecoder.h"
  17. #import "ZXAztecDetector.h"
  18. #import "ZXAztecDetectorResult.h"
  19. #import "ZXAztecReader.h"
  20. #import "ZXBinaryBitmap.h"
  21. #import "ZXDecodeHints.h"
  22. #import "ZXDecoderResult.h"
  23. #import "ZXReader.h"
  24. #import "ZXResult.h"
  25. #import "ZXResultPointCallback.h"
  26. @implementation ZXAztecReader
  27. - (ZXResult *)decode:(ZXBinaryBitmap *)image error:(NSError **)error {
  28. return [self decode:image hints:nil error:error];
  29. }
  30. - (ZXResult *)decode:(ZXBinaryBitmap *)image hints:(ZXDecodeHints *)hints error:(NSError **)error {
  31. ZXBitMatrix *matrix = [image blackMatrixWithError:error];
  32. if (!matrix) {
  33. return nil;
  34. }
  35. ZXAztecDetector *detector = [[ZXAztecDetector alloc] initWithImage:matrix];
  36. NSArray *points = nil;
  37. ZXDecoderResult *decoderResult = nil;
  38. ZXAztecDetectorResult *detectorResult = [detector detectWithMirror:NO error:error];
  39. if (detectorResult) {
  40. points = detectorResult.points;
  41. decoderResult = [[[ZXAztecDecoder alloc] init] decode:detectorResult error:error];
  42. }
  43. if (decoderResult == nil) {
  44. detectorResult = [detector detectWithMirror:YES error:nil];
  45. points = detectorResult.points;
  46. if (detectorResult) {
  47. decoderResult = [[[ZXAztecDecoder alloc] init] decode:detectorResult error:nil];
  48. }
  49. }
  50. if (!decoderResult) {
  51. return nil;
  52. }
  53. if (hints != nil) {
  54. id <ZXResultPointCallback> rpcb = hints.resultPointCallback;
  55. if (rpcb != nil) {
  56. for (ZXResultPoint *p in points) {
  57. [rpcb foundPossibleResultPoint:p];
  58. }
  59. }
  60. }
  61. ZXResult *result = [ZXResult resultWithText:decoderResult.text rawBytes:decoderResult.rawBytes resultPoints:points format:kBarcodeFormatAztec];
  62. NSMutableArray *byteSegments = decoderResult.byteSegments;
  63. if (byteSegments != nil) {
  64. [result putMetadata:kResultMetadataTypeByteSegments value:byteSegments];
  65. }
  66. NSString *ecLevel = decoderResult.ecLevel;
  67. if (ecLevel != nil) {
  68. [result putMetadata:kResultMetadataTypeErrorCorrectionLevel value:ecLevel];
  69. }
  70. return result;
  71. }
  72. - (void)reset {
  73. // do nothing
  74. }
  75. @end