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

Avoid re-calculating the xScaleBlockOffset when not necessary in JpegImage._getLinearizedBlockData #11557

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/core/jpg.js
Expand Up @@ -1105,6 +1105,7 @@ var JpegImage = (function JpegImageClosure() {
var data = new Uint8ClampedArray(dataLength);
var xScaleBlockOffset = new Uint32Array(width);
var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
let lastComponentScaleX;

for (i = 0; i < numComponents; i++) {
component = this.components[i];
Expand All @@ -1113,10 +1114,14 @@ var JpegImage = (function JpegImageClosure() {
offset = i;
output = component.output;
blocksPerScanline = (component.blocksPerLine + 1) << 3;
// precalculate the xScaleBlockOffset
for (x = 0; x < width; x++) {
j = 0 | (x * componentScaleX);
xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
// Precalculate the `xScaleBlockOffset`. Since it doesn't depend on the
// component data, that's only necessary when `componentScaleX` changes.
if (componentScaleX !== lastComponentScaleX) {
for (x = 0; x < width; x++) {
j = 0 | (x * componentScaleX);
xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
}
lastComponentScaleX = componentScaleX;
}
// linearize the blocks of the component
for (y = 0; y < height; y++) {
Expand Down