| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | 4x 172x 172x 172x 172x 172x 172x 180x 2212x 2212x 2212x 172x | import { bit } from "../utils/bit-array";
export class NearestNeighbor {
static scale(matrix: bit[], width: number, factor: number) {
const ratio = 1 / factor;
const h1 = matrix.length / width;
const w2 = width * factor;
const h2 = h1 * factor;
let finalMatrix = new Array<bit>(w2 * h2);
for (let i = 0; i < h2; i++) {
for (let j = 0; j < w2; j++) {
const px = Math.floor(j * ratio);
const py = Math.floor(i * ratio);
finalMatrix[(i * w2) + j] = matrix[(py * width) + px];
}
}
return finalMatrix;
}
} |