UNPKG

3.06 kBJavaScriptView Raw
1/**
2 * @licstart The following is the entire license notice for the
3 * Javascript code in this page
4 *
5 * Copyright 2018 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
24Object.defineProperty(exports, "__esModule", {
25 value: true
26});
27exports.JpxStream = void 0;
28
29var _stream = require("./stream");
30
31var _jpx = require("./jpx");
32
33var _util = require("../shared/util");
34
35var 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
102exports.JpxStream = JpxStream;
\No newline at end of file