Line | Branch | Exec | 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 | #define pb_7f (~0UL / 255 * 0x7f) | ||
28 | #define pb_80 (~0UL / 255 * 0x80) | ||
29 | |||
30 | 58755 | static void add_bytes_c(uint8_t *dst, uint8_t *src, ptrdiff_t w) | |
31 | { | ||
32 | long i; | ||
33 | |||
34 |
2/2✓ Branch 0 taken 3683296 times.
✓ Branch 1 taken 58755 times.
|
3742051 | for (i = 0; i <= w - (int) sizeof(long); i += sizeof(long)) { |
35 | 3683296 | long a = *(long *) (src + i); | |
36 | 3683296 | long b = *(long *) (dst + i); | |
37 | 3683296 | *(long *) (dst + i) = ((a & pb_7f) + (b & pb_7f)) ^ ((a ^ b) & pb_80); | |
38 | } | ||
39 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 58755 times.
|
58755 | for (; i < w; i++) |
40 | ✗ | dst[i + 0] += src[i + 0]; | |
41 | 58755 | } | |
42 | |||
43 | 52760 | 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 | { | ||
47 | int i; | ||
48 | uint8_t l, lt; | ||
49 | |||
50 | 52760 | l = *left; | |
51 | 52760 | lt = *left_top; | |
52 | |||
53 |
2/2✓ Branch 0 taken 28941618 times.
✓ Branch 1 taken 52760 times.
|
28994378 | for (i = 0; i < w; i++) { |
54 | 28941618 | l = mid_pred(l, src1[i], (l + src1[i] - lt) & 0xFF) + diff[i]; | |
55 | 28941618 | lt = src1[i]; | |
56 | 28941618 | dst[i] = l; | |
57 | } | ||
58 | |||
59 | 52760 | *left = l; | |
60 | 52760 | *left_top = lt; | |
61 | 52760 | } | |
62 | |||
63 | 436946 | static int add_left_pred_c(uint8_t *dst, const uint8_t *src, ptrdiff_t w, | |
64 | int acc) | ||
65 | { | ||
66 | int i; | ||
67 | |||
68 |
2/2✓ Branch 0 taken 64524937 times.
✓ Branch 1 taken 436946 times.
|
64961883 | for (i = 0; i < w - 1; i++) { |
69 | 64524937 | acc += src[i]; | |
70 | 64524937 | dst[i] = acc; | |
71 | 64524937 | i++; | |
72 | 64524937 | acc += src[i]; | |
73 | 64524937 | dst[i] = acc; | |
74 | } | ||
75 | |||
76 |
2/2✓ Branch 0 taken 5516 times.
✓ Branch 1 taken 436946 times.
|
442462 | for (; i < w; i++) { |
77 | 5516 | acc += src[i]; | |
78 | 5516 | dst[i] = acc; | |
79 | } | ||
80 | |||
81 | 436946 | return acc; | |
82 | } | ||
83 | |||
84 | 359203 | static int add_left_pred_int16_c(uint16_t *dst, const uint16_t *src, unsigned mask, ptrdiff_t w, unsigned acc){ | |
85 | int i; | ||
86 | |||
87 |
2/2✓ Branch 0 taken 49606484 times.
✓ Branch 1 taken 359203 times.
|
49965687 | for(i=0; i<w-1; i++){ |
88 | 49606484 | acc+= src[i]; | |
89 | 49606484 | dst[i]= acc &= mask; | |
90 | 49606484 | i++; | |
91 | 49606484 | acc+= src[i]; | |
92 | 49606484 | dst[i]= acc &= mask; | |
93 | } | ||
94 | |||
95 |
2/2✓ Branch 0 taken 5100 times.
✓ Branch 1 taken 359203 times.
|
364303 | for(; i<w; i++){ |
96 | 5100 | acc+= src[i]; | |
97 | 5100 | dst[i]= acc &= mask; | |
98 | } | ||
99 | |||
100 | 359203 | return acc; | |
101 | } | ||
102 | |||
103 | 46608 | static void add_gradient_pred_c(uint8_t *src, const ptrdiff_t stride, const ptrdiff_t width){ | |
104 | int A, B, C, i; | ||
105 | |||
106 |
2/2✓ Branch 0 taken 14450808 times.
✓ Branch 1 taken 46608 times.
|
14497416 | for (i = 0; i < width; i++) { |
107 | 14450808 | A = src[i - stride]; | |
108 | 14450808 | B = src[i - (stride + 1)]; | |
109 | 14450808 | C = src[i - 1]; | |
110 | 14450808 | src[i] = (A - B + C + src[i]) & 0xFF; | |
111 | } | ||
112 | 46608 | } | |
113 | |||
114 | 190 | av_cold void ff_llviddsp_init(LLVidDSPContext *c) | |
115 | { | ||
116 | 190 | c->add_bytes = add_bytes_c; | |
117 | 190 | c->add_median_pred = add_median_pred_c; | |
118 | 190 | c->add_left_pred = add_left_pred_c; | |
119 | |||
120 | 190 | c->add_left_pred_int16 = add_left_pred_int16_c; | |
121 | 190 | 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 | ||
128 | 190 | ff_llviddsp_init_x86(c); | |
129 | #endif | ||
130 | 190 | } | |
131 |