1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | "use strict";
|
23 |
|
24 | Object.defineProperty(exports, "__esModule", {
|
25 | value: true
|
26 | });
|
27 | exports.JpxStream = void 0;
|
28 |
|
29 | var _stream = require("./stream");
|
30 |
|
31 | var _jpx = require("./jpx");
|
32 |
|
33 | var _util = require("../shared/util");
|
34 |
|
35 | var JpxStream = function JpxStreamClosure() {
|
36 | function JpxStream(stream, maybeLength, dict, params) {
|
37 | this.stream = stream;
|
38 | this.maybeLength = maybeLength;
|
39 | this.dict = dict;
|
40 | this.params = params;
|
41 |
|
42 | _stream.DecodeStream.call(this, maybeLength);
|
43 | }
|
44 |
|
45 | JpxStream.prototype = Object.create(_stream.DecodeStream.prototype);
|
46 | Object.defineProperty(JpxStream.prototype, 'bytes', {
|
47 | get: function JpxStream_bytes() {
|
48 | return (0, _util.shadow)(this, 'bytes', this.stream.getBytes(this.maybeLength));
|
49 | },
|
50 | configurable: true
|
51 | });
|
52 |
|
53 | JpxStream.prototype.ensureBuffer = function (requested) {};
|
54 |
|
55 | JpxStream.prototype.readBlock = function () {
|
56 | if (this.eof) {
|
57 | return;
|
58 | }
|
59 |
|
60 | var jpxImage = new _jpx.JpxImage();
|
61 | jpxImage.parse(this.bytes);
|
62 | var width = jpxImage.width;
|
63 | var height = jpxImage.height;
|
64 | var componentsCount = jpxImage.componentsCount;
|
65 | var tileCount = jpxImage.tiles.length;
|
66 |
|
67 | if (tileCount === 1) {
|
68 | this.buffer = jpxImage.tiles[0].items;
|
69 | } else {
|
70 | var data = new Uint8ClampedArray(width * height * componentsCount);
|
71 |
|
72 | for (var k = 0; k < tileCount; k++) {
|
73 | var tileComponents = jpxImage.tiles[k];
|
74 | var tileWidth = tileComponents.width;
|
75 | var tileHeight = tileComponents.height;
|
76 | var tileLeft = tileComponents.left;
|
77 | var tileTop = tileComponents.top;
|
78 | var src = tileComponents.items;
|
79 | var srcPosition = 0;
|
80 | var dataPosition = (width * tileTop + tileLeft) * componentsCount;
|
81 | var imgRowSize = width * componentsCount;
|
82 | var tileRowSize = tileWidth * componentsCount;
|
83 |
|
84 | for (var j = 0; j < tileHeight; j++) {
|
85 | var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
|
86 | data.set(rowBytes, dataPosition);
|
87 | srcPosition += tileRowSize;
|
88 | dataPosition += imgRowSize;
|
89 | }
|
90 | }
|
91 |
|
92 | this.buffer = data;
|
93 | }
|
94 |
|
95 | this.bufferLength = this.buffer.length;
|
96 | this.eof = true;
|
97 | };
|
98 |
|
99 | return JpxStream;
|
100 | }();
|
101 |
|
102 | exports.JpxStream = JpxStream; |
\ | No newline at end of file |