Coverage Report

Created: 2026-02-14 06:59

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
2.56G
#define pb_7f (~0UL / 255 * 0x7f)
28
1.28G
#define pb_80 (~0UL / 255 * 0x80)
29
30
static void add_bytes_c(uint8_t *dst, uint8_t *src, ptrdiff_t w)
31
23.8M
{
32
23.8M
    long i;
33
34
1.30G
    for (i = 0; i <= w - (int) sizeof(long); i += sizeof(long)) {
35
1.28G
        long a = *(long *) (src + i);
36
1.28G
        long b = *(long *) (dst + i);
37
1.28G
        *(long *) (dst + i) = ((a & pb_7f) + (b & pb_7f)) ^ ((a ^ b) & pb_80);
38
1.28G
    }
39
78.9M
    for (; i < w; i++)
40
55.1M
        dst[i + 0] += src[i + 0];
41
23.8M
}
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
72.6M
{
47
72.6M
    int i;
48
72.6M
    uint8_t l, lt;
49
50
72.6M
    l  = *left;
51
72.6M
    lt = *left_top;
52
53
1.80G
    for (i = 0; i < w; i++) {
54
1.73G
        l      = mid_pred(l, src1[i], (l + src1[i] - lt) & 0xFF) + diff[i];
55
1.73G
        lt     = src1[i];
56
1.73G
        dst[i] = l;
57
1.73G
    }
58
59
72.6M
    *left     = l;
60
72.6M
    *left_top = lt;
61
72.6M
}
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
347M
    for (i = 0; i < w - 1; i++) {
69
334M
        acc   += src[i];
70
334M
        dst[i] = acc;
71
334M
        i++;
72
334M
        acc   += src[i];
73
334M
        dst[i] = acc;
74
334M
    }
75
76
24.0M
    for (; i < w; i++) {
77
10.4M
        acc   += src[i];
78
10.4M
        dst[i] = acc;
79
10.4M
    }
80
81
13.5M
    return acc;
82
13.5M
}
83
84
6.02M
static int add_left_pred_int16_c(uint16_t *dst, const uint16_t *src, unsigned mask, ptrdiff_t w, unsigned acc){
85
6.02M
    int i;
86
87
576M
    for(i=0; i<w-1; i++){
88
570M
        acc+= src[i];
89
570M
        dst[i]= acc &= mask;
90
570M
        i++;
91
570M
        acc+= src[i];
92
570M
        dst[i]= acc &= mask;
93
570M
    }
94
95
10.6M
    for(; i<w; i++){
96
4.59M
        acc+= src[i];
97
4.59M
        dst[i]= acc &= mask;
98
4.59M
    }
99
100
6.02M
    return acc;
101
6.02M
}
102
103
7.27M
static void add_gradient_pred_c(uint8_t *src, const ptrdiff_t stride, const ptrdiff_t width){
104
7.27M
    int A, B, C, i;
105
106
1.60G
    for (i = 0; i < width; i++) {
107
1.59G
        A = src[i - stride];
108
1.59G
        B = src[i - (stride + 1)];
109
1.59G
        C = src[i - 1];
110
1.59G
        src[i] = (A - B + C + src[i]) & 0xFF;
111
1.59G
    }
112
7.27M
}
113
114
av_cold void ff_llviddsp_init(LLVidDSPContext *c)
115
15.5k
{
116
15.5k
    c->add_bytes                  = add_bytes_c;
117
15.5k
    c->add_median_pred            = add_median_pred_c;
118
15.5k
    c->add_left_pred              = add_left_pred_c;
119
120
15.5k
    c->add_left_pred_int16        = add_left_pred_int16_c;
121
15.5k
    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.5k
}