Merge pull request #436 from GoogleChromeLabs/optimize-rotate

Optimize rotate
This commit is contained in:
Surma
2019-01-23 22:45:10 -05:00
committed by GitHub

View File

@@ -1,7 +1,5 @@
import { RotateOptions } from './processor-meta';
const bpp = 4;
export function rotate(data: ImageData, opts: RotateOptions): ImageData {
const { rotate } = opts;
const flipDimensions = rotate % 180 !== 0;
@@ -61,16 +59,15 @@ export function rotate(data: ImageData, opts: RotateOptions): ImageData {
d2Multiplier = 1;
}
const inB = new Uint32Array(data.data.buffer);
const outB = new Uint32Array(out.data.buffer);
for (let d2 = d2Start; d2 >= 0 && d2 < d2Limit; d2 += d2Advance) {
for (let d1 = d1Start; d1 >= 0 && d1 < d1Limit; d1 += d1Advance) {
// Iterate over channels:
const start = ((d1 * d1Multiplier) + (d2 * d2Multiplier)) * bpp;
for (let j = 0; j < bpp; j += 1) {
out.data[i] = data.data[start + j];
const start = ((d1 * d1Multiplier) + (d2 * d2Multiplier));
outB[i] = inB[start];
i += 1;
}
}
}
return out;
}