-
Notifications
You must be signed in to change notification settings - Fork 10k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update the
examples/
-folder to account for outputting of JavaScript…
… modules *Please note:* These changes probably need to land *just after* the first release that introduces JavaScript modules, such that the examples aren't broken in the meantime. This patch also changes most examples to use "top level await", since that's now supported and slightly simplifies the code.
- Loading branch information
1 parent
927e50f
commit 0b5f70d
Showing
18 changed files
with
229 additions
and
249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* Copyright 2018 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. | ||
*/ | ||
|
||
if (!pdfjsImageDecoders.JpegImage) { | ||
// eslint-disable-next-line no-alert | ||
alert("Please build the pdfjs-dist library using `gulp dist-install`"); | ||
} | ||
|
||
const JPEG_IMAGE = "fish.jpg"; | ||
|
||
const jpegCanvas = document.getElementById("jpegCanvas"); | ||
const jpegCtx = jpegCanvas.getContext("2d"); | ||
|
||
// Load the image data, and convert it to a Uint8Array. | ||
// | ||
const response = await fetch(JPEG_IMAGE); | ||
if (!response.ok) { | ||
throw new Error(response.statusText); | ||
} | ||
const typedArrayImage = new Uint8Array(await response.arrayBuffer()); | ||
|
||
// Parse the image data using `JpegImage`. | ||
// | ||
const jpegImage = new pdfjsImageDecoders.JpegImage(); | ||
jpegImage.parse(typedArrayImage); | ||
|
||
const width = jpegImage.width, | ||
height = jpegImage.height; | ||
const jpegData = jpegImage.getData({ | ||
width, | ||
height, | ||
forceRGB: true, | ||
}); | ||
|
||
// Render the JPEG image on a <canvas>. | ||
// | ||
const imageData = jpegCtx.createImageData(width, height); | ||
const imageBytes = imageData.data; | ||
for (let j = 0, k = 0, jj = width * height * 4; j < jj; ) { | ||
imageBytes[j++] = jpegData[k++]; | ||
imageBytes[j++] = jpegData[k++]; | ||
imageBytes[j++] = jpegData[k++]; | ||
imageBytes[j++] = 255; | ||
} | ||
jpegCanvas.width = width; | ||
jpegCanvas.height = height; | ||
jpegCtx.putImageData(imageData, 0, 0); |
Oops, something went wrong.