-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9729 from Snuffleupagus/gulp-image_decoders
Add a `gulp image_decoders` command to package the image decoders (i.e. jpg.js, jpx.js, jbig2.js) separately, and publish them in pdfjs-dist
- Loading branch information
Showing
10 changed files
with
288 additions
and
14 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,40 @@ | ||
<!DOCTYPE html> | ||
<!-- | ||
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. | ||
--> | ||
<html dir="ltr" mozdisallowselectionprint> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> | ||
<meta name="google" content="notranslate"> | ||
<title>PDF.js standalone JpegImage parser</title> | ||
|
||
<style> | ||
body { | ||
background-color: #808080; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
</style> | ||
|
||
<script src="../../node_modules/pdfjs-dist/image_decoders/pdf.image_decoders.js"></script> | ||
</head> | ||
|
||
<body tabindex="1"> | ||
<canvas id="jpegCanvas" width="0" height="0"></canvas> | ||
|
||
<script src="jpeg_viewer.js"></script> | ||
</body> | ||
</html> |
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,75 @@ | ||
/* 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. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
if (!pdfjsImageDecoders.JpegImage) { | ||
alert('Please build the pdfjs-dist library using `gulp dist-install`'); | ||
} | ||
|
||
var JPEG_IMAGE = 'fish.jpg'; | ||
|
||
var jpegCanvas = document.getElementById('jpegCanvas'); | ||
var jpegCtx = jpegCanvas.getContext('2d'); | ||
|
||
// Load the image data, and convert it to a Uint8Array. | ||
// | ||
var nonBinaryRequest = false; | ||
var request = new XMLHttpRequest(); | ||
request.open('GET', JPEG_IMAGE, false); | ||
try { | ||
request.responseType = 'arraybuffer'; | ||
nonBinaryRequest = request.responseType !== 'arraybuffer'; | ||
} catch (e) { | ||
nonBinaryRequest = true; | ||
} | ||
if (nonBinaryRequest && request.overrideMimeType) { | ||
request.overrideMimeType('text/plain; charset=x-user-defined'); | ||
} | ||
request.send(null); | ||
|
||
var typedArrayImage; | ||
if (nonBinaryRequest) { | ||
var str = request.responseText, length = str.length; | ||
var bytes = new Uint8Array(length); | ||
for (var i = 0; i < length; ++i) { | ||
bytes[i] = str.charCodeAt(i) & 0xFF; | ||
} | ||
typedArrayImage = bytes; | ||
} else { | ||
typedArrayImage = new Uint8Array(request.response); | ||
} | ||
|
||
// Parse the image data using `JpegImage`. | ||
// | ||
var jpegImage = new pdfjsImageDecoders.JpegImage(); | ||
jpegImage.parse(typedArrayImage); | ||
|
||
var width = jpegImage.width, height = jpegImage.height; | ||
var jpegData = jpegImage.getData(width, height, /* forceRGB = */ true); | ||
|
||
// Render the JPEG image on a <canvas>. | ||
// | ||
var imageData = jpegCtx.createImageData(width, height); | ||
var imageBytes = imageData.data; | ||
for (var i = 0, j = 0, ii = width * height * 4; i < ii;) { | ||
imageBytes[i++] = jpegData[j++]; | ||
imageBytes[i++] = jpegData[j++]; | ||
imageBytes[i++] = jpegData[j++]; | ||
imageBytes[i++] = 255; | ||
} | ||
jpegCanvas.width = width, jpegCanvas.height = height; | ||
jpegCtx.putImageData(imageData, 0, 0); | ||
|
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
Oops, something went wrong.