Binarizer.d.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import LuminanceSource from './LuminanceSource';
  2. import BitArray from './common/BitArray';
  3. import BitMatrix from './common/BitMatrix';
  4. /**
  5. * This class hierarchy provides a set of methods to convert luminance data to 1 bit data.
  6. * It allows the algorithm to vary polymorphically, for example allowing a very expensive
  7. * thresholding technique for servers and a fast one for mobile. It also permits the implementation
  8. * to vary, e.g. a JNI version for Android and a Java fallback version for other platforms.
  9. *
  10. * @author dswitkin@google.com (Daniel Switkin)
  11. */
  12. declare abstract class Binarizer {
  13. private source;
  14. protected constructor(source: LuminanceSource);
  15. getLuminanceSource(): LuminanceSource;
  16. /**
  17. * Converts one row of luminance data to 1 bit data. May actually do the conversion, or return
  18. * cached data. Callers should assume this method is expensive and call it as seldom as possible.
  19. * This method is intended for decoding 1D barcodes and may choose to apply sharpening.
  20. * For callers which only examine one row of pixels at a time, the same BitArray should be reused
  21. * and passed in with each call for performance. However it is legal to keep more than one row
  22. * at a time if needed.
  23. *
  24. * @param y The row to fetch, which must be in [0, bitmap height)
  25. * @param row An optional preallocated array. If null or too small, it will be ignored.
  26. * If used, the Binarizer will call BitArray.clear(). Always use the returned object.
  27. * @return The array of bits for this row (true means black).
  28. * @throws NotFoundException if row can't be binarized
  29. */
  30. abstract getBlackRow(y: number, row: BitArray): BitArray;
  31. /**
  32. * Converts a 2D array of luminance data to 1 bit data. As above, assume this method is expensive
  33. * and do not call it repeatedly. This method is intended for decoding 2D barcodes and may or
  34. * may not apply sharpening. Therefore, a row from this matrix may not be identical to one
  35. * fetched using getBlackRow(), so don't mix and match between them.
  36. *
  37. * @return The 2D array of bits for the image (true means black).
  38. * @throws NotFoundException if image can't be binarized to make a matrix
  39. */
  40. abstract getBlackMatrix(): BitMatrix;
  41. /**
  42. * Creates a new object with the same type as this Binarizer implementation, but with pristine
  43. * state. This is needed because Binarizer implementations may be stateful, e.g. keeping a cache
  44. * of 1 bit data. See Effective Java for why we can't use Java's clone() method.
  45. *
  46. * @param source The LuminanceSource this Binarizer will operate on.
  47. * @return A new concrete Binarizer implementation object.
  48. */
  49. abstract createBinarizer(source: LuminanceSource): Binarizer;
  50. getWidth(): number;
  51. getHeight(): number;
  52. }
  53. export default Binarizer;