Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright 2013 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 "ZXPDF417BoundingBox.h"
  17. #import "ZXPDF417Codeword.h"
  18. #import "ZXPDF417DetectionResultColumn.h"
  19. const int ZX_PDF417_MAX_NEARBY_DISTANCE = 5;
  20. @implementation ZXPDF417DetectionResultColumn
  21. - (id)initWithBoundingBox:(ZXPDF417BoundingBox *)boundingBox {
  22. self = [super init];
  23. if (self) {
  24. _boundingBox = [[ZXPDF417BoundingBox alloc] initWithBoundingBox:boundingBox];
  25. _codewords = [NSMutableArray array];
  26. for (int i = 0; i < boundingBox.maxY - boundingBox.minY + 1; i++) {
  27. [_codewords addObject:[NSNull null]];
  28. }
  29. }
  30. return self;
  31. }
  32. - (ZXPDF417Codeword *)codewordNearby:(int)imageRow {
  33. ZXPDF417Codeword *codeword = [self codeword:imageRow];
  34. if (codeword) {
  35. return codeword;
  36. }
  37. for (int i = 1; i < ZX_PDF417_MAX_NEARBY_DISTANCE; i++) {
  38. int nearImageRow = [self imageRowToCodewordIndex:imageRow] - i;
  39. if (nearImageRow >= 0) {
  40. codeword = self.codewords[nearImageRow];
  41. if ((id)codeword != [NSNull null]) {
  42. return codeword;
  43. }
  44. }
  45. nearImageRow = [self imageRowToCodewordIndex:imageRow] + i;
  46. if (nearImageRow < [self.codewords count]) {
  47. codeword = self.codewords[nearImageRow];
  48. if ((id)codeword != [NSNull null]) {
  49. return codeword;
  50. }
  51. }
  52. }
  53. return nil;
  54. }
  55. - (int)imageRowToCodewordIndex:(int)imageRow {
  56. return imageRow - self.boundingBox.minY;
  57. }
  58. - (void)setCodeword:(int)imageRow codeword:(ZXPDF417Codeword *)codeword {
  59. _codewords[[self imageRowToCodewordIndex:imageRow]] = codeword;
  60. }
  61. - (ZXPDF417Codeword *)codeword:(int)imageRow {
  62. NSUInteger index = [self imageRowToCodewordIndex:imageRow];
  63. if (_codewords[index] == [NSNull null]) {
  64. return nil;
  65. }
  66. return _codewords[index];
  67. }
  68. - (NSString *)description {
  69. NSMutableString *result = [NSMutableString string];
  70. int row = 0;
  71. for (ZXPDF417Codeword *codeword in self.codewords) {
  72. if ((id)codeword == [NSNull null]) {
  73. [result appendFormat:@"%3d: | \n", row++];
  74. continue;
  75. }
  76. [result appendFormat:@"%3d: %3d|%3d\n", row++, codeword.rowNumber, codeword.value];
  77. }
  78. return [NSString stringWithString:result];
  79. }
  80. @end