All files / png / _common_filter.ts

90.91% Branches 10/11
46.94% Lines 23/49
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
x3
x3
x3
x3
x3
x3
 
x65546
x3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
x3
x3
x3
x3
x3
 
x1054001
x1054001
x1054001
x1054001
x1054001
x1054001
x1054001
x1054001
x2300966
 
 
x3

















































I


export const filterTypes = [
  function type0(
    _lines: Uint8Array[],
    _x: number,
    _y: number,
    _pSize: number,
  ): number {
    return 0;
  },
  function type1(
    lines: Uint8Array[],
    x: number,
    y: number,
    pSize: number,
  ): number {
    return lines[y][x - pSize] ?? 0;
  },
  function type2(
    lines: Uint8Array[],
    x: number,
    y: number,
    _pSize: number,
  ): number {
    return y === 0 ? 0 : lines[y - 1][x];
  },
  function type3(
    lines: Uint8Array[],
    x: number,
    y: number,
    pSize: number,
  ): number {
    return (
          (lines[y][x - pSize] ?? 0) +
          (y === 0 ? 0 : lines[y - 1][x])
        ) / 2 | 0;
  },
  function type4(
    lines: Uint8Array[],
    x: number,
    y: number,
    pSize: number,
  ): number {
    const a = lines[y][x - pSize] ?? 0;
    const b = y === 0 ? 0 : lines[y - 1][x];
    const c = y === 0 ? 0 : lines[y - 1][x - pSize] ?? 0;
    const p = a + b - c;
    const pa = Math.abs(p - a);
    const pb = Math.abs(p - b);
    const pc = Math.abs(p - c);
    if (pa <= pb && pa <= pc) return a;
    if (pb <= pc) return b;
    return c;
  },
] as const;