LuminanceSource.d.ts 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**
  2. * The purpose of this class hierarchy is to abstract different bitmap implementations across
  3. * platforms into a standard interface for requesting greyscale luminance values. The interface
  4. * only provides immutable methods; therefore crop and rotation create copies. This is to ensure
  5. * that one Reader does not modify the original luminance source and leave it in an unknown state
  6. * for other Readers in the chain.
  7. *
  8. * @author dswitkin@google.com (Daniel Switkin)
  9. */
  10. declare abstract class LuminanceSource {
  11. private width;
  12. private height;
  13. protected constructor(width: number, height: number);
  14. /**
  15. * Fetches one row of luminance data from the underlying platform's bitmap. Values range from
  16. * 0 (black) to 255 (white). Because Java does not have an unsigned byte type, callers will have
  17. * to bitwise and with 0xff for each value. It is preferable for implementations of this method
  18. * to only fetch this row rather than the whole image, since no 2D Readers may be installed and
  19. * getMatrix() may never be called.
  20. *
  21. * @param y The row to fetch, which must be in [0,getHeight())
  22. * @param row An optional preallocated array. If null or too small, it will be ignored.
  23. * Always use the returned object, and ignore the .length of the array.
  24. * @return An array containing the luminance data.
  25. */
  26. abstract getRow(y: number, row?: Uint8ClampedArray): Uint8ClampedArray;
  27. /**
  28. * Fetches luminance data for the underlying bitmap. Values should be fetched using:
  29. * {@code int luminance = array[y * width + x] & 0xff}
  30. *
  31. * @return A row-major 2D array of luminance values. Do not use result.length as it may be
  32. * larger than width * height bytes on some platforms. Do not modify the contents
  33. * of the result.
  34. */
  35. abstract getMatrix(): Uint8ClampedArray;
  36. /**
  37. * @return The width of the bitmap.
  38. */
  39. getWidth(): number;
  40. /**
  41. * @return The height of the bitmap.
  42. */
  43. getHeight(): number;
  44. /**
  45. * @return Whether this subclass supports cropping.
  46. */
  47. isCropSupported(): boolean;
  48. /**
  49. * Returns a new object with cropped image data. Implementations may keep a reference to the
  50. * original data rather than a copy. Only callable if isCropSupported() is true.
  51. *
  52. * @param left The left coordinate, which must be in [0,getWidth())
  53. * @param top The top coordinate, which must be in [0,getHeight())
  54. * @param width The width of the rectangle to crop.
  55. * @param height The height of the rectangle to crop.
  56. * @return A cropped version of this object.
  57. */
  58. crop(left: number, top: number, width: number, height: number): LuminanceSource;
  59. /**
  60. * @return Whether this subclass supports counter-clockwise rotation.
  61. */
  62. isRotateSupported(): boolean;
  63. /**
  64. * @return a wrapper of this {@code LuminanceSource} which inverts the luminances it returns -- black becomes
  65. * white and vice versa, and each value becomes (255-value).
  66. */
  67. abstract invert(): LuminanceSource;
  68. /**
  69. * Returns a new object with rotated image data by 90 degrees counterclockwise.
  70. * Only callable if {@link #isRotateSupported()} is true.
  71. *
  72. * @return A rotated version of this object.
  73. */
  74. rotateCounterClockwise(): LuminanceSource;
  75. /**
  76. * Returns a new object with rotated image data by 45 degrees counterclockwise.
  77. * Only callable if {@link #isRotateSupported()} is true.
  78. *
  79. * @return A rotated version of this object.
  80. */
  81. rotateCounterClockwise45(): LuminanceSource;
  82. toString(): string;
  83. }
  84. export default LuminanceSource;