InvertedLuminanceSource.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright 2009 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. var __extends = (this && this.__extends) || (function () {
  17. var extendStatics = function (d, b) {
  18. extendStatics = Object.setPrototypeOf ||
  19. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  20. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  21. return extendStatics(d, b);
  22. };
  23. return function (d, b) {
  24. extendStatics(d, b);
  25. function __() { this.constructor = d; }
  26. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  27. };
  28. })();
  29. import LuminanceSource from './LuminanceSource';
  30. /*namespace com.google.zxing {*/
  31. /**
  32. * A wrapper implementation of {@link LuminanceSource} which inverts the luminances it returns -- black becomes
  33. * white and vice versa, and each value becomes (255-value).
  34. *
  35. * @author Sean Owen
  36. */
  37. var InvertedLuminanceSource = /** @class */ (function (_super) {
  38. __extends(InvertedLuminanceSource, _super);
  39. function InvertedLuminanceSource(delegate) {
  40. var _this = _super.call(this, delegate.getWidth(), delegate.getHeight()) || this;
  41. _this.delegate = delegate;
  42. return _this;
  43. }
  44. /*@Override*/
  45. InvertedLuminanceSource.prototype.getRow = function (y /*int*/, row) {
  46. var sourceRow = this.delegate.getRow(y, row);
  47. var width = this.getWidth();
  48. for (var i = 0; i < width; i++) {
  49. sourceRow[i] = /*(byte)*/ (255 - (sourceRow[i] & 0xFF));
  50. }
  51. return sourceRow;
  52. };
  53. /*@Override*/
  54. InvertedLuminanceSource.prototype.getMatrix = function () {
  55. var matrix = this.delegate.getMatrix();
  56. var length = this.getWidth() * this.getHeight();
  57. var invertedMatrix = new Uint8ClampedArray(length);
  58. for (var i = 0; i < length; i++) {
  59. invertedMatrix[i] = /*(byte)*/ (255 - (matrix[i] & 0xFF));
  60. }
  61. return invertedMatrix;
  62. };
  63. /*@Override*/
  64. InvertedLuminanceSource.prototype.isCropSupported = function () {
  65. return this.delegate.isCropSupported();
  66. };
  67. /*@Override*/
  68. InvertedLuminanceSource.prototype.crop = function (left /*int*/, top /*int*/, width /*int*/, height /*int*/) {
  69. return new InvertedLuminanceSource(this.delegate.crop(left, top, width, height));
  70. };
  71. /*@Override*/
  72. InvertedLuminanceSource.prototype.isRotateSupported = function () {
  73. return this.delegate.isRotateSupported();
  74. };
  75. /**
  76. * @return original delegate {@link LuminanceSource} since invert undoes itself
  77. */
  78. /*@Override*/
  79. InvertedLuminanceSource.prototype.invert = function () {
  80. return this.delegate;
  81. };
  82. /*@Override*/
  83. InvertedLuminanceSource.prototype.rotateCounterClockwise = function () {
  84. return new InvertedLuminanceSource(this.delegate.rotateCounterClockwise());
  85. };
  86. /*@Override*/
  87. InvertedLuminanceSource.prototype.rotateCounterClockwise45 = function () {
  88. return new InvertedLuminanceSource(this.delegate.rotateCounterClockwise45());
  89. };
  90. return InvertedLuminanceSource;
  91. }(LuminanceSource));
  92. export default InvertedLuminanceSource;