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

@ -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