Coverage Report

Created: 2026-10-28 08:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ffmpeg/libavcodec/lossless_videodsp.c
Line
Count
Source
1
/*
2
 * Lossless video DSP utils
3
 *
4
 * This file is part of FFmpeg.
5
 *
6
 * FFmpeg is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU Lesser General Public
8
 * License as published by the Free Software Foundation; either
9
 * version 2.1 of the License, or (at your option) any later version.
10
 *
11
 * FFmpeg is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 * Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with FFmpeg; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
 */
20
21
#include "config.h"
22
#include "lossless_videodsp.h"
23
#include "libavcodec/mathops.h"
24
#include "libavutil/attributes.h"
25
26
// 0x7f7f7f7f or 0x7f7f7f7f7f7f7f7f or whatever, depending on the cpu's native arithmetic size
27
6.93G
#define pb_7f (~0UL / 255 * 0x7f)
28
3.46G
#define pb_80 (~0UL / 255 * 0x80)
29
30
static void add_bytes_c(uint8_t *dst, uint8_t *src, ptrdiff_t w)
31
28.5M
{
32
28.5M
    long i;
33
34
3.49G
    for (i = 0; i <= w - (int) sizeof(long); i += sizeof(long)) {
35
3.46G
        long a = *(long *) (src + i);
36
3.46G
        long b = *(long *) (dst + i);
37
3.46G
        *(long *) (dst + i) = ((a & pb_7f) + (b & pb_7f)) ^ ((a ^ b) & pb_80);
38
3.46G
    }
39
108M
    for (; i < w; i++)
40
80.0M
        dst[i + 0] += src[i + 0];
41
28.5M
}
42
43
static void add_median_pred_c(uint8_t *dst, const uint8_t *src1,
44
                              const uint8_t *diff, ptrdiff_t w,
45
                              int *left, int *left_top)
46
61.3M
{
47
61.3M
    int i;
48
61.3M
    uint8_t l, lt;
49
50
61.3M
    l  = *left;
51
61.3M
    lt = *left_top;
52
53
1.35G
    for (i = 0; i < w; i++) {
54
1.29G
        l      = mid_pred(l, src1[i], (l + src1[i] - lt) & 0xFF) + diff[i];
55
1.29G
        lt     = src1[i];
56
1.29G
        dst[i] = l;
57
1.29G
    }
58
59
61.3M
    *left     = l;
60
61.3M
    *left_top = lt;
61
61.3M
}
62
63
static int add_left_pred_c(uint8_t *dst, const uint8_t *src, ptrdiff_t w,
64
                           int acc)
65
13.5M
{
66
13.5M
    int i;
67
68
399M
    for (i = 0; i < w - 1; i++) {
69
385M
        acc   += src[i];
70
385M
        dst[i] = acc;
71
385M
        i++;
72
385M
        acc   += src[i];
73
385M
        dst[i] = acc;
74
385M
    }
75
76
19.2M
    for (; i < w; i++) {
77
5.72M
        acc   += src[i];
78
5.72M
        dst[i] = acc;
79
5.72M
    }
80
81
13.5M
    return acc;
82
13.5M
}
83
84
10.6M
static int add_left_pred_int16_c(uint16_t *dst, const uint16_t *src, unsigned mask, ptrdiff_t w, unsigned acc){
85
10.6M
    int i;
86
87
613M
    for(i=0; i<w-1; i++){
88
602M
        acc+= src[i];
89
602M
        dst[i]= acc &= mask;
90
602M
        i++;
91
602M
        acc+= src[i];
92
602M
        dst[i]= acc &= mask;
93
602M
    }
94
95
15.6M
    for(; i<w; i++){
96
5.05M
        acc+= src[i];
97
5.05M
        dst[i]= acc &= mask;
98
5.05M
    }
99
100
10.6M
    return acc;
101
10.6M
}
102
103
5.42M
static void add_gradient_pred_c(uint8_t *src, const ptrdiff_t stride, const ptrdiff_t width){
104
5.42M
    int A, B, C, i;
105
106
1.68G
    for (i = 0; i < width; i++) {
107
1.67G
        A = src[i - stride];
108
1.67G
        B = src[i - (stride + 1)];
109
1.67G
        C = src[i - 1];
110
1.67G
        src[i] = (A - B + C + src[i]) & 0xFF;
111
1.67G
    }
112
5.42M
}
113
114
av_cold void ff_llviddsp_init(LLVidDSPContext *c)
115
15.0k
{
116
15.0k
    c->add_bytes                  = add_bytes_c;
117
15.0k
    c->add_median_pred            = add_median_pred_c;
118
15.0k
    c->add_left_pred              = add_left_pred_c;
119
120
15.0k
    c->add_left_pred_int16        = add_left_pred_int16_c;
121
15.0k
    c->add_gradient_pred          = add_gradient_pred_c;
122
123
#if ARCH_PPC
124
    ff_llviddsp_init_ppc(c);
125
#elif ARCH_RISCV
126
    ff_llviddsp_init_riscv(c);
127
#elif ARCH_X86 && HAVE_X86ASM
128
    ff_llviddsp_init_x86(c);
129
#endif
130
15.0k
}