InvertedLuminanceSource.js 3.7 KB

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