All files / internal / apng_png / encode / _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
x4
x4
x4
x4
 
x43
x43
x43
x43
x43
x43
x88
x2178
x2178
x2178
 
x2178
x88
x88
x88
x43
x43




















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