mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 10:08:06 +02:00
Remove manual clamping/rounding from ColorSpace
and PDFImage
, by having their methods use Uint8ClampedArray
s
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:
parent
55199aa281
commit
731f2e6dfc
9 changed files with 150 additions and 157 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue