-
Notifications
You must be signed in to change notification settings - Fork 10.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update ColorSpace
and PDFImage
to use Uint8ClampedArray
s and remove manual clamping/rounding
#9802
Update ColorSpace
and PDFImage
to use Uint8ClampedArray
s and remove manual clamping/rounding
#9802
Conversation
…hunkedStream` able to return `Uint8ClampedArray`s The built-in image decoders are already returning data as `Uint8ClampedArray`, and subsequently the JPEG/JBIG2/JPX streams are as well. However, for general streams we obviously don't want to force the use of `Uint8ClampedArray` unless an "Image" is actually being decoded. Hence this patch, which adds a parameter that allows the caller of the `getBytes`/`peekBytes` methods to force a `Uint8ClampedArray` (rather than a `Uint8Array`) to be returned.
…the `resizeRgbImage` function in `src/core/colorspace.js`
…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).
…rList, getTextContent} when errors are being ignored Currently the actual errors aren't printed, which can make debugging harder than necessary.
…code-paths Since the tests (currently) run with the `pdf.worker.js` file built, i.e. with `PRODUCTION = true` set, there's no simple way to add e.g. `assert` calls for both non-production *and* test-only builds without also affecting PRODUCTION builds.
…ray` 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.
/botio test |
From: Bot.io (Linux m4)ReceivedCommand cmd_test from @Snuffleupagus received. Current queue size: 0 Live output at: http://54.67.70.0:8877/56860cacab0e86f/output.txt |
From: Bot.io (Windows)ReceivedCommand cmd_test from @Snuffleupagus received. Current queue size: 0 Live output at: http://54.215.176.217:8877/ff6da190a24bdcf/output.txt |
From: Bot.io (Linux m4)FailedFull output at http://54.67.70.0:8877/56860cacab0e86f/output.txt Total script time: 17.67 mins
Image differences available at: http://54.67.70.0:8877/56860cacab0e86f/reftest-analyzer.html#web=eq.log |
From: Bot.io (Windows)FailedFull output at http://54.215.176.217:8877/ff6da190a24bdcf/output.txt Total script time: 22.34 mins
Image differences available at: http://54.215.176.217:8877/ff6da190a24bdcf/reftest-analyzer.html#web=eq.log |
Looks good! I'll try to review this (and your other patches) during the weekend. |
/botio makeref |
From: Bot.io (Linux m4)ReceivedCommand cmd_makeref from @timvandermeij received. Current queue size: 0 Live output at: http://54.67.70.0:8877/839e25416b12bc8/output.txt |
From: Bot.io (Windows)ReceivedCommand cmd_makeref from @timvandermeij received. Current queue size: 0 Live output at: http://54.215.176.217:8877/1091904b2197b46/output.txt |
From: Bot.io (Windows)SuccessFull output at http://54.215.176.217:8877/1091904b2197b46/output.txt Total script time: 21.41 mins
|
From: Bot.io (Linux m4)SuccessFull output at http://54.67.70.0:8877/839e25416b12bc8/output.txt Total script time: 35.75 mins
|
Nice clean-up! Much more readable this way. |
…e-Uint8ClampedArray Update `ColorSpace` and `PDFImage` to use `Uint8ClampedArray`s and remove manual clamping/rounding
This supersedes PR #8789.
/cc @timvandermeij