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.

ZXBitArrayBuilder.m 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 "ZXBitArrayBuilder.h"
  18. #import "ZXRSSDataCharacter.h"
  19. #import "ZXRSSExpandedPair.h"
  20. @implementation ZXBitArrayBuilder
  21. + (ZXBitArray *)buildBitArray:(NSArray *)pairs {
  22. int charNumber = ((int)[pairs count] * 2) - 1;
  23. if ([pairs[pairs.count - 1] rightChar] == nil) {
  24. charNumber -= 1;
  25. }
  26. int size = 12 * charNumber;
  27. ZXBitArray *binary = [[ZXBitArray alloc] initWithSize:size];
  28. int accPos = 0;
  29. ZXRSSExpandedPair *firstPair = pairs[0];
  30. int firstValue = [[firstPair rightChar] value];
  31. for (int i = 11; i >= 0; --i) {
  32. if ((firstValue & (1 << i)) != 0) {
  33. [binary set:accPos];
  34. }
  35. accPos++;
  36. }
  37. for (int i = 1; i < [pairs count]; ++i) {
  38. ZXRSSExpandedPair *currentPair = pairs[i];
  39. int leftValue = [[currentPair leftChar] value];
  40. for (int j = 11; j >= 0; --j) {
  41. if ((leftValue & (1 << j)) != 0) {
  42. [binary set:accPos];
  43. }
  44. accPos++;
  45. }
  46. if ([currentPair rightChar] != nil) {
  47. int rightValue = [[currentPair rightChar] value];
  48. for (int j = 11; j >= 0; --j) {
  49. if ((rightValue & (1 << j)) != 0) {
  50. [binary set:accPos];
  51. }
  52. accPos++;
  53. }
  54. }
  55. }
  56. return binary;
  57. }
  58. @end