mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 01:58:06 +02:00
Enforce the use, in non-production/test-only mode, of Uint8ClampedArray
in all relevant methods in ColorSpace
and PDFImage
Since `ColorSpace` now depends on the native clamping of `Uint8ClampedArray`, this patch adds non-production/test-only `assert`s to enforce that the expected TypedArray is used for the output. These `assert`s are purposely *not* included in PRODUCTION builds since that would break rendering completely, as opposed to "only" displaying some weird colours, when a `Uint8Array` was used. Furthermore, these are mostly added to help catch explicit developer errors when working with the `ColorSpace` and `PDFImage` code.
This commit is contained in:
parent
4b69bb7fe9
commit
d4ff541b78
2 changed files with 108 additions and 2 deletions
|
@ -244,6 +244,11 @@ var PDFImage = (function PDFImageClosure() {
|
|||
|
||||
PDFImage.createMask = function({ imgArray, width, height,
|
||||
imageIsFromDecodeStream, inverseDecode, }) {
|
||||
if (typeof PDFJSDev === 'undefined' ||
|
||||
PDFJSDev.test('!PRODUCTION || TESTING')) {
|
||||
assert(imgArray instanceof Uint8ClampedArray,
|
||||
'PDFImage.createMask: Unsupported "imgArray" type.');
|
||||
}
|
||||
// |imgArray| might not contain full data for every pixel of the mask, so
|
||||
// we need to distinguish between |computedLength| and |actualLength|.
|
||||
// In particular, if inverseDecode is true, then the array we return must
|
||||
|
@ -399,6 +404,11 @@ var PDFImage = (function PDFImageClosure() {
|
|||
},
|
||||
|
||||
fillOpacity(rgbaBuf, width, height, actualHeight, image) {
|
||||
if (typeof PDFJSDev === 'undefined' ||
|
||||
PDFJSDev.test('!PRODUCTION || TESTING')) {
|
||||
assert(rgbaBuf instanceof Uint8ClampedArray,
|
||||
'PDFImage.fillOpacity: Unsupported "rgbaBuf" type.');
|
||||
}
|
||||
var smask = this.smask;
|
||||
var mask = this.mask;
|
||||
var alphaBuf, sw, sh, i, ii, j;
|
||||
|
@ -465,6 +475,11 @@ var PDFImage = (function PDFImageClosure() {
|
|||
},
|
||||
|
||||
undoPreblend(buffer, width, height) {
|
||||
if (typeof PDFJSDev === 'undefined' ||
|
||||
PDFJSDev.test('!PRODUCTION || TESTING')) {
|
||||
assert(buffer instanceof Uint8ClampedArray,
|
||||
'PDFImage.undoPreblend: Unsupported "buffer" type.');
|
||||
}
|
||||
var matte = this.smask && this.smask.matte;
|
||||
if (!matte) {
|
||||
return;
|
||||
|
@ -544,7 +559,8 @@ var PDFImage = (function PDFImageClosure() {
|
|||
}
|
||||
if (this.needsDecode) {
|
||||
// Invert the buffer (which must be grayscale if we reached here).
|
||||
assert(kind === ImageKind.GRAYSCALE_1BPP);
|
||||
assert(kind === ImageKind.GRAYSCALE_1BPP,
|
||||
'PDFImage.createImageData: The image must be grayscale.');
|
||||
var buffer = imgData.data;
|
||||
for (var i = 0, ii = buffer.length; i < ii; i++) {
|
||||
buffer[i] ^= 0xff;
|
||||
|
@ -610,6 +626,11 @@ var PDFImage = (function PDFImageClosure() {
|
|||
},
|
||||
|
||||
fillGrayBuffer(buffer) {
|
||||
if (typeof PDFJSDev === 'undefined' ||
|
||||
PDFJSDev.test('!PRODUCTION || TESTING')) {
|
||||
assert(buffer instanceof Uint8ClampedArray,
|
||||
'PDFImage.fillGrayBuffer: Unsupported "buffer" type.');
|
||||
}
|
||||
var numComps = this.numComps;
|
||||
if (numComps !== 1) {
|
||||
throw new FormatError(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue