2017-10-26 13:00:09 +02:00
|
|
|
/* Copyright 2012 Mozilla Foundation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2021-04-27 16:18:52 +02:00
|
|
|
import { DecodeStream } from "./decode_stream.js";
|
2020-01-02 12:00:16 +01:00
|
|
|
import { JpxImage } from "./jpx.js";
|
|
|
|
import { shadow } from "../shared/util.js";
|
2017-10-26 13:00:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* For JPEG 2000's we use a library to decode these images and
|
|
|
|
* the stream behaves like all the other DecodeStreams.
|
|
|
|
*/
|
2021-04-27 12:40:32 +02:00
|
|
|
class JpxStream extends DecodeStream {
|
2021-04-27 22:35:53 +02:00
|
|
|
constructor(stream, maybeLength, params) {
|
2021-04-27 12:40:32 +02:00
|
|
|
super(maybeLength);
|
|
|
|
|
2017-10-26 13:00:09 +02:00
|
|
|
this.stream = stream;
|
2021-04-27 22:35:53 +02:00
|
|
|
this.dict = stream.dict;
|
2017-10-26 13:00:09 +02:00
|
|
|
this.maybeLength = maybeLength;
|
|
|
|
this.params = params;
|
|
|
|
}
|
|
|
|
|
2021-04-27 12:40:32 +02:00
|
|
|
get bytes() {
|
|
|
|
// If `this.maybeLength` is null, we'll get the entire stream.
|
|
|
|
return shadow(this, "bytes", this.stream.getBytes(this.maybeLength));
|
|
|
|
}
|
2017-10-26 13:00:09 +02:00
|
|
|
|
2021-04-27 12:40:32 +02:00
|
|
|
ensureBuffer(requested) {
|
2017-10-26 13:15:57 +02:00
|
|
|
// No-op, since `this.readBlock` will always parse the entire image and
|
|
|
|
// directly insert all of its data into `this.buffer`.
|
2021-04-27 12:40:32 +02:00
|
|
|
}
|
2017-10-26 13:15:57 +02:00
|
|
|
|
2024-04-15 10:12:05 +02:00
|
|
|
readBlock(ignoreColorSpace) {
|
2017-10-26 13:15:57 +02:00
|
|
|
if (this.eof) {
|
2017-10-26 13:00:09 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-04-15 10:12:05 +02:00
|
|
|
this.buffer = JpxImage.decode(this.bytes, ignoreColorSpace);
|
2017-10-26 13:00:09 +02:00
|
|
|
this.bufferLength = this.buffer.length;
|
|
|
|
this.eof = true;
|
2021-04-27 12:40:32 +02:00
|
|
|
}
|
|
|
|
}
|
2017-10-26 13:00:09 +02:00
|
|
|
|
|
|
|
export { JpxStream };
|