Skip to content

Commit 0f52bb5

Browse files
committed
Fix conflicts
1 parent 76f86cd commit 0f52bb5

File tree

3 files changed

+18
-109
lines changed

3 files changed

+18
-109
lines changed

src/core/base_stream.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ class BaseStream {
6868
return false;
6969
}
7070

71-
async getTransferableImage() {
72-
return null;
73-
}
74-
7571
peekByte() {
7672
const peekedByte = this.getByte();
7773
if (peekedByte !== -1) {

src/core/image.js

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -752,10 +752,6 @@ class PDFImage {
752752
drawWidth === originalWidth &&
753753
drawHeight === originalHeight
754754
) {
755-
const image = await this.#getImage(originalWidth, originalHeight);
756-
if (image) {
757-
return image;
758-
}
759755
const data = await this.getImageBytes(originalHeight * rowBytes, {});
760756
if (isOffscreenCanvasSupported) {
761757
if (mustBeResized) {
@@ -814,10 +810,6 @@ class PDFImage {
814810
}
815811

816812
if (isHandled) {
817-
const image = await this.#getImage(drawWidth, drawHeight);
818-
if (image) {
819-
return image;
820-
}
821813
const rgba = await this.getImageBytes(imageLength, {
822814
drawWidth,
823815
drawHeight,
@@ -1021,20 +1013,6 @@ class PDFImage {
10211013
};
10221014
}
10231015

1024-
async #getImage(width, height) {
1025-
const bitmap = await this.image.getTransferableImage();
1026-
if (!bitmap) {
1027-
return null;
1028-
}
1029-
return {
1030-
data: null,
1031-
width,
1032-
height,
1033-
bitmap,
1034-
interpolate: this.interpolate,
1035-
};
1036-
}
1037-
10381016
async getImageBytes(
10391017
length,
10401018
{

src/core/jpeg_stream.js

Lines changed: 18 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
* limitations under the License.
1414
*/
1515

16-
import { shadow, warn } from "../shared/util.js";
1716
import { DecodeStream } from "./decode_stream.js";
1817
import { Dict } from "./primitives.js";
1918
import { JpegImage } from "./jpg.js";
19+
import { shadow } from "../shared/util.js";
2020

2121
/**
2222
* For JPEG's we use a library to decode these images and the stream behaves
@@ -32,18 +32,6 @@ class JpegStream extends DecodeStream {
3232
this.params = params;
3333
}
3434

35-
static get canUseImageDecoder() {
36-
return shadow(
37-
this,
38-
"canUseImageDecoder",
39-
// eslint-disable-next-line no-undef
40-
typeof ImageDecoder === "undefined"
41-
? Promise.resolve(false)
42-
: // eslint-disable-next-line no-undef
43-
ImageDecoder.isTypeSupported("image/jpeg")
44-
);
45-
}
46-
4735
get bytes() {
4836
// If `this.maybeLength` is null, we'll get the entire stream.
4937
return shadow(this, "bytes", this.stream.getBytes(this.maybeLength));
@@ -58,7 +46,22 @@ class JpegStream extends DecodeStream {
5846
this.decodeImage();
5947
}
6048

61-
get jpegOptions() {
49+
decodeImage(bytes) {
50+
if (this.eof) {
51+
return this.buffer;
52+
}
53+
bytes ||= this.bytes;
54+
55+
// Some images may contain 'junk' before the SOI (start-of-image) marker.
56+
// Note: this seems to mainly affect inline images.
57+
for (let i = 0, ii = bytes.length - 1; i < ii; i++) {
58+
if (bytes[i] === 0xff && bytes[i + 1] === 0xd8) {
59+
if (i > 0) {
60+
bytes = bytes.subarray(i);
61+
}
62+
break;
63+
}
64+
}
6265
const jpegOptions = {
6366
decodeTransform: undefined,
6467
colorTransform: undefined,
@@ -90,34 +93,8 @@ class JpegStream extends DecodeStream {
9093
jpegOptions.colorTransform = colorTransform;
9194
}
9295
}
93-
return shadow(this, "jpegOptions", jpegOptions);
94-
}
95-
96-
#skipUselessBytes(data) {
97-
// Some images may contain 'junk' before the SOI (start-of-image) marker.
98-
// Note: this seems to mainly affect inline images.
99-
for (let i = 0, ii = data.length - 1; i < ii; i++) {
100-
if (data[i] === 0xff && data[i + 1] === 0xd8) {
101-
if (i > 0) {
102-
data = data.subarray(i);
103-
}
104-
break;
105-
}
106-
}
107-
return data;
108-
}
109-
110-
decodeImage(bytes) {
111-
if (this.eof) {
112-
return this.buffer;
113-
}
114-
bytes = this.#skipUselessBytes(bytes || this.bytes);
11596

116-
// TODO: if an image has a mask we need to combine the data.
117-
// So ideally get a VideoFrame from getTransferableImage and then use
118-
// copyTo.
119-
120-
const jpegImage = new JpegImage(this.jpegOptions);
97+
const jpegImage = new JpegImage(jpegOptions);
12198
jpegImage.parse(bytes);
12299
const data = jpegImage.getData({
123100
width: this.drawWidth,
@@ -136,48 +113,6 @@ class JpegStream extends DecodeStream {
136113
get canAsyncDecodeImageFromBuffer() {
137114
return this.stream.isAsync;
138115
}
139-
140-
async getTransferableImage() {
141-
if (!(await JpegStream.canUseImageDecoder)) {
142-
return null;
143-
}
144-
const jpegOptions = this.jpegOptions;
145-
if (jpegOptions.decodeTransform) {
146-
// TODO: We could decode the image thanks to ImageDecoder and then
147-
// get the pixels with copyTo and apply the decodeTransform.
148-
return null;
149-
}
150-
let decoder;
151-
try {
152-
// TODO: If the stream is Flate & DCT we could try to just pipe the
153-
// the DecompressionStream into the ImageDecoder: it'll avoid the
154-
// intermediate ArrayBuffer.
155-
const bytes =
156-
(this.canAsyncDecodeImageFromBuffer &&
157-
(await this.stream.asyncGetBytes())) ||
158-
this.bytes;
159-
if (!bytes) {
160-
return null;
161-
}
162-
const data = this.#skipUselessBytes(bytes);
163-
if (!JpegImage.canUseImageDecoder(data, jpegOptions.colorTransform)) {
164-
return null;
165-
}
166-
// eslint-disable-next-line no-undef
167-
decoder = new ImageDecoder({
168-
data,
169-
type: "image/jpeg",
170-
preferAnimation: false,
171-
});
172-
173-
return (await decoder.decode()).image;
174-
} catch (reason) {
175-
warn(`getTransferableImage - failed: "${reason}".`);
176-
return null;
177-
} finally {
178-
decoder?.close();
179-
}
180-
}
181116
}
182117

183118
export { JpegStream };

0 commit comments

Comments
 (0)