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 _decode_stream = require("./decode_stream.js");
|
30 |
|
31 | var _jpx = require("./jpx.js");
|
32 |
|
33 | var _util = require("../shared/util.js");
|
34 |
|
35 | class JpxStream extends _decode_stream.DecodeStream {
|
36 | constructor(stream, maybeLength, params) {
|
37 | super(maybeLength);
|
38 | this.stream = stream;
|
39 | this.dict = stream.dict;
|
40 | this.maybeLength = maybeLength;
|
41 | this.params = params;
|
42 | }
|
43 |
|
44 | get bytes() {
|
45 | return (0, _util.shadow)(this, "bytes", this.stream.getBytes(this.maybeLength));
|
46 | }
|
47 |
|
48 | ensureBuffer(requested) {}
|
49 |
|
50 | readBlock() {
|
51 | if (this.eof) {
|
52 | return;
|
53 | }
|
54 |
|
55 | const jpxImage = new _jpx.JpxImage();
|
56 | jpxImage.parse(this.bytes);
|
57 | const width = jpxImage.width;
|
58 | const height = jpxImage.height;
|
59 | const componentsCount = jpxImage.componentsCount;
|
60 | const tileCount = jpxImage.tiles.length;
|
61 |
|
62 | if (tileCount === 1) {
|
63 | this.buffer = jpxImage.tiles[0].items;
|
64 | } else {
|
65 | const data = new Uint8ClampedArray(width * height * componentsCount);
|
66 |
|
67 | for (let k = 0; k < tileCount; k++) {
|
68 | const tileComponents = jpxImage.tiles[k];
|
69 | const tileWidth = tileComponents.width;
|
70 | const tileHeight = tileComponents.height;
|
71 | const tileLeft = tileComponents.left;
|
72 | const tileTop = tileComponents.top;
|
73 | const src = tileComponents.items;
|
74 | let srcPosition = 0;
|
75 | let dataPosition = (width * tileTop + tileLeft) * componentsCount;
|
76 | const imgRowSize = width * componentsCount;
|
77 | const tileRowSize = tileWidth * componentsCount;
|
78 |
|
79 | for (let j = 0; j < tileHeight; j++) {
|
80 | const rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
|
81 | data.set(rowBytes, dataPosition);
|
82 | srcPosition += tileRowSize;
|
83 | dataPosition += imgRowSize;
|
84 | }
|
85 | }
|
86 |
|
87 | this.buffer = data;
|
88 | }
|
89 |
|
90 | this.bufferLength = this.buffer.length;
|
91 | this.eof = true;
|
92 | }
|
93 |
|
94 | }
|
95 |
|
96 | exports.JpxStream = JpxStream; |
\ | No newline at end of file |