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.

ZXLuminanceSource.h 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. @class ZXByteArray;
  17. /**
  18. * The purpose of this class hierarchy is to abstract different bitmap implementations across
  19. * platforms into a standard interface for requesting greyscale luminance values. The interface
  20. * only provides immutable methods; therefore crop and rotation create copies. This is to ensure
  21. * that one Reader does not modify the original luminance source and leave it in an unknown state
  22. * for other Readers in the chain.
  23. */
  24. @interface ZXLuminanceSource : NSObject
  25. /**
  26. * @return The width of the bitmap.
  27. */
  28. @property (nonatomic, assign, readonly) int width;
  29. /**
  30. * @return The height of the bitmap.
  31. */
  32. @property (nonatomic, assign, readonly) int height;
  33. /**
  34. * @return Whether this subclass supports cropping.
  35. */
  36. @property (nonatomic, assign, readonly) BOOL cropSupported;
  37. /**
  38. * @return Whether this subclass supports counter-clockwise rotation.
  39. */
  40. @property (nonatomic, assign, readonly) BOOL rotateSupported;
  41. - (id)initWithWidth:(int)width height:(int)height;
  42. /**
  43. * Fetches one row of luminance data from the underlying platform's bitmap. Values range from
  44. * 0 (black) to 255 (white). Because Java does not have an unsigned byte type, callers will have
  45. * to bitwise and with 0xff for each value. It is preferable for implementations of this method
  46. * to only fetch this row rather than the whole image, since no 2D Readers may be installed and
  47. * getMatrix() may never be called.
  48. *
  49. * @param y The row to fetch, 0 <= y < getHeight().
  50. * @param row An optional preallocated array. If null or too small, it will be ignored.
  51. * Always use the returned object, and ignore the .length of the array.
  52. * @return An array containing the luminance data.
  53. */
  54. - (ZXByteArray *)rowAtY:(int)y row:(ZXByteArray *)row;
  55. /**
  56. * Fetches luminance data for the underlying bitmap. Values should be fetched using:
  57. * int luminance = array[y * width + x] & 0xff;
  58. *
  59. * @return A row-major 2D array of luminance values. Do not use result.length as it may be
  60. * larger than width * height bytes on some platforms. Do not modify the contents
  61. * of the result.
  62. */
  63. - (ZXByteArray *)matrix;
  64. /**
  65. * Returns a new object with cropped image data. Implementations may keep a reference to the
  66. * original data rather than a copy. Only callable if isCropSupported() is true.
  67. *
  68. * @param left The left coordinate, 0 <= left < getWidth().
  69. * @param top The top coordinate, 0 <= top <= getHeight().
  70. * @param width The width of the rectangle to crop.
  71. * @param height The height of the rectangle to crop.
  72. * @return A cropped version of this object.
  73. */
  74. - (ZXLuminanceSource *)crop:(int)left top:(int)top width:(int)width height:(int)height;
  75. /**
  76. * @return a wrapper of this ZXLuminanceSource which inverts the luminances it returns -- black becomes
  77. * white and vice versa, and each value becomes (255-value).
  78. */
  79. - (ZXLuminanceSource *)invert;
  80. /**
  81. * Returns a new object with rotated image data by 90 degrees counterclockwise.
  82. * Only callable if isRotateSupported is true.
  83. *
  84. * @return A rotated version of this object.
  85. */
  86. - (ZXLuminanceSource *)rotateCounterClockwise;
  87. /**
  88. * Returns a new object with rotated image data by 45 degrees counterclockwise.
  89. * Only callable if isRotateSupported is true.
  90. *
  91. * @return A rotated version of this object.
  92. */
  93. - (ZXLuminanceSource *)rotateCounterClockwise45;
  94. @end