diff --git a/src/core/annotation.js b/src/core/annotation.js index 9463525c1..5e0dac35b 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -261,6 +261,7 @@ class Annotation { /** * Set the color and take care of color space conversion. + * The default value is black, in RGB color space. * * @public * @memberof Annotation @@ -269,7 +270,7 @@ class Annotation { * 4 (CMYK) elements */ setColor(color) { - let rgbColor = new Uint8Array(3); // Black in RGB color space (default) + let rgbColor = new Uint8ClampedArray(3); if (!Array.isArray(color)) { this.color = rgbColor; return; diff --git a/src/core/colorspace.js b/src/core/colorspace.js index 4699195b1..0aa1b3986 100644 --- a/src/core/colorspace.js +++ b/src/core/colorspace.js @@ -65,7 +65,7 @@ var ColorSpace = (function ColorSpaceClosure() { * of the rgb components, each value ranging from [0,255]. */ getRgb(src, srcOffset) { - var rgb = new Uint8Array(3); + let rgb = new Uint8ClampedArray(3); this.getRgbItem(src, srcOffset, rgb, 0); return rgb; }, @@ -118,7 +118,7 @@ var ColorSpace = (function ColorSpaceClosure() { if (this.isPassthrough(bpc)) { rgbBuf = comps; } else if (this.numComps === 1 && count > numComponentColors && - this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') { + this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') { // Optimization: create a color map when there is just one component and // we are converting more colors than the size of the color map. We // don't build the map if the colorspace is gray or rgb since those @@ -134,7 +134,7 @@ var ColorSpace = (function ColorSpaceClosure() { for (i = 0; i < numComponentColors; i++) { allColors[i] = i; } - var colorMap = new Uint8Array(numComponentColors * 3); + var colorMap = new Uint8ClampedArray(numComponentColors * 3); this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc, /* alpha01 = */ 0); @@ -165,7 +165,7 @@ var ColorSpace = (function ColorSpaceClosure() { this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc, alpha01); } else { - rgbBuf = new Uint8Array(count * 3); + rgbBuf = new Uint8ClampedArray(count * 3); this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc, /* alpha01 = */ 0); } @@ -446,7 +446,8 @@ var AlternateCS = (function AlternateCSClosure() { var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) && alpha01 === 0; var pos = isPassthrough ? destOffset : 0; - var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count); + let baseBuf = isPassthrough ? + dest : new Uint8ClampedArray(baseNumComps * count); var numComps = this.numComps; var scaled = new Float32Array(numComps); @@ -569,15 +570,14 @@ var DeviceGrayCS = (function DeviceGrayCSClosure() { DeviceGrayCS.prototype = { getRgb: ColorSpace.prototype.getRgb, getRgbItem(src, srcOffset, dest, destOffset) { - var c = (src[srcOffset] * 255) | 0; - c = c < 0 ? 0 : c > 255 ? 255 : c; + let c = src[srcOffset] * 255; dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c; }, getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) { var scale = 255 / ((1 << bits) - 1); var j = srcOffset, q = destOffset; for (var i = 0; i < count; ++i) { - var c = (scale * src[j++]) | 0; + let c = scale * src[j++]; dest[q++] = c; dest[q++] = c; dest[q++] = c; @@ -606,12 +606,9 @@ var DeviceRgbCS = (function DeviceRgbCSClosure() { DeviceRgbCS.prototype = { getRgb: ColorSpace.prototype.getRgb, getRgbItem(src, srcOffset, dest, destOffset) { - var r = (src[srcOffset] * 255) | 0; - var g = (src[srcOffset + 1] * 255) | 0; - var b = (src[srcOffset + 2] * 255) | 0; - dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r; - dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g; - dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b; + dest[destOffset] = src[srcOffset] * 255; + dest[destOffset + 1] = src[srcOffset + 1] * 255; + dest[destOffset + 2] = src[srcOffset + 2] * 255; }, getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) { if (bits === 8 && alpha01 === 0) { @@ -621,9 +618,9 @@ var DeviceRgbCS = (function DeviceRgbCSClosure() { var scale = 255 / ((1 << bits) - 1); var j = srcOffset, q = destOffset; for (var i = 0; i < count; ++i) { - dest[q++] = (scale * src[j++]) | 0; - dest[q++] = (scale * src[j++]) | 0; - dest[q++] = (scale * src[j++]) | 0; + dest[q++] = scale * src[j++]; + dest[q++] = scale * src[j++]; + dest[q++] = scale * src[j++]; q += alpha01; } }, @@ -650,41 +647,39 @@ var DeviceCmykCS = (function DeviceCmykCSClosure() { // CMYK color conversion using the estimation below: // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255 function convertToRgb(src, srcOffset, srcScale, dest, destOffset) { - var c = src[srcOffset + 0] * srcScale; + var c = src[srcOffset] * srcScale; var m = src[srcOffset + 1] * srcScale; var y = src[srcOffset + 2] * srcScale; var k = src[srcOffset + 3] * srcScale; - var r = - (c * (-4.387332384609988 * c + 54.48615194189176 * m + - 18.82290502165302 * y + 212.25662451639585 * k + - -285.2331026137004) + - m * (1.7149763477362134 * m - 5.6096736904047315 * y + - -17.873870861415444 * k - 5.497006427196366) + - y * (-2.5217340131683033 * y - 21.248923337353073 * k + - 17.5119270841813) + - k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0; - var g = - (c * (8.841041422036149 * c + 60.118027045597366 * m + - 6.871425592049007 * y + 31.159100130055922 * k + - -79.2970844816548) + - m * (-15.310361306967817 * m + 17.575251261109482 * y + - 131.35250912493976 * k - 190.9453302588951) + - y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) + - k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0; - var b = - (c * (0.8842522430003296 * c + 8.078677503112928 * m + - 30.89978309703729 * y - 0.23883238689178934 * k + - -14.183576799673286) + - m * (10.49593273432072 * m + 63.02378494754052 * y + - 50.606957656360734 * k - 112.23884253719248) + - y * (0.03296041114873217 * y + 115.60384449646641 * k + - -193.58209356861505) + - k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0; + dest[destOffset] = 255 + + c * (-4.387332384609988 * c + 54.48615194189176 * m + + 18.82290502165302 * y + 212.25662451639585 * k + + -285.2331026137004) + + m * (1.7149763477362134 * m - 5.6096736904047315 * y + + -17.873870861415444 * k - 5.497006427196366) + + y * (-2.5217340131683033 * y - 21.248923337353073 * k + + 17.5119270841813) + + k * (-21.86122147463605 * k - 189.48180835922747); - dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r; - dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g; - dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b; + dest[destOffset + 1] = 255 + + c * (8.841041422036149 * c + 60.118027045597366 * m + + 6.871425592049007 * y + 31.159100130055922 * k + + -79.2970844816548) + + m * (-15.310361306967817 * m + 17.575251261109482 * y + + 131.35250912493976 * k - 190.9453302588951) + + y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) + + k * (-20.737325471181034 * k - 187.80453709719578); + + dest[destOffset + 2] = 255 + + c * (0.8842522430003296 * c + 8.078677503112928 * m + + 30.89978309703729 * y - 0.23883238689178934 * k + + -14.183576799673286) + + m * (10.49593273432072 * m + 63.02378494754052 * y + + 50.606957656360734 * k - 112.23884253719248) + + y * (0.03296041114873217 * y + 115.60384449646641 * k + + -193.58209356861505) + + k * (-22.33816807309886 * k - 180.12613974708367); } function DeviceCmykCS() { @@ -782,7 +777,7 @@ var CalGrayCS = (function CalGrayCSClosure() { var L = cs.YW * AG; // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4. // Convert values to rgb range [0, 255]. - var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0; + let val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0); dest[destOffset] = val; dest[destOffset + 1] = val; dest[destOffset + 2] = val; @@ -1071,14 +1066,10 @@ var CalRGBCS = (function CalRGBCSClosure() { var SRGB = tempConvertMatrix1; matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB); - var sR = sRGBTransferFunction(SRGB[0]); - var sG = sRGBTransferFunction(SRGB[1]); - var sB = sRGBTransferFunction(SRGB[2]); - // Convert the values to rgb range [0, 255]. - dest[destOffset] = Math.round(sR * 255); - dest[destOffset + 1] = Math.round(sG * 255); - dest[destOffset + 2] = Math.round(sB * 255); + dest[destOffset] = sRGBTransferFunction(SRGB[0]) * 255; + dest[destOffset + 1] = sRGBTransferFunction(SRGB[1]) * 255; + dest[destOffset + 2] = sRGBTransferFunction(SRGB[2]) * 255; } CalRGBCS.prototype = { @@ -1218,10 +1209,10 @@ var LabCS = (function LabCSClosure() { g = X * -0.9689 + Y * 1.8758 + Z * 0.0415; b = X * 0.0557 + Y * -0.2040 + Z * 1.0570; } - // clamp color values to [0,1] range then convert to [0,255] range. - dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0; - dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0; - dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0; + // Convert the color values to the [0,255] range (clamping is automatic). + dest[destOffset] = Math.sqrt(r) * 255; + dest[destOffset + 1] = Math.sqrt(g) * 255; + dest[destOffset + 2] = Math.sqrt(b) * 255; } LabCS.prototype = { diff --git a/src/core/evaluator.js b/src/core/evaluator.js index 302ed26a5..315b56b41 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -377,7 +377,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { var width = dict.get('Width', 'W'); var height = dict.get('Height', 'H'); var bitStrideLength = (width + 7) >> 3; - var imgArray = image.getBytes(bitStrideLength * height); + var imgArray = image.getBytes(bitStrideLength * height, + /* forceClamped = */ true); var decode = dict.getArray('Decode', 'D'); imgData = PDFImage.createMask({ diff --git a/src/core/image.js b/src/core/image.js index bd1896802..f564e95b6 100644 --- a/src/core/image.js +++ b/src/core/image.js @@ -259,10 +259,10 @@ var PDFImage = (function PDFImageClosure() { // form, so we can just transfer it. data = imgArray; } else if (!inverseDecode) { - data = new Uint8Array(actualLength); + data = new Uint8ClampedArray(actualLength); data.set(imgArray); } else { - data = new Uint8Array(computedLength); + data = new Uint8ClampedArray(computedLength); data.set(imgArray); for (i = actualLength; i < computedLength; i++) { data[i] = 0xff; @@ -406,7 +406,7 @@ var PDFImage = (function PDFImageClosure() { if (smask) { sw = smask.width; sh = smask.height; - alphaBuf = new Uint8Array(sw * sh); + alphaBuf = new Uint8ClampedArray(sw * sh); smask.fillGrayBuffer(alphaBuf); if (sw !== width || sh !== height) { alphaBuf = resizeImageMask(alphaBuf, smask.bpc, sw, sh, @@ -416,7 +416,7 @@ var PDFImage = (function PDFImageClosure() { if (mask instanceof PDFImage) { sw = mask.width; sh = mask.height; - alphaBuf = new Uint8Array(sw * sh); + alphaBuf = new Uint8ClampedArray(sw * sh); mask.numComps = 1; mask.fillGrayBuffer(alphaBuf); @@ -432,7 +432,7 @@ var PDFImage = (function PDFImageClosure() { } else if (Array.isArray(mask)) { // Color key mask: if any of the components are outside the range // then they should be painted. - alphaBuf = new Uint8Array(width * height); + alphaBuf = new Uint8ClampedArray(width * height); var numComps = this.numComps; for (i = 0, ii = width * height; i < ii; ++i) { var opacity = 0; @@ -474,7 +474,6 @@ var PDFImage = (function PDFImageClosure() { var matteG = matteRgb[1]; var matteB = matteRgb[2]; var length = width * height * 4; - var r, g, b; for (var i = 0; i < length; i += 4) { var alpha = buffer[i + 3]; if (alpha === 0) { @@ -486,12 +485,9 @@ var PDFImage = (function PDFImageClosure() { continue; } var k = 255 / alpha; - r = (buffer[i] - matteR) * k + matteR; - g = (buffer[i + 1] - matteG) * k + matteG; - b = (buffer[i + 2] - matteB) * k + matteB; - buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0; - buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0; - buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0; + buffer[i] = (buffer[i] - matteR) * k + matteR; + buffer[i + 1] = (buffer[i + 1] - matteG) * k + matteG; + buffer[i + 2] = (buffer[i + 2] - matteB) * k + matteB; } }, @@ -501,6 +497,8 @@ var PDFImage = (function PDFImageClosure() { var imgData = { // other fields are filled in below width: drawWidth, height: drawHeight, + kind: 0, + data: null, }; var numComps = this.numComps; @@ -540,7 +538,7 @@ var PDFImage = (function PDFImageClosure() { if (this.image instanceof DecodeStream) { imgData.data = imgArray; } else { - var newArray = new Uint8Array(imgArray.length); + var newArray = new Uint8ClampedArray(imgArray.length); newArray.set(imgArray); imgData.data = newArray; } @@ -584,12 +582,12 @@ var PDFImage = (function PDFImageClosure() { var alpha01, maybeUndoPreblend; if (!forceRGBA && !this.smask && !this.mask) { imgData.kind = ImageKind.RGB_24BPP; - imgData.data = new Uint8Array(drawWidth * drawHeight * 3); + imgData.data = new Uint8ClampedArray(drawWidth * drawHeight * 3); alpha01 = 0; maybeUndoPreblend = false; } else { imgData.kind = ImageKind.RGBA_32BPP; - imgData.data = new Uint8Array(drawWidth * drawHeight * 4); + imgData.data = new Uint8ClampedArray(drawWidth * drawHeight * 4); alpha01 = 1; maybeUndoPreblend = true; @@ -653,7 +651,7 @@ var PDFImage = (function PDFImageClosure() { // we aren't using a colorspace so we need to scale the value var scale = 255 / ((1 << bpc) - 1); for (i = 0; i < length; ++i) { - buffer[i] = (scale * comps[i]) | 0; + buffer[i] = scale * comps[i]; } }, @@ -662,7 +660,7 @@ var PDFImage = (function PDFImageClosure() { this.image.drawWidth = drawWidth || this.width; this.image.drawHeight = drawHeight || this.height; this.image.forceRGB = !!forceRGB; - return this.image.getBytes(length); + return this.image.getBytes(length, /* forceClamped = */ true); }, }; return PDFImage; diff --git a/src/core/obj.js b/src/core/obj.js index ada0977d1..9069cf747 100644 --- a/src/core/obj.js +++ b/src/core/obj.js @@ -114,7 +114,7 @@ var Catalog = (function CatalogClosure() { // To avoid recursion, keep track of the already processed items. var processed = new RefSet(); processed.put(obj); - var xref = this.xref, blackColor = new Uint8Array(3); + var xref = this.xref, blackColor = new Uint8ClampedArray(3); while (queue.length > 0) { var i = queue.shift(); diff --git a/src/display/api.js b/src/display/api.js index 6e71f8cc7..63ade2d12 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -671,7 +671,7 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() { * title: string, * bold: boolean, * italic: boolean, - * color: rgb Uint8Array, + * color: rgb Uint8ClampedArray, * dest: dest obj, * url: string, * items: array of more items like this diff --git a/test/unit/annotation_spec.js b/test/unit/annotation_spec.js index 1fb89116c..67e935aef 100644 --- a/test/unit/annotation_spec.js +++ b/test/unit/annotation_spec.js @@ -166,7 +166,7 @@ describe('annotation', function() { var annotation = new Annotation({ dict, ref, }); annotation.setColor('red'); - expect(annotation.color).toEqual(new Uint8Array([0, 0, 0])); + expect(annotation.color).toEqual(new Uint8ClampedArray([0, 0, 0])); }); it('should set and get a transparent color', function() { @@ -180,28 +180,28 @@ describe('annotation', function() { var annotation = new Annotation({ dict, ref, }); annotation.setColor([0.4]); - expect(annotation.color).toEqual(new Uint8Array([102, 102, 102])); + expect(annotation.color).toEqual(new Uint8ClampedArray([102, 102, 102])); }); it('should set and get an RGB color', function() { var annotation = new Annotation({ dict, ref, }); annotation.setColor([0, 0, 1]); - expect(annotation.color).toEqual(new Uint8Array([0, 0, 255])); + expect(annotation.color).toEqual(new Uint8ClampedArray([0, 0, 255])); }); it('should set and get a CMYK color', function() { var annotation = new Annotation({ dict, ref, }); annotation.setColor([0.1, 0.92, 0.84, 0.02]); - expect(annotation.color).toEqual(new Uint8Array([233, 59, 47])); + expect(annotation.color).toEqual(new Uint8ClampedArray([234, 59, 48])); }); it('should not set and get an invalid color', function() { var annotation = new Annotation({ dict, ref, }); annotation.setColor([0.4, 0.6]); - expect(annotation.color).toEqual(new Uint8Array([0, 0, 0])); + expect(annotation.color).toEqual(new Uint8ClampedArray([0, 0, 0])); }); }); diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js index 1d3264649..d8532f02b 100644 --- a/test/unit/api_spec.js +++ b/test/unit/api_spec.js @@ -764,7 +764,7 @@ describe('api', function() { expect(outlineItem.bold).toEqual(true); expect(outlineItem.italic).toEqual(false); - expect(outlineItem.color).toEqual(new Uint8Array([0, 64, 128])); + expect(outlineItem.color).toEqual(new Uint8ClampedArray([0, 64, 128])); expect(outlineItem.items.length).toEqual(1); expect(outlineItem.items[0].title).toEqual('Paragraph 1.1'); @@ -791,7 +791,8 @@ describe('api', function() { var outlineItemOne = outline[1]; expect(outlineItemOne.bold).toEqual(false); expect(outlineItemOne.italic).toEqual(true); - expect(outlineItemOne.color).toEqual(new Uint8Array([0, 0, 0])); + expect(outlineItemOne.color).toEqual( + new Uint8ClampedArray([0, 0, 0])); loadingTask.destroy().then(done); }); diff --git a/test/unit/colorspace_spec.js b/test/unit/colorspace_spec.js index 63c0db66f..c3c6f9488 100644 --- a/test/unit/colorspace_spec.js +++ b/test/unit/colorspace_spec.js @@ -61,8 +61,8 @@ describe('colorspace', function () { let colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory); let testSrc = new Uint8Array([27, 125, 250, 131]); - let testDest = new Uint8Array(4 * 4 * 3); - let expectedDest = new Uint8Array([ + let testDest = new Uint8ClampedArray(4 * 4 * 3); + let expectedDest = new Uint8ClampedArray([ 27, 27, 27, 27, 27, 27, 125, 125, 125, @@ -83,7 +83,7 @@ describe('colorspace', function () { colorSpace.fillRgb(testDest, 2, 2, 4, 4, 4, 8, testSrc, 0); expect(colorSpace.getRgb(new Float32Array([0.1]), 0)) - .toEqual(new Uint8Array([25, 25, 25])); + .toEqual(new Uint8ClampedArray([26, 26, 26])); expect(colorSpace.getOutputLength(2, 0)).toEqual(6); expect(colorSpace.isPassthrough(8)).toBeFalsy(); expect(testDest).toEqual(expectedDest); @@ -102,8 +102,8 @@ describe('colorspace', function () { let colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory); let testSrc = new Uint8Array([27, 125, 250, 131]); - let testDest = new Uint8Array(3 * 3 * 3); - let expectedDest = new Uint8Array([ + let testDest = new Uint8ClampedArray(3 * 3 * 3); + let expectedDest = new Uint8ClampedArray([ 27, 27, 27, 27, 27, 27, 125, 125, 125, @@ -117,7 +117,7 @@ describe('colorspace', function () { colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0); expect(colorSpace.getRgb(new Float32Array([0.2]), 0)) - .toEqual(new Uint8Array([51, 51, 51])); + .toEqual(new Uint8ClampedArray([51, 51, 51])); expect(colorSpace.getOutputLength(3, 1)).toEqual(12); expect(colorSpace.isPassthrough(8)).toBeFalsy(); expect(testDest).toEqual(expectedDest); @@ -144,8 +144,8 @@ describe('colorspace', function () { 111, 25, 198, 21, 147, 255 ]); - let testDest = new Uint8Array(4 * 4 * 3); - let expectedDest = new Uint8Array([ + let testDest = new Uint8ClampedArray(4 * 4 * 3); + let expectedDest = new Uint8ClampedArray([ 27, 125, 250, 27, 125, 250, 131, 139, 140, @@ -166,7 +166,7 @@ describe('colorspace', function () { colorSpace.fillRgb(testDest, 2, 2, 4, 4, 4, 8, testSrc, 0); expect(colorSpace.getRgb(new Float32Array([0.1, 0.2, 0.3]), 0)) - .toEqual(new Uint8Array([25, 51, 76])); + .toEqual(new Uint8ClampedArray([26, 51, 77])); expect(colorSpace.getOutputLength(4, 0)).toEqual(4); expect(colorSpace.isPassthrough(8)).toBeTruthy(); expect(testDest).toEqual(expectedDest); @@ -190,8 +190,8 @@ describe('colorspace', function () { 111, 25, 198, 21, 147, 255 ]); - let testDest = new Uint8Array(3 * 3 * 3); - let expectedDest = new Uint8Array([ + let testDest = new Uint8ClampedArray(3 * 3 * 3); + let expectedDest = new Uint8ClampedArray([ 27, 125, 250, 27, 125, 250, 131, 139, 140, @@ -205,7 +205,7 @@ describe('colorspace', function () { colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0); expect(colorSpace.getRgb(new Float32Array([0.1, 0.2, 0.3]), 0)) - .toEqual(new Uint8Array([25, 51, 76])); + .toEqual(new Uint8ClampedArray([26, 51, 77])); expect(colorSpace.getOutputLength(4, 1)).toEqual(5); expect(colorSpace.isPassthrough(8)).toBeTruthy(); expect(testDest).toEqual(expectedDest); @@ -232,29 +232,29 @@ describe('colorspace', function () { 111, 25, 198, 78, 21, 147, 255, 69 ]); - let testDest = new Uint8Array(4 * 4 * 3); - let expectedDest = new Uint8Array([ - 135, 80, 18, - 135, 80, 18, - 113, 102, 97, - 113, 102, 97, - 135, 80, 18, - 135, 80, 18, - 113, 102, 97, - 113, 102, 97, - 112, 143, 75, - 112, 143, 75, + let testDest = new Uint8ClampedArray(4 * 4 * 3); + let expectedDest = new Uint8ClampedArray([ + 135, 81, 18, + 135, 81, 18, + 114, 102, 97, + 114, 102, 97, + 135, 81, 18, + 135, 81, 18, + 114, 102, 97, + 114, 102, 97, + 112, 144, 75, + 112, 144, 75, 188, 98, 27, 188, 98, 27, - 112, 143, 75, - 112, 143, 75, + 112, 144, 75, + 112, 144, 75, 188, 98, 27, 188, 98, 27 ]); colorSpace.fillRgb(testDest, 2, 2, 4, 4, 4, 8, testSrc, 0); expect(colorSpace.getRgb(new Float32Array([0.1, 0.2, 0.3, 1]), - 0)).toEqual(new Uint8Array([31, 27, 20])); + 0)).toEqual(new Uint8ClampedArray([32, 28, 21])); expect(colorSpace.getOutputLength(4, 0)).toEqual(3); expect(colorSpace.isPassthrough(8)).toBeFalsy(); expect(testDest).toEqual(expectedDest); @@ -278,22 +278,22 @@ describe('colorspace', function () { 111, 25, 198, 78, 21, 147, 255, 69 ]); - let testDest = new Uint8Array(3 * 3 * 3); - let expectedDest = new Uint8Array([ - 135, 80, 18, - 135, 80, 18, - 113, 102, 97, - 135, 80, 18, - 135, 80, 18, - 113, 102, 97, - 112, 143, 75, - 112, 143, 75, + let testDest = new Uint8ClampedArray(3 * 3 * 3); + let expectedDest = new Uint8ClampedArray([ + 135, 81, 18, + 135, 81, 18, + 114, 102, 97, + 135, 81, 18, + 135, 81, 18, + 114, 102, 97, + 112, 144, 75, + 112, 144, 75, 188, 98, 27 ]); colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0); expect(colorSpace.getRgb(new Float32Array([0.1, 0.2, 0.3, 1]), 0)) - .toEqual(new Uint8Array([31, 27, 20])); + .toEqual(new Uint8ClampedArray([32, 28, 21])); expect(colorSpace.getOutputLength(4, 1)).toEqual(4); expect(colorSpace.isPassthrough(8)).toBeFalsy(); expect(testDest).toEqual(expectedDest); @@ -323,8 +323,8 @@ describe('colorspace', function () { let colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory); let testSrc = new Uint8Array([27, 125, 250, 131]); - let testDest = new Uint8Array(4 * 4 * 3); - let expectedDest = new Uint8Array([ + let testDest = new Uint8ClampedArray(4 * 4 * 3); + let expectedDest = new Uint8ClampedArray([ 25, 25, 25, 25, 25, 25, 143, 143, 143, @@ -335,17 +335,17 @@ describe('colorspace', function () { 143, 143, 143, 251, 251, 251, 251, 251, 251, - 148, 148, 148, - 148, 148, 148, + 149, 149, 149, + 149, 149, 149, 251, 251, 251, 251, 251, 251, - 148, 148, 148, - 148, 148, 148 + 149, 149, 149, + 149, 149, 149 ]); colorSpace.fillRgb(testDest, 2, 2, 4, 4, 4, 8, testSrc, 0); expect(colorSpace.getRgb(new Float32Array([1.0]), 0)) - .toEqual(new Uint8Array([255, 255, 255])); + .toEqual(new Uint8ClampedArray([255, 255, 255])); expect(colorSpace.getOutputLength(4, 0)).toEqual(12); expect(colorSpace.isPassthrough(8)).toBeFalsy(); expect(testDest).toEqual(expectedDest); @@ -381,8 +381,8 @@ describe('colorspace', function () { 111, 25, 198, 21, 147, 255 ]); - let testDest = new Uint8Array(3 * 3 * 3); - let expectedDest = new Uint8Array([ + let testDest = new Uint8ClampedArray(3 * 3 * 3); + let expectedDest = new Uint8ClampedArray([ 0, 238, 255, 0, 238, 255, 185, 196, 195, @@ -396,7 +396,7 @@ describe('colorspace', function () { colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0); expect(colorSpace.getRgb(new Float32Array([0.1, 0.2, 0.3]), 0)) - .toEqual(new Uint8Array([0, 147, 151])); + .toEqual(new Uint8ClampedArray([0, 147, 151])); expect(colorSpace.getOutputLength(4, 0)).toEqual(4); expect(colorSpace.isPassthrough(8)).toBeFalsy(); expect(testDest).toEqual(expectedDest); @@ -431,22 +431,22 @@ describe('colorspace', function () { 11, 25, 98, 21, 47, 55 ]); - let testDest = new Uint8Array(3 * 3 * 3); - let expectedDest = new Uint8Array([ + let testDest = new Uint8ClampedArray(3 * 3 * 3); + let expectedDest = new Uint8ClampedArray([ 0, 49, 101, 0, 49, 101, - 0, 53, 116, + 0, 53, 117, 0, 49, 101, 0, 49, 101, - 0, 53, 116, - 0, 40, 39, - 0, 40, 39, + 0, 53, 117, + 0, 41, 40, + 0, 41, 40, 0, 43, 90 ]); colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0); expect(colorSpace.getRgb([55, 25, 35], 0)) - .toEqual(new Uint8Array([188, 99, 61])); + .toEqual(new Uint8ClampedArray([188, 100, 61])); expect(colorSpace.getOutputLength(4, 0)).toEqual(4); expect(colorSpace.isPassthrough(8)).toBeFalsy(); expect(colorSpace.isDefaultDecode([0, 1])).toBeTruthy(); @@ -479,8 +479,8 @@ describe('colorspace', function () { let colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory); let testSrc = new Uint8Array([2, 2, 0, 1]); - let testDest = new Uint8Array(3 * 3 * 3); - let expectedDest = new Uint8Array([ + let testDest = new Uint8ClampedArray(3 * 3 * 3); + let expectedDest = new Uint8ClampedArray([ 255, 109, 70, 255, 109, 70, 255, 109, 70, @@ -493,7 +493,8 @@ describe('colorspace', function () { ]); colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0); - expect(colorSpace.getRgb([2], 0)).toEqual(new Uint8Array([255, 109, 70])); + expect(colorSpace.getRgb([2], 0)).toEqual( + new Uint8ClampedArray([255, 109, 70])); expect(colorSpace.isPassthrough(8)).toBeFalsy(); expect(colorSpace.isDefaultDecode([0, 1])).toBeTruthy(); expect(testDest).toEqual(expectedDest); @@ -534,22 +535,22 @@ describe('colorspace', function () { let colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory); let testSrc = new Uint8Array([27, 25, 50, 31]); - let testDest = new Uint8Array(3 * 3 * 3); - let expectedDest = new Uint8Array([ - 227, 243, 242, - 227, 243, 242, - 228, 243, 242, - 227, 243, 242, - 227, 243, 242, - 228, 243, 242, - 203, 233, 229, - 203, 233, 229, - 222, 241, 239 + let testDest = new Uint8ClampedArray(3 * 3 * 3); + let expectedDest = new Uint8ClampedArray([ + 226, 242, 241, + 226, 242, 241, + 229, 244, 242, + 226, 242, 241, + 226, 242, 241, + 229, 244, 242, + 203, 232, 229, + 203, 232, 229, + 222, 241, 238 ]); colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0); expect(colorSpace.getRgb([0.1], 0)) - .toEqual(new Uint8Array([228, 243, 241])); + .toEqual(new Uint8ClampedArray([228, 243, 242])); expect(colorSpace.isPassthrough(8)).toBeFalsy(); expect(colorSpace.isDefaultDecode([0, 1])).toBeTruthy(); expect(testDest).toEqual(expectedDest);