Merge pull request #11557 from Snuffleupagus/_getLinearizedBlockData-xScaleBlockOffset
Avoid re-calculating the `xScaleBlockOffset` when not necessary in `JpegImage._getLinearizedBlockData`
This commit is contained in:
commit
f178805412
@ -1105,6 +1105,7 @@ var JpegImage = (function JpegImageClosure() {
|
|||||||
var data = new Uint8ClampedArray(dataLength);
|
var data = new Uint8ClampedArray(dataLength);
|
||||||
var xScaleBlockOffset = new Uint32Array(width);
|
var xScaleBlockOffset = new Uint32Array(width);
|
||||||
var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
|
var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
|
||||||
|
let lastComponentScaleX;
|
||||||
|
|
||||||
for (i = 0; i < numComponents; i++) {
|
for (i = 0; i < numComponents; i++) {
|
||||||
component = this.components[i];
|
component = this.components[i];
|
||||||
@ -1113,11 +1114,15 @@ var JpegImage = (function JpegImageClosure() {
|
|||||||
offset = i;
|
offset = i;
|
||||||
output = component.output;
|
output = component.output;
|
||||||
blocksPerScanline = (component.blocksPerLine + 1) << 3;
|
blocksPerScanline = (component.blocksPerLine + 1) << 3;
|
||||||
// precalculate the xScaleBlockOffset
|
// 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++) {
|
for (x = 0; x < width; x++) {
|
||||||
j = 0 | (x * componentScaleX);
|
j = 0 | (x * componentScaleX);
|
||||||
xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
|
xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
|
||||||
}
|
}
|
||||||
|
lastComponentScaleX = componentScaleX;
|
||||||
|
}
|
||||||
// linearize the blocks of the component
|
// linearize the blocks of the component
|
||||||
for (y = 0; y < height; y++) {
|
for (y = 0; y < height; y++) {
|
||||||
j = 0 | (y * componentScaleY);
|
j = 0 | (y * componentScaleY);
|
||||||
|
Loading…
Reference in New Issue
Block a user