All files / png / decode / _filter.ts

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
























import { filterTypes } from "../_common_filter.ts";

export function filter(
  mid: Uint8Array,
  images: Uint8Array[][],
  pSize: number,
): Uint8Array {
  for (const lines of images) {
    for (let y = 0; y < lines.length; ++y) {
      const index = lines[y][0];
      lines[y] = lines[y].subarray(1);
      for (let x = 0; x < lines[y].length; ++x) {
        lines[y][x] += filterTypes[index](lines, x, y, pSize);
      }
    }
  }

  let o = 0;
  for (const image of images) {
    for (const line of image) {
      mid.set(line, o);
      o += line.length;
    }
  }
  return mid.subarray(0, o);
}