LuminanceSource.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. "use strict";
  2. /*
  3. * Copyright 2009 ZXing authors
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. Object.defineProperty(exports, "__esModule", { value: true });
  18. var StringBuilder_1 = require("./util/StringBuilder");
  19. var UnsupportedOperationException_1 = require("./UnsupportedOperationException");
  20. /*namespace com.google.zxing {*/
  21. /**
  22. * The purpose of this class hierarchy is to abstract different bitmap implementations across
  23. * platforms into a standard interface for requesting greyscale luminance values. The interface
  24. * only provides immutable methods; therefore crop and rotation create copies. This is to ensure
  25. * that one Reader does not modify the original luminance source and leave it in an unknown state
  26. * for other Readers in the chain.
  27. *
  28. * @author dswitkin@google.com (Daniel Switkin)
  29. */
  30. var LuminanceSource = /** @class */ (function () {
  31. function LuminanceSource(width /*int*/, height /*int*/) {
  32. this.width = width;
  33. this.height = height;
  34. }
  35. /**
  36. * @return The width of the bitmap.
  37. */
  38. LuminanceSource.prototype.getWidth = function () {
  39. return this.width;
  40. };
  41. /**
  42. * @return The height of the bitmap.
  43. */
  44. LuminanceSource.prototype.getHeight = function () {
  45. return this.height;
  46. };
  47. /**
  48. * @return Whether this subclass supports cropping.
  49. */
  50. LuminanceSource.prototype.isCropSupported = function () {
  51. return false;
  52. };
  53. /**
  54. * Returns a new object with cropped image data. Implementations may keep a reference to the
  55. * original data rather than a copy. Only callable if isCropSupported() is true.
  56. *
  57. * @param left The left coordinate, which must be in [0,getWidth())
  58. * @param top The top coordinate, which must be in [0,getHeight())
  59. * @param width The width of the rectangle to crop.
  60. * @param height The height of the rectangle to crop.
  61. * @return A cropped version of this object.
  62. */
  63. LuminanceSource.prototype.crop = function (left /*int*/, top /*int*/, width /*int*/, height /*int*/) {
  64. throw new UnsupportedOperationException_1.default('This luminance source does not support cropping.');
  65. };
  66. /**
  67. * @return Whether this subclass supports counter-clockwise rotation.
  68. */
  69. LuminanceSource.prototype.isRotateSupported = function () {
  70. return false;
  71. };
  72. /**
  73. * Returns a new object with rotated image data by 90 degrees counterclockwise.
  74. * Only callable if {@link #isRotateSupported()} is true.
  75. *
  76. * @return A rotated version of this object.
  77. */
  78. LuminanceSource.prototype.rotateCounterClockwise = function () {
  79. throw new UnsupportedOperationException_1.default('This luminance source does not support rotation by 90 degrees.');
  80. };
  81. /**
  82. * Returns a new object with rotated image data by 45 degrees counterclockwise.
  83. * Only callable if {@link #isRotateSupported()} is true.
  84. *
  85. * @return A rotated version of this object.
  86. */
  87. LuminanceSource.prototype.rotateCounterClockwise45 = function () {
  88. throw new UnsupportedOperationException_1.default('This luminance source does not support rotation by 45 degrees.');
  89. };
  90. /*@Override*/
  91. LuminanceSource.prototype.toString = function () {
  92. var row = new Uint8ClampedArray(this.width);
  93. var result = new StringBuilder_1.default();
  94. for (var y = 0; y < this.height; y++) {
  95. var sourceRow = this.getRow(y, row);
  96. for (var x = 0; x < this.width; x++) {
  97. var luminance = sourceRow[x] & 0xFF;
  98. var c = void 0;
  99. if (luminance < 0x40) {
  100. c = '#';
  101. }
  102. else if (luminance < 0x80) {
  103. c = '+';
  104. }
  105. else if (luminance < 0xC0) {
  106. c = '.';
  107. }
  108. else {
  109. c = ' ';
  110. }
  111. result.append(c);
  112. }
  113. result.append('\n');
  114. }
  115. return result.toString();
  116. };
  117. return LuminanceSource;
  118. }());
  119. exports.default = LuminanceSource;