Coverage Report

Created: 2026-06-10 07:00

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
0
{
37
0
  for (int k=0;k<4;k++) {
38
0
    pixel_t p0,p1,p2,p3,q0,q1,q2,q3;
39
0
    if (vertical) {
40
0
      p0=ptr[-1+k*stride]; p1=ptr[-2+k*stride]; p2=ptr[-3+k*stride]; p3=ptr[-4+k*stride];
41
0
      q0=ptr[ 0+k*stride]; q1=ptr[ 1+k*stride]; q2=ptr[ 2+k*stride]; q3=ptr[ 3+k*stride];
42
0
    } else {
43
0
      p0=ptr[k-1*stride]; p1=ptr[k-2*stride]; p2=ptr[k-3*stride]; p3=ptr[k-4*stride];
44
0
      q0=ptr[k+0*stride]; q1=ptr[k+1*stride]; q2=ptr[k+2*stride]; q3=ptr[k+3*stride];
45
0
    }
46
47
0
    if (dE==2) {
48
      // strong filtering
49
0
      pixel_t pnew[3],qnew[3];
50
0
      pnew[0] = Clip3(p0-2*tc,p0+2*tc, (p2 + 2*p1 + 2*p0 + 2*q0 + q1 +4)>>3);
51
0
      pnew[1] = Clip3(p1-2*tc,p1+2*tc, (p2 + p1 + p0 + q0+2)>>2);
52
0
      pnew[2] = Clip3(p2-2*tc,p2+2*tc, (2*p3 + 3*p2 + p1 + p0 + q0 + 4)>>3);
53
0
      qnew[0] = Clip3(q0-2*tc,q0+2*tc, (p1+2*p0+2*q0+2*q1+q2+4)>>3);
54
0
      qnew[1] = Clip3(q1-2*tc,q1+2*tc, (p0+q0+q1+q2+2)>>2);
55
0
      qnew[2] = Clip3(q2-2*tc,q2+2*tc, (p0+q0+q1+3*q2+2*q3+4)>>3);
56
57
0
      if (vertical) {
58
0
        for (int i=0;i<3;i++) {
59
0
          if (filterP) { ptr[-i-1+k*stride] = pnew[i]; }
60
0
          if (filterQ) { ptr[ i + k*stride] = qnew[i]; }
61
0
        }
62
0
      } else {
63
0
        for (int i=0;i<3;i++) {
64
0
          if (filterP) { ptr[ k -(i+1)*stride] = pnew[i]; }
65
0
          if (filterQ) { ptr[ k + i   *stride] = qnew[i]; }
66
0
        }
67
0
      }
68
0
    }
69
0
    else {
70
      // weak filtering
71
0
      int delta = (9*(q0-p0) - 3*(q1-p1) + 8)>>4;
72
73
0
      if (std::abs(delta) < tc*10) {
74
0
        delta = Clip3(-tc,tc,delta);
75
76
0
        if (vertical) {
77
0
          if (filterP) { ptr[-0-1+k*stride] = Clip_BitDepth(p0+delta, bitDepth); }
78
0
          if (filterQ) { ptr[ 0  +k*stride] = Clip_BitDepth(q0-delta, bitDepth); }
79
0
        } else {
80
0
          if (filterP) { ptr[ k -1*stride] = Clip_BitDepth(p0+delta, bitDepth); }
81
0
          if (filterQ) { ptr[ k +0*stride] = Clip_BitDepth(q0-delta, bitDepth); }
82
0
        }
83
84
0
        if (dEp==1 && filterP) {
85
0
          int delta_p = Clip3(-(tc>>1), tc>>1, (((p2+p0+1)>>1)-p1+delta)>>1);
86
0
          if (vertical) { ptr[-1-1+k*stride] = Clip_BitDepth(p1+delta_p, bitDepth); }
87
0
          else          { ptr[ k  -2*stride] = Clip_BitDepth(p1+delta_p, bitDepth); }
88
0
        }
89
90
0
        if (dEq==1 && filterQ) {
91
0
          int delta_q = Clip3(-(tc>>1), tc>>1, (((q2+q0+1)>>1)-q1-delta)>>1);
92
0
          if (vertical) { ptr[ 1  +k*stride] = Clip_BitDepth(q1+delta_q, bitDepth); }
93
0
          else          { ptr[ k  +1*stride] = Clip_BitDepth(q1+delta_q, bitDepth); }
94
0
        }
95
0
      }
96
0
    }
97
0
  }
98
0
}
Unexecuted instantiation: void deblock_luma_kernel<unsigned short>(unsigned short*, long, bool, int, int, int, int, bool, bool, int)
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
0
{
106
0
  for (int k=0;k<4;k++) {
107
0
    pixel_t p0,p1,q0,q1;
108
0
    if (vertical) {
109
0
      q0=ptr[ 0+k*stride]; q1=ptr[ 1+k*stride]; p0=ptr[-1+k*stride]; p1=ptr[-2+k*stride];
110
0
    } else {
111
0
      q0=ptr[k+0*stride]; q1=ptr[k+1*stride]; p0=ptr[k-1*stride]; p1=ptr[k-2*stride];
112
0
    }
113
114
0
    int delta = Clip3(-tc,tc, ((((q0-p0)*4)+p1-q1+4)>>3));
115
116
0
    if (vertical) {
117
0
      if (filterP) { ptr[-1+k*stride] = Clip_BitDepth(p0+delta, bitDepth); }
118
0
      if (filterQ) { ptr[ 0+k*stride] = Clip_BitDepth(q0-delta, bitDepth); }
119
0
    } else {
120
0
      if (filterP) { ptr[ k-1*stride] = Clip_BitDepth(p0+delta, bitDepth); }
121
0
      if (filterQ) { ptr[ k+0*stride] = Clip_BitDepth(q0-delta, bitDepth); }
122
0
    }
123
0
  }
124
0
}
Unexecuted instantiation: void deblock_chroma_kernel<unsigned short>(unsigned short*, long, bool, int, bool, bool, int)
Unexecuted instantiation: void deblock_chroma_kernel<unsigned char>(unsigned char*, long, bool, int, bool, bool, int)
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