All files / png / decode / _scanlines.ts

100.00% Branches 2/2
100.00% Lines 20/20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
x1
x1
x1
x1
 
x7
x7
x7
x7
x7
x7
x19
x28
x28
x28
 
x28
x19
x19
x19
x7
x7




















export function scanlines(
  mid: Uint8Array,
  pSize: number,
  sizes: [number, number][],
): Uint8Array[][] {
  const images: Uint8Array[][] = new Array(sizes.length)
    .fill(0)
    .map(() => []);
  let i = 0;
  let offset = 0;
  for (const [width, height] of sizes) {
    for (let h = 0; h < height; ++h) {
      images[i][h] = mid.subarray(
        offset + h * (width * pSize + 1),
        offset + (h + 1) * (width * pSize + 1),
      );
    }
    offset += height * (width * pSize + 1);
    ++i;
  }
  return images;
}