'use strict';
-// Some browsers can use UInt8Array directly as imageData.
-PDFJS.FEATURE_CANVAS_UINT_IMAGE_DATA = false;
-if (typeof window !== 'undefined') {
- window.addEventListener('load', function featureCanvasUIntImgaData() {
- var canvas = document.createElement('canvas');
- canvas.width = 1;
- canvas.height = 1;
- var ctx = canvas.getContext('2d');
-
- try {
- ctx.putImageData({
- width: 1,
- height: 1,
- data: new Uint8Array(4)
- }, 0, 0);
- } catch (e) {
- return;
- }
-
- PDFJS.FEATURE_CANVAS_UINT_IMAGE_DATA = true;
- });
-}
-
// <canvas> contexts store most of the state we need natively.
// However, PDF needs a bit more state, which we store here.
var tmpCanvas = new this.ScratchCanvas(w, h);
var tmpCtx = tmpCanvas.getContext('2d');
- var tmpImgData;
-
- if (PDFJS.FEATURE_CANVAS_UINT_IMAGE_DATA) {
- tmpImgData = imgData;
- } else {
- tmpImgData = tmpCtx.getImageData(0, 0, w, h);
-
- // Copy over the imageData pixel by pixel.
- var tmpImgDataPixels = tmpImgData.data;
- var len = tmpImgDataPixels.length;
-
- while (len--) {
- tmpImgDataPixels[len] = imgData.data[len];
- }
- }
+ this.putBinaryImageData(tmpCtx, imgData, w, h);
- tmpCtx.putImageData(tmpImgData, 0, 0);
ctx.drawImage(tmpCanvas, 0, -h);
this.restore();
},
+ putBinaryImageData: function canvasPutBinaryImageData() {
+ //
+ },
+
// Marked content
markPoint: function canvasGraphicsMarkPoint(tag) {
return constructor;
})();
+if (!isWorker) {
+ // Feature detection if the browser can use an Uint8Array directly as imgData.
+ var canvas = document.createElement('canvas');
+ canvas.width = 1;
+ canvas.height = 1;
+ var ctx = canvas.getContext('2d');
+
+ try {
+ ctx.putImageData({
+ width: 1,
+ height: 1,
+ data: new Uint8Array(4)
+ }, 0, 0);
+
+ CanvasGraphics.prototype.putBinaryImageData =
+ function CanvasGraphicsPutBinaryImageDataNative(ctx, imgData) {
+ ctx.putImageData(imgData, 0, 0);
+ };
+ } catch (e) {
+ CanvasGraphics.prototype.putBinaryImageData =
+ function CanvasGraphicsPutBinaryImageDataShim(ctx, imgData, w, h) {
+ var tmpImgData = ctx.getImageData(0, 0, w, h);
+
+ // Copy over the imageData pixel by pixel.
+ var tmpImgDataPixels = tmpImgData.data;
+ var len = tmpImgDataPixels.length;
+
+ while (len--) {
+ tmpImgDataPixels[len] = imgData.data[len];
+ }
+
+ ctx.putImageData(tmpImgData, 0, 0);
+ };
+ }
+}