Skip to content

Commit

Permalink
Merge pull request #17977 from Snuffleupagus/parseImageProperties-Typ…
Browse files Browse the repository at this point in the history
…edArray

Update `JpxImage.parseImageProperties` to support TypedArray data in IMAGE_DECODERS builds
  • Loading branch information
timvandermeij authored Apr 22, 2024
2 parents 9e80c6d + 8970786 commit 522af26
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/core/jpx.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import { BaseException, warn } from "../shared/util.js";
import OpenJPEG from "../../external/openjpeg/openjpeg.js";
import { Stream } from "./stream.js";

class JpxError extends BaseException {
constructor(msg) {
Expand All @@ -39,6 +40,13 @@ class JpxImage {
}

static parseImageProperties(stream) {
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("IMAGE_DECODERS")) {
if (stream instanceof ArrayBuffer || ArrayBuffer.isView(stream)) {
stream = new Stream(stream);
} else {
throw new JpxError("Invalid data format, must be a TypedArray.");
}
}
// No need to use OpenJPEG here since we're only getting very basic
// information which are located in the first bytes of the file.
let newByte = stream.getByte();
Expand Down

0 comments on commit 522af26

Please sign in to comment.