Skip to content
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

Reduce or improve calls to clamp0to255 in jpg js #4901

Closed
CodingFabian opened this issue Jun 6, 2014 · 6 comments
Closed

Reduce or improve calls to clamp0to255 in jpg js #4901

CodingFabian opened this issue Jun 6, 2014 · 6 comments

Comments

@CodingFabian
Copy link
Contributor

The following picture shows a profiling from IE10.
slow-pdfjs-ie
it shows that clamping is quite frequent. And because it is IE, it is super slow.
http://jsperf.com/clamp-functions/12
confirms that IE is way behind all modern browsers.

The question I am asking myself:
From the perspective of the algorithm, is the clamping actually needed?
and if so, is it needed in both directions?
Would a | 0 truncation be sufficient?

Maybe @p01 or @bthorben can give me a hint or help me out here.

@p01
Copy link
Contributor

p01 commented Jun 6, 2014

The clamping is needed, OTOH using Uint8ClampedArrays would work like a charm... except not all browsers support them ( PDF.js aims to work on a very broad range of browsers ) and shiming them using getters and setters would slow the shim'ed code path even more and take more memory.

@CodingFabian
Copy link
Contributor Author

would it be possible to polyfill Uint8ClampedArray with Canvas­Pixel­Array ? Canvas­Pixel­Array is supported by IE9.

@yurydelendik
Copy link
Contributor

would it be possible to polyfill Uint8ClampedArray with Canvas­Pixel­Array

Yeah, I thought about that. We will need to do that at some point -- it might take time to review entire code base to fix that for all image processing and colorspace parts.

@CodingFabian
Copy link
Contributor Author

wouldn't the data be automatically clamped when painted to canvas?

@p01
Copy link
Contributor

p01 commented Jun 23, 2014

Unfortunately the HTML5 spec remained fuzzy about clamping vs clipping for a while which lead to different behaviors across browser. Not sure what is the state of affairs in the browsers targeted by PDF.js

@CodingFabian
Copy link
Contributor Author

here a polyfill
https://gist.github.com/gengkev/2295355

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants