jpx_stream.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2019 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * Javascript code in this page
  21. */
  22. "use strict";
  23. Object.defineProperty(exports, "__esModule", {
  24. value: true
  25. });
  26. exports.JpxStream = void 0;
  27. var _stream = require("./stream");
  28. var _jpx = require("./jpx");
  29. var _util = require("../shared/util");
  30. var JpxStream = function JpxStreamClosure() {
  31. function JpxStream(stream, maybeLength, dict, params) {
  32. this.stream = stream;
  33. this.maybeLength = maybeLength;
  34. this.dict = dict;
  35. this.params = params;
  36. _stream.DecodeStream.call(this, maybeLength);
  37. }
  38. JpxStream.prototype = Object.create(_stream.DecodeStream.prototype);
  39. Object.defineProperty(JpxStream.prototype, 'bytes', {
  40. get: function JpxStream_bytes() {
  41. return (0, _util.shadow)(this, 'bytes', this.stream.getBytes(this.maybeLength));
  42. },
  43. configurable: true
  44. });
  45. JpxStream.prototype.ensureBuffer = function (requested) {};
  46. JpxStream.prototype.readBlock = function () {
  47. if (this.eof) {
  48. return;
  49. }
  50. var jpxImage = new _jpx.JpxImage();
  51. jpxImage.parse(this.bytes);
  52. var width = jpxImage.width;
  53. var height = jpxImage.height;
  54. var componentsCount = jpxImage.componentsCount;
  55. var tileCount = jpxImage.tiles.length;
  56. if (tileCount === 1) {
  57. this.buffer = jpxImage.tiles[0].items;
  58. } else {
  59. var data = new Uint8ClampedArray(width * height * componentsCount);
  60. for (var k = 0; k < tileCount; k++) {
  61. var tileComponents = jpxImage.tiles[k];
  62. var tileWidth = tileComponents.width;
  63. var tileHeight = tileComponents.height;
  64. var tileLeft = tileComponents.left;
  65. var tileTop = tileComponents.top;
  66. var src = tileComponents.items;
  67. var srcPosition = 0;
  68. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  69. var imgRowSize = width * componentsCount;
  70. var tileRowSize = tileWidth * componentsCount;
  71. for (var j = 0; j < tileHeight; j++) {
  72. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  73. data.set(rowBytes, dataPosition);
  74. srcPosition += tileRowSize;
  75. dataPosition += imgRowSize;
  76. }
  77. }
  78. this.buffer = data;
  79. }
  80. this.bufferLength = this.buffer.length;
  81. this.eof = true;
  82. };
  83. return JpxStream;
  84. }();
  85. exports.JpxStream = JpxStream;