Coverage Report

Created: 2026-10-28 06:18

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/libde265/libde265/fallback-deblk.h
Line
Count
Source
1
/*
2
 * H.265 video codec.
3
 * Copyright (c) 2026 Dirk Farin <dirk.farin@gmail.com>
4
 *
5
 * This file is part of libde265.
6
 *
7
 * libde265 is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU Lesser General Public License as
9
 * published by the Free Software Foundation, either version 3 of
10
 * the License, or (at your option) any later version.
11
 *
12
 * libde265 is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public License
18
 * along with libde265.  If not, see <http://www.gnu.org/licenses/>.
19
 */
20
21
#ifndef DE265_FALLBACK_DEBLK_H
22
#define DE265_FALLBACK_DEBLK_H
23
24
#include <stddef.h>
25
#include <stdint.h>
26
#include "util.h"
27
28
// One luma edge-filter segment (4 lines along the edge), spec 8.7.2.4.4.
29
// 'ptr' points at the q0 sample of line 0. dE in {1,2} (weak/strong); the
30
// caller guarantees dE != 0. The filterP/filterQ flags disable the p- resp.
31
// q-side (PCM / transquant-bypass).
32
template <class pixel_t>
33
void deblock_luma_kernel(pixel_t* ptr, ptrdiff_t stride, bool vertical,
34
                         int dE, int dEp, int dEq, int tc,
35
                         bool filterP, bool filterQ, int bitDepth)
36
1.89M
{
37
9.48M
  for (int k=0;k<4;k++) {
38
7.58M
    pixel_t p0,p1,p2,p3,q0,q1,q2,q3;
39
7.58M
    if (vertical) {
40
3.60M
      p0=ptr[-1+k*stride]; p1=ptr[-2+k*stride]; p2=ptr[-3+k*stride]; p3=ptr[-4+k*stride];
41
3.60M
      q0=ptr[ 0+k*stride]; q1=ptr[ 1+k*stride]; q2=ptr[ 2+k*stride]; q3=ptr[ 3+k*stride];
42
3.98M
    } else {
43
3.98M
      p0=ptr[k-1*stride]; p1=ptr[k-2*stride]; p2=ptr[k-3*stride]; p3=ptr[k-4*stride];
44
3.98M
      q0=ptr[k+0*stride]; q1=ptr[k+1*stride]; q2=ptr[k+2*stride]; q3=ptr[k+3*stride];
45
3.98M
    }
46
47
7.58M
    if (dE==2) {
48
      // strong filtering
49
4.11M
      pixel_t pnew[3],qnew[3];
50
4.11M
      pnew[0] = Clip3(p0-2*tc,p0+2*tc, (p2 + 2*p1 + 2*p0 + 2*q0 + q1 +4)>>3);
51
4.11M
      pnew[1] = Clip3(p1-2*tc,p1+2*tc, (p2 + p1 + p0 + q0+2)>>2);
52
4.11M
      pnew[2] = Clip3(p2-2*tc,p2+2*tc, (2*p3 + 3*p2 + p1 + p0 + q0 + 4)>>3);
53
4.11M
      qnew[0] = Clip3(q0-2*tc,q0+2*tc, (p1+2*p0+2*q0+2*q1+q2+4)>>3);
54
4.11M
      qnew[1] = Clip3(q1-2*tc,q1+2*tc, (p0+q0+q1+q2+2)>>2);
55
4.11M
      qnew[2] = Clip3(q2-2*tc,q2+2*tc, (p0+q0+q1+3*q2+2*q3+4)>>3);
56
57
4.11M
      if (vertical) {
58
7.76M
        for (int i=0;i<3;i++) {
59
5.82M
          if (filterP) { ptr[-i-1+k*stride] = pnew[i]; }
60
5.82M
          if (filterQ) { ptr[ i + k*stride] = qnew[i]; }
61
5.82M
        }
62
2.16M
      } else {
63
8.67M
        for (int i=0;i<3;i++) {
64
6.50M
          if (filterP) { ptr[ k -(i+1)*stride] = pnew[i]; }
65
6.50M
          if (filterQ) { ptr[ k + i   *stride] = qnew[i]; }
66
6.50M
        }
67
2.16M
      }
68
4.11M
    }
69
3.47M
    else {
70
      // weak filtering
71
3.47M
      int delta = (9*(q0-p0) - 3*(q1-p1) + 8)>>4;
72
73
3.47M
      if (std::abs(delta) < tc*10) {
74
3.36M
        delta = Clip3(-tc,tc,delta);
75
76
3.36M
        if (vertical) {
77
1.61M
          if (filterP) { ptr[-0-1+k*stride] = Clip_BitDepth(p0+delta, bitDepth); }
78
1.61M
          if (filterQ) { ptr[ 0  +k*stride] = Clip_BitDepth(q0-delta, bitDepth); }
79
1.74M
        } else {
80
1.74M
          if (filterP) { ptr[ k -1*stride] = Clip_BitDepth(p0+delta, bitDepth); }
81
1.74M
          if (filterQ) { ptr[ k +0*stride] = Clip_BitDepth(q0-delta, bitDepth); }
82
1.74M
        }
83
84
3.36M
        if (dEp==1 && filterP) {
85
1.23M
          int delta_p = Clip3(-(tc>>1), tc>>1, (((p2+p0+1)>>1)-p1+delta)>>1);
86
1.23M
          if (vertical) { ptr[-1-1+k*stride] = Clip_BitDepth(p1+delta_p, bitDepth); }
87
633k
          else          { ptr[ k  -2*stride] = Clip_BitDepth(p1+delta_p, bitDepth); }
88
1.23M
        }
89
90
3.36M
        if (dEq==1 && filterQ) {
91
1.02M
          int delta_q = Clip3(-(tc>>1), tc>>1, (((q2+q0+1)>>1)-q1-delta)>>1);
92
1.02M
          if (vertical) { ptr[ 1  +k*stride] = Clip_BitDepth(q1+delta_q, bitDepth); }
93
661k
          else          { ptr[ k  +1*stride] = Clip_BitDepth(q1+delta_q, bitDepth); }
94
1.02M
        }
95
3.36M
      }
96
3.47M
    }
97
7.58M
  }
98
1.89M
}
void deblock_luma_kernel<unsigned short>(unsigned short*, long, bool, int, int, int, int, bool, bool, int)
Line
Count
Source
36
1.89M
{
37
9.48M
  for (int k=0;k<4;k++) {
38
7.58M
    pixel_t p0,p1,p2,p3,q0,q1,q2,q3;
39
7.58M
    if (vertical) {
40
3.60M
      p0=ptr[-1+k*stride]; p1=ptr[-2+k*stride]; p2=ptr[-3+k*stride]; p3=ptr[-4+k*stride];
41
3.60M
      q0=ptr[ 0+k*stride]; q1=ptr[ 1+k*stride]; q2=ptr[ 2+k*stride]; q3=ptr[ 3+k*stride];
42
3.98M
    } else {
43
3.98M
      p0=ptr[k-1*stride]; p1=ptr[k-2*stride]; p2=ptr[k-3*stride]; p3=ptr[k-4*stride];
44
3.98M
      q0=ptr[k+0*stride]; q1=ptr[k+1*stride]; q2=ptr[k+2*stride]; q3=ptr[k+3*stride];
45
3.98M
    }
46
47
7.58M
    if (dE==2) {
48
      // strong filtering
49
4.11M
      pixel_t pnew[3],qnew[3];
50
4.11M
      pnew[0] = Clip3(p0-2*tc,p0+2*tc, (p2 + 2*p1 + 2*p0 + 2*q0 + q1 +4)>>3);
51
4.11M
      pnew[1] = Clip3(p1-2*tc,p1+2*tc, (p2 + p1 + p0 + q0+2)>>2);
52
4.11M
      pnew[2] = Clip3(p2-2*tc,p2+2*tc, (2*p3 + 3*p2 + p1 + p0 + q0 + 4)>>3);
53
4.11M
      qnew[0] = Clip3(q0-2*tc,q0+2*tc, (p1+2*p0+2*q0+2*q1+q2+4)>>3);
54
4.11M
      qnew[1] = Clip3(q1-2*tc,q1+2*tc, (p0+q0+q1+q2+2)>>2);
55
4.11M
      qnew[2] = Clip3(q2-2*tc,q2+2*tc, (p0+q0+q1+3*q2+2*q3+4)>>3);
56
57
4.11M
      if (vertical) {
58
7.76M
        for (int i=0;i<3;i++) {
59
5.82M
          if (filterP) { ptr[-i-1+k*stride] = pnew[i]; }
60
5.82M
          if (filterQ) { ptr[ i + k*stride] = qnew[i]; }
61
5.82M
        }
62
2.16M
      } else {
63
8.67M
        for (int i=0;i<3;i++) {
64
6.50M
          if (filterP) { ptr[ k -(i+1)*stride] = pnew[i]; }
65
6.50M
          if (filterQ) { ptr[ k + i   *stride] = qnew[i]; }
66
6.50M
        }
67
2.16M
      }
68
4.11M
    }
69
3.47M
    else {
70
      // weak filtering
71
3.47M
      int delta = (9*(q0-p0) - 3*(q1-p1) + 8)>>4;
72
73
3.47M
      if (std::abs(delta) < tc*10) {
74
3.36M
        delta = Clip3(-tc,tc,delta);
75
76
3.36M
        if (vertical) {
77
1.61M
          if (filterP) { ptr[-0-1+k*stride] = Clip_BitDepth(p0+delta, bitDepth); }
78
1.61M
          if (filterQ) { ptr[ 0  +k*stride] = Clip_BitDepth(q0-delta, bitDepth); }
79
1.74M
        } else {
80
1.74M
          if (filterP) { ptr[ k -1*stride] = Clip_BitDepth(p0+delta, bitDepth); }
81
1.74M
          if (filterQ) { ptr[ k +0*stride] = Clip_BitDepth(q0-delta, bitDepth); }
82
1.74M
        }
83
84
3.36M
        if (dEp==1 && filterP) {
85
1.23M
          int delta_p = Clip3(-(tc>>1), tc>>1, (((p2+p0+1)>>1)-p1+delta)>>1);
86
1.23M
          if (vertical) { ptr[-1-1+k*stride] = Clip_BitDepth(p1+delta_p, bitDepth); }
87
633k
          else          { ptr[ k  -2*stride] = Clip_BitDepth(p1+delta_p, bitDepth); }
88
1.23M
        }
89
90
3.36M
        if (dEq==1 && filterQ) {
91
1.02M
          int delta_q = Clip3(-(tc>>1), tc>>1, (((q2+q0+1)>>1)-q1-delta)>>1);
92
1.02M
          if (vertical) { ptr[ 1  +k*stride] = Clip_BitDepth(q1+delta_q, bitDepth); }
93
661k
          else          { ptr[ k  +1*stride] = Clip_BitDepth(q1+delta_q, bitDepth); }
94
1.02M
        }
95
3.36M
      }
96
3.47M
    }
97
7.58M
  }
98
1.89M
}
Unexecuted instantiation: void deblock_luma_kernel<unsigned char>(unsigned char*, long, bool, int, int, int, int, bool, bool, int)
99
100
101
// One chroma edge-filter segment (4 lines), spec 8.7.2.4.5.
102
template <class pixel_t>
103
void deblock_chroma_kernel(pixel_t* ptr, ptrdiff_t stride, bool vertical,
104
                           int tc, bool filterP, bool filterQ, int bitDepth)
105
16.5M
{
106
82.7M
  for (int k=0;k<4;k++) {
107
66.1M
    pixel_t p0,p1,q0,q1;
108
66.1M
    if (vertical) {
109
33.8M
      q0=ptr[ 0+k*stride]; q1=ptr[ 1+k*stride]; p0=ptr[-1+k*stride]; p1=ptr[-2+k*stride];
110
33.8M
    } else {
111
32.3M
      q0=ptr[k+0*stride]; q1=ptr[k+1*stride]; p0=ptr[k-1*stride]; p1=ptr[k-2*stride];
112
32.3M
    }
113
114
66.1M
    int delta = Clip3(-tc,tc, ((((q0-p0)*4)+p1-q1+4)>>3));
115
116
66.1M
    if (vertical) {
117
33.8M
      if (filterP) { ptr[-1+k*stride] = Clip_BitDepth(p0+delta, bitDepth); }
118
33.8M
      if (filterQ) { ptr[ 0+k*stride] = Clip_BitDepth(q0-delta, bitDepth); }
119
33.8M
    } else {
120
32.3M
      if (filterP) { ptr[ k-1*stride] = Clip_BitDepth(p0+delta, bitDepth); }
121
32.3M
      if (filterQ) { ptr[ k+0*stride] = Clip_BitDepth(q0-delta, bitDepth); }
122
32.3M
    }
123
66.1M
  }
124
16.5M
}
void deblock_chroma_kernel<unsigned short>(unsigned short*, long, bool, int, bool, bool, int)
Line
Count
Source
105
1.44M
{
106
7.22M
  for (int k=0;k<4;k++) {
107
5.78M
    pixel_t p0,p1,q0,q1;
108
5.78M
    if (vertical) {
109
3.27M
      q0=ptr[ 0+k*stride]; q1=ptr[ 1+k*stride]; p0=ptr[-1+k*stride]; p1=ptr[-2+k*stride];
110
3.27M
    } else {
111
2.50M
      q0=ptr[k+0*stride]; q1=ptr[k+1*stride]; p0=ptr[k-1*stride]; p1=ptr[k-2*stride];
112
2.50M
    }
113
114
5.78M
    int delta = Clip3(-tc,tc, ((((q0-p0)*4)+p1-q1+4)>>3));
115
116
5.78M
    if (vertical) {
117
3.27M
      if (filterP) { ptr[-1+k*stride] = Clip_BitDepth(p0+delta, bitDepth); }
118
3.27M
      if (filterQ) { ptr[ 0+k*stride] = Clip_BitDepth(q0-delta, bitDepth); }
119
3.27M
    } else {
120
2.50M
      if (filterP) { ptr[ k-1*stride] = Clip_BitDepth(p0+delta, bitDepth); }
121
2.50M
      if (filterQ) { ptr[ k+0*stride] = Clip_BitDepth(q0-delta, bitDepth); }
122
2.50M
    }
123
5.78M
  }
124
1.44M
}
void deblock_chroma_kernel<unsigned char>(unsigned char*, long, bool, int, bool, bool, int)
Line
Count
Source
105
15.1M
{
106
75.5M
  for (int k=0;k<4;k++) {
107
60.4M
    pixel_t p0,p1,q0,q1;
108
60.4M
    if (vertical) {
109
30.5M
      q0=ptr[ 0+k*stride]; q1=ptr[ 1+k*stride]; p0=ptr[-1+k*stride]; p1=ptr[-2+k*stride];
110
30.5M
    } else {
111
29.8M
      q0=ptr[k+0*stride]; q1=ptr[k+1*stride]; p0=ptr[k-1*stride]; p1=ptr[k-2*stride];
112
29.8M
    }
113
114
60.4M
    int delta = Clip3(-tc,tc, ((((q0-p0)*4)+p1-q1+4)>>3));
115
116
60.4M
    if (vertical) {
117
30.5M
      if (filterP) { ptr[-1+k*stride] = Clip_BitDepth(p0+delta, bitDepth); }
118
30.5M
      if (filterQ) { ptr[ 0+k*stride] = Clip_BitDepth(q0-delta, bitDepth); }
119
30.5M
    } else {
120
29.8M
      if (filterP) { ptr[ k-1*stride] = Clip_BitDepth(p0+delta, bitDepth); }
121
29.8M
      if (filterQ) { ptr[ k+0*stride] = Clip_BitDepth(q0-delta, bitDepth); }
122
29.8M
    }
123
60.4M
  }
124
15.1M
}
125
126
127
// 8-bit fallback wrappers stored in the acceleration table.
128
void deblock_luma_8_fallback(uint8_t* ptr, ptrdiff_t stride, int vertical,
129
                             int dE, int dEp, int dEq, int tc, int filterP, int filterQ);
130
void deblock_chroma_8_fallback(uint8_t* ptr, ptrdiff_t stride, int vertical,
131
                               int tc, int filterP, int filterQ);
132
133
#endif