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.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 "ZXPDF417BarcodeMatrix.h"
  17. #import "ZXPDF417BarcodeRow.h"
  18. @interface ZXPDF417BarcodeMatrix ()
  19. @property (nonatomic, assign) int currentRowIndex;
  20. @property (nonatomic, strong, readonly) NSArray *rowMatrix;
  21. @end
  22. @implementation ZXPDF417BarcodeMatrix
  23. - (id)initWithHeight:(int)height width:(int)width {
  24. if (self = [super init]) {
  25. NSMutableArray *matrix = [NSMutableArray array];
  26. for (int i = 0, matrixLength = height; i < matrixLength; i++) {
  27. [matrix addObject:[ZXPDF417BarcodeRow barcodeRowWithWidth:(width + 4) * 17 + 1]];
  28. }
  29. _rowMatrix = matrix;
  30. _width = width * 17;
  31. _height = height;
  32. _currentRowIndex = -1;
  33. }
  34. return self;
  35. }
  36. - (void)setX:(int)x y:(int)y value:(int8_t)value {
  37. [self.rowMatrix[y] setX:x value:value];
  38. }
  39. /*
  40. - (void)setMatrixX:(int)x y:(int)y black:(BOOL)black {
  41. [self setX:x y:y value:(int8_t)(black ? 1 : 0)];
  42. }
  43. */
  44. - (void)startRow {
  45. ++self.currentRowIndex;
  46. }
  47. - (ZXPDF417BarcodeRow *)currentRow {
  48. return self.rowMatrix[self.currentRowIndex];
  49. }
  50. - (NSArray *)matrix {
  51. return [self scaledMatrixWithXScale:1 yScale:1];
  52. }
  53. /*
  54. - (NSArray *)scaledMatrix:(int)scale {
  55. return [self scaledMatrixWithXScale:scale yScale:scale];
  56. }
  57. */
  58. - (NSArray *)scaledMatrixWithXScale:(int)xScale yScale:(int)yScale {
  59. int yMax = self.height * yScale;
  60. NSMutableArray *matrixOut = [NSMutableArray array];
  61. for (int i = 0; i < yMax; i++) {
  62. [matrixOut addObject:[NSNull null]];
  63. }
  64. for (int i = 0; i < yMax; i++) {
  65. matrixOut[yMax - i - 1] = [(ZXPDF417BarcodeRow *)self.rowMatrix[i / yScale] scaledRow:xScale];
  66. }
  67. return matrixOut;
  68. }
  69. @end