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.

ZXBinarizer.h 3.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 <CoreGraphics/CoreGraphics.h>
  17. #import "ZXBitArray.h"
  18. #import "ZXBitMatrix.h"
  19. #import "ZXLuminanceSource.h"
  20. /**
  21. * This class hierarchy provides a set of methods to convert luminance data to 1 bit data.
  22. * It allows the algorithm to vary polymorphically, for example allowing a very expensive
  23. * thresholding technique for servers and a fast one for mobile. It also permits the implementation
  24. * to vary, e.g. a JNI version for Android and a Java fallback version for other platforms.
  25. */
  26. @interface ZXBinarizer : NSObject
  27. @property (nonatomic, strong, readonly) ZXLuminanceSource *luminanceSource;
  28. @property (nonatomic, assign, readonly) int width;
  29. @property (nonatomic, assign, readonly) int height;
  30. - (id)initWithSource:(ZXLuminanceSource *)source;
  31. + (id)binarizerWithSource:(ZXLuminanceSource *)source;
  32. /**
  33. * Converts one row of luminance data to 1 bit data. May actually do the conversion, or return
  34. * cached data. Callers should assume this method is expensive and call it as seldom as possible.
  35. * This method is intended for decoding 1D barcodes and may choose to apply sharpening.
  36. * For callers which only examine one row of pixels at a time, the same BitArray should be reused
  37. * and passed in with each call for performance. However it is legal to keep more than one row
  38. * at a time if needed.
  39. *
  40. * @param y The row to fetch, 0 <= y < bitmap height.
  41. * @param row An optional preallocated array. If null or too small, it will be ignored.
  42. * If used, the Binarizer will call ZXBitArray clear. Always use the returned object.
  43. * @return The array of bits for this row (true means black).
  44. */
  45. - (ZXBitArray *)blackRow:(int)y row:(ZXBitArray *)row error:(NSError **)error;
  46. /**
  47. * Converts a 2D array of luminance data to 1 bit data. As above, assume this method is expensive
  48. * and do not call it repeatedly. This method is intended for decoding 2D barcodes and may or
  49. * may not apply sharpening. Therefore, a row from this matrix may not be identical to one
  50. * fetched using getBlackRow(), so don't mix and match between them.
  51. *
  52. * @return The 2D array of bits for the image (true means black).
  53. */
  54. - (ZXBitMatrix *)blackMatrixWithError:(NSError **)error;
  55. /**
  56. * Creates a new object with the same type as this Binarizer implementation, but with pristine
  57. * state. This is needed because Binarizer implementations may be stateful, e.g. keeping a cache
  58. * of 1 bit data. See Effective Java for why we can't use Java's clone() method.
  59. *
  60. * @param source The LuminanceSource this Binarizer will operate on.
  61. * @return A new concrete Binarizer implementation object.
  62. */
  63. - (ZXBinarizer *)createBinarizer:(ZXLuminanceSource *)source;
  64. - (CGImageRef)createImage CF_RETURNS_RETAINED;
  65. @end