1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 01:58:06 +02:00

Remove manual clamping/rounding from ColorSpace and PDFImage, by having their methods use Uint8ClampedArrays

The built-in image decoders are already using `Uint8ClampedArray` when returning data, and this patch simply extends that to the rest of the image/colorspace code.

As far as I can tell, the only reason for using manual clamping/rounding in the first place was because TypedArrays used to be polyfilled (using regular arrays). And trying to polyfill the native clamping/rounding would probably have been had too much overhead, but given that TypedArray support is required in PDF.js version `2.0` that's no longer a concern.

*Please note:* Because of different rounding behaviour, basically `Math.round` in `Uint8ClampedArray` respectively `Math.floor` in the old code, there will be very slight movement in quite a few existing test-cases. However, the changes should be imperceivable to the naked eye, given that the absolute difference is *at most* `1` for each RGB component when comparing `master` and this patch (see also the updated expectation values in the unit-tests).
This commit is contained in:
Jonas Jenwald 2018-06-11 17:25:40 +02:00
parent 55199aa281
commit 731f2e6dfc
9 changed files with 150 additions and 157 deletions

View file

@ -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();